Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java @ 2923:43e0f6d96206
FixA: Make the km chart helper panel more useful.
flys-client/trunk@4788 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 25 Jun 2012 17:33:27 +0000 |
parents | 71db63f67d31 |
children | f14d4c668ec5 |
comparison
equal
deleted
inserted
replaced
2922:71db63f67d31 | 2923:43e0f6d96206 |
---|---|
72 protected TabSet tabs; | 72 protected TabSet tabs; |
73 protected Tab events; | 73 protected Tab events; |
74 protected Tab chart; | 74 protected Tab chart; |
75 protected VLayout chartContainer; | 75 protected VLayout chartContainer; |
76 protected Img chartImg; | 76 protected Img chartImg; |
77 protected TextItem kmText; | |
77 | 78 |
78 public FixationPanel() { | 79 public FixationPanel() { |
79 chartImg = new Img(); | 80 chartImg = new Img(); |
80 htmlOverview = ""; | 81 htmlOverview = ""; |
81 } | 82 } |
150 public void onSuccess(FixingsOverviewInfo info) { | 151 public void onSuccess(FixingsOverviewInfo info) { |
151 GWT.log("Successfully loaded overview."); | 152 GWT.log("Successfully loaded overview."); |
152 fixInfo = info; | 153 fixInfo = info; |
153 htmlOverview = info.getHTML(); | 154 htmlOverview = info.getHTML(); |
154 FixAnalysisArtifact art = (FixAnalysisArtifact)artifact; | 155 FixAnalysisArtifact art = (FixAnalysisArtifact)artifact; |
155 art.getFilter().setRiver(info.getRiver()); | 156 FixFilter filter = art.getFilter(); |
156 art.getFilter().setCurrentKm(1d); | 157 filter.setRiver(info.getRiver()); |
157 art.getFilter().setFromKm(info.getFrom()); | 158 if (filter.getCurrentKm() == -Double.MAX_VALUE) { |
158 art.getFilter().setToKm(info.getTo()); | 159 filter.setCurrentKm(info.getFrom()); |
160 filter.setToKm(info.getTo()); | |
161 } | |
162 if (kmText != null) { | |
163 kmText.setValue(filter.getCurrentKm()); | |
164 } | |
159 eventPane.setContents(htmlOverview); | 165 eventPane.setContents(htmlOverview); |
160 updateChartTab(fixInfo.getFrom()); | 166 updateChartTab(fixInfo.getFrom()); |
161 events.setPane(eventPane); | 167 events.setPane(eventPane); |
162 success(); | 168 success(); |
163 } | 169 } |
170 } | 176 } |
171 | 177 |
172 | 178 |
173 protected Canvas createChartHelper() { | 179 protected Canvas createChartHelper() { |
174 | 180 |
175 | |
176 DynamicForm form = new DynamicForm(); | 181 DynamicForm form = new DynamicForm(); |
177 Button lower = new Button("<<"); | 182 Button lower = new Button("<<"); |
178 lower.setWidth(30); | 183 lower.setWidth(30); |
179 Button upper = new Button(">>"); | 184 Button upper = new Button(">>"); |
180 upper.setWidth(30); | 185 upper.setWidth(30); |
181 final TextItem currentkm = new TextItem(); | 186 kmText = new TextItem(); |
182 currentkm.setWidth(60); | 187 kmText.setWidth(60); |
183 currentkm.setShowTitle(false); | 188 kmText.setShowTitle(false); |
184 currentkm.setValidators(new IsFloatValidator()); | 189 kmText.setValidators(new IsFloatValidator()); |
185 | 190 |
186 form.setFields(currentkm); | 191 form.setFields(kmText); |
187 form.setWidth(60); | 192 form.setWidth(60); |
188 lower.addClickHandler(new ClickHandler() { | 193 lower.addClickHandler(new ClickHandler() { |
189 public void onClick(ClickEvent ce) { | 194 public void onClick(ClickEvent ce) { |
190 updateChartTabLow(); | 195 FixFilter filter = updateChartTabLow(); |
191 FixAnalysisArtifact art = (FixAnalysisArtifact) artifact; | 196 FixAnalysisArtifact art = (FixAnalysisArtifact) artifact; |
192 currentkm.setValue(art.getFilter().getCurrentKm()); | 197 kmText.setValue(filter.getCurrentKm()); |
193 } | 198 } |
194 }); | 199 }); |
195 | 200 |
196 upper.addClickHandler(new ClickHandler() { | 201 upper.addClickHandler(new ClickHandler() { |
197 public void onClick(ClickEvent ce) { | 202 public void onClick(ClickEvent ce) { |
198 updateChartTabUp(); | 203 FixFilter filter = updateChartTabUp(); |
199 FixAnalysisArtifact art = (FixAnalysisArtifact) artifact; | 204 FixAnalysisArtifact art = (FixAnalysisArtifact) artifact; |
200 currentkm.setValue(art.getFilter().getCurrentKm()); | 205 kmText.setValue(filter.getCurrentKm()); |
201 } | 206 } |
202 }); | 207 }); |
203 | 208 |
204 currentkm.addChangedHandler(new ChangedHandler() { | 209 kmText.addChangedHandler(new ChangedHandler() { |
205 public void onChanged(ChangedEvent ce) { | 210 public void onChanged(ChangedEvent ce) { |
206 //TODO: get current value. | 211 //TODO: get current value. |
207 if(ce.getForm().validate() && ce.getItem().getValue() != null) { | 212 if(ce.getForm().validate() && ce.getItem().getValue() != null) { |
208 try { | 213 try { |
209 String s = ce.getItem().getValue().toString(); | 214 double d = Double.parseDouble( |
210 Double d = new Double(s); | 215 ce.getItem().getValue().toString()); |
211 updateChartTab(d.doubleValue()); | 216 updateChartTab(d); |
212 } | 217 } |
213 catch(NumberFormatException nfe) { | 218 catch(NumberFormatException nfe) { |
214 // Do nothing. | 219 // Do nothing. |
215 } | 220 } |
216 } | 221 } |
229 protected void updateChartTab(double km) { | 234 protected void updateChartTab(double km) { |
230 Config config = Config.getInstance(); | 235 Config config = Config.getInstance(); |
231 String locale = config.getLocale (); | 236 String locale = config.getLocale (); |
232 | 237 |
233 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; | 238 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; |
234 if (km < 0) { | 239 |
235 km = 0; | 240 if (fixInfo != null) { |
236 } | 241 if (km < fixInfo.getFrom()) km = fixInfo.getFrom(); |
237 art.getFilter().setCurrentKm(km); | 242 if (km > fixInfo.getTo()) km = fixInfo.getTo(); |
243 } | |
244 | |
245 FixFilter filter = art.getFilter(); | |
246 | |
247 if (km < filter.getFromKm()) km = filter.getFromKm(); | |
248 if (km > filter.getToKm()) km = filter.getToKm(); | |
249 | |
250 filter.setCurrentKm(km); | |
238 | 251 |
239 int hWidth = helperContainer.getWidth() - 12; | 252 int hWidth = helperContainer.getWidth() - 12; |
240 int hHeight = helperContainer.getHeight() - 62; | 253 int hHeight = helperContainer.getHeight() - 62; |
241 | 254 |
242 if ((int)(hHeight *4f/3) < hWidth) { | 255 if ((int)(hHeight *4f/3) < hWidth) { |
247 } | 260 } |
248 | 261 |
249 String imgUrl = GWT.getModuleBaseURL(); | 262 String imgUrl = GWT.getModuleBaseURL(); |
250 imgUrl += "fixings-km-chart"; | 263 imgUrl += "fixings-km-chart"; |
251 imgUrl += "?locale=" + locale; | 264 imgUrl += "?locale=" + locale; |
252 imgUrl += "&filter=" + art.getFilter().getChartFilter(hWidth, hHeight); | 265 imgUrl += "&filter=" + filter.getChartFilter(hWidth, hHeight); |
253 | 266 |
254 if (chartContainer.hasMember(chartImg)) { | 267 if (chartContainer.hasMember(chartImg)) { |
255 chartImg.setWidth(hWidth); | 268 chartImg.setWidth(hWidth); |
256 chartImg.setHeight(hHeight); | 269 chartImg.setHeight(hHeight); |
257 chartImg.setSrc(imgUrl); | 270 chartImg.setSrc(imgUrl); |
261 chartContainer.addMember(chartImg); | 274 chartContainer.addMember(chartImg); |
262 } | 275 } |
263 } | 276 } |
264 | 277 |
265 | 278 |
266 protected void updateChartTabLow() { | 279 protected FixFilter updateChartTabLow() { |
267 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; | 280 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; |
268 | 281 |
269 double curr = art.getFilter().getCurrentKm(); | 282 FixFilter filter = art.getFilter(); |
270 if (curr > art.getFilter().getFromKm()) { | 283 |
284 double curr = filter.getCurrentKm(); | |
285 if (curr > filter.getFromKm()) { | |
271 double newVal = (curr - 0.1) * 10; | 286 double newVal = (curr - 0.1) * 10; |
272 long round = Math.round(newVal); | 287 long round = Math.round(newVal); |
273 updateChartTab(((double)round) / 10); | 288 updateChartTab(((double)round) / 10); |
274 } | 289 } |
275 return; | 290 return filter; |
276 } | 291 } |
277 | 292 |
278 | 293 |
279 protected void updateChartTabUp() { | 294 protected FixFilter updateChartTabUp() { |
280 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; | 295 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; |
281 | 296 |
282 double curr = art.getFilter().getCurrentKm(); | 297 FixFilter filter = art.getFilter(); |
283 if (curr < art.getFilter().getToKm()) { | 298 |
299 double curr = filter.getCurrentKm(); | |
300 if (curr < filter.getToKm()) { | |
284 double newVal = (curr + 0.1) * 10; | 301 double newVal = (curr + 0.1) * 10; |
285 long round = Math.round(newVal); | 302 long round = Math.round(newVal); |
286 updateChartTab(((double)round) / 10); | 303 updateChartTab(((double)round) / 10); |
287 } | 304 } |
288 return; | 305 return filter; |
289 } | 306 } |
290 | 307 |
291 | 308 |
292 public void onResized(ResizedEvent re) { | 309 public void onResized(ResizedEvent re) { |
293 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; | 310 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; |
309 p.setValues(cid, checked); | 326 p.setValues(cid, checked); |
310 } | 327 } |
311 } | 328 } |
312 | 329 |
313 private static FixationPanel getInstance(String uuid) { | 330 private static FixationPanel getInstance(String uuid) { |
314 for (int i = 0; i < instances.size(); i++) { | 331 return instances.get(uuid); |
315 if (instances.get(uuid) != null) { | |
316 return instances.get(uuid); | |
317 } | |
318 } | |
319 return null; | |
320 } | 332 } |
321 | 333 |
322 public abstract Canvas createWidget(DataList data); | 334 public abstract Canvas createWidget(DataList data); |
323 public abstract void setValues(String cid, boolean checked); | 335 public abstract void setValues(String cid, boolean checked); |
324 public abstract boolean renderCheckboxes(); | 336 public abstract boolean renderCheckboxes(); |
336 protected boolean hasDate; | 348 protected boolean hasDate; |
337 protected int[] events; | 349 protected int[] events; |
338 | 350 |
339 public FixFilter() { | 351 public FixFilter() { |
340 this.river = ""; | 352 this.river = ""; |
341 this.fromKm = -1d; | 353 this.fromKm = -Double.MAX_VALUE; |
342 this.toKm = -1; | 354 this.toKm = -1; |
343 this.currentKm = -1; | 355 this.currentKm = -1; |
344 this.fromClass = -1; | 356 this.fromClass = -1; |
345 this.toClass = -1; | 357 this.toClass = -1; |
346 this.fromDate = -1; | 358 this.fromDate = -1; |