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