|
1 |
/**
|
|
2 |
* gvSIG. Desktop Geographic Information System.
|
|
3 |
*
|
|
4 |
* Copyright ? 2007-2014 gvSIG Association
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or
|
|
7 |
* modify it under the terms of the GNU General Public License
|
|
8 |
* as published by the Free Software Foundation; either version 2
|
|
9 |
* of the License, or (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
19 |
* MA 02110-1301, USA.
|
|
20 |
*
|
|
21 |
* For any additional information, do not hesitate to contact us
|
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
23 |
*/
|
|
24 |
|
|
25 |
package org.gvsig.vectorediting.main;
|
|
26 |
|
|
27 |
import java.awt.BorderLayout;
|
|
28 |
import java.awt.Dimension;
|
|
29 |
import java.awt.GridLayout;
|
|
30 |
import java.awt.event.ActionEvent;
|
|
31 |
import java.io.File;
|
|
32 |
import java.util.ArrayList;
|
|
33 |
import java.util.List;
|
|
34 |
|
|
35 |
import javax.swing.AbstractAction;
|
|
36 |
import javax.swing.JButton;
|
|
37 |
import javax.swing.JFileChooser;
|
|
38 |
import javax.swing.JFrame;
|
|
39 |
import javax.swing.JMenu;
|
|
40 |
import javax.swing.JMenuBar;
|
|
41 |
import javax.swing.JMenuItem;
|
|
42 |
import javax.swing.JToolBar;
|
|
43 |
import javax.swing.SwingUtilities;
|
|
44 |
import javax.swing.WindowConstants;
|
|
45 |
|
|
46 |
import org.cresques.cts.IProjection;
|
|
47 |
import org.slf4j.Logger;
|
|
48 |
import org.slf4j.LoggerFactory;
|
|
49 |
|
|
50 |
import org.gvsig.fmap.crs.CRSFactory;
|
|
51 |
import org.gvsig.fmap.dal.DALLocator;
|
|
52 |
import org.gvsig.fmap.dal.DataManager;
|
|
53 |
import org.gvsig.fmap.dal.DataStoreParameters;
|
|
54 |
import org.gvsig.fmap.dal.exception.InitializeException;
|
|
55 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
|
|
56 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
|
|
57 |
import org.gvsig.fmap.dal.feature.FeatureStore;
|
|
58 |
import org.gvsig.fmap.geom.primitive.Envelope;
|
|
59 |
import org.gvsig.fmap.mapcontext.MapContext;
|
|
60 |
import org.gvsig.fmap.mapcontext.MapContextLocator;
|
|
61 |
import org.gvsig.fmap.mapcontext.MapContextManager;
|
|
62 |
import org.gvsig.fmap.mapcontext.ViewPort;
|
|
63 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
|
|
64 |
import org.gvsig.fmap.mapcontext.layers.FLayer;
|
|
65 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
|
|
66 |
import org.gvsig.fmap.mapcontrol.MapControl;
|
|
67 |
import org.gvsig.fmap.mapcontrol.MapControlCreationException;
|
|
68 |
import org.gvsig.fmap.mapcontrol.MapControlLocator;
|
|
69 |
import org.gvsig.fmap.mapcontrol.MapControlManager;
|
|
70 |
import org.gvsig.fmap.mapcontrol.tools.PanListenerImpl;
|
|
71 |
import org.gvsig.fmap.mapcontrol.tools.PointSelectionListener;
|
|
72 |
import org.gvsig.fmap.mapcontrol.tools.ZoomInListenerImpl;
|
|
73 |
import org.gvsig.fmap.mapcontrol.tools.ZoomOutListenerImpl;
|
|
74 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
|
|
75 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MoveBehavior;
|
|
76 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior;
|
|
77 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.RectangleBehavior;
|
|
78 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
|
|
79 |
import org.gvsig.tools.observer.Observable;
|
|
80 |
import org.gvsig.tools.observer.Observer;
|
|
81 |
import org.gvsig.tools.swing.api.ToolsSwingLocator;
|
|
82 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
|
|
83 |
import org.gvsig.utils.GenericFileFilter;
|
|
84 |
import org.gvsig.vectorediting.lib.api.EditingLocator;
|
|
85 |
import org.gvsig.vectorediting.lib.api.EditingManager;
|
|
86 |
import org.gvsig.vectorediting.lib.prov.arc.ArcEditingProviderFactory;
|
|
87 |
import org.gvsig.vectorediting.lib.prov.autopolygon.AutopolygonEditingProviderFactory;
|
|
88 |
import org.gvsig.vectorediting.lib.prov.circle3p.Circle3PEditingProviderFactory;
|
|
89 |
import org.gvsig.vectorediting.lib.prov.circle3p.Circumference3PEditingProviderFactory;
|
|
90 |
import org.gvsig.vectorediting.lib.prov.circlecr.CircleCREditingProviderFactory;
|
|
91 |
import org.gvsig.vectorediting.lib.prov.circlecr.CircumferenceCREditingProviderFactory;
|
|
92 |
import org.gvsig.vectorediting.lib.prov.duplicate.DuplicateEditingProviderFactory;
|
|
93 |
import org.gvsig.vectorediting.lib.prov.editvertex.EditVertexEditingProviderFactory;
|
|
94 |
import org.gvsig.vectorediting.lib.prov.ellipse.EllipseEditingProviderFactory;
|
|
95 |
import org.gvsig.vectorediting.lib.prov.ellipse.FilledEllipseEditingProviderFactory;
|
|
96 |
import org.gvsig.vectorediting.lib.prov.explode.ExplodeEditingProviderFactory;
|
|
97 |
import org.gvsig.vectorediting.lib.prov.extendline.ExtendLineEditingProviderFactory;
|
|
98 |
import org.gvsig.vectorediting.lib.prov.internalpolygon.InternalPolygonEditingProviderFactory;
|
|
99 |
import org.gvsig.vectorediting.lib.prov.join.JoinEditingProviderFactory;
|
|
100 |
import org.gvsig.vectorediting.lib.prov.line.LineEditingProviderFactory;
|
|
101 |
import org.gvsig.vectorediting.lib.prov.move.MoveEditingProviderFactory;
|
|
102 |
import org.gvsig.vectorediting.lib.prov.multipoint.MultipointEditingProviderFactory;
|
|
103 |
import org.gvsig.vectorediting.lib.prov.point.PointEditingProviderFactory;
|
|
104 |
import org.gvsig.vectorediting.lib.prov.polarmatrix.PolarMatrixEditingProviderFactory;
|
|
105 |
import org.gvsig.vectorediting.lib.prov.polyline.PolygonEditingProviderFactory;
|
|
106 |
import org.gvsig.vectorediting.lib.prov.polyline.PolylineEditingProviderFactory;
|
|
107 |
import org.gvsig.vectorediting.lib.prov.rectangle.FilledRectangleEditingProviderFactory;
|
|
108 |
import org.gvsig.vectorediting.lib.prov.rectangle.RectangleEditingProviderFactory;
|
|
109 |
import org.gvsig.vectorediting.lib.prov.rectangularmatrix.RectangularMatrixEditingProviderFactory;
|
|
110 |
import org.gvsig.vectorediting.lib.prov.regularpolygon.FilledRegularPolygonEditingProviderFactory;
|
|
111 |
import org.gvsig.vectorediting.lib.prov.regularpolygon.RegularPolygonEditingProviderFactory;
|
|
112 |
import org.gvsig.vectorediting.lib.prov.rotate.RotateEditingProviderFactory;
|
|
113 |
import org.gvsig.vectorediting.lib.prov.scale.ScaleEditingProviderFactory;
|
|
114 |
import org.gvsig.vectorediting.lib.prov.simplify.SimplifyEditingProviderFactory;
|
|
115 |
import org.gvsig.vectorediting.lib.prov.smoothline.SmoothLineEditingProviderFactory;
|
|
116 |
import org.gvsig.vectorediting.lib.prov.spline.FilledSplineEditingProviderFactory;
|
|
117 |
import org.gvsig.vectorediting.lib.prov.spline.SplineEditingProviderFactory;
|
|
118 |
import org.gvsig.vectorediting.lib.prov.split.SplitEditingProviderFactory;
|
|
119 |
import org.gvsig.vectorediting.lib.prov.splitline.SplitLineEditingProviderFactory;
|
|
120 |
import org.gvsig.vectorediting.lib.prov.stretch.StretchEditingProviderFactory;
|
|
121 |
import org.gvsig.vectorediting.lib.prov.trimline.TrimLineEditingProviderFactory;
|
|
122 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator;
|
|
123 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager;
|
|
124 |
import org.gvsig.vectorediting.swing.api.EditingContext;
|
|
125 |
import org.gvsig.vectorediting.swing.api.EditingSwingLocator;
|
|
126 |
import org.gvsig.vectorediting.swing.api.EditingSwingManager;
|
|
127 |
import org.gvsig.vectorediting.swing.impl.DefaultEditingBehavior;
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Main executable class for testing the VectorEditing library.
|
|
131 |
*
|
|
132 |
* @author gvSIG Team
|
|
133 |
* @version $Id$
|
|
134 |
*/
|
|
135 |
public class Main implements Observer {
|
|
136 |
|
|
137 |
public static void main(String args[]) {
|
|
138 |
new DefaultLibrariesInitializer().fullInitialize();
|
|
139 |
Main main = new Main();
|
|
140 |
main.doMain();
|
|
141 |
}
|
|
142 |
|
|
143 |
private static final Logger logger = LoggerFactory.getLogger(Main.class);
|
|
144 |
|
|
145 |
final EditingManager manager;
|
|
146 |
|
|
147 |
final EditingSwingManager swingManager;
|
|
148 |
|
|
149 |
final EditingProviderManager providerManager;
|
|
150 |
|
|
151 |
final MapControlManager mapControlManager;
|
|
152 |
|
|
153 |
final DataManager dataManager;
|
|
154 |
|
|
155 |
final MapContextManager mapContextManager;
|
|
156 |
|
|
157 |
DefaultEditingBehavior editingBehavior;
|
|
158 |
|
|
159 |
MapControl mapControl;
|
|
160 |
|
|
161 |
EditingContext editingContext;
|
|
162 |
|
|
163 |
FeatureStore store;
|
|
164 |
|
|
165 |
FLyrVect currentLayer;
|
|
166 |
|
|
167 |
final String DEFAULT_CRS_CODE = "EPSG:23030";
|
|
168 |
|
|
169 |
IProjection defaultProjection;
|
|
170 |
|
|
171 |
JFrame mainFrame;
|
|
172 |
|
|
173 |
JFrame paletteTools;
|
|
174 |
|
|
175 |
JButton openPaletteToolsButtons;
|
|
176 |
|
|
177 |
JButton editingExtensionButtons;
|
|
178 |
|
|
179 |
JButton endEditingExtensionButtons;
|
|
180 |
|
|
181 |
JButton cleanMapButton;
|
|
182 |
|
|
183 |
List<JButton> buttons;
|
|
184 |
|
|
185 |
public Main() {
|
|
186 |
manager = EditingLocator.getManager();
|
|
187 |
swingManager = EditingSwingLocator.getSwingManager();
|
|
188 |
providerManager = EditingProviderLocator.getProviderManager();
|
|
189 |
mapControlManager = MapControlLocator.getMapControlManager();
|
|
190 |
dataManager = DALLocator.getDataManager();
|
|
191 |
mapContextManager = MapContextLocator.getMapContextManager();
|
|
192 |
defaultProjection = CRSFactory.getCRS(DEFAULT_CRS_CODE);
|
|
193 |
|
|
194 |
MapContextLocator
|
|
195 |
.registerDefaultOrderManager(DummieLayerOrderManager.class);
|
|
196 |
}
|
|
197 |
|
|
198 |
public void addLayer(String shpPath) throws InitializeException,
|
|
199 |
ProviderNotRegisteredException, ValidateDataParametersException,
|
|
200 |
LoadLayerException {
|
|
201 |
DataStoreParameters params;
|
|
202 |
params = dataManager.createStoreParameters("Shape");
|
|
203 |
|
|
204 |
String dbfPath =
|
|
205 |
shpPath.substring(0, shpPath.length() - 3).concat("dbf");
|
|
206 |
String shxPath =
|
|
207 |
shpPath.substring(0, shpPath.length() - 3).concat("shx");
|
|
208 |
|
|
209 |
File shpFile = new File(shpPath);
|
|
210 |
File dbFile = new File(dbfPath);
|
|
211 |
File shxFile = new File(shxPath);
|
|
212 |
|
|
213 |
params.setDynValue("shpFile", shpFile.getPath());
|
|
214 |
params.setDynValue("dbfFile", dbFile.getPath());
|
|
215 |
params.setDynValue("shxFile", shxFile.getPath());
|
|
216 |
params.setDynValue("CRS", defaultProjection);
|
|
217 |
|
|
218 |
store = (FeatureStore) dataManager.openStore("Shape", params);
|
|
219 |
|
|
220 |
FLayer layer = mapContextManager.createLayer(store.getName(), store);
|
|
221 |
mapControl.getMapContext().getLayers().addLayer(layer);
|
|
222 |
layer.setActive(true);
|
|
223 |
try {
|
|
224 |
currentLayer = (FLyrVect) layer;
|
|
225 |
} catch (Exception e) {
|
|
226 |
logger.error("Can't load layer " + e.getMessage());
|
|
227 |
}
|
|
228 |
refreshButtons();
|
|
229 |
}
|
|
230 |
|
|
231 |
private void createActionButtons() {
|
|
232 |
|
|
233 |
buttons = new ArrayList<JButton>();
|
|
234 |
|
|
235 |
buttons.add(new JButton(getPointAction()));
|
|
236 |
buttons.add(new JButton(getMultiPointAction()));
|
|
237 |
buttons.add(new JButton(getLineAction()));
|
|
238 |
buttons.add(new JButton(getArcAction()));
|
|
239 |
buttons.add(new JButton(getCircumferenceCrAction()));
|
|
240 |
buttons.add(new JButton(getCircleCrAction()));
|
|
241 |
buttons.add(new JButton(getCircumference3PAction()));
|
|
242 |
buttons.add(new JButton(getCircle3PAction()));
|
|
243 |
buttons.add(new JButton(getPolylineAction()));
|
|
244 |
buttons.add(new JButton(getPolygonAction()));
|
|
245 |
buttons.add(new JButton(getEclipseAction()));
|
|
246 |
buttons.add(new JButton(getFilledEclipseAction()));
|
|
247 |
buttons.add(new JButton(getRegularPolygonAction()));
|
|
248 |
buttons.add(new JButton(getFilledRegularPolygonAction()));
|
|
249 |
buttons.add(new JButton(getRectangleAction()));
|
|
250 |
buttons.add(new JButton(getFilledRectangleAction()));
|
|
251 |
buttons.add(new JButton(getSplineAction()));
|
|
252 |
buttons.add(new JButton(getFilledSplineAction()));
|
|
253 |
buttons.add(new JButton(getAutopolygonAction()));
|
|
254 |
buttons.add(new JButton(getInternalPolygonAction()));
|
|
255 |
buttons.add(new JButton(getExplodeGeometryAction()));
|
|
256 |
buttons.add(new JButton(getMoveAction()));
|
|
257 |
buttons.add(new JButton(getDuplicateAction()));
|
|
258 |
buttons.add(new JButton(getStretchAction()));
|
|
259 |
buttons.add(new JButton(getRotateAction()));
|
|
260 |
buttons.add(new JButton(getSplitLineAction()));
|
|
261 |
buttons.add(new JButton(getSplitAction()));
|
|
262 |
buttons.add(new JButton(getExtendLineAction()));
|
|
263 |
buttons.add(new JButton(getTrimLineAction()));
|
|
264 |
buttons.add(new JButton(getSimplifyAction()));
|
|
265 |
buttons.add(new JButton(getScaleAction()));
|
|
266 |
buttons.add(new JButton(getJoinAction()));
|
|
267 |
buttons.add(new JButton(getSmoothLineAction()));
|
|
268 |
buttons.add(new JButton(getRectangularMatrixAction()));
|
|
269 |
buttons.add(new JButton(getPolarMatrixAction()));
|
|
270 |
buttons.add(new JButton(getEditVertexAction()));
|
|
271 |
|
|
272 |
}
|
|
273 |
|
|
274 |
private JButton getOpenPaletteToolsButton() {
|
|
275 |
|
|
276 |
if (openPaletteToolsButtons == null) {
|
|
277 |
openPaletteToolsButtons = new JButton(getOpenPaletteToolsAction());
|
|
278 |
openPaletteToolsButtons.setEnabled(false);
|
|
279 |
}
|
|
280 |
return openPaletteToolsButtons;
|
|
281 |
}
|
|
282 |
|
|
283 |
private JButton getEditingExtensionButton() {
|
|
284 |
|
|
285 |
if (editingExtensionButtons == null) {
|
|
286 |
editingExtensionButtons = new JButton(getEditingExtensionAction());
|
|
287 |
}
|
|
288 |
return editingExtensionButtons;
|
|
289 |
}
|
|
290 |
|
|
291 |
private JButton getEndEditingExtensionButton() {
|
|
292 |
|
|
293 |
if (endEditingExtensionButtons == null) {
|
|
294 |
endEditingExtensionButtons =
|
|
295 |
new JButton(getEndEditingExtensionAction());
|
|
296 |
endEditingExtensionButtons.setEnabled(false);
|
|
297 |
}
|
|
298 |
return endEditingExtensionButtons;
|
|
299 |
}
|
|
300 |
|
|
301 |
private JButton getCleanMapButton() {
|
|
302 |
if (cleanMapButton == null) {
|
|
303 |
cleanMapButton = new JButton(getCleanMapAction());
|
|
304 |
cleanMapButton.setEnabled(false);
|
|
305 |
}
|
|
306 |
return cleanMapButton;
|
|
307 |
}
|
|
308 |
|
|
309 |
private AbstractAction getInternalPolygonAction() {
|
|
310 |
return new AbstractAction(
|
|
311 |
InternalPolygonEditingProviderFactory.PROVIDER_NAME) {
|
|
312 |
|
|
313 |
/**
|
|
314 |
*
|
|
315 |
*/
|
|
316 |
private static final long serialVersionUID = -5366590032240258186L;
|
|
317 |
|
|
318 |
public void actionPerformed(ActionEvent e) {
|
|
319 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
320 |
editingContext
|
|
321 |
.activateService(InternalPolygonEditingProviderFactory.PROVIDER_NAME);
|
|
322 |
}
|
|
323 |
};
|
|
324 |
}
|
|
325 |
|
|
326 |
private AbstractAction getExplodeGeometryAction() {
|
|
327 |
return new AbstractAction(ExplodeEditingProviderFactory.PROVIDER_NAME) {
|
|
328 |
|
|
329 |
/**
|
|
330 |
*
|
|
331 |
*/
|
|
332 |
private static final long serialVersionUID = -5366590032240258186L;
|
|
333 |
|
|
334 |
public void actionPerformed(ActionEvent e) {
|
|
335 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
336 |
editingContext
|
|
337 |
.activateService(ExplodeEditingProviderFactory.PROVIDER_NAME);
|
|
338 |
}
|
|
339 |
};
|
|
340 |
}
|
|
341 |
|
|
342 |
private AbstractAction getMoveAction() {
|
|
343 |
return new AbstractAction(MoveEditingProviderFactory.PROVIDER_NAME) {
|
|
344 |
|
|
345 |
/**
|
|
346 |
*
|
|
347 |
*/
|
|
348 |
private static final long serialVersionUID = -5366590032240258186L;
|
|
349 |
|
|
350 |
public void actionPerformed(ActionEvent e) {
|
|
351 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
352 |
editingContext
|
|
353 |
.activateService(MoveEditingProviderFactory.PROVIDER_NAME);
|
|
354 |
}
|
|
355 |
};
|
|
356 |
}
|
|
357 |
|
|
358 |
private AbstractAction getDuplicateAction() {
|
|
359 |
return new AbstractAction(DuplicateEditingProviderFactory.PROVIDER_NAME) {
|
|
360 |
|
|
361 |
/**
|
|
362 |
*
|
|
363 |
*/
|
|
364 |
private static final long serialVersionUID = -5366590032240258186L;
|
|
365 |
|
|
366 |
public void actionPerformed(ActionEvent e) {
|
|
367 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
368 |
editingContext
|
|
369 |
.activateService(DuplicateEditingProviderFactory.PROVIDER_NAME);
|
|
370 |
}
|
|
371 |
};
|
|
372 |
}
|
|
373 |
|
|
374 |
private AbstractAction getSimplifyAction() {
|
|
375 |
return new AbstractAction(SimplifyEditingProviderFactory.PROVIDER_NAME) {
|
|
376 |
|
|
377 |
/**
|
|
378 |
*
|
|
379 |
*/
|
|
380 |
private static final long serialVersionUID = -5366590032240258186L;
|
|
381 |
|
|
382 |
public void actionPerformed(ActionEvent e) {
|
|
383 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
384 |
editingContext
|
|
385 |
.activateService(SimplifyEditingProviderFactory.PROVIDER_NAME);
|
|
386 |
}
|
|
387 |
};
|
|
388 |
}
|
|
389 |
|
|
390 |
private AbstractAction getFilledSplineAction() {
|
|
391 |
return new AbstractAction(
|
|
392 |
FilledSplineEditingProviderFactory.PROVIDER_NAME) {
|
|
393 |
|
|
394 |
/**
|
|
395 |
*
|
|
396 |
*/
|
|
397 |
private static final long serialVersionUID = 357716596419507221L;
|
|
398 |
|
|
399 |
public void actionPerformed(ActionEvent e) {
|
|
400 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
401 |
editingContext
|
|
402 |
.activateService(FilledSplineEditingProviderFactory.PROVIDER_NAME);
|
|
403 |
|
|
404 |
}
|
|
405 |
};
|
|
406 |
}
|
|
407 |
|
|
408 |
private AbstractAction getSplineAction() {
|
|
409 |
return new AbstractAction(SplineEditingProviderFactory.PROVIDER_NAME) {
|
|
410 |
|
|
411 |
/**
|
|
412 |
*
|
|
413 |
*/
|
|
414 |
private static final long serialVersionUID = -2308770572409304622L;
|
|
415 |
|
|
416 |
public void actionPerformed(ActionEvent e) {
|
|
417 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
418 |
editingContext
|
|
419 |
.activateService(SplineEditingProviderFactory.PROVIDER_NAME);
|
|
420 |
|
|
421 |
}
|
|
422 |
};
|
|
423 |
}
|
|
424 |
|
|
425 |
private AbstractAction getFilledRectangleAction() {
|
|
426 |
return new AbstractAction(
|
|
427 |
FilledRectangleEditingProviderFactory.PROVIDER_NAME) {
|
|
428 |
|
|
429 |
/**
|
|
430 |
*
|
|
431 |
*/
|
|
432 |
private static final long serialVersionUID = 2293196006002423664L;
|
|
433 |
|
|
434 |
public void actionPerformed(ActionEvent e) {
|
|
435 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
436 |
editingContext
|
|
437 |
.activateService(FilledRectangleEditingProviderFactory.PROVIDER_NAME);
|
|
438 |
|
|
439 |
}
|
|
440 |
};
|
|
441 |
}
|
|
442 |
|
|
443 |
private AbstractAction getRectangleAction() {
|
|
444 |
return new AbstractAction(RectangleEditingProviderFactory.PROVIDER_NAME) {
|
|
445 |
|
|
446 |
/**
|
|
447 |
*
|
|
448 |
*/
|
|
449 |
private static final long serialVersionUID = -6429005619655148416L;
|
|
450 |
|
|
451 |
public void actionPerformed(ActionEvent e) {
|
|
452 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
453 |
editingContext
|
|
454 |
.activateService(RectangleEditingProviderFactory.PROVIDER_NAME);
|
|
455 |
|
|
456 |
}
|
|
457 |
};
|
|
458 |
}
|
|
459 |
|
|
460 |
private AbstractAction getFilledRegularPolygonAction() {
|
|
461 |
return new AbstractAction(
|
|
462 |
FilledRegularPolygonEditingProviderFactory.PROVIDER_NAME) {
|
|
463 |
|
|
464 |
/**
|
|
465 |
*
|
|
466 |
*/
|
|
467 |
private static final long serialVersionUID = 7944728685657584703L;
|
|
468 |
|
|
469 |
public void actionPerformed(ActionEvent e) {
|
|
470 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
471 |
editingContext
|
|
472 |
.activateService(FilledRegularPolygonEditingProviderFactory.PROVIDER_NAME);
|
|
473 |
|
|
474 |
}
|
|
475 |
};
|
|
476 |
}
|
|
477 |
|
|
478 |
private AbstractAction getRegularPolygonAction() {
|
|
479 |
return new AbstractAction(
|
|
480 |
RegularPolygonEditingProviderFactory.PROVIDER_NAME) {
|
|
481 |
|
|
482 |
/**
|
|
483 |
*
|
|
484 |
*/
|
|
485 |
private static final long serialVersionUID = 1465569443777907186L;
|
|
486 |
|
|
487 |
public void actionPerformed(ActionEvent e) {
|
|
488 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
489 |
editingContext
|
|
490 |
.activateService(RegularPolygonEditingProviderFactory.PROVIDER_NAME);
|
|
491 |
}
|
|
492 |
};
|
|
493 |
}
|
|
494 |
|
|
495 |
private AbstractAction getPolygonAction() {
|
|
496 |
return new AbstractAction(PolygonEditingProviderFactory.PROVIDER_NAME) {
|
|
497 |
|
|
498 |
/**
|
|
499 |
*
|
|
500 |
*/
|
|
501 |
private static final long serialVersionUID = 966582628310445218L;
|
|
502 |
|
|
503 |
public void actionPerformed(ActionEvent e) {
|
|
504 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
505 |
editingContext
|
|
506 |
.activateService(PolygonEditingProviderFactory.PROVIDER_NAME);
|
|
507 |
}
|
|
508 |
};
|
|
509 |
}
|
|
510 |
|
|
511 |
private AbstractAction getPolylineAction() {
|
|
512 |
return new AbstractAction(PolylineEditingProviderFactory.PROVIDER_NAME) {
|
|
513 |
|
|
514 |
/**
|
|
515 |
*
|
|
516 |
*/
|
|
517 |
private static final long serialVersionUID = 2859732316623830924L;
|
|
518 |
|
|
519 |
public void actionPerformed(ActionEvent e) {
|
|
520 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
521 |
editingContext
|
|
522 |
.activateService(PolylineEditingProviderFactory.PROVIDER_NAME);
|
|
523 |
}
|
|
524 |
};
|
|
525 |
}
|
|
526 |
|
|
527 |
private AbstractAction getEclipseAction() {
|
|
528 |
return new AbstractAction(EllipseEditingProviderFactory.PROVIDER_NAME) {
|
|
529 |
|
|
530 |
/**
|
|
531 |
*
|
|
532 |
*/
|
|
533 |
private static final long serialVersionUID = -4698275458250358502L;
|
|
534 |
|
|
535 |
public void actionPerformed(ActionEvent e) {
|
|
536 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
537 |
editingContext
|
|
538 |
.activateService(EllipseEditingProviderFactory.PROVIDER_NAME);
|
|
539 |
}
|
|
540 |
};
|
|
541 |
}
|
|
542 |
|
|
543 |
private AbstractAction getFilledEclipseAction() {
|
|
544 |
return new AbstractAction(
|
|
545 |
FilledEllipseEditingProviderFactory.PROVIDER_NAME) {
|
|
546 |
|
|
547 |
/**
|
|
548 |
*
|
|
549 |
*/
|
|
550 |
private static final long serialVersionUID = -4698275458250358502L;
|
|
551 |
|
|
552 |
public void actionPerformed(ActionEvent e) {
|
|
553 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
554 |
editingContext
|
|
555 |
.activateService(FilledEllipseEditingProviderFactory.PROVIDER_NAME);
|
|
556 |
}
|
|
557 |
};
|
|
558 |
}
|
|
559 |
|
|
560 |
private AbstractAction getCircumferenceCrAction() {
|
|
561 |
return new AbstractAction(
|
|
562 |
CircumferenceCREditingProviderFactory.PROVIDER_NAME) {
|
|
563 |
|
|
564 |
/**
|
|
565 |
*
|
|
566 |
*/
|
|
567 |
private static final long serialVersionUID = -4422429984929119239L;
|
|
568 |
|
|
569 |
public void actionPerformed(ActionEvent e) {
|
|
570 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
571 |
editingContext
|
|
572 |
.activateService(CircumferenceCREditingProviderFactory.PROVIDER_NAME);
|
|
573 |
}
|
|
574 |
};
|
|
575 |
}
|
|
576 |
|
|
577 |
private AbstractAction getCircleCrAction() {
|
|
578 |
return new AbstractAction(CircleCREditingProviderFactory.PROVIDER_NAME) {
|
|
579 |
|
|
580 |
/**
|
|
581 |
*
|
|
582 |
*/
|
|
583 |
private static final long serialVersionUID = 1564163738941995373L;
|
|
584 |
|
|
585 |
public void actionPerformed(ActionEvent e) {
|
|
586 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
587 |
editingContext
|
|
588 |
.activateService(CircleCREditingProviderFactory.PROVIDER_NAME);
|
|
589 |
}
|
|
590 |
};
|
|
591 |
}
|
|
592 |
|
|
593 |
private AbstractAction getCircumference3PAction() {
|
|
594 |
return new AbstractAction(
|
|
595 |
Circumference3PEditingProviderFactory.PROVIDER_NAME) {
|
|
596 |
|
|
597 |
/**
|
|
598 |
*
|
|
599 |
*/
|
|
600 |
private static final long serialVersionUID = -4422429984929119239L;
|
|
601 |
|
|
602 |
public void actionPerformed(ActionEvent e) {
|
|
603 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
604 |
editingContext
|
|
605 |
.activateService(Circumference3PEditingProviderFactory.PROVIDER_NAME);
|
|
606 |
}
|
|
607 |
};
|
|
608 |
}
|
|
609 |
|
|
610 |
private AbstractAction getCircle3PAction() {
|
|
611 |
return new AbstractAction(Circle3PEditingProviderFactory.PROVIDER_NAME) {
|
|
612 |
|
|
613 |
/**
|
|
614 |
*
|
|
615 |
*/
|
|
616 |
private static final long serialVersionUID = 1564163738941995373L;
|
|
617 |
|
|
618 |
public void actionPerformed(ActionEvent e) {
|
|
619 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
620 |
editingContext
|
|
621 |
.activateService(Circle3PEditingProviderFactory.PROVIDER_NAME);
|
|
622 |
}
|
|
623 |
};
|
|
624 |
}
|
|
625 |
|
|
626 |
private AbstractAction getArcAction() {
|
|
627 |
return new AbstractAction(ArcEditingProviderFactory.PROVIDER_NAME) {
|
|
628 |
|
|
629 |
/**
|
|
630 |
*
|
|
631 |
*/
|
|
632 |
private static final long serialVersionUID = 5529987067864211418L;
|
|
633 |
|
|
634 |
public void actionPerformed(ActionEvent e) {
|
|
635 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
636 |
editingContext
|
|
637 |
.activateService(ArcEditingProviderFactory.PROVIDER_NAME);
|
|
638 |
}
|
|
639 |
};
|
|
640 |
}
|
|
641 |
|
|
642 |
private AbstractAction getLineAction() {
|
|
643 |
return new AbstractAction(LineEditingProviderFactory.PROVIDER_NAME) {
|
|
644 |
|
|
645 |
/**
|
|
646 |
*
|
|
647 |
*/
|
|
648 |
private static final long serialVersionUID = 7464822491323014704L;
|
|
649 |
|
|
650 |
public void actionPerformed(ActionEvent e) {
|
|
651 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
652 |
editingContext
|
|
653 |
.activateService(LineEditingProviderFactory.PROVIDER_NAME);
|
|
654 |
}
|
|
655 |
};
|
|
656 |
}
|
|
657 |
|
|
658 |
private AbstractAction getPointAction() {
|
|
659 |
return new AbstractAction(PointEditingProviderFactory.PROVIDER_NAME) {
|
|
660 |
|
|
661 |
/**
|
|
662 |
*
|
|
663 |
*/
|
|
664 |
private static final long serialVersionUID = -9147590153911397886L;
|
|
665 |
|
|
666 |
public void actionPerformed(ActionEvent e) {
|
|
667 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
668 |
editingContext
|
|
669 |
.activateService(PointEditingProviderFactory.PROVIDER_NAME);
|
|
670 |
}
|
|
671 |
|
|
672 |
};
|
|
673 |
}
|
|
674 |
|
|
675 |
private AbstractAction getMultiPointAction() {
|
|
676 |
return new AbstractAction(
|
|
677 |
MultipointEditingProviderFactory.PROVIDER_NAME) {
|
|
678 |
|
|
679 |
/**
|
|
680 |
*
|
|
681 |
*/
|
|
682 |
private static final long serialVersionUID = -9147590153911397886L;
|
|
683 |
|
|
684 |
public void actionPerformed(ActionEvent e) {
|
|
685 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
686 |
editingContext
|
|
687 |
.activateService(MultipointEditingProviderFactory.PROVIDER_NAME);
|
|
688 |
}
|
|
689 |
|
|
690 |
};
|
|
691 |
}
|
|
692 |
|
|
693 |
private AbstractAction getSplitLineAction() {
|
|
694 |
return new AbstractAction(SplitLineEditingProviderFactory.PROVIDER_NAME) {
|
|
695 |
|
|
696 |
/**
|
|
697 |
*
|
|
698 |
*/
|
|
699 |
private static final long serialVersionUID = -5366590032240258186L;
|
|
700 |
|
|
701 |
public void actionPerformed(ActionEvent e) {
|
|
702 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
703 |
editingContext
|
|
704 |
.activateService(SplitLineEditingProviderFactory.PROVIDER_NAME);
|
|
705 |
}
|
|
706 |
};
|
|
707 |
}
|
|
708 |
|
|
709 |
private AbstractAction getSplitAction() {
|
|
710 |
return new AbstractAction(SplitEditingProviderFactory.PROVIDER_NAME) {
|
|
711 |
|
|
712 |
/**
|
|
713 |
*
|
|
714 |
*/
|
|
715 |
private static final long serialVersionUID = -5366590032240258186L;
|
|
716 |
|
|
717 |
public void actionPerformed(ActionEvent e) {
|
|
718 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
719 |
editingContext
|
|
720 |
.activateService(SplitEditingProviderFactory.PROVIDER_NAME);
|
|
721 |
}
|
|
722 |
};
|
|
723 |
}
|
|
724 |
|
|
725 |
private AbstractAction getExtendLineAction() {
|
|
726 |
return new AbstractAction(
|
|
727 |
ExtendLineEditingProviderFactory.PROVIDER_NAME) {
|
|
728 |
|
|
729 |
/**
|
|
730 |
*
|
|
731 |
*/
|
|
732 |
private static final long serialVersionUID = -5366590032240258186L;
|
|
733 |
|
|
734 |
public void actionPerformed(ActionEvent e) {
|
|
735 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
736 |
editingContext
|
|
737 |
.activateService(ExtendLineEditingProviderFactory.PROVIDER_NAME);
|
|
738 |
}
|
|
739 |
};
|
|
740 |
}
|
|
741 |
|
|
742 |
private AbstractAction getTrimLineAction() {
|
|
743 |
return new AbstractAction(TrimLineEditingProviderFactory.PROVIDER_NAME) {
|
|
744 |
|
|
745 |
/**
|
|
746 |
*
|
|
747 |
*/
|
|
748 |
private static final long serialVersionUID = -5366590032240258186L;
|
|
749 |
|
|
750 |
public void actionPerformed(ActionEvent e) {
|
|
751 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
752 |
editingContext
|
|
753 |
.activateService(TrimLineEditingProviderFactory.PROVIDER_NAME);
|
|
754 |
}
|
|
755 |
};
|
|
756 |
}
|
|
757 |
|
|
758 |
private AbstractAction getEndEditingExtensionAction() {
|
|
759 |
return new AbstractAction("end-editing") {
|
|
760 |
|
|
761 |
/**
|
|
762 |
*
|
|
763 |
*/
|
|
764 |
private static final long serialVersionUID = -1026680183527522379L;
|
|
765 |
|
|
766 |
public void actionPerformed(ActionEvent e) {
|
|
767 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
768 |
editingContext.endEdition(currentLayer);
|
|
769 |
|
|
770 |
if (currentLayer != null && !currentLayer.isEditing()) {
|
|
771 |
getPaletteTools().setVisible(false);
|
|
772 |
}
|
|
773 |
|
|
774 |
refreshButtons();
|
|
775 |
}
|
|
776 |
};
|
|
777 |
}
|
|
778 |
|
|
779 |
private AbstractAction getRotateAction() {
|
|
780 |
return new AbstractAction(RotateEditingProviderFactory.PROVIDER_NAME) {
|
|
781 |
|
|
782 |
/**
|
|
783 |
*
|
|
784 |
*/
|
|
785 |
private static final long serialVersionUID = -1026680183527522379L;
|
|
786 |
|
|
787 |
public void actionPerformed(ActionEvent e) {
|
|
788 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
789 |
editingContext
|
|
790 |
.activateService(RotateEditingProviderFactory.PROVIDER_NAME);
|
|
791 |
}
|
|
792 |
};
|
|
793 |
}
|
|
794 |
|
|
795 |
private AbstractAction getEditingExtensionAction() {
|
|
796 |
return new AbstractAction("start-editing") {
|
|
797 |
|
|
798 |
/**
|
|
799 |
*
|
|
800 |
*/
|
|
801 |
private static final long serialVersionUID = 5524271695550380473L;
|
|
802 |
|
|
803 |
public void actionPerformed(ActionEvent e) {
|
|
804 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
805 |
registerObserver(editingContext);
|
|
806 |
editingContext.beginEdition(currentLayer);
|
|
807 |
refreshButtons();
|
|
808 |
|
|
809 |
// XXX Forces component repaint.
|
|
810 |
SwingUtilities.updateComponentTreeUI(mainFrame);
|
|
811 |
}
|
|
812 |
};
|
|
813 |
}
|
|
814 |
|
|
815 |
private AbstractAction getExitAction() {
|
|
816 |
return new AbstractAction("Exit") {
|
|
817 |
|
|
818 |
/**
|
|
819 |
*
|
|
820 |
*/
|
|
821 |
private static final long serialVersionUID = 7506436995278783992L;
|
|
822 |
|
|
823 |
public void actionPerformed(ActionEvent e) {
|
|
824 |
System.exit(0);
|
|
825 |
}
|
|
826 |
};
|
|
827 |
}
|
|
828 |
|
|
829 |
private AbstractAction getOpenPaletteToolsAction() {
|
|
830 |
return new AbstractAction("Show palette tools") {
|
|
831 |
|
|
832 |
/**
|
|
833 |
*
|
|
834 |
*/
|
|
835 |
private static final long serialVersionUID = -2643193186380529723L;
|
|
836 |
|
|
837 |
public void actionPerformed(ActionEvent e) {
|
|
838 |
getPaletteTools().setVisible(true);
|
|
839 |
}
|
|
840 |
};
|
|
841 |
}
|
|
842 |
|
|
843 |
private AbstractAction getAddLayerAction() {
|
|
844 |
return new AbstractAction("Add layer") {
|
|
845 |
|
|
846 |
/**
|
|
847 |
*
|
|
848 |
*/
|
|
849 |
private static final long serialVersionUID = -7527908235576117027L;
|
|
850 |
|
|
851 |
public void actionPerformed(ActionEvent e) {
|
|
852 |
ThreadSafeDialogsManager dlgManager =
|
|
853 |
ToolsSwingLocator.getThreadSafeDialogsManager();
|
|
854 |
|
|
855 |
File[] file =
|
|
856 |
dlgManager.showChooserDialog("Seleccione archivo SHP",
|
|
857 |
JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY,
|
|
858 |
false, new File(System.getProperty("user.home")),
|
|
859 |
new GenericFileFilter(new String[] { ".shp" },
|
|
860 |
"(*.shp)"), true);
|
|
861 |
|
|
862 |
if (file != null) {
|
|
863 |
try {
|
|
864 |
addLayer(file[0].getAbsolutePath());
|
|
865 |
} catch (Exception ex) {
|
|
866 |
logger.warn("Problems adding layer", ex);
|
|
867 |
}
|
|
868 |
}
|
|
869 |
}
|
|
870 |
};
|
|
871 |
}
|
|
872 |
|
|
873 |
private AbstractAction getCleanMapAction() {
|
|
874 |
return new AbstractAction("Clean Map") {
|
|
875 |
|
|
876 |
/**
|
|
877 |
*
|
|
878 |
*/
|
|
879 |
private static final long serialVersionUID = 5059847015866672405L;
|
|
880 |
|
|
881 |
public void actionPerformed(ActionEvent e) {
|
|
882 |
MapContext mapContext = mapControl.getMapContext();
|
|
883 |
mapContext.beginAtomicEvent();
|
|
884 |
while (mapContext.getLayers().getLayersCount() > 0) {
|
|
885 |
mapContext.getLayers().removeLayer(0);
|
|
886 |
}
|
|
887 |
mapContext.endAtomicEvent();
|
|
888 |
currentLayer = null;
|
|
889 |
refreshButtons();
|
|
890 |
}
|
|
891 |
};
|
|
892 |
}
|
|
893 |
|
|
894 |
private AbstractAction getZoomAllAction() {
|
|
895 |
return new AbstractAction("Zoom all") {
|
|
896 |
|
|
897 |
/**
|
|
898 |
*
|
|
899 |
*/
|
|
900 |
private static final long serialVersionUID = -1338436395515982258L;
|
|
901 |
|
|
902 |
public void actionPerformed(ActionEvent e) {
|
|
903 |
zoomAll();
|
|
904 |
}
|
|
905 |
};
|
|
906 |
}
|
|
907 |
|
|
908 |
private AbstractAction getZoomAction() {
|
|
909 |
return new AbstractAction("Zoom") {
|
|
910 |
|
|
911 |
/**
|
|
912 |
*
|
|
913 |
*/
|
|
914 |
private static final long serialVersionUID = -7231543178928614445L;
|
|
915 |
|
|
916 |
public void actionPerformed(ActionEvent e) {
|
|
917 |
mapControl.setTool("zoom");
|
|
918 |
}
|
|
919 |
};
|
|
920 |
}
|
|
921 |
|
|
922 |
private AbstractAction getPanAction() {
|
|
923 |
return new AbstractAction("Pan") {
|
|
924 |
|
|
925 |
/**
|
|
926 |
*
|
|
927 |
*/
|
|
928 |
private static final long serialVersionUID = -6520053841602571307L;
|
|
929 |
|
|
930 |
public void actionPerformed(ActionEvent e) {
|
|
931 |
mapControl.setTool("pan");
|
|
932 |
}
|
|
933 |
};
|
|
934 |
}
|
|
935 |
|
|
936 |
private AbstractAction getAutopolygonAction() {
|
|
937 |
return new AbstractAction(
|
|
938 |
AutopolygonEditingProviderFactory.PROVIDER_NAME) {
|
|
939 |
|
|
940 |
/**
|
|
941 |
*
|
|
942 |
*/
|
|
943 |
private static final long serialVersionUID = -6520053841602571307L;
|
|
944 |
|
|
945 |
public void actionPerformed(ActionEvent e) {
|
|
946 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
947 |
editingContext
|
|
948 |
.activateService(AutopolygonEditingProviderFactory.PROVIDER_NAME);
|
|
949 |
}
|
|
950 |
};
|
|
951 |
}
|
|
952 |
|
|
953 |
private AbstractAction getJoinAction() {
|
|
954 |
return new AbstractAction(JoinEditingProviderFactory.PROVIDER_NAME) {
|
|
955 |
|
|
956 |
/**
|
|
957 |
*
|
|
958 |
*/
|
|
959 |
private static final long serialVersionUID = -6520053841602571307L;
|
|
960 |
|
|
961 |
public void actionPerformed(ActionEvent e) {
|
|
962 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
963 |
editingContext
|
|
964 |
.activateService(JoinEditingProviderFactory.PROVIDER_NAME);
|
|
965 |
}
|
|
966 |
};
|
|
967 |
}
|
|
968 |
|
|
969 |
private AbstractAction getSmoothLineAction() {
|
|
970 |
return new AbstractAction(
|
|
971 |
SmoothLineEditingProviderFactory.PROVIDER_NAME) {
|
|
972 |
|
|
973 |
/**
|
|
974 |
*
|
|
975 |
*/
|
|
976 |
private static final long serialVersionUID = 4659561526143686702L;
|
|
977 |
|
|
978 |
public void actionPerformed(ActionEvent e) {
|
|
979 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
980 |
editingContext
|
|
981 |
.activateService(SmoothLineEditingProviderFactory.PROVIDER_NAME);
|
|
982 |
}
|
|
983 |
};
|
|
984 |
}
|
|
985 |
|
|
986 |
private AbstractAction getScaleAction() {
|
|
987 |
return new AbstractAction(ScaleEditingProviderFactory.PROVIDER_NAME) {
|
|
988 |
|
|
989 |
/**
|
|
990 |
*
|
|
991 |
*/
|
|
992 |
private static final long serialVersionUID = -6520053841602571307L;
|
|
993 |
|
|
994 |
public void actionPerformed(ActionEvent e) {
|
|
995 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
996 |
editingContext
|
|
997 |
.activateService(ScaleEditingProviderFactory.PROVIDER_NAME);
|
|
998 |
}
|
|
999 |
};
|
|
1000 |
}
|
|
1001 |
|
|
1002 |
private AbstractAction getRectangularMatrixAction() {
|
|
1003 |
return new AbstractAction(
|
|
1004 |
RectangularMatrixEditingProviderFactory.PROVIDER_NAME) {
|
|
1005 |
|
|
1006 |
/**
|
|
1007 |
*
|
|
1008 |
*/
|
|
1009 |
private static final long serialVersionUID = -6520053841602571307L;
|
|
1010 |
|
|
1011 |
public void actionPerformed(ActionEvent e) {
|
|
1012 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
1013 |
editingContext
|
|
1014 |
.activateService(RectangularMatrixEditingProviderFactory.PROVIDER_NAME);
|
|
1015 |
}
|
|
1016 |
};
|
|
1017 |
}
|
|
1018 |
|
|
1019 |
private AbstractAction getPolarMatrixAction() {
|
|
1020 |
return new AbstractAction(
|
|
1021 |
PolarMatrixEditingProviderFactory.PROVIDER_NAME) {
|
|
1022 |
|
|
1023 |
/**
|
|
1024 |
*
|
|
1025 |
*/
|
|
1026 |
private static final long serialVersionUID = -6520053841602571307L;
|
|
1027 |
|
|
1028 |
public void actionPerformed(ActionEvent e) {
|
|
1029 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
1030 |
editingContext
|
|
1031 |
.activateService(PolarMatrixEditingProviderFactory.PROVIDER_NAME);
|
|
1032 |
}
|
|
1033 |
};
|
|
1034 |
}
|
|
1035 |
|
|
1036 |
private AbstractAction getEditVertexAction() {
|
|
1037 |
return new AbstractAction(
|
|
1038 |
EditVertexEditingProviderFactory.PROVIDER_NAME) {
|
|
1039 |
|
|
1040 |
/**
|
|
1041 |
*
|
|
1042 |
*/
|
|
1043 |
private static final long serialVersionUID = 6445235261647995856L;
|
|
1044 |
|
|
1045 |
public void actionPerformed(ActionEvent e) {
|
|
1046 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
1047 |
editingContext
|
|
1048 |
.activateService(EditVertexEditingProviderFactory.PROVIDER_NAME);
|
|
1049 |
}
|
|
1050 |
};
|
|
1051 |
}
|
|
1052 |
|
|
1053 |
private AbstractAction getStretchAction() {
|
|
1054 |
return new AbstractAction(StretchEditingProviderFactory.PROVIDER_NAME) {
|
|
1055 |
|
|
1056 |
/**
|
|
1057 |
*
|
|
1058 |
*/
|
|
1059 |
private static final long serialVersionUID = 6445235261647995856L;
|
|
1060 |
|
|
1061 |
public void actionPerformed(ActionEvent e) {
|
|
1062 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
1063 |
editingContext
|
|
1064 |
.activateService(StretchEditingProviderFactory.PROVIDER_NAME);
|
|
1065 |
}
|
|
1066 |
};
|
|
1067 |
}
|
|
1068 |
|
|
1069 |
private void createMenu() {
|
|
1070 |
// Create the menu bar.
|
|
1071 |
JMenuBar menuBar = new JMenuBar();
|
|
1072 |
|
|
1073 |
// Build the menu.
|
|
1074 |
JMenu menuFile = new JMenu("File");
|
|
1075 |
menuFile.add(new JMenuItem(getExitAction()));
|
|
1076 |
|
|
1077 |
menuBar.add(menuFile);
|
|
1078 |
|
|
1079 |
mainFrame.setJMenuBar(menuBar);
|
|
1080 |
}
|
|
1081 |
|
|
1082 |
private JFrame getPaletteTools() {
|
|
1083 |
if (paletteTools == null) {
|
|
1084 |
paletteTools = new JFrame("Palette tools");
|
|
1085 |
paletteTools.setLayout(new GridLayout(0, 2, 1, 5));
|
|
1086 |
paletteTools.setLocation(0, 0);
|
|
1087 |
paletteTools
|
|
1088 |
.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
|
|
1089 |
|
|
1090 |
for (JButton button : buttons) {
|
|
1091 |
paletteTools.add(button);
|
|
1092 |
}
|
|
1093 |
|
|
1094 |
paletteTools.pack();
|
|
1095 |
}
|
|
1096 |
return paletteTools;
|
|
1097 |
}
|
|
1098 |
|
|
1099 |
private void createToolBar() {
|
|
1100 |
JToolBar toolBar = new JToolBar();
|
|
1101 |
|
|
1102 |
toolBar.add(new JButton(getAddLayerAction()));
|
|
1103 |
toolBar.add(getEditingExtensionButton());
|
|
1104 |
toolBar.add(getEndEditingExtensionButton());
|
|
1105 |
toolBar.add(new JButton(getPanAction()));
|
|
1106 |
toolBar.add(new JButton(getZoomAction()));
|
|
1107 |
toolBar.add(new JButton(getZoomAllAction()));
|
|
1108 |
toolBar.add(getCleanMapButton());
|
|
1109 |
toolBar.add(getOpenPaletteToolsButton());
|
|
1110 |
|
|
1111 |
mainFrame.add(toolBar, BorderLayout.PAGE_START);
|
|
1112 |
}
|
|
1113 |
|
|
1114 |
public void doMain() {
|
|
1115 |
|
|
1116 |
try {
|
|
1117 |
MapContext mapContext =
|
|
1118 |
new MapContext(new ViewPort(defaultProjection));
|
|
1119 |
mapControl = mapControlManager.createJMapControlPanel(mapContext);
|
|
1120 |
|
|
1121 |
mapControl.addBehavior("zoom", new Behavior[] {
|
|
1122 |
new RectangleBehavior(new ZoomInListenerImpl(mapControl)),
|
|
1123 |
new PointBehavior(new ZoomOutListenerImpl(mapControl),
|
|
1124 |
Behavior.BUTTON_RIGHT) });
|
|
1125 |
mapControl.addBehavior("pan", new MoveBehavior(new PanListenerImpl(
|
|
1126 |
mapControl)));
|
|
1127 |
|
|
1128 |
mapControl.addBehavior("pointSelection",
|
|
1129 |
new Behavior[] { new PointBehavior(new PointSelectionListener(
|
|
1130 |
mapControl)) });
|
|
1131 |
|
|
1132 |
IProjection defaultProjection = CRSFactory.getCRS(DEFAULT_CRS_CODE);
|
|
1133 |
mapControl.getViewPort().setProjection(defaultProjection);
|
|
1134 |
|
|
1135 |
mapControl.setTool("pan");
|
|
1136 |
|
|
1137 |
swingManager.registerEditingContext(mapControl);
|
|
1138 |
|
|
1139 |
// Create buttons
|
|
1140 |
createActionButtons();
|
|
1141 |
|
|
1142 |
} catch (MapControlCreationException e) {
|
|
1143 |
logger.error("Can't create mapControl", e);
|
|
1144 |
}
|
|
1145 |
|
|
1146 |
// Create JFrame to show data
|
|
1147 |
mainFrame = new JFrame("Editing test app");
|
|
1148 |
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
|
1149 |
mainFrame.setPreferredSize(new Dimension(800, 680));
|
|
1150 |
mainFrame.add(mapControl, BorderLayout.CENTER);
|
|
1151 |
|
|
1152 |
// Create menu bar
|
|
1153 |
createMenu();
|
|
1154 |
|
|
1155 |
// Create tools bar
|
|
1156 |
createToolBar();
|
|
1157 |
|
|
1158 |
// Display the window.
|
|
1159 |
mainFrame.pack();
|
|
1160 |
mainFrame.setLocation(500, 0);
|
|
1161 |
mainFrame.setVisible(true);
|
|
1162 |
}
|
|
1163 |
|
|
1164 |
private void registerObserver(EditingContext editingContext) {
|
|
1165 |
editingContext.addObserver(this);
|
|
1166 |
}
|
|
1167 |
|
|
1168 |
private void refreshButtons() {
|
|
1169 |
|
|
1170 |
// Refresh palette tool buttons
|
|
1171 |
for (JButton button : buttons) {
|
|
1172 |
String acctionCommand = button.getActionCommand();
|
|
1173 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
1174 |
boolean enable = editingContext.isServiceCompatible(acctionCommand);
|
|
1175 |
button.setEnabled(enable);
|
|
1176 |
}
|
|
1177 |
|
|
1178 |
// Refresh toolbar buttons
|
|
1179 |
|
|
1180 |
if (currentLayer != null) {
|
|
1181 |
|
|
1182 |
if (currentLayer.isEditing()) {
|
|
1183 |
getOpenPaletteToolsButton().setEnabled(true);
|
|
1184 |
getEditingExtensionButton().setEnabled(false);
|
|
1185 |
getEndEditingExtensionButton().setEnabled(true);
|
|
1186 |
getCleanMapButton().setEnabled(false);
|
|
1187 |
} else {
|
|
1188 |
getOpenPaletteToolsButton().setEnabled(false);
|
|
1189 |
getEditingExtensionButton().setEnabled(true);
|
|
1190 |
getEndEditingExtensionButton().setEnabled(false);
|
|
1191 |
getCleanMapButton().setEnabled(true);
|
|
1192 |
}
|
|
1193 |
} else {
|
|
1194 |
getOpenPaletteToolsButton().setEnabled(false);
|
|
1195 |
getEditingExtensionButton().setEnabled(false);
|
|
1196 |
getEndEditingExtensionButton().setEnabled(false);
|
|
1197 |
getCleanMapButton().setEnabled(false);
|
|
1198 |
}
|
|
1199 |
}
|
|
1200 |
|
|
1201 |
private void zoomAll() {
|
|
1202 |
MapContext mapContext = mapControl.getMapContext();
|
|
1203 |
Envelope all = mapContext.getLayers().getFullEnvelope();
|
|
1204 |
logger.info("Full extdents " + all.toString());
|
|
1205 |
mapContext.getViewPort().setEnvelope(all);
|
|
1206 |
mapContext.invalidate();
|
|
1207 |
}
|
|
1208 |
|
|
1209 |
public void update(Observable observable, Object notification) {
|
|
1210 |
|
|
1211 |
if (observable instanceof EditingContext) {
|
|
1212 |
refreshButtons();
|
|
1213 |
}
|
|
1214 |
}
|
|
1215 |
}
|