Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/map/DrawControl.java @ 800:95cc560ce7c4
Added map controls for digitizing and removing barriers.
flys-client/trunk@2321 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 12 Jul 2011 13:43:49 +0000 |
parents | |
children | d02c3835df28 |
comparison
equal
deleted
inserted
replaced
799:f4299b90c996 | 800:95cc560ce7c4 |
---|---|
1 package de.intevation.flys.client.client.ui.map; | |
2 | |
3 import java.util.LinkedHashMap; | |
4 | |
5 import com.google.gwt.core.client.GWT; | |
6 | |
7 import com.smartgwt.client.types.SelectionType; | |
8 import com.smartgwt.client.widgets.ImgButton; | |
9 import com.smartgwt.client.widgets.events.ClickEvent; | |
10 import com.smartgwt.client.widgets.events.ClickHandler; | |
11 import com.smartgwt.client.widgets.form.DynamicForm; | |
12 import com.smartgwt.client.widgets.form.fields.SelectItem; | |
13 import com.smartgwt.client.widgets.form.fields.FormItem; | |
14 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; | |
15 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; | |
16 import com.smartgwt.client.widgets.layout.HLayout; | |
17 | |
18 import org.gwtopenmaps.openlayers.client.Map; | |
19 import org.gwtopenmaps.openlayers.client.control.Control; | |
20 import org.gwtopenmaps.openlayers.client.control.DrawFeature; | |
21 import org.gwtopenmaps.openlayers.client.handler.Handler; | |
22 import org.gwtopenmaps.openlayers.client.handler.PathHandler; | |
23 import org.gwtopenmaps.openlayers.client.handler.PolygonHandler; | |
24 import org.gwtopenmaps.openlayers.client.layer.Vector; | |
25 | |
26 import de.intevation.flys.client.client.FLYSConstants; | |
27 import de.intevation.flys.client.client.utils.EnableDisableCmd; | |
28 | |
29 | |
30 public class DrawControl extends HLayout { | |
31 | |
32 public static final String BARRIER_PIPE1 = "pipe1"; | |
33 public static final String BARRIER_PIPE2 = "pipe2"; | |
34 public static final String BARRIER_DITCH = "ditch"; | |
35 public static final String BARRIER_DAM = "dam"; | |
36 public static final String BARRIER_RINGDIKE = "ring_dike"; | |
37 | |
38 public static final String FIELD_BARRIER_TYPE = "field_barrier_type"; | |
39 | |
40 | |
41 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
42 | |
43 protected EnableDisableCmd cmd; | |
44 | |
45 protected ImgButton button; | |
46 protected DynamicForm form; | |
47 | |
48 protected Map map; | |
49 protected Vector layer; | |
50 | |
51 protected Control control; | |
52 | |
53 | |
54 public DrawControl(Map map, Vector layer, EnableDisableCmd cmd) { | |
55 this.map = map; | |
56 this.layer = layer; | |
57 this.cmd = cmd; | |
58 | |
59 initialize(); | |
60 } | |
61 | |
62 | |
63 protected void initialize() { | |
64 setWidth(100); | |
65 setMembersMargin(0); | |
66 | |
67 button = new ImgButton(); | |
68 | |
69 String baseUrl = GWT.getHostPageBaseURL(); | |
70 button.setSrc(baseUrl + MSG.digitize()); | |
71 button.setActionType(SelectionType.CHECKBOX); | |
72 button.setSize(20); | |
73 button.setShowRollOver(false); | |
74 button.setSelected(false); | |
75 | |
76 button.addClickHandler(new ClickHandler() { | |
77 public void onClick(ClickEvent e) { | |
78 if (button.isSelected()) { | |
79 cmd.enable(); | |
80 } | |
81 else { | |
82 cmd.disable(); | |
83 } | |
84 } | |
85 }); | |
86 | |
87 form = new DynamicForm(); | |
88 form.setWidth(75); | |
89 form.setTitlePrefix(""); | |
90 form.setTitleSuffix(""); | |
91 | |
92 LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(); | |
93 map.put(BARRIER_PIPE1, MSG.getString(BARRIER_PIPE1)); | |
94 map.put(BARRIER_PIPE2, MSG.getString(BARRIER_PIPE2)); | |
95 map.put(BARRIER_DITCH, MSG.getString(BARRIER_DITCH)); | |
96 map.put(BARRIER_DAM, MSG.getString(BARRIER_DAM)); | |
97 map.put(BARRIER_RINGDIKE, MSG.getString(BARRIER_RINGDIKE)); | |
98 | |
99 SelectItem box = new SelectItem(FIELD_BARRIER_TYPE); | |
100 box.setTitle(""); | |
101 box.setWidth(75); | |
102 box.setValueMap(map); | |
103 box.addChangedHandler(new ChangedHandler() { | |
104 public void onChanged(ChangedEvent e) { | |
105 setSelectedControl(); | |
106 } | |
107 }); | |
108 | |
109 form.setFields(box); | |
110 | |
111 addMember(button); | |
112 addMember(form); | |
113 | |
114 activate(false); | |
115 } | |
116 | |
117 | |
118 protected String getSelectedType() { | |
119 return form.getValueAsString(FIELD_BARRIER_TYPE); | |
120 } | |
121 | |
122 | |
123 protected void removeControl() { | |
124 if (control != null) { | |
125 control.deactivate(); | |
126 map.removeControl(control); | |
127 } | |
128 } | |
129 | |
130 | |
131 protected void setSelectedControl() { | |
132 removeControl(); | |
133 | |
134 String type = getSelectedType(); | |
135 | |
136 if (type == null || type.length() == 0) { | |
137 return; | |
138 } | |
139 | |
140 if (type.equalsIgnoreCase(BARRIER_RINGDIKE)) { | |
141 control = createDrawPolygonControl(); | |
142 } | |
143 else { | |
144 control = createDrawLineControl(); | |
145 } | |
146 | |
147 map.addControl(control); | |
148 control.activate(); | |
149 } | |
150 | |
151 | |
152 protected Control createDrawControl(Handler handler) { | |
153 return new DrawFeature(layer, handler); | |
154 } | |
155 | |
156 | |
157 protected Control createDrawPolygonControl() { | |
158 return createDrawControl(new PolygonHandler()); | |
159 } | |
160 | |
161 | |
162 protected Control createDrawLineControl() { | |
163 return createDrawControl(new PathHandler()); | |
164 } | |
165 | |
166 | |
167 public void activate(boolean activate) { | |
168 FormItem item = form.getField(FIELD_BARRIER_TYPE); | |
169 | |
170 if (activate) { | |
171 button.select(); | |
172 item.enable(); | |
173 setSelectedControl(); | |
174 } | |
175 else { | |
176 removeControl(); | |
177 button.deselect(); | |
178 item.disable(); | |
179 } | |
180 } | |
181 } | |
182 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |