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