comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/NaviChartOutputTab.java @ 9072:02739b8c010d

bundu progress (Klon FixationAnalysis +Vollmer funktioniert; Verzweigung neue Berechnungsart Bezugswst)
author gernotbelger
date Wed, 16 May 2018 17:43:47 +0200
parents 5e38e2924c07
children 850ce16034e9
comparison
equal deleted inserted replaced
9071:a561b882436d 9072:02739b8c010d
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.client.client.ui.chart; 9 package org.dive4elements.river.client.client.ui.chart;
10 10
11 import java.util.Date;
12 import java.util.HashMap;
11 import java.util.Map; 13 import java.util.Map;
12 import java.util.HashMap; 14
15 import org.dive4elements.river.client.client.Config;
16 import org.dive4elements.river.client.client.ui.CollectionView;
17 import org.dive4elements.river.client.shared.model.AbstractFixBunduArtifact;
18 import org.dive4elements.river.client.shared.model.Artifact;
19 import org.dive4elements.river.client.shared.model.Collection;
20 import org.dive4elements.river.client.shared.model.FixFilter;
21 import org.dive4elements.river.client.shared.model.OutputMode;
13 22
14 import com.google.gwt.core.client.GWT; 23 import com.google.gwt.core.client.GWT;
15 import com.google.gwt.i18n.client.NumberFormat; 24 import com.google.gwt.i18n.client.NumberFormat;
16
17 import com.smartgwt.client.types.Alignment; 25 import com.smartgwt.client.types.Alignment;
18
19 import com.smartgwt.client.widgets.Button; 26 import com.smartgwt.client.widgets.Button;
20 import com.smartgwt.client.widgets.Canvas; 27 import com.smartgwt.client.widgets.Canvas;
21
22 import com.smartgwt.client.widgets.events.ClickEvent; 28 import com.smartgwt.client.widgets.events.ClickEvent;
23 import com.smartgwt.client.widgets.events.ClickHandler; 29 import com.smartgwt.client.widgets.events.ClickHandler;
24
25 import com.smartgwt.client.widgets.form.DynamicForm; 30 import com.smartgwt.client.widgets.form.DynamicForm;
26
27 import com.smartgwt.client.widgets.form.fields.TextItem; 31 import com.smartgwt.client.widgets.form.fields.TextItem;
28
29 import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent; 32 import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent;
30 import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler; 33 import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler;
31
32 import com.smartgwt.client.widgets.layout.HLayout; 34 import com.smartgwt.client.widgets.layout.HLayout;
33 import com.smartgwt.client.widgets.layout.VLayout; 35 import com.smartgwt.client.widgets.layout.VLayout;
34
35 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; 36 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent;
36 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; 37 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler;
37
38 import org.dive4elements.river.client.client.Config;
39
40 import org.dive4elements.river.client.client.ui.CollectionView;
41
42 import org.dive4elements.river.client.shared.model.Artifact;
43 import org.dive4elements.river.client.shared.model.Collection;
44 import org.dive4elements.river.client.shared.model.FixAnalysisArtifact;
45 import org.dive4elements.river.client.shared.model.FixFilter;
46 import org.dive4elements.river.client.shared.model.OutputMode;
47
48 import java.util.Date;
49
50 38
51 /** 39 /**
52 * Tab representing and showing one Chart-output with a "navi" thing. 40 * Tab representing and showing one Chart-output with a "navi" thing.
53 * 41 *
54 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 42 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
55 */ 43 */
56 public class NaviChartOutputTab 44 public class NaviChartOutputTab extends ChartOutputTab implements TabSelectedHandler {
57 extends ChartOutputTab
58 implements TabSelectedHandler
59 {
60 protected TextItem currentkm; 45 protected TextItem currentkm;
61 46
62 public NaviChartOutputTab( 47 public NaviChartOutputTab(final String title, final Collection collection, final OutputMode mode, final CollectionView collectionView) {
63 String title,
64 Collection collection,
65 OutputMode mode,
66 CollectionView collectionView
67 ){
68 super(title, collection, mode, collectionView); 48 super(title, collection, mode, collectionView);
69 right.removeChild(chart); 49 this.right.removeChild(this.chart);
70 right.addChild(createNaviChart()); 50 this.right.addChild(createNaviChart());
71 collectionView.registerTabHandler(this); 51 collectionView.registerTabHandler(this);
72 } 52 }
73 53
74
75 protected Canvas createNaviChart() { 54 protected Canvas createNaviChart() {
76 final Artifact art = collectionView.getArtifact(); 55 final Artifact art = this.collectionView.getArtifact();
77 VLayout root = new VLayout(); 56 final VLayout root = new VLayout();
78 root.setWidth100(); 57 root.setWidth100();
79 root.setHeight100(); 58 root.setHeight100();
80 59
81 HLayout layout = new HLayout(); 60 final HLayout layout = new HLayout();
82 layout.setAlign(Alignment.CENTER); 61 layout.setAlign(Alignment.CENTER);
83 62
84 DynamicForm form = new DynamicForm(); 63 final DynamicForm form = new DynamicForm();
85 Button lower = new Button("<<"); 64 final Button lower = new Button("<<");
86 lower.setWidth(30); 65 lower.setWidth(30);
87 Button upper = new Button(">>"); 66 final Button upper = new Button(">>");
88 upper.setWidth(30); 67 upper.setWidth(30);
89 currentkm = new TextItem(); 68 this.currentkm = new TextItem();
90 currentkm.setWidth(60); 69 this.currentkm.setWidth(60);
91 currentkm.setShowTitle(false); 70 this.currentkm.setShowTitle(false);
92 71
93 form.setFields(currentkm); 72 form.setFields(this.currentkm);
94 form.setWidth(60); 73 form.setWidth(60);
95 74
96 double fromKm; 75 double fromKm;
97 double toKm; 76 double toKm;
98 77
99 if (art instanceof FixAnalysisArtifact) { 78 if (art instanceof AbstractFixBunduArtifact) {
100 FixAnalysisArtifact fix = (FixAnalysisArtifact) art; 79 final AbstractFixBunduArtifact fix = (AbstractFixBunduArtifact) art;
101 FixFilter fixFilter = fix.getFilter(); 80 final FixFilter fixFilter = fix.getFilter();
102 String s = fix.getArtifactDescription().getDataValueAsString( 81 final String s = fix.getArtifactDescription().getDataValueAsString("ld_step");
103 "ld_step");
104 try { 82 try {
105 double ds = Double.parseDouble(s); 83 final double ds = Double.parseDouble(s);
106 collectionView.setSteps(ds); 84 this.collectionView.setSteps(ds);
107 } 85 }
108 catch(NumberFormatException nfe) { 86 catch (final NumberFormatException nfe) {
109 collectionView.setSteps(100d); 87 this.collectionView.setSteps(100d);
110 } 88 }
111 fromKm = fixFilter.getFromKm(); 89 fromKm = fixFilter.getFromKm();
112 toKm = fixFilter.getToKm(); 90 toKm = fixFilter.getToKm();
113 } 91 } else {
114 else {
115 // Probably WINFOArtifact kind of artifact. 92 // Probably WINFOArtifact kind of artifact.
116 String ld_step = 93 final String ld_step = art.getArtifactDescription().getDataValueAsString("ld_step");
117 art.getArtifactDescription().getDataValueAsString(
118 "ld_step");
119 try { 94 try {
120 collectionView.setSteps(Double.valueOf(ld_step)); 95 this.collectionView.setSteps(Double.valueOf(ld_step));
121 } 96 }
122 catch (Exception e) { 97 catch (final Exception e) {
123 GWT.log("No ld_steps data or not parsable."); 98 GWT.log("No ld_steps data or not parsable.");
124 return root; 99 return root;
125 } 100 }
126 101
127 double[] kmRange = art.getArtifactDescription().getKMRange(); 102 final double[] kmRange = art.getArtifactDescription().getKMRange();
128 if (kmRange == null || kmRange.length == 2) { 103 if (kmRange == null || kmRange.length == 2) {
129 fromKm = kmRange[0]; 104 fromKm = kmRange[0];
130 toKm = kmRange[1]; 105 toKm = kmRange[1];
131 } 106 } else {
132 else {
133 GWT.log("No KM range in description found."); 107 GWT.log("No KM range in description found.");
134 return root; 108 return root;
135 } 109 }
136 } 110 }
137 111
138 collectionView.setMinKm(fromKm); 112 this.collectionView.setMinKm(fromKm);
139 collectionView.setMaxKm(toKm); 113 this.collectionView.setMaxKm(toKm);
140 114
141 final NumberFormat nf = NumberFormat.getDecimalFormat(); 115 final NumberFormat nf = NumberFormat.getDecimalFormat();
142 116
143 // Always jump to the from km when initialized. 117 // Always jump to the from km when initialized.
144 try { 118 try {
145 double d = Double.valueOf(fromKm); 119 final double d = Double.valueOf(fromKm);
146 currentkm.setValue(nf.format(d)); 120 this.currentkm.setValue(nf.format(d));
147 } catch (NumberFormatException e) { 121 }
148 currentkm.setValue(fromKm); 122 catch (final NumberFormatException e) {
149 } 123 this.currentkm.setValue(fromKm);
150 collectionView.setCurrentKm(fromKm); 124 }
125 this.collectionView.setCurrentKm(fromKm);
151 126
152 lower.addClickHandler(new ClickHandler() { 127 lower.addClickHandler(new ClickHandler() {
153 public void onClick(ClickEvent ce) { 128 @Override
154 tbarPanel.deselectControls(); 129 public void onClick(final ClickEvent ce) {
130 NaviChartOutputTab.this.tbarPanel.deselectControls();
155 updateChartDown(); 131 updateChartDown();
156 try { 132 try {
157 double d = Double.valueOf(collectionView.getCurrentKm()); 133 final double d = Double.valueOf(NaviChartOutputTab.this.collectionView.getCurrentKm());
158 currentkm.setValue(nf.format(d)); 134 NaviChartOutputTab.this.currentkm.setValue(nf.format(d));
159 tbarPanel.onZoom(null); 135 NaviChartOutputTab.this.tbarPanel.onZoom(null);
160 } catch (NumberFormatException e) { 136 }
161 currentkm.setValue(collectionView.getCurrentKm()); 137 catch (final NumberFormatException e) {
138 NaviChartOutputTab.this.currentkm.setValue(NaviChartOutputTab.this.collectionView.getCurrentKm());
162 } 139 }
163 } 140 }
164 }); 141 });
165 142
166 upper.addClickHandler(new ClickHandler() { 143 upper.addClickHandler(new ClickHandler() {
167 public void onClick(ClickEvent ce) { 144 @Override
168 tbarPanel.deselectControls(); 145 public void onClick(final ClickEvent ce) {
146 NaviChartOutputTab.this.tbarPanel.deselectControls();
169 updateChartUp(); 147 updateChartUp();
170 try { 148 try {
171 double d = Double.valueOf(collectionView.getCurrentKm()); 149 final double d = Double.valueOf(NaviChartOutputTab.this.collectionView.getCurrentKm());
172 currentkm.setValue(nf.format(d)); 150 NaviChartOutputTab.this.currentkm.setValue(nf.format(d));
173 tbarPanel.onZoom(null); 151 NaviChartOutputTab.this.tbarPanel.onZoom(null);
174 } catch (NumberFormatException e) { 152 }
175 currentkm.setValue(collectionView.getCurrentKm()); 153 catch (final NumberFormatException e) {
154 NaviChartOutputTab.this.currentkm.setValue(NaviChartOutputTab.this.collectionView.getCurrentKm());
176 } 155 }
177 } 156 }
178 }); 157 });
179 158
180 currentkm.addKeyPressHandler(new KeyPressHandler() { 159 this.currentkm.addKeyPressHandler(new KeyPressHandler() {
181 public void onKeyPress(KeyPressEvent kpe) { 160 @Override
161 public void onKeyPress(final KeyPressEvent kpe) {
182 if (!kpe.getKeyName().equals("Enter")) { 162 if (!kpe.getKeyName().equals("Enter")) {
183 return; 163 return;
184 } 164 }
185 if(kpe.getItem().getValue() != null) { 165 if (kpe.getItem().getValue() != null) {
186 tbarPanel.deselectControls(); 166 NaviChartOutputTab.this.tbarPanel.deselectControls();
187 try { 167 try {
188 String s = kpe.getItem().getValue().toString(); 168 final String s = kpe.getItem().getValue().toString();
189 double d; 169 double d;
190 try { 170 try {
191 d = nf.parse(s); 171 d = nf.parse(s);
192 currentkm.setValue(nf.format(d)); 172 NaviChartOutputTab.this.currentkm.setValue(nf.format(d));
193 } catch (NumberFormatException e) { 173 }
174 catch (final NumberFormatException e) {
194 d = -1d; 175 d = -1d;
195 } 176 }
196 if (d <= collectionView.getMaxKm() && 177 if (d <= NaviChartOutputTab.this.collectionView.getMaxKm() && d >= NaviChartOutputTab.this.collectionView.getMinKm()) {
197 d >= collectionView.getMinKm()) { 178 NaviChartOutputTab.this.collectionView.setCurrentKm(d);
198 collectionView.setCurrentKm(d); 179 NaviChartOutputTab.this.tbarPanel.updateLinks();
199 tbarPanel.updateLinks(); 180 NaviChartOutputTab.this.tbarPanel.onZoom(null);
200 tbarPanel.onZoom(null); 181 if (NaviChartOutputTab.this.right != null) {
201 if (right != null) {
202 updateChartPanel(); 182 updateChartPanel();
203 updateChartInfo(); 183 updateChartInfo();
204 } 184 }
205 } 185 }
206 } 186 }
207 catch(NumberFormatException nfe) { 187 catch (final NumberFormatException nfe) {
208 // Do nothing. 188 // Do nothing.
209 } 189 }
210 } 190 }
211 } 191 }
212 }); 192 });
213 layout.addMember(lower); 193 layout.addMember(lower);
214 layout.addMember(form); 194 layout.addMember(form);
215 layout.addMember(upper); 195 layout.addMember(upper);
216 196
217 root.addMember(chart); 197 root.addMember(this.chart);
218 root.addMember(layout); 198 root.addMember(layout);
219 return root; 199 return root;
220 } 200 }
221 201
222
223 /** 202 /**
224 * Callback when km-up-button is clicked. 203 * Callback when km-up-button is clicked.
225 * Increases collectionViews KM and refreshes view. 204 * Increases collectionViews KM and refreshes view.
226 */ 205 */
227 protected void updateChartUp() { 206 protected void updateChartUp() {
228 double currentKm = collectionView.getCurrentKm(); 207 final double currentKm = this.collectionView.getCurrentKm();
229 if (currentKm < collectionView.getMaxKm()) { 208 if (currentKm < this.collectionView.getMaxKm()) {
230 // Why this math? 209 // Why this math?
231 double newVal = currentKm * 100; 210 double newVal = currentKm * 100;
232 newVal += (collectionView.getSteps() / 10); 211 newVal += (this.collectionView.getSteps() / 10);
233 collectionView.setCurrentKm((double)Math.round(newVal) / 100); 212 this.collectionView.setCurrentKm((double) Math.round(newVal) / 100);
234 tbarPanel.updateLinks(); 213 this.tbarPanel.updateLinks();
235 updateChartPanel(); 214 updateChartPanel();
236 updateChartInfo(); 215 updateChartInfo();
237 } 216 }
238 } 217 }
239 218
240 /** 219 /**
241 * Callback when km-down-button is clicked. 220 * Callback when km-down-button is clicked.
242 * Decreases collectionViews KM and refreshes view. 221 * Decreases collectionViews KM and refreshes view.
243 */ 222 */
244 protected void updateChartDown() { 223 protected void updateChartDown() {
245 double currentKm = collectionView.getCurrentKm(); 224 final double currentKm = this.collectionView.getCurrentKm();
246 if (currentKm > collectionView.getMinKm()) { 225 if (currentKm > this.collectionView.getMinKm()) {
247 // Why this math? 226 // Why this math?
248 double newVal = currentKm * 100; 227 double newVal = currentKm * 100;
249 newVal -= (collectionView.getSteps() / 10); 228 newVal -= (this.collectionView.getSteps() / 10);
250 collectionView.setCurrentKm((double)Math.round(newVal) / 100); 229 this.collectionView.setCurrentKm((double) Math.round(newVal) / 100);
251 tbarPanel.updateLinks(); 230 this.tbarPanel.updateLinks();
252 updateChartPanel(); 231 updateChartPanel();
253 updateChartInfo(); 232 updateChartInfo();
254 } 233 }
255 234
256 } 235 }
257 236
258 /** 237 /**
259 * Returns the existing chart panel. 238 * Returns the existing chart panel.
260 * 239 *
261 * @return the existing chart panel. 240 * @return the existing chart panel.
262 */ 241 */
263 @Override 242 @Override
264 public Canvas getChartPanel() { 243 public Canvas getChartPanel() {
265 return chart; 244 return this.chart;
266 } 245 }
267 246
268 /** 247 /**
269 * Builds the URL that points to the chart image. 248 * Builds the URL that points to the chart image.
270 * 249 *
271 * @param width The width of the requested chart. 250 * @param width
272 * @param height The height of the requested chart. 251 * The width of the requested chart.
273 * @param xr Optional x range (used for zooming). 252 * @param height
274 * @param yr Optional y range (used for zooming). 253 * The height of the requested chart.
254 * @param xr
255 * Optional x range (used for zooming).
256 * @param yr
257 * Optional y range (used for zooming).
275 * 258 *
276 * @return the URL to the chart image. 259 * @return the URL to the chart image.
277 */ 260 */
278 @Override 261 @Override
279 protected String getImgUrl(int width, int height) { 262 protected String getImgUrl(final int width, final int height) {
280 Config config = Config.getInstance(); 263 final Config config = Config.getInstance();
281 264
282 String imgUrl = GWT.getModuleBaseURL(); 265 String imgUrl = GWT.getModuleBaseURL();
283 imgUrl += "chart"; 266 imgUrl += "chart";
284 imgUrl += "?uuid=" + collection.identifier(); 267 imgUrl += "?uuid=" + this.collection.identifier();
285 imgUrl += "&type=" + mode.getName(); 268 imgUrl += "&type=" + this.mode.getName();
286 imgUrl += "&locale=" + config.getLocale(); 269 imgUrl += "&locale=" + config.getLocale();
287 imgUrl += "&timestamp=" + new Date().getTime(); 270 imgUrl += "&timestamp=" + new Date().getTime();
288 imgUrl += "&width=" + Integer.toString(width); 271 imgUrl += "&width=" + Integer.toString(width);
289 imgUrl += "&height=" + Integer.toString(height - 40); 272 imgUrl += "&height=" + Integer.toString(height - 40);
290 273
291 Number[] zoom = getZoomValues(); 274 final Number[] zoom = getZoomValues();
292 275
293 if (zoom != null) { 276 if (zoom != null) {
294 if (zoom[0].intValue() != 0 || zoom[1].intValue() != 1) { 277 if (zoom[0].intValue() != 0 || zoom[1].intValue() != 1) {
295 // a zoom range of 0-1 means displaying the whole range. In such 278 // a zoom range of 0-1 means displaying the whole range. In such
296 // case we don't need to zoom. 279 // case we don't need to zoom.
304 imgUrl += "&miny=" + zoom[2]; 287 imgUrl += "&miny=" + zoom[2];
305 imgUrl += "&maxy=" + zoom[3]; 288 imgUrl += "&maxy=" + zoom[3];
306 } 289 }
307 } 290 }
308 291
309 if (collectionView.getArtifact() instanceof FixAnalysisArtifact) { 292 if (this.collectionView.getArtifact() instanceof AbstractFixBunduArtifact) {
310 if (collectionView.getCurrentKm() == -1) { 293 if (this.collectionView.getCurrentKm() == -1) {
311 FixAnalysisArtifact fix = 294 final AbstractFixBunduArtifact fix = (AbstractFixBunduArtifact) this.collectionView.getArtifact();
312 (FixAnalysisArtifact) collectionView.getArtifact(); 295 this.collectionView.setCurrentKm(fix.getFilter().getFromKm());
313 collectionView.setCurrentKm(fix.getFilter().getFromKm()); 296 }
314 } 297 } else if (this.collectionView.getCurrentKm() == -1) {
315 } 298 this.collectionView.setCurrentKm(this.collectionView.getArtifact().getArtifactDescription().getKMRange()[0]);
316 else if (collectionView.getCurrentKm() == -1) { 299 }
317 collectionView.setCurrentKm( 300 if (this.collectionView.getCurrentKm() != -1) {
318 collectionView.getArtifact().getArtifactDescription() 301 imgUrl += "&currentKm=" + this.collectionView.getCurrentKm();
319 .getKMRange()[0]);
320 }
321 if (collectionView.getCurrentKm() != -1) {
322 imgUrl += "&currentKm=" + collectionView.getCurrentKm();
323 } 302 }
324 303
325 return imgUrl; 304 return imgUrl;
326 } 305 }
327 306
328 public void onTabSelected(TabSelectedEvent tse) { 307 @Override
308 public void onTabSelected(final TabSelectedEvent tse) {
329 if (this.equals(tse.getTab())) { 309 if (this.equals(tse.getTab())) {
330 updateChartPanel(); 310 updateChartPanel();
331 updateChartInfo(); 311 updateChartInfo();
332 currentkm.setValue(collectionView.getCurrentKm()); 312 this.currentkm.setValue(this.collectionView.getCurrentKm());
333 } 313 }
334 } 314 }
335 315
336 @Override 316 @Override
337 public Map<String, String> getChartAttributes() { 317 public Map<String, String> getChartAttributes() {
338 Map<String, String> attr = new HashMap<String, String>(); 318 Map<String, String> attr = new HashMap<String, String>();
339 319
340 attr = super.getChartAttributes(); 320 attr = super.getChartAttributes();
341 attr.put("km", String.valueOf(collectionView.getCurrentKm())); 321 attr.put("km", String.valueOf(this.collectionView.getCurrentKm()));
342 322
343 return attr; 323 return attr;
344 } 324 }
345 325
346 /** In contrast to supers implementation, include the currently selected 326 /**
347 * km in the url. */ 327 * In contrast to supers implementation, include the currently selected
348 @Override 328 * km in the url.
349 public String getExportUrl(int width, int height, String format) { 329 */
330 @Override
331 public String getExportUrl(final int width, final int height, final String format) {
350 String url = super.getExportUrl(width, height, format); 332 String url = super.getExportUrl(width, height, format);
351 if (collectionView.getCurrentKm() != -1) { 333 if (this.collectionView.getCurrentKm() != -1) {
352 url += "&currentKm=" + collectionView.getCurrentKm(); 334 url += "&currentKm=" + this.collectionView.getCurrentKm();
353 } 335 }
354 return url; 336 return url;
355 } 337 }
356 } 338 }
357 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 339 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org