Revision 110
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.main/src/main/java/org/gvsig/vectorediting/main/Main.java | ||
---|---|---|
78 | 78 |
import org.gvsig.vectorediting.lib.prov.circlecr.CircumferenceCREditingProviderFactory; |
79 | 79 |
import org.gvsig.vectorediting.lib.prov.insertpoint.InsertPointEditingProviderFactory; |
80 | 80 |
import org.gvsig.vectorediting.lib.prov.internalpolygon.InternalPolygonEditingProviderFactory; |
81 |
import org.gvsig.vectorediting.lib.prov.polyline.PolygonEditingProviderFactory; |
|
81 | 82 |
import org.gvsig.vectorediting.lib.prov.polyline.PolylineEditingProviderFactory; |
82 | 83 |
import org.gvsig.vectorediting.lib.prov.symmetry.SymmetryEditingProviderFactory; |
83 | 84 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
... | ... | |
95 | 96 |
*/ |
96 | 97 |
public class Main { |
97 | 98 |
|
99 |
public static void main(String args[]) { |
|
100 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
101 |
Main main = new Main(); |
|
102 |
main.doMain(); |
|
103 |
} |
|
104 |
|
|
98 | 105 |
private static final Logger logger = LoggerFactory.getLogger(Main.class); |
99 | 106 |
|
100 | 107 |
final EditingManager manager; |
... | ... | |
156 | 163 |
|
157 | 164 |
AbstractAction circleCr; |
158 | 165 |
|
159 |
AbstractAction circunferenceCr;
|
|
166 |
AbstractAction circumferenceCr;
|
|
160 | 167 |
|
161 | 168 |
AbstractAction polyline; |
162 | 169 |
|
... | ... | |
166 | 173 |
|
167 | 174 |
AbstractAction internalPolygon; |
168 | 175 |
|
169 |
public static void main(String args[]) { |
|
170 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
171 |
Main main = new Main(); |
|
172 |
main.doMain(); |
|
173 |
} |
|
174 |
|
|
175 | 176 |
public Main() { |
176 | 177 |
manager = EditingLocator.getManager(); |
177 | 178 |
swingManager = EditingSwingLocator.getSwingManager(); |
... | ... | |
185 | 186 |
.registerDefaultOrderManager(DummieLayerOrderManager.class); |
186 | 187 |
} |
187 | 188 |
|
188 |
public void doMain() { |
|
189 |
|
|
190 |
try { |
|
191 |
mapControl = mapControlManager.createJMapControlPanel(); |
|
192 |
|
|
193 |
mapControl |
|
194 |
.addBehavior("zoom", new Behavior[] { |
|
195 |
new RectangleBehavior(new ZoomInListenerImpl(mapControl)), |
|
196 |
new PointBehavior( |
|
197 |
new ZoomOutRightButtonListener(mapControl)) }); |
|
198 |
mapControl.addBehavior("pan", new MoveBehavior(new PanListenerImpl( |
|
199 |
mapControl))); |
|
200 |
|
|
201 |
IProjection defaultProjection = CRSFactory.getCRS(DEFAULT_CRS_CODE); |
|
202 |
mapControl.getViewPort().setProjection(defaultProjection); |
|
203 |
|
|
204 |
// Create actions |
|
205 |
createActions(); |
|
206 |
} catch (MapControlCreationException e) { |
|
207 |
logger.error("Can't create mapControl", e); |
|
189 |
public void addLayer(String shpPath) throws InitializeException, |
|
190 |
ProviderNotRegisteredException, ValidateDataParametersException, |
|
191 |
LoadLayerException { |
|
192 |
DataStoreParameters params; |
|
193 |
params = dataManager.createStoreParameters("Shape"); |
|
194 |
if (shpPath.isEmpty()) { |
|
195 |
shpPath = |
|
196 |
"/home/lmarques/data/cartography/Andalucia/muni_andalucia.shp"; |
|
208 | 197 |
} |
209 | 198 |
|
210 |
// Create JFrame to show data |
|
211 |
mainFrame = new JFrame("Editing test app"); |
|
212 |
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
213 |
mainFrame.setPreferredSize(new Dimension(800, 680)); |
|
214 |
mainFrame.add(mapControl, BorderLayout.CENTER); |
|
199 |
String dbfPath = |
|
200 |
shpPath.substring(0, shpPath.length() - 3).concat("dbf"); |
|
201 |
String shxPath = |
|
202 |
shpPath.substring(0, shpPath.length() - 3).concat("shx"); |
|
215 | 203 |
|
216 |
// Create JFrame to add layer |
|
217 |
createAddLayerJFrame(); |
|
204 |
File shpFile = new File(shpPath); |
|
205 |
File dbFile = new File(dbfPath); |
|
206 |
File shxFile = new File(shxPath); |
|
218 | 207 |
|
219 |
// create JFrame palette tools |
|
220 |
createShowPaletteTools(); |
|
208 |
params.setDynValue("shpFile", shpFile.getPath()); |
|
209 |
params.setDynValue("dbfFile", dbFile.getPath()); |
|
210 |
params.setDynValue("shxFile", shxFile.getPath()); |
|
211 |
params.setDynValue("CRS", defaultProjection); |
|
221 | 212 |
|
222 |
// Create menu bar |
|
223 |
createMenu(); |
|
213 |
store = (FeatureStore) dataManager.openStore("Shape", params); |
|
224 | 214 |
|
225 |
// Create tools bar |
|
226 |
createToolBar(); |
|
215 |
FLayer layer = mapContextManager.createLayer("prueba", store); |
|
216 |
mapControl.getMapContext().getLayers().addLayer(layer); |
|
217 |
mapControl.getMapContext().getLayers().setActive(true); |
|
218 |
try { |
|
219 |
currentLayer = (FLyrVect) layer; |
|
220 |
} catch (Exception e) { |
|
221 |
logger.error("Can't load layer " + e.getMessage()); |
|
222 |
} |
|
227 | 223 |
|
228 |
// Display the window. |
|
229 |
mainFrame.pack(); |
|
230 |
mainFrame.setLocation(500, 0); |
|
231 |
mainFrame.setVisible(true); |
|
232 | 224 |
} |
233 | 225 |
|
234 |
private void createAddLayerJFrame() { |
|
235 |
addLayerFrame = new JFrame("Add layer"); |
|
236 |
addLayerFrame.setLayout(new GridLayout(4, 2, 3, 3)); |
|
237 |
addLayerFrame.setPreferredSize(new Dimension(400, 150)); |
|
238 |
addLayerFrame.pack(); |
|
239 |
addLayerFrame.setLocation(250, 250); |
|
240 |
addLayerFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); |
|
241 |
|
|
242 |
JLabel shpLabel = new JLabel("Archivo SHP"); |
|
243 |
shpField = new JTextField(); |
|
244 |
|
|
245 |
addLayerFrame.add(shpLabel); |
|
246 |
addLayerFrame.add(shpField); |
|
247 |
addLayerFrame.add(new JLabel()); |
|
248 |
|
|
249 |
JButton aceptarButton = new JButton(addLayer); |
|
250 |
addLayerFrame.add(aceptarButton, BorderLayout.LINE_END); |
|
251 |
|
|
252 |
} |
|
253 |
|
|
254 |
private void createShowPaletteTools() { |
|
255 |
paletteTools = new JFrame("Palette tools"); |
|
256 |
paletteTools.setLayout(new GridLayout(20, 1, 1, 5)); |
|
257 |
paletteTools.setPreferredSize(new Dimension(200, 600)); |
|
258 |
paletteTools.pack(); |
|
259 |
paletteTools.setLocation(0, 0); |
|
260 |
paletteTools.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); |
|
261 |
|
|
262 |
JButton insertPointButton = new JButton(insertPoint); |
|
263 |
JButton circleCrButton = new JButton(circleCr); |
|
264 |
JButton polylineButton = new JButton(polyline); |
|
265 |
JButton symmetryButton = new JButton(symmetry); |
|
266 |
JButton internalPolygonButton = new JButton(internalPolygon); |
|
267 |
|
|
268 |
paletteTools.add(new JLabel("Insert tools")); |
|
269 |
paletteTools.add(insertPointButton); |
|
270 |
paletteTools.add(circleCrButton); |
|
271 |
paletteTools.add(polylineButton); |
|
272 |
|
|
273 |
paletteTools.add(new JLabel("Modify tools")); |
|
274 |
paletteTools.add(symmetryButton); |
|
275 |
paletteTools.add(internalPolygonButton); |
|
276 |
} |
|
277 |
|
|
278 |
private void createToolBar() { |
|
279 |
JToolBar toolBar = new JToolBar(); |
|
280 |
|
|
281 |
toolBar.add(new JButton(openAddLayerDialog)); |
|
282 |
toolBar.add(new JButton(editingExtensionAction)); |
|
283 |
toolBar.add(new JButton(endEditingExtensionAction)); |
|
284 |
toolBar.add(new JButton(pan)); |
|
285 |
toolBar.add(new JButton(zoom)); |
|
286 |
toolBar.add(new JButton(zoomall)); |
|
287 |
toolBar.add(new JButton(cleanMap)); |
|
288 |
toolBar.add(new JButton(openPaletteTools)); |
|
289 |
|
|
290 |
mainFrame.add(toolBar, BorderLayout.PAGE_START); |
|
291 |
} |
|
292 |
|
|
293 |
private void createMenu() { |
|
294 |
// Create the menu bar. |
|
295 |
JMenuBar menuBar = new JMenuBar(); |
|
296 |
|
|
297 |
// Build the menu. |
|
298 |
JMenu menuFile = new JMenu("File"); |
|
299 |
menuFile.add(new JMenuItem(exit)); |
|
300 |
|
|
301 |
JMenu menuLayer = new JMenu("Layer"); |
|
302 |
menuLayer.add(new JMenuItem(openAddLayerDialog)); |
|
303 |
menuLayer.add(new JMenuItem(pan)); |
|
304 |
menuLayer.add(new JMenuItem(zoom)); |
|
305 |
menuLayer.add(new JMenuItem(zoomall)); |
|
306 |
menuLayer.add(new JMenuItem(cleanMap)); |
|
307 |
|
|
308 |
JMenu menuTool = new JMenu("Tools"); |
|
309 |
menuTool.add(new JMenuItem(editingExtensionAction)); |
|
310 |
menuTool.add(new JMenuItem(endEditingExtensionAction)); |
|
311 |
menuTool.addSeparator(); |
|
312 |
menuTool.add(new JMenuItem(insertPoint)); |
|
313 |
menuTool.add(new JMenuItem(circleCr)); |
|
314 |
menuTool.add(new JMenuItem(polyline)); |
|
315 |
menuTool.add(new JMenuItem(polygon)); |
|
316 |
menuTool.add(new JMenuItem(symmetry)); |
|
317 |
|
|
318 |
menuBar.add(menuFile); |
|
319 |
menuBar.add(menuTool); |
|
320 |
|
|
321 |
mainFrame.setJMenuBar(menuBar); |
|
322 |
} |
|
323 |
|
|
324 | 226 |
@SuppressWarnings("serial") |
325 | 227 |
private void createActions() throws MapControlCreationException { |
326 | 228 |
|
... | ... | |
432 | 334 |
} |
433 | 335 |
}; |
434 | 336 |
|
435 |
circunferenceCr = new AbstractAction("CircunferenceCrAction") {
|
|
337 |
circumferenceCr = new AbstractAction("CircumferenceCrAction") {
|
|
436 | 338 |
|
437 | 339 |
public void actionPerformed(ActionEvent e) { |
438 | 340 |
editingContext = swingManager.getEditingContext(mapControl); |
... | ... | |
455 | 357 |
public void actionPerformed(ActionEvent e) { |
456 | 358 |
editingContext = swingManager.getEditingContext(mapControl); |
457 | 359 |
editingContext |
458 |
.activateService(PolylineEditingProviderFactory.PROVIDER_NAME);
|
|
360 |
.activateService(PolygonEditingProviderFactory.PROVIDER_NAME);
|
|
459 | 361 |
} |
460 | 362 |
}; |
461 | 363 |
|
... | ... | |
479 | 381 |
|
480 | 382 |
} |
481 | 383 |
|
482 |
public void addLayer(String shpPath) throws InitializeException, |
|
483 |
ProviderNotRegisteredException, ValidateDataParametersException, |
|
484 |
LoadLayerException { |
|
485 |
DataStoreParameters params; |
|
486 |
params = dataManager.createStoreParameters("Shape"); |
|
487 |
if (shpPath.isEmpty()) { |
|
488 |
shpPath = |
|
489 |
"/home/lmarques/data/cartography/Andalucia/muni_andalucia.shp"; |
|
490 |
} |
|
384 |
private void createAddLayerJFrame() { |
|
385 |
addLayerFrame = new JFrame("Add layer"); |
|
386 |
addLayerFrame.setLayout(new GridLayout(4, 2, 3, 3)); |
|
387 |
addLayerFrame.setPreferredSize(new Dimension(400, 150)); |
|
388 |
addLayerFrame.pack(); |
|
389 |
addLayerFrame.setLocation(250, 250); |
|
390 |
addLayerFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); |
|
491 | 391 |
|
492 |
String dbfPath = |
|
493 |
shpPath.substring(0, shpPath.length() - 3).concat("dbf"); |
|
494 |
String shxPath = |
|
495 |
shpPath.substring(0, shpPath.length() - 3).concat("shx"); |
|
392 |
JLabel shpLabel = new JLabel("Archivo SHP"); |
|
393 |
shpField = new JTextField(); |
|
496 | 394 |
|
497 |
File shpFile = new File(shpPath);
|
|
498 |
File dbFile = new File(dbfPath);
|
|
499 |
File shxFile = new File(shxPath);
|
|
395 |
addLayerFrame.add(shpLabel);
|
|
396 |
addLayerFrame.add(shpField);
|
|
397 |
addLayerFrame.add(new JLabel());
|
|
500 | 398 |
|
501 |
params.setDynValue("shpFile", shpFile.getPath()); |
|
502 |
params.setDynValue("dbfFile", dbFile.getPath()); |
|
503 |
params.setDynValue("shxFile", shxFile.getPath()); |
|
504 |
params.setDynValue("CRS", defaultProjection); |
|
399 |
JButton aceptarButton = new JButton(addLayer); |
|
400 |
addLayerFrame.add(aceptarButton, BorderLayout.LINE_END); |
|
505 | 401 |
|
506 |
store = (FeatureStore) dataManager.openStore("Shape", params);
|
|
402 |
}
|
|
507 | 403 |
|
508 |
FLayer layer = mapContextManager.createLayer("prueba", store); |
|
509 |
mapControl.getMapContext().getLayers().addLayer(layer); |
|
510 |
mapControl.getMapContext().getLayers().setActive(true); |
|
404 |
private void createMenu() { |
|
405 |
// Create the menu bar. |
|
406 |
JMenuBar menuBar = new JMenuBar(); |
|
407 |
|
|
408 |
// Build the menu. |
|
409 |
JMenu menuFile = new JMenu("File"); |
|
410 |
menuFile.add(new JMenuItem(exit)); |
|
411 |
|
|
412 |
JMenu menuLayer = new JMenu("Layer"); |
|
413 |
menuLayer.add(new JMenuItem(openAddLayerDialog)); |
|
414 |
menuLayer.add(new JMenuItem(pan)); |
|
415 |
menuLayer.add(new JMenuItem(zoom)); |
|
416 |
menuLayer.add(new JMenuItem(zoomall)); |
|
417 |
menuLayer.add(new JMenuItem(cleanMap)); |
|
418 |
|
|
419 |
JMenu menuTool = new JMenu("Tools"); |
|
420 |
menuTool.add(new JMenuItem(editingExtensionAction)); |
|
421 |
menuTool.add(new JMenuItem(endEditingExtensionAction)); |
|
422 |
menuTool.addSeparator(); |
|
423 |
menuTool.add(new JMenuItem(insertPoint)); |
|
424 |
menuTool.add(new JMenuItem(circleCr)); |
|
425 |
menuTool.add(new JMenuItem(circumferenceCr)); |
|
426 |
menuTool.add(new JMenuItem(polyline)); |
|
427 |
menuTool.add(new JMenuItem(polygon)); |
|
428 |
menuTool.add(new JMenuItem(symmetry)); |
|
429 |
|
|
430 |
menuBar.add(menuFile); |
|
431 |
menuBar.add(menuTool); |
|
432 |
|
|
433 |
mainFrame.setJMenuBar(menuBar); |
|
434 |
} |
|
435 |
|
|
436 |
private void createShowPaletteTools() { |
|
437 |
paletteTools = new JFrame("Palette tools"); |
|
438 |
paletteTools.setLayout(new GridLayout(20, 1, 1, 5)); |
|
439 |
paletteTools.setPreferredSize(new Dimension(200, 600)); |
|
440 |
paletteTools.pack(); |
|
441 |
paletteTools.setLocation(0, 0); |
|
442 |
paletteTools.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); |
|
443 |
|
|
444 |
JButton insertPointButton = new JButton(insertPoint); |
|
445 |
JButton circleCrButton = new JButton(circleCr); |
|
446 |
JButton circumferenceCr = new JButton("circumferenceCr"); |
|
447 |
JButton polylineButton = new JButton(polyline); |
|
448 |
JButton polygonButton = new JButton(polygon); |
|
449 |
JButton symmetryButton = new JButton(symmetry); |
|
450 |
JButton internalPolygonButton = new JButton(internalPolygon); |
|
451 |
|
|
452 |
paletteTools.add(new JLabel("Insert tools")); |
|
453 |
paletteTools.add(insertPointButton); |
|
454 |
paletteTools.add(circleCrButton); |
|
455 |
paletteTools.add(circumferenceCr); |
|
456 |
paletteTools.add(polylineButton); |
|
457 |
paletteTools.add(polygonButton); |
|
458 |
|
|
459 |
paletteTools.add(new JLabel("Modify tools")); |
|
460 |
paletteTools.add(symmetryButton); |
|
461 |
paletteTools.add(internalPolygonButton); |
|
462 |
} |
|
463 |
|
|
464 |
private void createToolBar() { |
|
465 |
JToolBar toolBar = new JToolBar(); |
|
466 |
|
|
467 |
toolBar.add(new JButton(openAddLayerDialog)); |
|
468 |
toolBar.add(new JButton(editingExtensionAction)); |
|
469 |
toolBar.add(new JButton(endEditingExtensionAction)); |
|
470 |
toolBar.add(new JButton(pan)); |
|
471 |
toolBar.add(new JButton(zoom)); |
|
472 |
toolBar.add(new JButton(zoomall)); |
|
473 |
toolBar.add(new JButton(cleanMap)); |
|
474 |
toolBar.add(new JButton(openPaletteTools)); |
|
475 |
|
|
476 |
mainFrame.add(toolBar, BorderLayout.PAGE_START); |
|
477 |
} |
|
478 |
|
|
479 |
public void doMain() { |
|
480 |
|
|
511 | 481 |
try { |
512 |
currentLayer = (FLyrVect) layer; |
|
513 |
} catch (Exception e) { |
|
514 |
logger.error("Can't load layer " + e.getMessage()); |
|
482 |
mapControl = mapControlManager.createJMapControlPanel(); |
|
483 |
|
|
484 |
mapControl |
|
485 |
.addBehavior("zoom", new Behavior[] { |
|
486 |
new RectangleBehavior(new ZoomInListenerImpl(mapControl)), |
|
487 |
new PointBehavior( |
|
488 |
new ZoomOutRightButtonListener(mapControl)) }); |
|
489 |
mapControl.addBehavior("pan", new MoveBehavior(new PanListenerImpl( |
|
490 |
mapControl))); |
|
491 |
|
|
492 |
IProjection defaultProjection = CRSFactory.getCRS(DEFAULT_CRS_CODE); |
|
493 |
mapControl.getViewPort().setProjection(defaultProjection); |
|
494 |
|
|
495 |
swingManager.registerEditingContext(mapControl); |
|
496 |
|
|
497 |
// Create actions |
|
498 |
createActions(); |
|
499 |
} catch (MapControlCreationException e) { |
|
500 |
logger.error("Can't create mapControl", e); |
|
515 | 501 |
} |
516 | 502 |
|
503 |
// Create JFrame to show data |
|
504 |
mainFrame = new JFrame("Editing test app"); |
|
505 |
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
506 |
mainFrame.setPreferredSize(new Dimension(800, 680)); |
|
507 |
mainFrame.add(mapControl, BorderLayout.CENTER); |
|
508 |
|
|
509 |
// Create JFrame to add layer |
|
510 |
createAddLayerJFrame(); |
|
511 |
|
|
512 |
// create JFrame palette tools |
|
513 |
createShowPaletteTools(); |
|
514 |
|
|
515 |
// Create menu bar |
|
516 |
createMenu(); |
|
517 |
|
|
518 |
// Create tools bar |
|
519 |
createToolBar(); |
|
520 |
|
|
521 |
// Display the window. |
|
522 |
mainFrame.pack(); |
|
523 |
mainFrame.setLocation(500, 0); |
|
524 |
mainFrame.setVisible(true); |
|
517 | 525 |
} |
518 | 526 |
|
527 |
public JFrame getJFrame() { |
|
528 |
return this.addLayerFrame; |
|
529 |
} |
|
530 |
|
|
519 | 531 |
private void zoomAll() { |
520 | 532 |
MapContext mapContext = mapControl.getMapContext(); |
521 | 533 |
Envelope all = mapContext.getLayers().getFullEnvelope(); |
... | ... | |
523 | 535 |
mapContext.getViewPort().setEnvelope(all); |
524 | 536 |
mapContext.invalidate(); |
525 | 537 |
} |
526 |
|
|
527 |
public JFrame getJFrame() { |
|
528 |
return this.addLayerFrame; |
|
529 |
} |
|
530 | 538 |
} |
Also available in: Unified diff