comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java @ 2517:8f528f5ae137

Added filter object class and scrollable chart to helper panel. flys-client/trunk@4392 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 11 May 2012 12:42:29 +0000
parents 87ac5c532523
children a911e2968cb1
comparison
equal deleted inserted replaced
2516:5d62aa5a57e3 2517:8f528f5ae137
1 package de.intevation.flys.client.client.ui.fixation; 1 package de.intevation.flys.client.client.ui.fixation;
2 2
3 import java.util.HashMap; 3 import java.util.HashMap;
4 import java.util.Date;
5 import java.lang.Math;
6
7 import java.lang.NumberFormatException;
4 8
5 import com.google.gwt.core.client.GWT; 9 import com.google.gwt.core.client.GWT;
6 import com.google.gwt.user.client.rpc.AsyncCallback; 10 import com.google.gwt.user.client.rpc.AsyncCallback;
7 11
8 import com.smartgwt.client.util.SC; 12 import com.smartgwt.client.util.SC;
9 13
10 import com.smartgwt.client.widgets.Canvas; 14 import com.smartgwt.client.widgets.Canvas;
15 import com.smartgwt.client.widgets.Button;
11 import com.smartgwt.client.widgets.form.DynamicForm; 16 import com.smartgwt.client.widgets.form.DynamicForm;
12 import com.smartgwt.client.widgets.HTMLPane; 17 import com.smartgwt.client.widgets.HTMLPane;
13 import com.smartgwt.client.widgets.layout.VLayout; 18 import com.smartgwt.client.widgets.layout.VLayout;
19 import com.smartgwt.client.widgets.layout.HLayout;
20 import com.smartgwt.client.widgets.form.fields.TextItem;
21 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
22 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
23 import com.smartgwt.client.widgets.events.ClickHandler;
24 import com.smartgwt.client.widgets.events.ClickEvent;
25 import com.smartgwt.client.widgets.events.ResizedHandler;
26 import com.smartgwt.client.widgets.events.ResizedEvent;
27 import com.smartgwt.client.widgets.form.validator.IsFloatValidator;
28 import com.smartgwt.client.types.Alignment;
29
30 import com.smartgwt.client.widgets.tab.Tab;
31 import com.smartgwt.client.widgets.tab.TabSet;
32 import com.smartgwt.client.widgets.Img;
14 33
15 import de.intevation.flys.client.client.FLYSConstants; 34 import de.intevation.flys.client.client.FLYSConstants;
16 import de.intevation.flys.client.client.ui.AbstractUIProvider; 35 import de.intevation.flys.client.client.ui.AbstractUIProvider;
17 36
18 import de.intevation.flys.client.client.Config; 37 import de.intevation.flys.client.client.Config;
30 * elements. 49 * elements.
31 * 50 *
32 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 51 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
33 */ 52 */
34 public abstract class FixationPanel 53 public abstract class FixationPanel
35 extends AbstractUIProvider 54 extends AbstractUIProvider
55 implements ResizedHandler
36 { 56 {
37 protected static HashMap<String, FixationPanel> instances = new HashMap<String, FixationPanel>(); 57 protected static HashMap<String, FixationPanel> instances = new HashMap<String, FixationPanel>();
38 58
39 /** The message class that provides i18n strings. */ 59 /** The message class that provides i18n strings. */
40 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); 60 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
42 protected FixingsOverviewServiceAsync overviewService = 62 protected FixingsOverviewServiceAsync overviewService =
43 GWT.create(FixingsOverviewService.class); 63 GWT.create(FixingsOverviewService.class);
44 64
45 protected String htmlOverview; 65 protected String htmlOverview;
46 protected FixingsOverviewInfo fixInfo; 66 protected FixingsOverviewInfo fixInfo;
67 protected FixFilter fixFilter;
68 protected TabSet tabs;
69 protected Tab events;
70 protected Tab chart;
71 protected VLayout chartContainer;
72 protected Img chartImg;
47 73
48 public FixationPanel() { 74 public FixationPanel() {
75 fixFilter = new FixFilter();
76 chartImg = new Img();
49 htmlOverview = ""; 77 htmlOverview = "";
50 } 78 }
51 79
52 protected String getArtifactUuid() { 80 protected String getArtifactUuid() {
53 return this.artifact.getUuid(); 81 return this.artifact.getUuid();
81 109
82 protected Canvas createHelper() { 110 protected Canvas createHelper() {
83 Config config = Config.getInstance(); 111 Config config = Config.getInstance();
84 String locale = config.getLocale (); 112 String locale = config.getLocale ();
85 113
86 final HTMLPane helper = new HTMLPane(); 114 tabs = new TabSet();
115 events = new Tab(MESSAGES.events());
116 chart = new Tab(MESSAGES.kmchart());
117
118 chartContainer = new VLayout();
119 Canvas scroll = createChartHelper();
120
121 VLayout layout = new VLayout();
122 layout.addResizedHandler(this);
123 layout.addMember(chartContainer);
124 layout.addMember(scroll);
125 layout.setAlign(Alignment.CENTER);
126 chart.setPane(layout);
127
128 final HTMLPane eventPane = new HTMLPane();
87 129
88 String river = artifact.getArtifactDescription().getRiver(); 130 String river = artifact.getArtifactDescription().getRiver();
89 131
90 createCallback(); 132 createCallback();
91 /* 133 /*
107 } 149 }
108 public void onSuccess(FixingsOverviewInfo info) { 150 public void onSuccess(FixingsOverviewInfo info) {
109 GWT.log("Successfully loaded overview."); 151 GWT.log("Successfully loaded overview.");
110 fixInfo = info; 152 fixInfo = info;
111 htmlOverview = info.getHTML(); 153 htmlOverview = info.getHTML();
112 GWT.log("html: " + info.getHTML()); 154 fixFilter.setRiver(info.getRiver());
113 helper.setContents(htmlOverview); 155 fixFilter.setCurrentKm(1d);
114 156 fixFilter.setFromKm(info.getFrom());
157 fixFilter.setToKm(info.getTo());
158 eventPane.setContents(htmlOverview);
159 updateChartTab(fixInfo.getFrom());
160 events.setPane(eventPane);
115 } 161 }
116 }); 162 });
117 163
118 this.helperContainer.addMember(helper); 164 tabs.addTab(events);
119 165 tabs.addTab(chart);
120 return helper; 166
121 } 167 return tabs;
168 }
169
170
171 protected Canvas createChartHelper() {
172
173
174 DynamicForm form = new DynamicForm();
175 Button lower = new Button("<<");
176 lower.setWidth(30);
177 Button upper = new Button(">>");
178 upper.setWidth(30);
179 final TextItem currentkm = new TextItem();
180 currentkm.setWidth(60);
181 currentkm.setShowTitle(false);
182 currentkm.setValidators(new IsFloatValidator());
183
184 form.setFields(currentkm);
185 form.setWidth(60);
186 lower.addClickHandler(new ClickHandler() {
187 public void onClick(ClickEvent ce) {
188 updateChartTabLow();
189 currentkm.setValue(fixFilter.getCurrentKm());
190 }
191 });
192
193 upper.addClickHandler(new ClickHandler() {
194 public void onClick(ClickEvent ce) {
195 updateChartTabUp();
196 currentkm.setValue(fixFilter.getCurrentKm());
197 }
198 });
199
200 currentkm.addChangedHandler(new ChangedHandler() {
201 public void onChanged(ChangedEvent ce) {
202 //TODO: get current value.
203 if(ce.getForm().validate() && ce.getItem().getValue() != null) {
204 try {
205 String s = ce.getItem().getValue().toString();
206 Double d = new Double(s);
207 updateChartTab(d.doubleValue());
208 }
209 catch(NumberFormatException nfe) {
210 // Do nothing.
211 }
212 }
213 }
214 });
215
216 HLayout layout = new HLayout();
217 layout.setAlign(Alignment.CENTER);
218
219 layout.addMember(lower);
220 layout.addMember(form);
221 layout.addMember(upper);
222 return layout;
223 }
224
225 protected void updateChartTab(double km) {
226 Config config = Config.getInstance();
227 String locale = config.getLocale ();
228
229 fixFilter.setCurrentKm(km);
230 chartContainer.removeMember(chartImg);
231 String imgUrl = GWT.getModuleBaseURL();
232 imgUrl += "fixings-km-chart";
233 imgUrl += "?locale=" + locale;
234 imgUrl += "&filter=" + fixFilter.getChartFilter(helperContainer.getWidth() - 12, (int)(helperContainer.getWidth()*3/4) - 12);
235
236 chartImg = new Img(imgUrl, helperContainer.getWidth() - 12, (int)(helperContainer.getWidth()*3/4) - 12);
237 chartContainer.addMember(chartImg);
238
239 }
240
241
242 protected void updateChartTabLow() {
243 double curr = fixFilter.getCurrentKm();
244 if (curr > fixFilter.getFromKm()) {
245 double newVal = (curr - 0.1) * 10;
246 long round = Math.round(newVal);
247 updateChartTab(((double)round) / 10);
248 }
249 return;
250 }
251
252
253 protected void updateChartTabUp() {
254 double curr = fixFilter.getCurrentKm();
255 if (curr < fixFilter.getToKm()) {
256 double newVal = (curr + 0.1) * 10;
257 long round = Math.round(newVal);
258 updateChartTab(((double)round) / 10);
259 }
260 return;
261 }
262
263
264 public void onResized(ResizedEvent re) {
265 updateChartTab(fixFilter.getCurrentKm());
266 }
267
122 268
123 private native void createCallback() /*-{ 269 private native void createCallback() /*-{
124 $wnd.fixationCallback = @de.intevation.flys.client.client.ui.fixation.FixationPanel::helperCallback(ZLjava/lang/String;); 270 $wnd.fixationCallback = @de.intevation.flys.client.client.ui.fixation.FixationPanel::helperCallback(ZLjava/lang/String;);
125 }-*/; 271 }-*/;
126 272
144 } 290 }
145 291
146 public abstract Canvas createWidget(DataList data); 292 public abstract Canvas createWidget(DataList data);
147 public abstract void setValues(String cid, boolean checked); 293 public abstract void setValues(String cid, boolean checked);
148 public abstract boolean renderCheckboxes(); 294 public abstract boolean renderCheckboxes();
295 public abstract FixFilter getFilter();
296 public abstract void setFilter(FixFilter filter);
297
298
299 public static class FixFilter {
300 protected String river;
301 protected double fromKm;
302 protected double toKm;
303 protected double currentKm;
304 protected int fromClass;
305 protected int toClass;
306 protected Date fromDate;
307 protected Date toDate;
308 protected int[] events;
309
310 public FixFilter() {}
311
312 public void setRiver(String river) {
313 this.river = river;
314 }
315
316 public void setFromKm(double from) {
317 this.fromKm = from;
318 }
319
320 public void setToKm(double to) {
321 this.toKm = to;
322 }
323
324 public void setCurrentKm(double km) {
325 this.currentKm = km;
326 }
327
328 public void setFromClass(int from) {
329 this.fromClass = from;
330 }
331
332 public void setToClass(int to) {
333 this.toClass = to;
334 }
335
336 public void setFromDate(Date from) {
337 this.fromDate = from;
338 }
339
340 public void setToDate(Date to) {
341 this.toDate = to;
342 }
343
344 public void setEvents(int[] ev) {
345 this.events = ev;
346 }
347
348 public String getRiver() {
349 return this.river;
350 }
351
352 public double getFromKm() {
353 return this.fromKm;
354 }
355
356 public double getToKm() {
357 return this.toKm;
358 }
359
360 public double getCurrentKm() {
361 return this.currentKm;
362 }
363
364 public int getFromClass() {
365 return this.fromClass;
366 }
367
368 public int getToClass() {
369 return this.toClass;
370 }
371
372 public Date getFromDate() {
373 return this.fromDate;
374 }
375
376 public Date getToDate() {
377 return this.toDate;
378 }
379
380 public int[] getEvents() {
381 return this.events;
382 }
383
384 public String getOverviewFilter() {
385 String filter = "";
386 if (river != null && river.length() > 0) {
387 filter = "{\"fixings\": {\"river\": {\"name\": \"" + river + "\"}}";
388 filter += createFilter();
389 filter += "}";
390 }
391 return filter;
392 }
393
394 public String getChartFilter(int width, int height) {
395 String filter = "";
396 if (river != null && river.length() > 0 &&
397 currentKm >= fromKm && currentKm <= toKm)
398 {
399 filter = "{\"fixings\": "+
400 "{\"river\": {\"name\": \"" + river + "\"}," +
401 "\"km\": {\"value\": \"" + currentKm + "\"}," +
402 "\"extent\": {\"width\": \"" + width + "\", \"height\": \"" + height + "\"}}";
403 filter += createFilter();
404 filter += "}";
405 }
406 return filter;
407 }
408
409 protected String createFilter() {
410 //TODO create filter...
411 return "";
412 }
413 }
149 } 414 }

http://dive4elements.wald.intevation.org