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