raimund@2953: package de.intevation.flys.client.client.ui.sq; raimund@2953: raimund@2953: import com.google.gwt.json.client.JSONObject; raimund@2953: import com.google.gwt.json.client.JSONNumber; raimund@2953: import com.google.gwt.json.client.JSONString; raimund@2953: raimund@2953: import com.google.gwt.core.client.GWT; raimund@2953: raimund@2953: import com.smartgwt.client.types.Alignment; raimund@2953: raimund@2953: import com.smartgwt.client.widgets.Img; raimund@2953: import com.smartgwt.client.widgets.Canvas; raimund@2953: import com.smartgwt.client.widgets.layout.VLayout; raimund@2953: import com.smartgwt.client.widgets.events.ResizedHandler; raimund@2953: import com.smartgwt.client.widgets.events.ResizedEvent; raimund@2953: raimund@2953: import de.intevation.flys.client.client.ui.MultiPeriodPanel; raimund@2953: raimund@2953: import de.intevation.flys.client.shared.model.DataList; raimund@2953: raimund@2953: import de.intevation.flys.client.client.Config; raimund@2953: /** raimund@2953: * This UIProvider creates helper panel for sq relation. raimund@2953: * raimund@2953: * @author Raimund Renkert raimund@2953: */ raimund@2953: public class SQMultiPeriodPanel raimund@2953: extends MultiPeriodPanel raimund@2953: implements ResizedHandler raimund@2953: { raimund@2953: protected VLayout chartContainer; raimund@2953: raimund@2953: protected Img chartImg; raimund@2953: raimund@2953: public SQMultiPeriodPanel() { raimund@2953: chartImg = new Img(); raimund@2953: } raimund@2953: raimund@2953: raimund@2953: protected Canvas createHelper() { raimund@2953: Config config = Config.getInstance(); raimund@2953: String locale = config.getLocale (); raimund@2953: raimund@2953: chartContainer = new VLayout(); raimund@2953: chartContainer.addResizedHandler(this); raimund@2953: chartContainer.setAlign(Alignment.CENTER); raimund@2953: raimund@2953: return chartContainer; raimund@2953: } raimund@2953: raimund@2953: raimund@2953: protected void updateChart() { raimund@2953: Config config = Config.getInstance(); raimund@2953: String locale = config.getLocale (); raimund@2953: raimund@2953: int hWidth = chartContainer.getWidth() - 12; raimund@2953: int hHeight = chartContainer.getHeight() - 12; raimund@2953: raimund@2953: if ((int)(hHeight *4f/3) < hWidth) { raimund@2953: hWidth = (int)(hHeight * 4f/3); raimund@2953: } raimund@2953: else { raimund@2953: hHeight = (int)(hWidth *3f/4); raimund@2953: } raimund@2953: String river = artifact.getArtifactDescription().getRiver(); raimund@2953: raimund@2953: JSONObject jfix = new JSONObject(); raimund@2953: JSONObject jfilter = new JSONObject(); raimund@2953: JSONObject jrName = new JSONObject(); raimund@2953: JSONString jrValue = new JSONString(river); raimund@2953: JSONObject jextent = new JSONObject(); raimund@2953: JSONNumber jwidth = new JSONNumber(hWidth); raimund@2953: JSONNumber jheight = new JSONNumber(hHeight); raimund@2953: raimund@2953: jrName.put("name", jrValue); raimund@2953: jfilter.put("river", jrName); raimund@2953: jextent.put("width", jwidth); raimund@2953: jextent.put("height", jheight); raimund@2953: jfilter.put("extent", jextent); raimund@2953: jfix.put("sq", jfilter); raimund@2953: String filter = jfix.toString(); raimund@2953: raimund@2953: String imgUrl = GWT.getModuleBaseURL(); raimund@2953: imgUrl += "sq-km-chart"; raimund@2953: imgUrl += "?locale=" + locale; raimund@2953: imgUrl += "&filter=" + filter; raimund@2953: if (chartContainer.hasMember(chartImg)) { raimund@2953: chartImg.setWidth(hWidth); raimund@2953: chartImg.setHeight(hHeight); raimund@2953: chartImg.setSrc(imgUrl); raimund@2953: } raimund@2953: else { raimund@2953: chartImg = new Img(imgUrl, hWidth, hHeight); raimund@2953: chartContainer.addMember(chartImg); raimund@2953: } raimund@2953: } raimund@2953: raimund@2953: raimund@2953: public void onResized(ResizedEvent re) { raimund@2953: updateChart(); raimund@2953: } raimund@2953: }