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