Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java @ 837:29966a53cfeb
Datacage: Use 'ids' instead of 'num' in user specific part, too.
flys-client/trunk@2553 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 24 Aug 2011 10:58:15 +0000 |
parents | dcecdd9693a8 |
children | 22dc88b17253 |
line wrap: on
line source
package de.intevation.flys.client.client.ui.map; import com.google.gwt.core.client.GWT; import com.smartgwt.client.types.SelectionType; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.ImgButton; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.layout.HLayout; import org.gwtopenmaps.openlayers.client.Map; import org.gwtopenmaps.openlayers.client.control.DragPan; import org.gwtopenmaps.openlayers.client.control.SelectFeature; import org.gwtopenmaps.openlayers.client.control.SelectFeatureOptions; import org.gwtopenmaps.openlayers.client.control.ZoomBox; import org.gwtopenmaps.openlayers.client.feature.VectorFeature; import org.gwtopenmaps.openlayers.client.layer.Vector; import org.gwtopenmaps.openlayers.client.util.Attributes; import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.client.utils.EnableDisableCmd; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class MapToolbar extends HLayout { public static final String MARK_TO_DELETE = "mark.delete"; protected FLYSConstants MSG = GWT.create(FLYSConstants.class); protected FloodMap floodMap; protected DragPan pan; protected ZoomBox zoomBox; protected SelectFeature selectFeature; protected ImgButton zoomToMaxButton; protected ImgButton zoomBoxButton; protected ImgButton zoomOutButton; protected ImgButton panButton; protected ImgButton selectButton; protected ImgButton removeButton; protected DrawControl drawControl; protected MeasureControl measureControl; protected Canvas position; public MapToolbar(FloodMap floodMap, Canvas wrapper) { this(floodMap, wrapper, true); } public MapToolbar(FloodMap floodMap, Canvas wrapper, boolean digitize) { super(); setWidth100(); setHeight(30); setMembersMargin(10); setPadding(5); setBorder("1px solid black"); this.floodMap = floodMap; Canvas spacer = new Canvas(); spacer.setWidth("*"); zoomToMaxButton = createMaxExtentControl(); zoomBoxButton = createZoomBoxControl(); zoomOutButton = createZoomOutControl(); panButton = createPanControl(); drawControl = createDrawControl(); selectButton = createSelectFeatureControl(); measureControl = createMeasureControl(); position = createMousePosition(wrapper); removeButton = createRemoveFeatureControl(); addMember(zoomToMaxButton); addMember(zoomBoxButton); addMember(zoomOutButton); addMember(panButton); if (digitize) { addMember(drawControl); addMember(selectButton); addMember(removeButton); } addMember(measureControl); addMember(spacer); addMember(position); } protected Map getMap() { return floodMap.getMap(); } protected void activatePan(boolean activate) { if (activate) { panButton.select(); pan.activate(); } else { panButton.deselect(); pan.deactivate(); } } protected void activateZoomBox(boolean activate) { if (activate) { zoomBoxButton.select(); zoomBox.activate(); } else { zoomBoxButton.deselect(); zoomBox.deactivate(); } } protected void activateDrawFeature(boolean activate) { drawControl.activate(activate); } protected void activateSelectFeature(boolean activate) { if (activate) { selectButton.select(); selectFeature.activate(); } else { selectButton.deselect(); selectFeature.deactivate(); } } protected void activateMeasureControl(boolean activate) { measureControl.activate(activate); } protected ImgButton createButton(String img, ClickHandler handler) { ImgButton btn = new ImgButton(); String baseUrl = GWT.getHostPageBaseURL(); btn.setSrc(baseUrl + img); btn.setWidth(20); btn.setHeight(20); btn.setShowDown(false); btn.setShowRollOver(false); btn.setShowDisabled(false); btn.setShowDisabledIcon(true); btn.setShowDownIcon(false); btn.setShowFocusedIcon(false); if (handler != null) { btn.addClickHandler(handler); } return btn; } protected ImgButton createToggleButton( String img, final EnableDisableCmd cmd ) { final ImgButton btn = new ImgButton(); String baseUrl = GWT.getHostPageBaseURL(); btn.setSrc(baseUrl + img); btn.setActionType(SelectionType.CHECKBOX); btn.setSize(20); btn.setShowRollOver(false); btn.setSelected(false); btn.addClickHandler(new ClickHandler() { public void onClick(ClickEvent e) { if (btn.isSelected()) { cmd.enable(); } else { cmd.disable(); } } }); return btn; } protected ImgButton createMaxExtentControl() { ImgButton zoomToMax = createButton(MSG.zoom_all(), new ClickHandler() { public void onClick(ClickEvent event) { floodMap.getMap().zoomToMaxExtent(); } }); return zoomToMax; } protected ImgButton createZoomBoxControl() { zoomBox = new ZoomBox(); EnableDisableCmd cmd = new EnableDisableCmd() { public void enable() { activateZoomBox(true); activatePan(false); activateDrawFeature(false); activateSelectFeature(false); activateMeasureControl(false); } public void disable() { activateZoomBox(false); } }; ImgButton button = createToggleButton(MSG.zoom_in(), cmd); Map map = getMap(); map.addControl(zoomBox); return button; } protected ImgButton createZoomOutControl() { ImgButton zoomOut = createButton(MSG.zoom_out(), new ClickHandler() { public void onClick(ClickEvent event) { Map map = floodMap.getMap(); int level = map.getZoom(); if (level > 1) { map.zoomTo(level-1); } } }); return zoomOut; } protected ImgButton createPanControl() { pan = new DragPan(); getMap().addControl(pan); EnableDisableCmd cmd = new EnableDisableCmd() { public void enable() { activateZoomBox(false); activatePan(true); activateDrawFeature(false); activateSelectFeature(false); activateMeasureControl(false); } public void disable() { activatePan(false); } }; final ImgButton button = createToggleButton(MSG.pan(), cmd); return button; } protected DrawControl createDrawControl() { EnableDisableCmd cmd = new EnableDisableCmd() { public void enable() { activateZoomBox(false); activatePan(false); activateDrawFeature(true); activateSelectFeature(false); activateMeasureControl(false); } public void disable() { activateDrawFeature(false); } }; return new DrawControl(getMap(), floodMap.getBarrierLayer(), cmd); } protected ImgButton createSelectFeatureControl() { SelectFeatureOptions opts = new SelectFeatureOptions(); opts.setBox(true); // VectorFeatures selected by the SelectFeature control are manually // marked with the string "mark.delete". The control to remove selected // features makes use of this string to determine if the feature should // be deleted (is marked) or not. Actually, we would like to use the // OpenLayers native mechanism to select features, but for some reason // this doesn't work here. After a feature has been selected, the layer // still has no selected features. opts.onSelect(new SelectFeature.SelectFeatureListener() { public void onFeatureSelected(VectorFeature feature) { Attributes attr = feature.getAttributes(); attr.setAttribute(MARK_TO_DELETE, 1); } }); opts.onUnSelect(new SelectFeature.UnselectFeatureListener() { public void onFeatureUnselected(VectorFeature feature) { Attributes attr = feature.getAttributes(); attr.setAttribute(MARK_TO_DELETE, 0); } }); selectFeature = new SelectFeature(floodMap.getBarrierLayer(), opts); getMap().addControl(selectFeature); EnableDisableCmd cmd = new EnableDisableCmd() { public void enable() { activateDrawFeature(false); activatePan(false); activateZoomBox(false); activateSelectFeature(true); activateMeasureControl(false); } public void disable() { activateSelectFeature(false); } }; ImgButton button = createToggleButton(MSG.selectFeature(), cmd); return button; } protected ImgButton createRemoveFeatureControl() { ImgButton remove = createButton(MSG.removeFeature(),new ClickHandler() { public void onClick(ClickEvent event) { Vector barriers = floodMap.getBarrierLayer(); VectorFeature[] features = barriers.getFeatures(); if (features == null || features.length == 0) { return; } for (int i = features.length-1; i >= 0; i--) { VectorFeature feature = features[i]; Attributes attr = feature.getAttributes(); int del = attr.getAttributeAsInt(MARK_TO_DELETE); if (del == 1) { barriers.removeFeature(feature); feature.destroy(); } } } }); return remove; } protected Canvas createMousePosition(Canvas mapWrapper) { return new MapPositionPanel(floodMap.getMapWidget(), mapWrapper); } protected MeasureControl createMeasureControl() { EnableDisableCmd cmd = new EnableDisableCmd() { public void enable() { activateDrawFeature(false); activatePan(false); activateZoomBox(false); activateSelectFeature(false); } public void disable() { // do nothing } }; return new MeasureControl(floodMap, cmd); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :