comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sq/SQCampaignChart.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-client/src/main/java/org/dive4elements/river/client/client/ui/sq/SQCampaignChart.java@821a02bbfb4e
children 172338b1407f
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.client.client.ui.sq;
2
3 import com.google.gwt.core.client.GWT;
4 import com.google.gwt.json.client.JSONNumber;
5 import com.google.gwt.json.client.JSONObject;
6 import com.google.gwt.json.client.JSONString;
7 import com.smartgwt.client.types.Alignment;
8 import com.smartgwt.client.widgets.Img;
9 import com.smartgwt.client.widgets.events.ResizedHandler;
10 import com.smartgwt.client.widgets.layout.VLayout;
11
12 import org.dive4elements.river.client.client.Config;
13 import org.dive4elements.river.client.shared.model.Artifact;
14
15
16 public class SQCampaignChart extends VLayout {
17
18 private final Artifact artifact;
19
20 protected Img chartImg;
21
22 public SQCampaignChart(Artifact artifact, ResizedHandler resizeHandler) {
23 super();
24
25 this.artifact = artifact;
26 this.chartImg = new Img();
27
28 addResizedHandler(resizeHandler);
29 setAlign(Alignment.CENTER);
30 }
31
32 public void update() {
33 Config config = Config.getInstance();
34 String locale = config.getLocale();
35
36 int hWidth = getWidth() - 12;
37 int hHeight = getHeight() - 12;
38
39 if ((int) (hHeight * 4f / 3) < hWidth) {
40 hWidth = (int) (hHeight * 4f / 3);
41 }
42 else {
43 hHeight = (int) (hWidth * 3f / 4);
44 }
45
46 String river = artifact.getArtifactDescription().getRiver();
47
48 JSONObject jfix = new JSONObject();
49 JSONObject jfilter = new JSONObject();
50 JSONObject jrName = new JSONObject();
51 JSONString jrValue = new JSONString(river);
52 JSONObject jextent = new JSONObject();
53 JSONNumber jwidth = new JSONNumber(hWidth);
54 JSONNumber jheight = new JSONNumber(hHeight);
55
56 jrName.put("name", jrValue);
57 jfilter.put("river", jrName);
58 jextent.put("width", jwidth);
59 jextent.put("height", jheight);
60 jfilter.put("extent", jextent);
61 jfix.put("sq", jfilter);
62 String filter = jfix.toString();
63
64 String imgUrl = GWT.getModuleBaseURL();
65 imgUrl += "sq-km-chart";
66 imgUrl += "?locale=" + locale;
67 imgUrl += "&filter=" + filter;
68
69 if (chartImg != null && hasMember(chartImg)) {
70 chartImg.setWidth(hWidth);
71 chartImg.setHeight(hHeight);
72 chartImg.setSrc(imgUrl);
73 }
74 else {
75 chartImg = new Img(imgUrl, hWidth, hHeight);
76 addMember(chartImg);
77 }
78 }
79 }

http://dive4elements.wald.intevation.org