Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java @ 3719:e82acd5c86f7
Merged revisions 5495-5496,5509,5514-5515,5521-5526 via svnmerge from
file:///home/clients/bsh/bsh-generischer-viewer/Material/SVN/flys-client/trunk
........
r5495 | ingo | 2012-09-17 14:55:09 +0200 (Mo, 17 Sep 2012) | 1 line
Added missing i18n strings for minfo state description.
........
r5496 | ingo | 2012-09-17 15:47:43 +0200 (Mo, 17 Sep 2012) | 1 line
Tagged 'flys-client' as 2.9.1
........
r5509 | teichmann | 2012-09-18 17:54:37 +0200 (Di, 18 Sep 2012) | 1 line
Removed trailing whitespace.
........
r5514 | bricks | 2012-09-19 09:56:42 +0200 (Mi, 19 Sep 2012) | 2 lines
Add missing Changelog entry for r5472
........
r5515 | bricks | 2012-09-19 09:59:35 +0200 (Mi, 19 Sep 2012) | 2 lines
Implement a scrolling gauge info tree
........
r5521 | bricks | 2012-09-19 14:41:48 +0200 (Mi, 19 Sep 2012) | 2 lines
Add station info to the gauges
........
r5522 | bricks | 2012-09-19 14:43:43 +0200 (Mi, 19 Sep 2012) | 2 lines
Improve the handling of the GaugePanel in the ParameterList
........
r5523 | bricks | 2012-09-19 14:51:02 +0200 (Mi, 19 Sep 2012) | 4 lines
Improve the GaugePanel
Be locale aware and only load the gauge info if the river name changes.
........
r5524 | bricks | 2012-09-19 15:14:46 +0200 (Mi, 19 Sep 2012) | 5 lines
Fix a NullPointerException
When iterating over a list it must be checked if the reference to the list is
valid.
........
r5525 | bricks | 2012-09-19 15:16:24 +0200 (Mi, 19 Sep 2012) | 2 lines
Don't display the GaugePanel if no river is selected
........
r5526 | bricks | 2012-09-19 15:18:36 +0200 (Mi, 19 Sep 2012) | 2 lines
Use the wstunit from the river as unit for the Pegelnullpunkt
........
flys-client/tags/2.9.1@5528 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 19 Sep 2012 14:42:48 +0000 |
parents | 4e33aa341e51 |
children | 22cd60315e08 |
comparison
equal
deleted
inserted
replaced
3718:1598d324fbc2 | 3719:e82acd5c86f7 |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | 2 |
3 import java.util.ArrayList; | |
4 import java.util.Iterator; | |
3 import java.util.List; | 5 import java.util.List; |
4 | 6 |
5 import com.google.gwt.core.client.GWT; | 7 import com.google.gwt.core.client.GWT; |
8 import com.google.gwt.i18n.client.NumberFormat; | |
6 import com.google.gwt.user.client.rpc.AsyncCallback; | 9 import com.google.gwt.user.client.rpc.AsyncCallback; |
10 import com.google.gwt.user.client.ui.DecoratorPanel; | |
11 import com.google.gwt.user.client.ui.Grid; | |
12 import com.google.gwt.user.client.ui.HorizontalPanel; | |
13 import com.google.gwt.user.client.ui.Label; | |
14 import com.google.gwt.user.client.ui.ScrollPanel; | |
7 import com.google.gwt.user.client.ui.Tree; | 15 import com.google.gwt.user.client.ui.Tree; |
8 import com.google.gwt.user.client.ui.TreeItem; | 16 import com.google.gwt.user.client.ui.TreeItem; |
9 import com.google.gwt.user.client.ui.Grid; | 17 |
10 import com.google.gwt.user.client.ui.DecoratorPanel; | 18 import com.smartgwt.client.types.Alignment; |
11 | |
12 import com.smartgwt.client.types.Overflow; | 19 import com.smartgwt.client.types.Overflow; |
13 import com.smartgwt.client.types.Alignment; | 20 import com.smartgwt.client.widgets.events.ResizedEvent; |
21 import com.smartgwt.client.widgets.events.ResizedHandler; | |
22 import com.smartgwt.client.widgets.layout.HLayout; | |
14 import com.smartgwt.client.widgets.layout.SectionStackSection; | 23 import com.smartgwt.client.widgets.layout.SectionStackSection; |
15 import com.smartgwt.client.widgets.layout.HLayout; | |
16 import com.smartgwt.client.widgets.layout.VLayout; | 24 import com.smartgwt.client.widgets.layout.VLayout; |
17 import com.smartgwt.client.widgets.Label; | |
18 | 25 |
19 import de.intevation.flys.client.client.FLYSConstants; | 26 import de.intevation.flys.client.client.FLYSConstants; |
20 import de.intevation.flys.client.client.services.GaugeOverviewInfoService; | 27 import de.intevation.flys.client.client.services.GaugeOverviewInfoService; |
21 import de.intevation.flys.client.client.services.GaugeOverviewInfoServiceAsync; | 28 import de.intevation.flys.client.client.services.GaugeOverviewInfoServiceAsync; |
22 import de.intevation.flys.client.shared.model.GaugeInfo; | 29 import de.intevation.flys.client.shared.model.GaugeInfo; |
25 /** | 32 /** |
26 * The GaugePanel is intendet to be used within a SectionStackSection | 33 * The GaugePanel is intendet to be used within a SectionStackSection |
27 * It extends the VLayout by two methods to show and hide the | 34 * It extends the VLayout by two methods to show and hide the |
28 * section stack section. | 35 * section stack section. |
29 */ | 36 */ |
30 public class GaugePanel extends VLayout { | 37 public class GaugePanel extends VLayout implements ResizedHandler { |
31 | 38 |
32 /** SectionStackSection where this GaugePanel belongs in*/ | 39 /** SectionStackSection where this GaugePanel belongs in*/ |
33 private SectionStackSection sectionStack; | 40 private SectionStackSection sectionStack; |
34 | 41 |
35 /** Name of the river */ | 42 /** Name of the river */ |
38 /** The message class that provides i18n strings.*/ | 45 /** The message class that provides i18n strings.*/ |
39 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | 46 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); |
40 | 47 |
41 protected GaugeOverviewInfoServiceAsync gaugeOverviewInfoService = | 48 protected GaugeOverviewInfoServiceAsync gaugeOverviewInfoService = |
42 GWT.create(GaugeOverviewInfoService.class); | 49 GWT.create(GaugeOverviewInfoService.class); |
50 | |
51 protected GaugeTree gaugetree = new GaugeTree(); | |
52 | |
53 protected RiverInfoPanel riverinfopanel; | |
43 | 54 |
44 /** | 55 /** |
45 * Creates a new VLayout with a SectionStackSection | 56 * Creates a new VLayout with a SectionStackSection |
46 * The GaugePanel's SectionStackSection is hidden by default. | 57 * The GaugePanel's SectionStackSection is hidden by default. |
47 * @param sectionStack The section stack section to place the VLayout in. | 58 * @param sectionStack The section stack section to place the VLayout in. |
48 */ | 59 */ |
49 public GaugePanel(SectionStackSection sectionStack) { | 60 public GaugePanel(SectionStackSection sectionStack) { |
50 super(); | 61 setOverflow(Overflow.HIDDEN); |
62 sectionStack.setHidden(true); | |
51 sectionStack.setItems(this); | 63 sectionStack.setItems(this); |
52 sectionStack.setHidden(true); | |
53 this.sectionStack = sectionStack; | 64 this.sectionStack = sectionStack; |
54 setStyleName("gaugeoverview"); | 65 setStyleName("gaugepanel"); |
55 } | 66 addResizedHandler(this); |
56 | 67 } |
68 | |
69 /** | |
70 * Sets and loads the river data if river is not the current set river | |
71 */ | |
57 public void setRiver(String river) { | 72 public void setRiver(String river) { |
58 this.river = river; | 73 if (!river.equals(this.river)) { |
59 this.refresh(); | 74 this.river = river; |
75 this.refresh(); | |
76 } | |
60 } | 77 } |
61 | 78 |
62 /** | 79 /** |
63 * Loads the river info and renders it afterwards | 80 * Loads the river info and renders it afterwards |
64 */ | 81 */ |
69 } | 86 } |
70 | 87 |
71 public void onSuccess(RiverInfo riverinfo) { | 88 public void onSuccess(RiverInfo riverinfo) { |
72 GWT.log("Loaded river info"); | 89 GWT.log("Loaded river info"); |
73 renderGaugeOverviewInfo(riverinfo); | 90 renderGaugeOverviewInfo(riverinfo); |
91 gaugetree.openAll(); | |
74 } | 92 } |
75 }); | 93 }); |
76 } | 94 } |
77 | 95 |
78 public void renderGaugeOverviewInfo(RiverInfo riverinfo) { | 96 public void renderGaugeOverviewInfo(RiverInfo riverinfo) { |
79 setStyleName("gaugepanel"); | 97 removeMembers(getMembers()); |
80 sectionStack.setResizeable(true); | 98 |
81 | 99 riverinfopanel = new RiverInfoPanel(riverinfo); |
82 RiverInfoPanel riverinfopanel = new RiverInfoPanel(riverinfo); | |
83 | |
84 addMember(riverinfopanel); | 100 addMember(riverinfopanel); |
85 | 101 addMember(gaugetree); |
86 VLayout treewrapper = new VLayout(); | 102 |
87 Tree gaugetree = new Tree(); | 103 gaugetree.setGauges(riverinfo); |
88 gaugetree.setHeight("100%"); | 104 } |
89 | 105 |
90 treewrapper.addMember(gaugetree); | 106 @Override |
91 treewrapper.setHeight100(); | 107 public void onResized(ResizedEvent event) { |
92 treewrapper.setOverflow(Overflow.AUTO); | 108 /* this height calculation is only an approximation and doesn't reflect |
93 | 109 * the real height of the the gaugetree. */ |
94 addMember(treewrapper); | 110 int height = getInnerContentHeight() - |
95 | 111 (RiverInfoPanel.HEIGHT + |
96 List<GaugeInfo> gauges = riverinfo.getGauges(); | 112 (2 * RiverInfoPanel.BORDER_WIDTH) + |
97 if (!gauges.isEmpty()) { | 113 (2 * RiverInfoPanel.PADDING) + |
98 | 114 (2 * RiverInfoPanel.MARGIN)); |
99 for (GaugeInfo gauge : gauges) { | 115 |
100 TreeItem gaugeitem = new GaugeInfoItem(gauge); | 116 if (height < 0) { |
101 gaugetree.addItem(gaugeitem); | 117 height = 0; |
102 } | 118 } |
103 } | 119 |
104 } | 120 gaugetree.setHeight("" + height + "px"); |
121 } | |
122 | |
105 | 123 |
106 /** | 124 /** |
107 * Hide the section stack section. | 125 * Hide the section stack section. |
108 */ | 126 */ |
109 public void hide() { | 127 public void hide() { |
117 public void show() { | 135 public void show() { |
118 GWT.log("GaugePanel - show"); | 136 GWT.log("GaugePanel - show"); |
119 this.sectionStack.setHidden(false); | 137 this.sectionStack.setHidden(false); |
120 } | 138 } |
121 | 139 |
122 class RiverInfoPanel extends HLayout { | 140 class GaugeTree extends ScrollPanel { |
141 | |
142 private Tree tree; | |
143 | |
144 public GaugeTree() { | |
145 tree = new Tree(); | |
146 setWidget(tree); | |
147 } | |
148 | |
149 /** | |
150 * Resets the items of the tree. | |
151 * If the list of gauges is empty or null the tree will be empty. | |
152 */ | |
153 public void setGauges(RiverInfo riverinfo) { | |
154 tree.clear(); | |
155 | |
156 List<GaugeInfo> gauges = riverinfo.getGauges(); | |
157 | |
158 if (gauges != null && !gauges.isEmpty()) { | |
159 | |
160 ArrayList<GaugeInfo> emptygauges = new ArrayList<GaugeInfo>(); | |
161 | |
162 if (!riverinfo.isKmUp()) { | |
163 for (GaugeInfo gauge : gauges) { | |
164 addGauge(gauge, emptygauges); | |
165 } | |
166 } | |
167 else { | |
168 for (int i = gauges.size(); i >= 0; i--) { | |
169 GaugeInfo gauge = gauges.get(i); | |
170 addGauge(gauge, emptygauges); | |
171 } | |
172 } | |
173 | |
174 // put empty gauges to the end | |
175 for (GaugeInfo gauge : emptygauges) { | |
176 addGauge(gauge); | |
177 } | |
178 } | |
179 } | |
180 | |
181 private void addGauge(GaugeInfo gauge, List<GaugeInfo> empty) { | |
182 if (gauge.getKmStart() != null && gauge.getKmEnd() != null) { | |
183 addGauge(gauge); | |
184 } | |
185 else { | |
186 empty.add(gauge); | |
187 } | |
188 } | |
189 | |
190 private void addGauge(GaugeInfo gauge) { | |
191 TreeItem gaugeitem = new GaugeInfoItem(gauge); | |
192 tree.addItem(gaugeitem); | |
193 } | |
194 | |
195 public void openAll() { | |
196 for (Iterator<TreeItem> it = tree.treeItemIterator(); it.hasNext();) { | |
197 TreeItem item = it.next(); | |
198 item.setState(true); | |
199 } | |
200 } | |
201 } | |
202 | |
203 class RiverInfoPanel extends HorizontalPanel { | |
204 | |
205 public final static int HEIGHT = 30; | |
206 public final static int BORDER_WIDTH = 3; | |
207 public final static int PADDING = 8; | |
208 public final static int MARGIN = 10; | |
123 | 209 |
124 public RiverInfoPanel(RiverInfo riverinfo) { | 210 public RiverInfoPanel(RiverInfo riverinfo) { |
125 setStyleName("riverinfo"); | 211 setStyleName("riverinfopanel"); |
126 setShowEdges(true); | 212 setHeight("" + HEIGHT + "px"); |
127 setEdgeSize(3); | 213 setVerticalAlignment(ALIGN_MIDDLE); |
128 setBackgroundColor("white"); | 214 |
129 setEdgeImage(""); | 215 NumberFormat nf = NumberFormat.getDecimalFormat(); |
130 setEdgeBackgroundColor("#CFE1F1"); | 216 |
131 setPadding(8); | 217 addLabel(riverinfo.getName(), false); |
132 setOverflow(Overflow.VISIBLE); | |
133 setAutoHeight(); | |
134 setWidth100(); | |
135 setMembersMargin(10); | |
136 setMinHeight(30); | |
137 | |
138 Label label = new Label(riverinfo.getName()); | |
139 label.setWidth("*"); | |
140 addMember(label); | |
141 | 218 |
142 String kmtext = ""; | 219 String kmtext = ""; |
143 Double start = riverinfo.getKmStart(); | 220 Double start = riverinfo.getKmStart(); |
144 Double end = riverinfo.getKmEnd(); | 221 Double end = riverinfo.getKmEnd(); |
145 | 222 |
147 Double tmp = end; | 224 Double tmp = end; |
148 end = start; | 225 end = start; |
149 start = tmp; | 226 start = tmp; |
150 } | 227 } |
151 if (end != null) { | 228 if (end != null) { |
152 kmtext += end.toString(); | 229 kmtext += nf.format(end); |
153 kmtext += " - "; | 230 kmtext += " - "; |
154 } | 231 } |
155 if (start != null) { | 232 if (start != null) { |
156 kmtext += start.toString(); | 233 kmtext += nf.format(start); |
157 } | 234 } |
158 kmtext += " km"; | 235 kmtext += " km"; |
159 | 236 |
160 label = new Label(kmtext); | 237 addLabel(kmtext, false); |
161 label.setWidth("*"); | |
162 label.setAlign(Alignment.CENTER); | |
163 addMember(label); | |
164 | 238 |
165 String qtext = ""; | 239 String qtext = ""; |
166 Double qmin = riverinfo.getMinQ(); | 240 Double qmin = riverinfo.getMinQ(); |
167 Double qmax = riverinfo.getMaxQ(); | 241 Double qmax = riverinfo.getMaxQ(); |
168 if (qmin != null) { | 242 if (qmin != null) { |
169 qtext += qmin.toString(); | 243 qtext += nf.format(qmin); |
170 qtext += " qm/s"; | 244 qtext += " " + MSG.gauge_q_unit(); |
171 qtext += " - "; | 245 qtext += " - "; |
172 } | 246 } |
173 if (qmax != null) { | 247 if (qmax != null) { |
174 qtext += qmax.toString(); | 248 qtext += nf.format(qmax); |
175 qtext += " qm/s"; | 249 qtext += " " + MSG.gauge_q_unit(); |
176 } | 250 } |
177 | 251 |
178 label = new Label(qtext); | 252 addLabel(qtext, false); |
179 label.setWidth("*"); | 253 } |
180 label.setAlign(Alignment.CENTER); | 254 |
181 addMember(label); | 255 private void addLabel(String text, boolean wordwrap) { |
256 Label label = new Label(text, wordwrap); | |
257 add(label); | |
258 setCellHeight(label, "" + HEIGHT + "px"); | |
182 } | 259 } |
183 } | 260 } |
184 | 261 |
185 class GaugeInfoItem extends TreeItem { | 262 class GaugeInfoItem extends TreeItem { |
186 public GaugeInfoItem(GaugeInfo gauge) { | 263 public GaugeInfoItem(GaugeInfo gauge) { |
193 | 270 |
194 class GaugeInfoHead extends HLayout { | 271 class GaugeInfoHead extends HLayout { |
195 | 272 |
196 public GaugeInfoHead(GaugeInfo gauge) { | 273 public GaugeInfoHead(GaugeInfo gauge) { |
197 setStyleName("gaugeinfohead"); | 274 setStyleName("gaugeinfohead"); |
198 setOverflow(Overflow.VISIBLE); | |
199 setAutoHeight(); | 275 setAutoHeight(); |
200 setAutoWidth(); | 276 setAutoWidth(); |
201 | 277 |
202 Label label = new Label(gauge.getName()); | 278 NumberFormat nf = NumberFormat.getDecimalFormat(); |
279 | |
280 Label label = new Label(gauge.getName(), true); | |
203 addMember(label); | 281 addMember(label); |
204 | 282 |
205 Double start = gauge.getKmStart(); | 283 Double start; |
206 Double end = gauge.getKmEnd(); | 284 Double end; |
285 | |
286 if (!gauge.isKmUp()) { | |
287 start = gauge.getKmStart(); | |
288 end = gauge.getKmEnd(); | |
289 } | |
290 else { | |
291 start = gauge.getKmEnd(); | |
292 end = gauge.getKmStart(); | |
293 } | |
294 | |
207 String kmtext = ""; | 295 String kmtext = ""; |
208 if (start != null) { | 296 if (start != null) { |
209 kmtext += start.toString(); | 297 kmtext += nf.format(start); |
210 kmtext += " - "; | 298 kmtext += " - "; |
211 } | 299 } |
212 if (end != null) { | 300 if (end != null) { |
213 kmtext += end.toString(); | 301 kmtext += nf.format(end); |
214 } | 302 } |
215 kmtext +=" km"; | 303 if (start != null || end != null) { |
304 kmtext += " km"; | |
305 } | |
216 | 306 |
217 label = new Label(kmtext); | 307 label = new Label(kmtext); |
218 | 308 |
219 addMember(label); | 309 addMember(label); |
310 | |
311 Double station = gauge.getStation(); | |
312 if (station != null) { | |
313 String stext = nf.format(station); | |
314 stext += " km"; | |
315 label = new Label(stext); | |
316 addMember(label); | |
317 } | |
220 } | 318 } |
221 } | 319 } |
222 | 320 |
223 class GaugeInfoPanel extends DecoratorPanel { | 321 class GaugeInfoPanel extends DecoratorPanel { |
322 | |
224 public GaugeInfoPanel(GaugeInfo gauge) { | 323 public GaugeInfoPanel(GaugeInfo gauge) { |
225 setStyleName("gaugeinfopanel"); | 324 setStyleName("gaugeinfopanel"); |
226 Grid grid = new Grid(4, 2); | 325 Grid grid = new Grid(4, 2); |
227 | 326 |
228 grid.setText(0, 0, "W-Bereich [cm]"); | 327 NumberFormat nf = NumberFormat.getDecimalFormat(); |
229 grid.setText(0, 1, "" + gauge.getMinW() + " - " + gauge.getMaxW()); | 328 |
230 grid.setText(1, 0, "Q-Bereich [m²/s]"); | 329 Double minw = gauge.getMinW(); |
231 grid.setText(1, 1, "" + gauge.getMinQ() + " - " + gauge.getMaxQ()); | 330 Double maxw = gauge.getMaxW(); |
232 grid.setText(2, 0, "AEO [km²]"); | 331 if (minw != null && maxw != null) { |
233 grid.setText(2, 1, "" + gauge.getAeo()); | 332 grid.setText(0, 0, MSG.wq_value_q()); |
234 grid.setText(3, 0, "Pegelnullpunk [NN+m]"); | 333 grid.setText(0, 1, "" + nf.format(minw) + |
235 grid.setText(3, 1, "" + gauge.getDatum()); | 334 " - " + nf.format(maxw)); |
335 } | |
336 | |
337 Double minq = gauge.getMinQ(); | |
338 Double maxq = gauge.getMaxQ(); | |
339 if (minq != null && maxq != null) { | |
340 grid.setText(1, 0, MSG.wq_value_w()); | |
341 grid.setText(1, 1, "" + nf.format(minq) + | |
342 " - " + nf.format(maxq)); | |
343 } | |
344 | |
345 Double aeo = gauge.getAeo(); | |
346 if (aeo != null) { | |
347 grid.setText(2, 0, "AEO [km²]"); | |
348 grid.setText(2, 1, "" + nf.format(aeo)); | |
349 } | |
350 | |
351 Double datum = gauge.getDatum(); | |
352 if (datum != null) { | |
353 grid.setText(3, 0, MSG.gauge_zero() + " [" + | |
354 gauge.getWstUnit() + "]"); | |
355 grid.setText(3, 1, "" + nf.format(datum)); | |
356 } | |
236 | 357 |
237 setWidget(grid); | 358 setWidget(grid); |
238 } | 359 } |
239 } | 360 } |
240 } | 361 } |