teichmann@5835: package org.dive4elements.river.client.client.ui.sq; ingo@3373: ingo@3373: import com.google.gwt.core.client.GWT; ingo@3373: import com.google.gwt.json.client.JSONNumber; ingo@3373: import com.google.gwt.json.client.JSONObject; ingo@3373: import com.google.gwt.json.client.JSONString; ingo@3373: import com.smartgwt.client.types.Alignment; ingo@3373: import com.smartgwt.client.widgets.Img; ingo@3373: import com.smartgwt.client.widgets.events.ResizedHandler; ingo@3373: import com.smartgwt.client.widgets.layout.VLayout; ingo@3373: teichmann@5835: import org.dive4elements.river.client.client.Config; teichmann@5835: import org.dive4elements.river.client.shared.model.Artifact; ingo@3373: ingo@3373: ingo@3373: public class SQCampaignChart extends VLayout { ingo@3373: ingo@3373: private final Artifact artifact; ingo@3373: ingo@3373: protected Img chartImg; ingo@3373: ingo@3373: public SQCampaignChart(Artifact artifact, ResizedHandler resizeHandler) { ingo@3373: super(); ingo@3373: ingo@3373: this.artifact = artifact; ingo@3373: this.chartImg = new Img(); ingo@3373: ingo@3373: addResizedHandler(resizeHandler); ingo@3373: setAlign(Alignment.CENTER); ingo@3373: } ingo@3373: ingo@3373: public void update() { ingo@3373: Config config = Config.getInstance(); ingo@3373: String locale = config.getLocale(); ingo@3373: ingo@3373: int hWidth = getWidth() - 12; ingo@3373: int hHeight = getHeight() - 12; ingo@3373: ingo@3373: if ((int) (hHeight * 4f / 3) < hWidth) { ingo@3373: hWidth = (int) (hHeight * 4f / 3); ingo@3373: } ingo@3373: else { ingo@3373: hHeight = (int) (hWidth * 3f / 4); ingo@3373: } ingo@3373: ingo@3373: String river = artifact.getArtifactDescription().getRiver(); ingo@3373: ingo@3373: JSONObject jfix = new JSONObject(); ingo@3373: JSONObject jfilter = new JSONObject(); ingo@3373: JSONObject jrName = new JSONObject(); ingo@3373: JSONString jrValue = new JSONString(river); ingo@3373: JSONObject jextent = new JSONObject(); ingo@3373: JSONNumber jwidth = new JSONNumber(hWidth); ingo@3373: JSONNumber jheight = new JSONNumber(hHeight); ingo@3373: ingo@3373: jrName.put("name", jrValue); ingo@3373: jfilter.put("river", jrName); ingo@3373: jextent.put("width", jwidth); ingo@3373: jextent.put("height", jheight); ingo@3373: jfilter.put("extent", jextent); ingo@3373: jfix.put("sq", jfilter); ingo@3373: String filter = jfix.toString(); ingo@3373: ingo@3373: String imgUrl = GWT.getModuleBaseURL(); ingo@3373: imgUrl += "sq-km-chart"; ingo@3373: imgUrl += "?locale=" + locale; ingo@3373: imgUrl += "&filter=" + filter; ingo@3373: ingo@3373: if (chartImg != null && hasMember(chartImg)) { ingo@3373: chartImg.setWidth(hWidth); ingo@3373: chartImg.setHeight(hHeight); ingo@3373: chartImg.setSrc(imgUrl); ingo@3373: } ingo@3373: else { ingo@3373: chartImg = new Img(imgUrl, hWidth, hHeight); ingo@3373: addMember(chartImg); ingo@3373: } ingo@3373: } ingo@3373: }