Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/widgets/DischargeTablesChart.java @ 4218:6ae99d996f79
flys/issue903: Display the discharge tables of the selected gauge as chart in historical discharge calculation.
There is a new class 'DischargeTablesChart' which is a Canvas and displays the chart using the new service
'DischargeTablesServiceImpl'.
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 23 Oct 2012 12:01:19 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4217:08b6458909a9 | 4218:6ae99d996f79 |
---|---|
1 package de.intevation.flys.client.client.widgets; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 import com.smartgwt.client.widgets.Canvas; | |
5 import com.smartgwt.client.widgets.Img; | |
6 import com.smartgwt.client.widgets.events.ResizedEvent; | |
7 import com.smartgwt.client.widgets.events.ResizedHandler; | |
8 | |
9 import de.intevation.flys.client.shared.model.Artifact; | |
10 import de.intevation.flys.client.shared.model.ArtifactDescription; | |
11 | |
12 | |
13 public class DischargeTablesChart extends Canvas implements ResizedHandler { | |
14 | |
15 protected Artifact artifact; | |
16 | |
17 protected Img img; | |
18 | |
19 public DischargeTablesChart() { | |
20 super(); | |
21 } | |
22 | |
23 public DischargeTablesChart(Artifact artifact) { | |
24 super(); | |
25 this.artifact = artifact; | |
26 init(); | |
27 } | |
28 | |
29 private void init() { | |
30 addChild(createImage()); | |
31 addResizedHandler(this); | |
32 setSize("100%", "100%"); | |
33 } | |
34 | |
35 protected Img createImage() { | |
36 img = new Img(getUrl()); | |
37 img.setSize("100%", "100%"); | |
38 | |
39 return img; | |
40 } | |
41 | |
42 protected String getUrl() { | |
43 String url = GWT.getModuleBaseURL(); | |
44 url += "dischargetablesoverview"; | |
45 url += "?gauge=" + getGauge(); | |
46 url += "&format=png"; | |
47 | |
48 String[] timerange = getTimerange(); | |
49 url += "&lower=" + timerange[0]; | |
50 url += "&upper=" + timerange[1]; | |
51 | |
52 int width = 600; | |
53 int height = 400; | |
54 if (img != null) { | |
55 width = img.getWidth(); | |
56 height = img.getHeight(); | |
57 } | |
58 | |
59 url += "&width=" + String.valueOf(width); | |
60 url += "&height=" + String.valueOf(height); | |
61 | |
62 // add time millis to 'deactivate' caching | |
63 url += "&timemillis" + System.currentTimeMillis(); | |
64 | |
65 GWT.log("DischargeTablesService URL = '" + url + "'"); | |
66 return url; | |
67 } | |
68 | |
69 protected String getGauge() { | |
70 ArtifactDescription desc = artifact.getArtifactDescription(); | |
71 return desc.getReferenceGauge(); | |
72 } | |
73 | |
74 protected String[] getTimerange() { | |
75 ArtifactDescription desc = artifact.getArtifactDescription(); | |
76 String yearStr = desc.getDataValueAsString("year_range"); | |
77 | |
78 if (yearStr != null && yearStr.length() > 0) { | |
79 return yearStr.split(";"); | |
80 } | |
81 | |
82 return new String[2]; | |
83 } | |
84 | |
85 @Override | |
86 public void onResized(ResizedEvent event) { | |
87 GWT.log("resized discharge tables overview chart"); | |
88 img.setSrc(getUrl()); | |
89 } | |
90 } |