Rev 25 | Rev 27 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/*
* Copyright 2006 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.tela_botanica.client;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.HTTPRequest;
import com.google.gwt.user.client.ResponseTextHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
* Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget()
*/
public class InfoPopup extends PopupPanel {
private Mediator mediator=null;
private Image imageTop = new Image();
private Image imageBottom = new Image();
public InfoPopup(final Mediator med) {
super(true);
mediator=med;
imageBottom.setPixelSize(150,150);
imageTop.setPixelSize(150,150);
// HorizontalPanel panel = new HorizontalPanel();
VerticalPanel panel = new VerticalPanel();
panel.add(imageTop);
panel.add(imageBottom);
add(panel);
}
public void setImageUrl(String value) {
HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/NameImage/" + value,
new ResponseTextHandler() {
public void onCompletion(String strcomplete) {
JSONValue jsonValue = JSONParser.parse(strcomplete);
JSONArray jsonArray;
if ((jsonArray = jsonValue.isArray()) != null) {
// Url Image
setImageTop(((JSONString) jsonArray.get(0)).stringValue());
}
}
});
HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/NameMap/" + value,
new ResponseTextHandler() {
public void onCompletion(String strcomplete) {
JSONValue jsonValue = JSONParser.parse(strcomplete);
JSONArray jsonArray;
if ((jsonArray = jsonValue.isArray()) != null) {
// Url Image
setImageBottom(((JSONString) jsonArray.get(0)).stringValue());
}
}
});
}
public void setImageTop(String url) {
if (url.compareTo("null")!=0) {
// setPopupPosition(3*(Window.getClientWidth()/4), mediator.getInventoryItemList().getAbsoluteTop()+50);
setPopupPosition(mediator.getLeftPanel().getAbsoluteLeft()+10, mediator.getLeftPanel().getAbsoluteTop() + (mediator.getLeftPanel().getOffsetHeight()/2));
show();
imageTop.setUrl(url);
}
else {
hide();
}
}
public void setImageBottom(String url) {
if (url.compareTo("null")!=0) {
// setPopupPosition(3*(Window.getClientWidth()/4), mediator.getInventoryItemList().getAbsoluteTop()+50);
setPopupPosition(mediator.getLeftPanel().getAbsoluteLeft()+10, mediator.getLeftPanel().getAbsoluteTop() + (mediator.getLeftPanel().getOffsetHeight()/2));
show();
imageBottom.setUrl(url);
}
else {
hide();
}
}
}