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