Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/DrawControl.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/map/DrawControl.java@80e8ef91223c |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client.ui.map; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 import com.smartgwt.client.types.SelectionType; | |
5 import com.smartgwt.client.widgets.ImgButton; | |
6 import com.smartgwt.client.widgets.events.ClickEvent; | |
7 import com.smartgwt.client.widgets.events.ClickHandler; | |
8 import com.smartgwt.client.widgets.form.DynamicForm; | |
9 import com.smartgwt.client.widgets.form.fields.FormItem; | |
10 import com.smartgwt.client.widgets.form.fields.SelectItem; | |
11 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; | |
12 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; | |
13 import com.smartgwt.client.widgets.layout.HLayout; | |
14 | |
15 import de.intevation.flys.client.client.FLYSConstants; | |
16 import de.intevation.flys.client.client.utils.EnableDisableCmd; | |
17 | |
18 import java.util.LinkedHashMap; | |
19 | |
20 import org.gwtopenmaps.openlayers.client.Map; | |
21 import org.gwtopenmaps.openlayers.client.Style; | |
22 import org.gwtopenmaps.openlayers.client.control.Control; | |
23 import org.gwtopenmaps.openlayers.client.control.DrawFeature; | |
24 import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener; | |
25 import org.gwtopenmaps.openlayers.client.feature.VectorFeature; | |
26 import org.gwtopenmaps.openlayers.client.handler.Handler; | |
27 import org.gwtopenmaps.openlayers.client.handler.PathHandler; | |
28 import org.gwtopenmaps.openlayers.client.handler.PolygonHandler; | |
29 import org.gwtopenmaps.openlayers.client.layer.Vector; | |
30 import org.gwtopenmaps.openlayers.client.util.Attributes; | |
31 | |
32 /** | |
33 * Widget that handles the drawing of pipes and dikes in the DigitizePanel (MapPanel). | |
34 */ | |
35 public class DrawControl extends HLayout implements VectorFeatureAddedListener { | |
36 | |
37 public static final String BARRIER_PIPE1 = "pipe1"; | |
38 public static final String BARRIER_PIPE2 = "pipe2"; | |
39 public static final String BARRIER_DITCH = "ditch"; | |
40 public static final String BARRIER_DAM = "dam"; | |
41 public static final String BARRIER_RINGDIKE = "ring_dike"; | |
42 | |
43 // FIXME: i18n | |
44 public static final String BARRIER_PIPE1_VALUE = "Rohr 1"; | |
45 public static final String BARRIER_PIPE2_VALUE = "Rohr 2"; | |
46 public static final String BARRIER_DITCH_VALUE = "Graben"; | |
47 public static final String BARRIER_DAM_VALUE = "Damm"; | |
48 public static final String BARRIER_RINGDIKE_VALUE = "Ringdeich"; | |
49 | |
50 public static final String FIELD_BARRIER_TYPE = "field_barrier_type"; | |
51 | |
52 | |
53 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
54 | |
55 protected EnableDisableCmd cmd; | |
56 | |
57 protected ImgButton button; | |
58 protected DynamicForm form; | |
59 | |
60 protected Map map; | |
61 protected Vector layer; | |
62 | |
63 protected Control control; | |
64 | |
65 | |
66 public DrawControl(Map map, Vector layer, EnableDisableCmd cmd) { | |
67 this.map = map; | |
68 this.layer = layer; | |
69 this.cmd = cmd; | |
70 | |
71 initialize(); | |
72 } | |
73 | |
74 | |
75 protected void initialize() { | |
76 setWidth(100); | |
77 setMembersMargin(0); | |
78 | |
79 button = new ImgButton(); | |
80 | |
81 final String baseUrl = GWT.getHostPageBaseURL(); | |
82 button.setSrc(baseUrl + MSG.digitize()); | |
83 button.setActionType(SelectionType.CHECKBOX); | |
84 button.setSize(20); | |
85 button.setShowRollOver(false); | |
86 button.setSelected(false); | |
87 button.setTooltip(MSG.digitizeObjects()); | |
88 | |
89 button.addClickHandler(new ClickHandler() { | |
90 @Override | |
91 public void onClick(ClickEvent e) { | |
92 if (button.isSelected()) { | |
93 cmd.enable(); | |
94 } | |
95 else { | |
96 cmd.disable(); | |
97 } | |
98 } | |
99 }); | |
100 | |
101 form = new DynamicForm(); | |
102 form.setWidth(100); | |
103 form.setTitlePrefix(""); | |
104 form.setTitleSuffix(""); | |
105 | |
106 final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(); | |
107 map.put(BARRIER_PIPE1, MSG.getString(BARRIER_PIPE1)); | |
108 map.put(BARRIER_PIPE2, MSG.getString(BARRIER_PIPE2)); | |
109 map.put(BARRIER_DITCH, MSG.getString(BARRIER_DITCH)); | |
110 map.put(BARRIER_DAM, MSG.getString(BARRIER_DAM)); | |
111 map.put(BARRIER_RINGDIKE, MSG.getString(BARRIER_RINGDIKE)); | |
112 | |
113 final LinkedHashMap<String, String> ics = new LinkedHashMap<String, String>(); | |
114 ics.put(BARRIER_PIPE1, BARRIER_PIPE1); | |
115 ics.put(BARRIER_PIPE2, BARRIER_PIPE2); | |
116 ics.put(BARRIER_DITCH, BARRIER_DITCH); | |
117 ics.put(BARRIER_DAM, BARRIER_DAM); | |
118 ics.put(BARRIER_RINGDIKE, BARRIER_RINGDIKE); | |
119 | |
120 final SelectItem box = new SelectItem(FIELD_BARRIER_TYPE); | |
121 box.setTitle(""); | |
122 box.setWidth(100); | |
123 box.setValueMap(map); | |
124 box.setImageURLSuffix(".png"); | |
125 box.setValueIcons(ics); | |
126 | |
127 box.addChangedHandler(new ChangedHandler() { | |
128 @Override | |
129 public void onChanged(ChangedEvent e) { | |
130 setSelectedControl(); | |
131 } | |
132 }); | |
133 | |
134 form.setFields(box); | |
135 | |
136 addMember(button); | |
137 addMember(form); | |
138 | |
139 layer.addVectorFeatureAddedListener(this); | |
140 | |
141 activate(false); | |
142 } | |
143 | |
144 | |
145 protected String getSelectedType() { | |
146 return form.getValueAsString(FIELD_BARRIER_TYPE); | |
147 } | |
148 | |
149 | |
150 @Override | |
151 public void onFeatureAdded(FeatureAddedEvent evt) { | |
152 setCurrentType(evt.getVectorFeature()); | |
153 } | |
154 | |
155 | |
156 protected void setCurrentType(VectorFeature feature) { | |
157 final Attributes attrs = feature.getAttributes(); | |
158 String type = attrs.getAttributeAsString("typ"); | |
159 | |
160 if (type == null || type.length() == 0) { | |
161 type = getSelectedType(); | |
162 | |
163 final Style style = FloodMap.getStyle(type); | |
164 if (style != null) { | |
165 feature.setStyle(style); | |
166 } | |
167 | |
168 if (type.equals(BARRIER_PIPE1)) { | |
169 attrs.setAttribute("typ", BARRIER_PIPE1_VALUE); | |
170 } | |
171 else if (type.equals(BARRIER_PIPE2)) { | |
172 attrs.setAttribute("typ", BARRIER_PIPE2_VALUE); | |
173 } | |
174 else if (type.equals(BARRIER_DAM)) { | |
175 attrs.setAttribute("typ", BARRIER_DAM_VALUE); | |
176 } | |
177 else if (type.equals(BARRIER_DITCH)) { | |
178 attrs.setAttribute("typ", BARRIER_DITCH_VALUE); | |
179 } | |
180 else if (type.equals(BARRIER_RINGDIKE)) { | |
181 attrs.setAttribute("typ", BARRIER_RINGDIKE_VALUE); | |
182 } | |
183 | |
184 layer.redraw(); | |
185 } | |
186 } | |
187 | |
188 | |
189 protected void removeControl() { | |
190 if (control != null) { | |
191 control.deactivate(); | |
192 map.removeControl(control); | |
193 } | |
194 } | |
195 | |
196 | |
197 protected void setSelectedControl() { | |
198 removeControl(); | |
199 | |
200 final String type = getSelectedType(); | |
201 | |
202 if (type == null || type.length() == 0) { | |
203 return; | |
204 } | |
205 | |
206 if (type.equalsIgnoreCase(BARRIER_RINGDIKE)) { | |
207 control = createDrawPolygonControl(); | |
208 } | |
209 else { | |
210 control = createDrawLineControl(); | |
211 } | |
212 | |
213 map.addControl(control); | |
214 control.activate(); | |
215 | |
216 // Make sure the barrier layer is on top; sometime it looses it z-index... | |
217 layer.setZIndex(1000); | |
218 } | |
219 | |
220 | |
221 protected Control createDrawControl(Handler handler) { | |
222 return new DrawFeature(layer, handler); | |
223 } | |
224 | |
225 | |
226 protected Control createDrawPolygonControl() { | |
227 return createDrawControl(new PolygonHandler()); | |
228 } | |
229 | |
230 | |
231 protected Control createDrawLineControl() { | |
232 return createDrawControl(new PathHandler()); | |
233 } | |
234 | |
235 | |
236 public void activate(boolean activate) { | |
237 final FormItem item = form.getField(FIELD_BARRIER_TYPE); | |
238 | |
239 if (activate) { | |
240 button.select(); | |
241 item.enable(); | |
242 setSelectedControl(); | |
243 } | |
244 else { | |
245 removeControl(); | |
246 button.deselect(); | |
247 item.disable(); | |
248 } | |
249 } | |
250 } | |
251 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |