Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapToolbar.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapToolbar.java@821a02bbfb4e |
children | a3cd78333185 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.client.client.ui.map; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 | |
5 import com.smartgwt.client.types.Alignment; | |
6 import com.smartgwt.client.types.SelectionType; | |
7 import com.smartgwt.client.util.SC; | |
8 import com.smartgwt.client.widgets.Button; | |
9 import com.smartgwt.client.widgets.Canvas; | |
10 import com.smartgwt.client.widgets.ImgButton; | |
11 import com.smartgwt.client.widgets.Label; | |
12 import com.smartgwt.client.widgets.events.ClickEvent; | |
13 import com.smartgwt.client.widgets.events.ClickHandler; | |
14 import com.smartgwt.client.widgets.layout.HLayout; | |
15 | |
16 import org.dive4elements.river.client.client.FLYSConstants; | |
17 import org.dive4elements.river.client.client.ui.ImgLink; | |
18 import org.dive4elements.river.client.client.ui.Toolbar; | |
19 import org.dive4elements.river.client.client.utils.EnableDisableCmd; | |
20 import org.dive4elements.river.client.shared.model.Collection; | |
21 import org.dive4elements.river.client.shared.model.Property; | |
22 import org.dive4elements.river.client.shared.model.PropertySetting; | |
23 import org.dive4elements.river.client.shared.model.Settings; | |
24 import org.dive4elements.river.client.shared.model.ThemeList; | |
25 | |
26 import java.util.List; | |
27 | |
28 import org.gwtopenmaps.openlayers.client.Map; | |
29 import org.gwtopenmaps.openlayers.client.control.DragPan; | |
30 import org.gwtopenmaps.openlayers.client.control.SelectFeature; | |
31 import org.gwtopenmaps.openlayers.client.control.SelectFeatureOptions; | |
32 import org.gwtopenmaps.openlayers.client.control.ZoomBox; | |
33 import org.gwtopenmaps.openlayers.client.event.MapZoomListener; | |
34 import org.gwtopenmaps.openlayers.client.feature.VectorFeature; | |
35 import org.gwtopenmaps.openlayers.client.layer.Vector; | |
36 import org.gwtopenmaps.openlayers.client.util.Attributes; | |
37 | |
38 | |
39 /** | |
40 * Toolbar for the Map views. | |
41 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
42 */ | |
43 public class MapToolbar | |
44 extends Toolbar | |
45 implements MapZoomListener | |
46 { | |
47 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
48 | |
49 protected FloodMap floodMap; | |
50 protected DragPan pan; | |
51 protected ZoomBox zoomBox; | |
52 protected SelectFeature selectFeature; | |
53 protected GetFeatureInfo getFeatureInfo; | |
54 | |
55 protected Button manageThemesButton; | |
56 protected Button datacageButton; | |
57 protected Button legendButton; | |
58 | |
59 protected ImgButton addWMSButton; | |
60 protected ImgButton zoomToMaxButton; | |
61 protected ImgButton zoomBoxButton; | |
62 protected ImgButton zoomOutButton; | |
63 protected ImgButton panButton; | |
64 protected ImgButton selectButton; | |
65 protected ImgButton infoButton; | |
66 protected ImgButton removeButton; | |
67 protected ImgButton elevationButton; | |
68 protected ImgButton printMap; | |
69 | |
70 protected Label epsgLabel; | |
71 | |
72 protected DrawControl drawControl; | |
73 protected MeasureControl measureControl; | |
74 | |
75 protected LegendWindow legendWindow; | |
76 | |
77 protected Canvas position; | |
78 | |
79 | |
80 public MapToolbar(FloodMap floodMap, boolean digitize) { | |
81 this(null, floodMap, digitize); | |
82 } | |
83 | |
84 | |
85 public MapToolbar( | |
86 MapOutputTab mapTab, | |
87 FloodMap floodMap, | |
88 boolean digitize) | |
89 { | |
90 super(mapTab); | |
91 | |
92 setWidth100(); | |
93 setHeight(38); | |
94 setMembersMargin(10); | |
95 setPadding(5); | |
96 setBorder("1px solid black"); | |
97 this.floodMap = floodMap; | |
98 | |
99 zoomToMaxButton = createMaxExtentControl(); | |
100 zoomBoxButton = createZoomBoxControl(); | |
101 zoomOutButton = createZoomOutControl(); | |
102 panButton = createPanControl(); | |
103 drawControl = createDrawControl(); | |
104 selectButton = createSelectFeatureControl(); | |
105 infoButton = createGetFeatureInfo(); | |
106 measureControl = createMeasureControl(); | |
107 position = createMousePosition(); | |
108 removeButton = createRemoveFeatureControl(); | |
109 elevationButton = createElevationControl(); | |
110 epsgLabel = createEPSGLabel(); | |
111 | |
112 if (mapTab != null) { | |
113 manageThemesButton = createManageThemesControl(); | |
114 addMember(manageThemesButton); | |
115 | |
116 datacageButton = createDatacageControl(); | |
117 addMember(datacageButton); | |
118 | |
119 legendButton = createLegendControl(); | |
120 addMember(legendButton); | |
121 | |
122 addWMSButton = createWMSControl(); | |
123 addMember(addWMSButton); | |
124 | |
125 printMap = createMapPrintControl(); | |
126 addMember(printMap); | |
127 } | |
128 | |
129 addMember(zoomToMaxButton); | |
130 addMember(zoomBoxButton); | |
131 addMember(zoomOutButton); | |
132 addMember(panButton); | |
133 | |
134 if (digitize) { | |
135 addMember(drawControl); | |
136 addMember(selectButton); | |
137 addMember(removeButton); | |
138 addMember(elevationButton); | |
139 } | |
140 | |
141 if (infoButton != null) { | |
142 addMember(infoButton); | |
143 } | |
144 | |
145 addMember(measureControl); | |
146 addMember(createRightPanel()); | |
147 } | |
148 | |
149 | |
150 protected HLayout createRightPanel() { | |
151 HLayout right = new HLayout(); | |
152 right.setAlign(Alignment.RIGHT); | |
153 | |
154 right.addMember(epsgLabel); | |
155 right.addMember(position); | |
156 | |
157 return right; | |
158 } | |
159 | |
160 | |
161 protected Map getMap() { | |
162 return floodMap.getMap(); | |
163 } | |
164 | |
165 | |
166 protected void activatePan(boolean activate) { | |
167 if (activate) { | |
168 panButton.select(); | |
169 pan.activate(); | |
170 } | |
171 else { | |
172 panButton.deselect(); | |
173 pan.deactivate(); | |
174 } | |
175 } | |
176 | |
177 | |
178 protected void activateZoomBox(boolean activate) { | |
179 if (activate) { | |
180 zoomBoxButton.select(); | |
181 zoomBox.activate(); | |
182 } | |
183 else { | |
184 zoomBoxButton.deselect(); | |
185 zoomBox.deactivate(); | |
186 } | |
187 } | |
188 | |
189 | |
190 public void activateDrawFeature(boolean activate) { | |
191 drawControl.activate(activate); | |
192 } | |
193 | |
194 | |
195 protected void activateSelectFeature(boolean activate) { | |
196 if (activate) { | |
197 selectButton.select(); | |
198 selectFeature.activate(); | |
199 } | |
200 else { | |
201 selectButton.deselect(); | |
202 selectFeature.deactivate(); | |
203 } | |
204 } | |
205 | |
206 | |
207 protected void activateMeasureControl(boolean activate) { | |
208 measureControl.activate(activate); | |
209 } | |
210 | |
211 | |
212 protected void activateGetFeatureInfo(boolean activate) { | |
213 if (infoButton == null) { | |
214 return; | |
215 } | |
216 | |
217 if (activate) { | |
218 infoButton.select(); | |
219 } | |
220 else { | |
221 infoButton.deselect(); | |
222 } | |
223 | |
224 getFeatureInfo.activate(activate); | |
225 } | |
226 | |
227 | |
228 protected ImgButton createButton(String img, ClickHandler handler) { | |
229 ImgButton btn = new ImgButton(); | |
230 | |
231 String baseUrl = GWT.getHostPageBaseURL(); | |
232 btn.setSrc(baseUrl + img); | |
233 btn.setWidth(20); | |
234 btn.setHeight(20); | |
235 btn.setShowDown(false); | |
236 btn.setShowRollOver(false); | |
237 btn.setShowRollOverIcon(false); | |
238 btn.setShowDisabled(false); | |
239 btn.setShowDisabledIcon(true); | |
240 btn.setShowDownIcon(false); | |
241 btn.setShowFocusedIcon(false); | |
242 | |
243 if (handler != null) { | |
244 btn.addClickHandler(handler); | |
245 } | |
246 | |
247 return btn; | |
248 } | |
249 | |
250 | |
251 protected ImgButton createToggleButton( | |
252 String img, | |
253 final EnableDisableCmd cmd | |
254 ) { | |
255 final ImgButton btn = new ImgButton(); | |
256 | |
257 String baseUrl = GWT.getHostPageBaseURL(); | |
258 btn.setSrc(baseUrl + img); | |
259 btn.setActionType(SelectionType.CHECKBOX); | |
260 btn.setSize(20); | |
261 btn.setShowRollOver(false); | |
262 btn.setShowRollOverIcon(false); | |
263 btn.setSelected(false); | |
264 btn.addClickHandler(new ClickHandler() { | |
265 @Override | |
266 public void onClick(ClickEvent e) { | |
267 if (btn.isSelected()) { | |
268 cmd.enable(); | |
269 } | |
270 else { | |
271 cmd.disable(); | |
272 } | |
273 } | |
274 }); | |
275 | |
276 return btn; | |
277 } | |
278 | |
279 | |
280 protected ImgButton createMaxExtentControl() { | |
281 ImgButton zoomToMax = createButton(MSG.zoom_all(), new ClickHandler() { | |
282 @Override | |
283 public void onClick(ClickEvent event) { | |
284 floodMap.getMap().zoomToMaxExtent(); | |
285 } | |
286 }); | |
287 | |
288 zoomToMax.setTooltip(MSG.zoomMaxExtent()); | |
289 | |
290 return zoomToMax; | |
291 } | |
292 | |
293 | |
294 protected ImgButton createZoomBoxControl() { | |
295 zoomBox = new ZoomBox(); | |
296 | |
297 EnableDisableCmd cmd = new EnableDisableCmd() { | |
298 @Override | |
299 public void enable() { | |
300 activatePan(false); | |
301 activateDrawFeature(false); | |
302 activateSelectFeature(false); | |
303 activateMeasureControl(false); | |
304 activateGetFeatureInfo(false); | |
305 activateZoomBox(true); | |
306 } | |
307 | |
308 @Override | |
309 public void disable() { | |
310 activateZoomBox(false); | |
311 } | |
312 }; | |
313 | |
314 ImgButton button = createToggleButton(MSG.zoom_in(), cmd); | |
315 button.setTooltip(MSG.zoomIn()); | |
316 | |
317 Map map = getMap(); | |
318 map.addControl(zoomBox); | |
319 | |
320 return button; | |
321 } | |
322 | |
323 | |
324 protected ImgButton createZoomOutControl() { | |
325 ImgButton zoomOut = createButton(MSG.zoom_out(), new ClickHandler() { | |
326 @Override | |
327 public void onClick(ClickEvent event) { | |
328 Map map = floodMap.getMap(); | |
329 int level = map.getZoom(); | |
330 | |
331 if (level > 1) { | |
332 map.zoomTo(level-1); | |
333 } | |
334 } | |
335 }); | |
336 | |
337 zoomOut.setTooltip(MSG.zoomOut()); | |
338 | |
339 return zoomOut; | |
340 } | |
341 | |
342 | |
343 protected ImgButton createPanControl() { | |
344 pan = new DragPan(); | |
345 getMap().addControl(pan); | |
346 | |
347 EnableDisableCmd cmd = new EnableDisableCmd() { | |
348 @Override | |
349 public void enable() { | |
350 activateZoomBox(false); | |
351 activateDrawFeature(false); | |
352 activateSelectFeature(false); | |
353 activateMeasureControl(false); | |
354 activateGetFeatureInfo(false); | |
355 activatePan(true); | |
356 } | |
357 | |
358 @Override | |
359 public void disable() { | |
360 activatePan(false); | |
361 } | |
362 }; | |
363 | |
364 final ImgButton button = createToggleButton(MSG.pan(), cmd); | |
365 button.setTooltip(MSG.moveMap()); | |
366 | |
367 return button; | |
368 } | |
369 | |
370 | |
371 protected DrawControl createDrawControl() { | |
372 EnableDisableCmd cmd = new EnableDisableCmd() { | |
373 @Override | |
374 public void enable() { | |
375 activateZoomBox(false); | |
376 activatePan(false); | |
377 activateDrawFeature(true); | |
378 activateSelectFeature(false); | |
379 activateMeasureControl(false); | |
380 } | |
381 | |
382 @Override | |
383 public void disable() { | |
384 activateDrawFeature(false); | |
385 } | |
386 }; | |
387 return new DrawControl(getMap(), floodMap.getBarrierLayer(), cmd); | |
388 } | |
389 | |
390 | |
391 protected ImgButton createSelectFeatureControl() { | |
392 SelectFeatureOptions opts = new SelectFeatureOptions(); | |
393 opts.setBox(true); | |
394 | |
395 // VectorFeatures selected by the SelectFeature control are manually | |
396 // marked with the string "mark.delete". The control to remove selected | |
397 // features makes use of this string to determine if the feature should | |
398 // be deleted (is marked) or not. Actually, we would like to use the | |
399 // OpenLayers native mechanism to select features, but for some reason | |
400 // this doesn't work here. After a feature has been selected, the layer | |
401 // still has no selected features. | |
402 opts.onSelect(new SelectFeature.SelectFeatureListener() { | |
403 @Override | |
404 public void onFeatureSelected(VectorFeature feature) { | |
405 floodMap.selectFeature(feature); | |
406 } | |
407 }); | |
408 | |
409 opts.onUnSelect(new SelectFeature.UnselectFeatureListener() { | |
410 @Override | |
411 public void onFeatureUnselected(VectorFeature feature) { | |
412 floodMap.disableFeature(feature); | |
413 } | |
414 }); | |
415 | |
416 selectFeature = new SelectFeature(floodMap.getBarrierLayer(), opts); | |
417 getMap().addControl(selectFeature); | |
418 | |
419 EnableDisableCmd cmd = new EnableDisableCmd() { | |
420 @Override | |
421 public void enable() { | |
422 activateDrawFeature(false); | |
423 activatePan(false); | |
424 activateZoomBox(false); | |
425 activateSelectFeature(true); | |
426 activateMeasureControl(false); | |
427 } | |
428 | |
429 @Override | |
430 public void disable() { | |
431 activateSelectFeature(false); | |
432 floodMap.disableFeatures(); | |
433 } | |
434 }; | |
435 | |
436 ImgButton button = createToggleButton(MSG.selectFeature(), cmd); | |
437 button.setTooltip(MSG.selectObject()); | |
438 | |
439 return button; | |
440 } | |
441 | |
442 | |
443 protected ImgButton createRemoveFeatureControl() { | |
444 ImgButton remove = createButton(MSG.removeFeature(),new ClickHandler() { | |
445 @Override | |
446 public void onClick(ClickEvent event) { | |
447 Vector barriers = floodMap.getBarrierLayer(); | |
448 VectorFeature[] features = barriers.getFeatures(); | |
449 | |
450 if (features == null || features.length == 0) { | |
451 return; | |
452 } | |
453 | |
454 for (int i = features.length-1; i >= 0; i--) { | |
455 VectorFeature feature = features[i]; | |
456 | |
457 Attributes attr = feature.getAttributes(); | |
458 int del = attr.getAttributeAsInt(FloodMap.MARK_SELECTED); | |
459 | |
460 if (del == 1) { | |
461 barriers.removeFeature(feature); | |
462 feature.destroy(); | |
463 } | |
464 } | |
465 } | |
466 }); | |
467 | |
468 remove.setTooltip(MSG.removeObject()); | |
469 | |
470 return remove; | |
471 } | |
472 | |
473 | |
474 protected ImgButton createElevationControl() { | |
475 ImgButton btn = createButton(MSG.adjustElevation(), new ClickHandler() { | |
476 @Override | |
477 public void onClick(ClickEvent evt) { | |
478 Vector barriers = floodMap.getBarrierLayer(); | |
479 VectorFeature[] features = barriers.getFeatures(); | |
480 | |
481 VectorFeature feature = null; | |
482 | |
483 if (features == null || features.length == 0) { | |
484 SC.warn(MSG.error_no_feature_selected()); | |
485 return; | |
486 } | |
487 | |
488 boolean multipleFeatures = false; | |
489 | |
490 for (VectorFeature f: features) { | |
491 Attributes attr = f.getAttributes(); | |
492 if (attr.getAttributeAsInt(FloodMap.MARK_SELECTED) == 1) { | |
493 if (feature == null) { | |
494 feature = f; | |
495 } | |
496 else { | |
497 multipleFeatures = true; | |
498 } | |
499 } | |
500 } | |
501 | |
502 if (feature == null) { | |
503 SC.warn(MSG.error_no_feature_selected()); | |
504 return; | |
505 } | |
506 | |
507 new ElevationWindow(floodMap, feature).show(); | |
508 | |
509 if (multipleFeatures) { | |
510 SC.warn(MSG.warning_use_first_feature()); | |
511 } | |
512 } | |
513 }); | |
514 | |
515 btn.setTooltip(MSG.adjustElevationTooltip()); | |
516 | |
517 return btn; | |
518 } | |
519 | |
520 | |
521 protected Canvas createMousePosition() { | |
522 return new MapPositionPanel(floodMap.getMapWidget()); | |
523 } | |
524 | |
525 | |
526 protected MeasureControl createMeasureControl() { | |
527 EnableDisableCmd cmd = new EnableDisableCmd() { | |
528 @Override | |
529 public void enable() { | |
530 activateDrawFeature(false); | |
531 activatePan(false); | |
532 activateZoomBox(false); | |
533 activateSelectFeature(false); | |
534 activateGetFeatureInfo(false); | |
535 } | |
536 | |
537 @Override | |
538 public void disable() { | |
539 // do nothing | |
540 } | |
541 }; | |
542 | |
543 return new MeasureControl(floodMap, cmd); | |
544 } | |
545 | |
546 | |
547 protected Button createDatacageControl() { | |
548 Button btn = new Button(MSG.databasket()); | |
549 btn.addClickHandler(new ClickHandler() { | |
550 @Override | |
551 public void onClick(ClickEvent evt) { | |
552 openDatacageWindow((MapOutputTab) getOutputTab()); | |
553 } | |
554 }); | |
555 | |
556 return btn; | |
557 } | |
558 | |
559 | |
560 protected Button createLegendControl() { | |
561 Button btn = new Button(MSG.legend()); | |
562 btn.addClickHandler(new ClickHandler() { | |
563 @Override | |
564 public void onClick(ClickEvent event) { | |
565 openLegendWindow(); | |
566 } | |
567 }); | |
568 | |
569 return btn; | |
570 } | |
571 | |
572 | |
573 protected void openLegendWindow() { | |
574 if (legendWindow == null) { | |
575 MapOutputTab tab = (MapOutputTab) getOutputTab(); | |
576 legendWindow = new LegendWindow(tab.getThemePanel().getThemeList()); | |
577 } | |
578 | |
579 legendWindow.show(); | |
580 } | |
581 | |
582 | |
583 protected ImgButton createGetFeatureInfo() { | |
584 MapOutputTab ot = (MapOutputTab) getOutputTab(); | |
585 if (ot == null) { | |
586 return null; | |
587 } | |
588 | |
589 //ThemeList tl = ot.getCollection().getThemeList("floodmap"); | |
590 | |
591 getFeatureInfo = new GetFeatureInfo( | |
592 getMap(), | |
593 ot.getThemePanel(), | |
594 "gml"); | |
595 | |
596 EnableDisableCmd cmd = new EnableDisableCmd() { | |
597 @Override | |
598 public void enable() { | |
599 activateDrawFeature(false); | |
600 activatePan(false); | |
601 activateZoomBox(false); | |
602 activateSelectFeature(false); | |
603 activateMeasureControl(false); | |
604 activateGetFeatureInfo(true); | |
605 } | |
606 | |
607 @Override | |
608 public void disable() { | |
609 activateGetFeatureInfo(false); | |
610 } | |
611 }; | |
612 | |
613 ImgButton button = createToggleButton(MSG.getFeatureInfo(), cmd); | |
614 button.setTooltip(MSG.getFeatureInfoTooltip()); | |
615 | |
616 return button; | |
617 } | |
618 | |
619 | |
620 protected Button createManageThemesControl() { | |
621 Button btn = new Button(MSG.manageThemes()); | |
622 btn.addClickHandler(new ClickHandler() { | |
623 | |
624 @Override | |
625 public void onClick(ClickEvent event) { | |
626 ((MapOutputTab)getOutputTab()).toogleThemePanel(); | |
627 } | |
628 }); | |
629 return btn; | |
630 } | |
631 | |
632 | |
633 protected ImgButton createMapPrintControl() { | |
634 final MapToolbar mtb = this; | |
635 ImgButton btn = createButton(MSG.printMapSettings(), new ClickHandler() { | |
636 @Override | |
637 public void onClick(ClickEvent event) { | |
638 MapPrintWindow mpsw = | |
639 new MapPrintWindow(outputTab.getCollection(), mtb); | |
640 outputTab.getCollectionView().addChild(mpsw); | |
641 } | |
642 }); | |
643 btn.setTooltip(MSG.printTooltip()); | |
644 | |
645 return btn; | |
646 } | |
647 | |
648 | |
649 protected ImgButton createWMSControl() { | |
650 final String srs = floodMap.getRiverProjection(); | |
651 | |
652 ImgButton add = createButton(MSG.addWMS(), new ClickHandler() { | |
653 @Override | |
654 public void onClick(ClickEvent event) { | |
655 MapOutputTab ot = (MapOutputTab) getOutputTab(); | |
656 new ExternalWMSWindow(ot, srs).start(); | |
657 } | |
658 }); | |
659 | |
660 add.setTooltip(MSG.addWMSTooltip()); | |
661 | |
662 return add; | |
663 } | |
664 | |
665 | |
666 protected Label createEPSGLabel() { | |
667 Label epsgLabel = new Label(floodMap.getRiverProjection()); | |
668 | |
669 epsgLabel.setAlign(Alignment.RIGHT); | |
670 epsgLabel.setWidth(75); | |
671 | |
672 return epsgLabel; | |
673 } | |
674 | |
675 @Override | |
676 public void onMapZoom(MapZoomListener.MapZoomEvent e) { | |
677 // updatePrintUrl(); | |
678 } | |
679 | |
680 public void updateThemes(ThemeList themeList) { | |
681 if (legendWindow != null) { | |
682 legendWindow.update(themeList); | |
683 } | |
684 } | |
685 } | |
686 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |