Revision 95 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.main/src/main/java/org/gvsig/vectorediting/main/Main.java
Main.java | ||
---|---|---|
76 | 76 |
import org.gvsig.vectorediting.lib.prov.circlecr.CircumferenceCREditingProviderFactory; |
77 | 77 |
import org.gvsig.vectorediting.lib.prov.insertpoint.InsertPointEditingProviderFactory; |
78 | 78 |
import org.gvsig.vectorediting.lib.prov.internalpolygon.InternalPolygonEditingProviderFactory; |
79 |
import org.gvsig.vectorediting.lib.prov.polyline.PolygonEditingProviderFactory; |
|
79 | 80 |
import org.gvsig.vectorediting.lib.prov.polyline.PolylineEditingProviderFactory; |
80 | 81 |
import org.gvsig.vectorediting.lib.prov.symmetry.SymmetryEditingProviderFactory; |
81 | 82 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
... | ... | |
95 | 96 |
*/ |
96 | 97 |
public class Main { |
97 | 98 |
|
98 |
private static final Logger logger = LoggerFactory.getLogger(Main.class);
|
|
99 |
private static final Logger logger = LoggerFactory.getLogger(Main.class);
|
|
99 | 100 |
|
100 |
final EditingManager manager;
|
|
101 |
final EditingManager manager;
|
|
101 | 102 |
|
102 |
final EditingSwingManager swingManager;
|
|
103 |
final EditingSwingManager swingManager;
|
|
103 | 104 |
|
104 |
final EditingProviderManager providerManager;
|
|
105 |
final EditingProviderManager providerManager;
|
|
105 | 106 |
|
106 |
final MapControlManager mapControlManager;
|
|
107 |
final MapControlManager mapControlManager;
|
|
107 | 108 |
|
108 |
final DataManager dataManager;
|
|
109 |
final DataManager dataManager;
|
|
109 | 110 |
|
110 |
final MapContextManager mapContextManager;
|
|
111 |
final MapContextManager mapContextManager;
|
|
111 | 112 |
|
112 |
EditingBehavior editingBehavior;
|
|
113 |
EditingBehavior editingBehavior;
|
|
113 | 114 |
|
114 |
MapControl mapControl;
|
|
115 |
|
|
115 |
MapControl mapControl;
|
|
116 |
|
|
116 | 117 |
EditingContext editingContext; |
117 | 118 |
|
118 |
FeatureStore store;
|
|
119 |
FeatureStore store;
|
|
119 | 120 |
|
120 |
FLyrVect currentLayer;
|
|
121 |
FLyrVect currentLayer;
|
|
121 | 122 |
|
122 |
final String DEFAULT_CRS_CODE = "EPSG:23030";
|
|
123 |
final String DEFAULT_CRS_CODE = "EPSG:23030";
|
|
123 | 124 |
|
124 |
IProjection defaultProjection;
|
|
125 |
IProjection defaultProjection;
|
|
125 | 126 |
|
126 |
TrivialLayerOrderManager layerOrderManager;
|
|
127 |
TrivialLayerOrderManager layerOrderManager;
|
|
127 | 128 |
|
128 |
JFrame mainFrame;
|
|
129 |
JFrame mainFrame;
|
|
129 | 130 |
|
130 |
JFrame addLayerFrame;
|
|
131 |
JFrame addLayerFrame;
|
|
131 | 132 |
|
132 |
JFrame paletteTools;
|
|
133 |
JFrame paletteTools;
|
|
133 | 134 |
|
134 |
JTextField shpField;
|
|
135 |
JTextField shpField;
|
|
135 | 136 |
|
136 |
// Actions
|
|
137 |
AbstractAction pan;
|
|
137 |
// Actions
|
|
138 |
AbstractAction pan;
|
|
138 | 139 |
|
139 |
AbstractAction zoom;
|
|
140 |
AbstractAction zoom;
|
|
140 | 141 |
|
141 |
AbstractAction zoomall;
|
|
142 |
AbstractAction zoomall;
|
|
142 | 143 |
|
143 |
AbstractAction cleanMap;
|
|
144 |
AbstractAction cleanMap;
|
|
144 | 145 |
|
145 |
AbstractAction openAddLayerDialog;
|
|
146 |
AbstractAction openAddLayerDialog;
|
|
146 | 147 |
|
147 |
AbstractAction openPaletteTools;
|
|
148 |
AbstractAction openPaletteTools;
|
|
148 | 149 |
|
149 |
AbstractAction editingExtensionAction; |
|
150 |
|
|
151 |
AbstractAction endEditingExtensionAction; |
|
150 |
AbstractAction editingExtensionAction; |
|
152 | 151 |
|
153 |
AbstractAction insertPoint;
|
|
152 |
AbstractAction endEditingExtensionAction;
|
|
154 | 153 |
|
155 |
AbstractAction exit;
|
|
154 |
AbstractAction insertPoint;
|
|
156 | 155 |
|
157 |
AbstractAction addLayer;
|
|
156 |
AbstractAction exit;
|
|
158 | 157 |
|
159 |
AbstractAction circleCr;
|
|
158 |
AbstractAction addLayer;
|
|
160 | 159 |
|
161 |
AbstractAction circunferenceCr;
|
|
160 |
AbstractAction circleCr;
|
|
162 | 161 |
|
163 |
AbstractAction polyline;
|
|
162 |
AbstractAction circunferenceCr;
|
|
164 | 163 |
|
165 |
AbstractAction symmetry; |
|
166 |
|
|
167 |
AbstractAction internalPolygon; |
|
164 |
AbstractAction polyline; |
|
168 | 165 |
|
169 |
public static void main(String args[]) { |
|
170 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
171 |
Main main = new Main(); |
|
172 |
main.doMain(); |
|
173 |
} |
|
166 |
AbstractAction polygon; |
|
174 | 167 |
|
175 |
public Main() { |
|
176 |
manager = EditingLocator.getManager(); |
|
177 |
swingManager = EditingSwingLocator.getSwingManager(); |
|
178 |
providerManager = EditingProviderLocator.getProviderManager(); |
|
179 |
mapControlManager = MapControlLocator.getMapControlManager(); |
|
180 |
dataManager = DALLocator.getDataManager(); |
|
181 |
mapContextManager = MapContextLocator.getMapContextManager(); |
|
182 |
defaultProjection = CRSFactory.getCRS(DEFAULT_CRS_CODE); |
|
183 |
layerOrderManager = new TrivialLayerOrderManager(); |
|
184 |
} |
|
168 |
AbstractAction symmetry; |
|
185 | 169 |
|
186 |
public void doMain() {
|
|
170 |
AbstractAction internalPolygon;
|
|
187 | 171 |
|
188 |
try { |
|
189 |
mapControl = mapControlManager.createJMapControlPanel(); |
|
190 |
|
|
191 |
// editingBehavior = new DefaultEditingBehavior(editingContext, mapControl); |
|
192 |
// EditingCompoundBehavior editingCompoundBehavior = new EditingCompoundBehavior(editingBehavior); |
|
193 |
// mapControl.addBehavior("VectorEditing", editingCompoundBehavior); |
|
172 |
public static void main(String args[]) { |
|
173 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
174 |
Main main = new Main(); |
|
175 |
main.doMain(); |
|
176 |
} |
|
194 | 177 |
|
195 |
mapControl.addBehavior("zoom", new Behavior[] { |
|
196 |
new RectangleBehavior(new ZoomInListenerImpl(mapControl)), |
|
197 |
new PointBehavior(new ZoomOutRightButtonListener(mapControl)) }); |
|
198 |
mapControl.addBehavior("pan", new MoveBehavior(new PanListenerImpl(mapControl))); |
|
178 |
public Main() { |
|
179 |
manager = EditingLocator.getManager(); |
|
180 |
swingManager = EditingSwingLocator.getSwingManager(); |
|
181 |
providerManager = EditingProviderLocator.getProviderManager(); |
|
182 |
mapControlManager = MapControlLocator.getMapControlManager(); |
|
183 |
dataManager = DALLocator.getDataManager(); |
|
184 |
mapContextManager = MapContextLocator.getMapContextManager(); |
|
185 |
defaultProjection = CRSFactory.getCRS(DEFAULT_CRS_CODE); |
|
186 |
layerOrderManager = new TrivialLayerOrderManager(); |
|
187 |
} |
|
199 | 188 |
|
189 |
public void doMain() { |
|
200 | 190 |
|
201 |
IProjection defaultProjection = CRSFactory.getCRS(DEFAULT_CRS_CODE);
|
|
202 |
mapControl.getViewPort().setProjection(defaultProjection);
|
|
191 |
try {
|
|
192 |
mapControl = mapControlManager.createJMapControlPanel();
|
|
203 | 193 |
|
204 |
// Create actions |
|
205 |
createActions(); |
|
206 |
} |
|
207 |
catch (MapControlCreationException e) { |
|
208 |
logger.error("Can't create mapControl",e); |
|
209 |
} |
|
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); |
|
194 |
// editingBehavior = new DefaultEditingBehavior(editingContext, mapControl); |
|
195 |
// EditingCompoundBehavior editingCompoundBehavior = new EditingCompoundBehavior(editingBehavior); |
|
196 |
// mapControl.addBehavior("VectorEditing", editingCompoundBehavior); |
|
215 | 197 |
|
216 |
// Create JFrame to add layer |
|
217 |
createAddLayerJFrame(); |
|
198 |
mapControl.addBehavior("zoom", new Behavior[] { |
|
199 |
new RectangleBehavior(new ZoomInListenerImpl(mapControl)), |
|
200 |
new PointBehavior( |
|
201 |
new ZoomOutRightButtonListener(mapControl)) }); |
|
202 |
mapControl.addBehavior("pan", new MoveBehavior(new PanListenerImpl( |
|
203 |
mapControl))); |
|
218 | 204 |
|
219 |
// create JFrame palette tools
|
|
220 |
createShowPaletteTools();
|
|
205 |
IProjection defaultProjection = CRSFactory.getCRS(DEFAULT_CRS_CODE);
|
|
206 |
mapControl.getViewPort().setProjection(defaultProjection);
|
|
221 | 207 |
|
222 |
// Create menu bar |
|
223 |
createMenu(); |
|
208 |
// Create actions |
|
209 |
createActions(); |
|
210 |
} catch (MapControlCreationException e) { |
|
211 |
logger.error("Can't create mapControl", e); |
|
212 |
} |
|
224 | 213 |
|
225 |
// Create tools bar |
|
226 |
createToolBar(); |
|
214 |
// Create JFrame to show data |
|
215 |
mainFrame = new JFrame("Editing test app"); |
|
216 |
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
217 |
mainFrame.setPreferredSize(new Dimension(800, 680)); |
|
218 |
mainFrame.add(mapControl, BorderLayout.CENTER); |
|
227 | 219 |
|
228 |
// Display the window. |
|
229 |
mainFrame.pack(); |
|
230 |
mainFrame.setLocation(500, 0); |
|
231 |
mainFrame.setVisible(true); |
|
232 |
} |
|
220 |
// Create JFrame to add layer |
|
221 |
createAddLayerJFrame(); |
|
233 | 222 |
|
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); |
|
223 |
// create JFrame palette tools |
|
224 |
createShowPaletteTools(); |
|
241 | 225 |
|
242 |
JLabel shpLabel = new JLabel("Archivo SHP");
|
|
243 |
shpField = new JTextField();
|
|
226 |
// Create menu bar
|
|
227 |
createMenu();
|
|
244 | 228 |
|
245 |
addLayerFrame.add(shpLabel); |
|
246 |
addLayerFrame.add(shpField); |
|
247 |
addLayerFrame.add(new JLabel()); |
|
229 |
// Create tools bar |
|
230 |
createToolBar(); |
|
248 | 231 |
|
249 |
JButton aceptarButton = new JButton(addLayer); |
|
250 |
addLayerFrame.add(aceptarButton, BorderLayout.LINE_END); |
|
232 |
// Display the window. |
|
233 |
mainFrame.pack(); |
|
234 |
mainFrame.setLocation(500, 0); |
|
235 |
mainFrame.setVisible(true); |
|
236 |
} |
|
251 | 237 |
|
252 |
} |
|
238 |
private void createAddLayerJFrame() { |
|
239 |
addLayerFrame = new JFrame("Add layer"); |
|
240 |
addLayerFrame.setLayout(new GridLayout(4, 2, 3, 3)); |
|
241 |
addLayerFrame.setPreferredSize(new Dimension(400, 150)); |
|
242 |
addLayerFrame.pack(); |
|
243 |
addLayerFrame.setLocation(250, 250); |
|
244 |
addLayerFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); |
|
253 | 245 |
|
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); |
|
246 |
JLabel shpLabel = new JLabel("Archivo SHP"); |
|
247 |
shpField = new JTextField(); |
|
261 | 248 |
|
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); |
|
249 |
addLayerFrame.add(shpLabel); |
|
250 |
addLayerFrame.add(shpField); |
|
251 |
addLayerFrame.add(new JLabel()); |
|
267 | 252 |
|
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 |
} |
|
253 |
JButton aceptarButton = new JButton(addLayer); |
|
254 |
addLayerFrame.add(aceptarButton, BorderLayout.LINE_END); |
|
277 | 255 |
|
278 |
private void createToolBar() { |
|
279 |
JToolBar toolBar = new JToolBar(); |
|
256 |
} |
|
280 | 257 |
|
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)); |
|
258 |
private void createShowPaletteTools() { |
|
259 |
paletteTools = new JFrame("Palette tools"); |
|
260 |
paletteTools.setLayout(new GridLayout(20, 1, 1, 5)); |
|
261 |
paletteTools.setPreferredSize(new Dimension(200, 600)); |
|
262 |
paletteTools.pack(); |
|
263 |
paletteTools.setLocation(0, 0); |
|
264 |
paletteTools.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); |
|
289 | 265 |
|
290 |
mainFrame.add(toolBar, BorderLayout.PAGE_START); |
|
291 |
} |
|
266 |
JButton insertPointButton = new JButton(insertPoint); |
|
267 |
JButton circleCrButton = new JButton(circleCr); |
|
268 |
JButton polylineButton = new JButton(polyline); |
|
269 |
JButton symmetryButton = new JButton(symmetry); |
|
270 |
JButton internalPolygonButton = new JButton(internalPolygon); |
|
292 | 271 |
|
293 |
private void createMenu() { |
|
294 |
// Create the menu bar. |
|
295 |
JMenuBar menuBar = new JMenuBar(); |
|
272 |
paletteTools.add(new JLabel("Insert tools")); |
|
273 |
paletteTools.add(insertPointButton); |
|
274 |
paletteTools.add(circleCrButton); |
|
275 |
paletteTools.add(polylineButton); |
|
296 | 276 |
|
297 |
// Build the menu. |
|
298 |
JMenu menuFile = new JMenu("File"); |
|
299 |
menuFile.add(new JMenuItem(exit)); |
|
277 |
paletteTools.add(new JLabel("Modify tools")); |
|
278 |
paletteTools.add(symmetryButton); |
|
279 |
paletteTools.add(internalPolygonButton); |
|
280 |
} |
|
300 | 281 |
|
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)); |
|
282 |
private void createToolBar() { |
|
283 |
JToolBar toolBar = new JToolBar(); |
|
307 | 284 |
|
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(symmetry));
|
|
285 |
toolBar.add(new JButton(openAddLayerDialog));
|
|
286 |
toolBar.add(new JButton(editingExtensionAction));
|
|
287 |
toolBar.add(new JButton(endEditingExtensionAction));
|
|
288 |
toolBar.add(new JButton(pan));
|
|
289 |
toolBar.add(new JButton(zoom));
|
|
290 |
toolBar.add(new JButton(zoomall));
|
|
291 |
toolBar.add(new JButton(cleanMap));
|
|
292 |
toolBar.add(new JButton(openPaletteTools));
|
|
316 | 293 |
|
317 |
menuBar.add(menuFile);
|
|
318 |
menuBar.add(menuTool);
|
|
294 |
mainFrame.add(toolBar, BorderLayout.PAGE_START);
|
|
295 |
}
|
|
319 | 296 |
|
320 |
mainFrame.setJMenuBar(menuBar); |
|
321 |
} |
|
297 |
private void createMenu() { |
|
298 |
// Create the menu bar. |
|
299 |
JMenuBar menuBar = new JMenuBar(); |
|
322 | 300 |
|
323 |
@SuppressWarnings("serial") |
|
324 |
private void createActions() throws MapControlCreationException { |
|
301 |
// Build the menu. |
|
302 |
JMenu menuFile = new JMenu("File"); |
|
303 |
menuFile.add(new JMenuItem(exit)); |
|
325 | 304 |
|
326 |
pan = new AbstractAction("Pan") { |
|
305 |
JMenu menuLayer = new JMenu("Layer"); |
|
306 |
menuLayer.add(new JMenuItem(openAddLayerDialog)); |
|
307 |
menuLayer.add(new JMenuItem(pan)); |
|
308 |
menuLayer.add(new JMenuItem(zoom)); |
|
309 |
menuLayer.add(new JMenuItem(zoomall)); |
|
310 |
menuLayer.add(new JMenuItem(cleanMap)); |
|
327 | 311 |
|
328 |
public void actionPerformed(ActionEvent e) { |
|
329 |
mapControl.setTool("pan"); |
|
330 |
} |
|
331 |
}; |
|
312 |
JMenu menuTool = new JMenu("Tools"); |
|
313 |
menuTool.add(new JMenuItem(editingExtensionAction)); |
|
314 |
menuTool.add(new JMenuItem(endEditingExtensionAction)); |
|
315 |
menuTool.addSeparator(); |
|
316 |
menuTool.add(new JMenuItem(insertPoint)); |
|
317 |
menuTool.add(new JMenuItem(circleCr)); |
|
318 |
menuTool.add(new JMenuItem(polyline)); |
|
319 |
menuTool.add(new JMenuItem(polygon)); |
|
320 |
menuTool.add(new JMenuItem(symmetry)); |
|
332 | 321 |
|
333 |
zoom = new AbstractAction("Zoom") { |
|
322 |
menuBar.add(menuFile); |
|
323 |
menuBar.add(menuTool); |
|
334 | 324 |
|
335 |
public void actionPerformed(ActionEvent e) { |
|
336 |
mapControl.setTool("zoom"); |
|
337 |
} |
|
338 |
}; |
|
325 |
mainFrame.setJMenuBar(menuBar); |
|
326 |
} |
|
339 | 327 |
|
340 |
zoomall = new AbstractAction("Zoom all") { |
|
328 |
@SuppressWarnings("serial") |
|
329 |
private void createActions() throws MapControlCreationException { |
|
341 | 330 |
|
342 |
public void actionPerformed(ActionEvent e) { |
|
343 |
zoomAll(); |
|
344 |
} |
|
345 |
}; |
|
331 |
pan = new AbstractAction("Pan") { |
|
346 | 332 |
|
347 |
cleanMap = new AbstractAction("Clean Map") { |
|
333 |
public void actionPerformed(ActionEvent e) { |
|
334 |
mapControl.setTool("pan"); |
|
335 |
} |
|
336 |
}; |
|
348 | 337 |
|
349 |
public void actionPerformed(ActionEvent e) { |
|
350 |
MapContext mapContext = mapControl.getMapContext(); |
|
351 |
mapContext.beginAtomicEvent(); |
|
352 |
while (mapContext.getLayers().getLayersCount() > 0) { |
|
353 |
mapContext.getLayers().removeLayer(0); |
|
354 |
} |
|
355 |
mapContext.endAtomicEvent(); |
|
356 |
|
|
357 |
} |
|
358 |
}; |
|
338 |
zoom = new AbstractAction("Zoom") { |
|
359 | 339 |
|
360 |
openAddLayerDialog = new AbstractAction("Add layer") { |
|
340 |
public void actionPerformed(ActionEvent e) { |
|
341 |
mapControl.setTool("zoom"); |
|
342 |
} |
|
343 |
}; |
|
361 | 344 |
|
362 |
public void actionPerformed(ActionEvent e) { |
|
363 |
addLayerFrame.setVisible(true); |
|
364 |
} |
|
365 |
}; |
|
345 |
zoomall = new AbstractAction("Zoom all") { |
|
366 | 346 |
|
367 |
openPaletteTools = new AbstractAction("Show palette tools") { |
|
347 |
public void actionPerformed(ActionEvent e) { |
|
348 |
zoomAll(); |
|
349 |
} |
|
350 |
}; |
|
368 | 351 |
|
369 |
public void actionPerformed(ActionEvent e) { |
|
370 |
paletteTools.setVisible(true); |
|
371 |
} |
|
372 |
}; |
|
352 |
cleanMap = new AbstractAction("Clean Map") { |
|
373 | 353 |
|
374 |
addLayer = new AbstractAction("OK") { |
|
354 |
public void actionPerformed(ActionEvent e) { |
|
355 |
MapContext mapContext = mapControl.getMapContext(); |
|
356 |
mapContext.beginAtomicEvent(); |
|
357 |
while (mapContext.getLayers().getLayersCount() > 0) { |
|
358 |
mapContext.getLayers().removeLayer(0); |
|
359 |
} |
|
360 |
mapContext.endAtomicEvent(); |
|
375 | 361 |
|
376 |
public void actionPerformed(ActionEvent e) {
|
|
377 |
String shpPath = shpField.getText();
|
|
362 |
}
|
|
363 |
};
|
|
378 | 364 |
|
379 |
try { |
|
380 |
addLayer(shpPath); |
|
381 |
} |
|
382 |
catch (Exception e1) { |
|
383 |
logger.error("Problems adding layer"); |
|
384 |
e1.printStackTrace(); |
|
385 |
} |
|
386 |
addLayerFrame.setVisible(false); |
|
387 |
} |
|
388 |
}; |
|
365 |
openAddLayerDialog = new AbstractAction("Add layer") { |
|
389 | 366 |
|
390 |
exit = new AbstractAction("Exit") { |
|
367 |
public void actionPerformed(ActionEvent e) { |
|
368 |
addLayerFrame.setVisible(true); |
|
369 |
} |
|
370 |
}; |
|
391 | 371 |
|
392 |
public void actionPerformed(ActionEvent e) { |
|
393 |
System.exit(0); |
|
394 |
} |
|
395 |
}; |
|
372 |
openPaletteTools = new AbstractAction("Show palette tools") { |
|
396 | 373 |
|
397 |
editingExtensionAction = new AbstractAction("EditingExtension") { |
|
374 |
public void actionPerformed(ActionEvent e) { |
|
375 |
paletteTools.setVisible(true); |
|
376 |
} |
|
377 |
}; |
|
398 | 378 |
|
399 |
public void actionPerformed(ActionEvent e) { |
|
379 |
addLayer = new AbstractAction("OK") { |
|
380 |
|
|
381 |
public void actionPerformed(ActionEvent e) { |
|
382 |
String shpPath = shpField.getText(); |
|
383 |
|
|
384 |
try { |
|
385 |
addLayer(shpPath); |
|
386 |
} catch (Exception e1) { |
|
387 |
logger.error("Problems adding layer"); |
|
388 |
e1.printStackTrace(); |
|
389 |
} |
|
390 |
addLayerFrame.setVisible(false); |
|
391 |
} |
|
392 |
}; |
|
393 |
|
|
394 |
exit = new AbstractAction("Exit") { |
|
395 |
|
|
396 |
public void actionPerformed(ActionEvent e) { |
|
397 |
System.exit(0); |
|
398 |
} |
|
399 |
}; |
|
400 |
|
|
401 |
editingExtensionAction = new AbstractAction("EditingExtension") { |
|
402 |
|
|
403 |
public void actionPerformed(ActionEvent e) { |
|
400 | 404 |
editingContext = swingManager.getEditingContext(mapControl); |
401 | 405 |
editingContext.beginEdition(currentLayer, null); |
402 | 406 |
|
403 | 407 |
// XXX Forces component repaint. |
404 | 408 |
SwingUtilities.updateComponentTreeUI(mainFrame); |
405 |
} |
|
406 |
}; |
|
407 |
|
|
408 |
endEditingExtensionAction = new AbstractAction("EndEditingExtension") { |
|
409 |
} |
|
410 |
}; |
|
409 | 411 |
|
410 |
public void actionPerformed(ActionEvent e) { |
|
412 |
endEditingExtensionAction = new AbstractAction("EndEditingExtension") { |
|
413 |
|
|
414 |
public void actionPerformed(ActionEvent e) { |
|
411 | 415 |
editingContext = swingManager.getEditingContext(mapControl); |
412 | 416 |
editingContext.endEdition(currentLayer); |
413 |
}
|
|
414 |
};
|
|
417 |
}
|
|
418 |
};
|
|
415 | 419 |
|
416 |
insertPoint = new AbstractAction("InsertPointAction") {
|
|
420 |
insertPoint = new AbstractAction("InsertPointAction") {
|
|
417 | 421 |
|
418 |
public void actionPerformed(ActionEvent e) {
|
|
419 |
editingContext = swingManager.getEditingContext(mapControl); |
|
420 |
editingContext.activateService( |
|
421 |
InsertPointEditingProviderFactory.PROVIDER_NAME); |
|
422 |
}
|
|
422 |
public void actionPerformed(ActionEvent e) {
|
|
423 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
424 |
editingContext.activateService(
|
|
425 |
InsertPointEditingProviderFactory.PROVIDER_NAME);
|
|
426 |
}
|
|
423 | 427 |
|
424 |
};
|
|
428 |
};
|
|
425 | 429 |
|
426 |
circleCr = new AbstractAction("CircleCrAction") {
|
|
430 |
circleCr = new AbstractAction("CircleCrAction") {
|
|
427 | 431 |
|
428 |
public void actionPerformed(ActionEvent e) {
|
|
429 |
editingContext = swingManager.getEditingContext(mapControl); |
|
430 |
editingContext.activateService(CircleCREditingProviderFactory.PROVIDER_NAME); |
|
431 |
}
|
|
432 |
};
|
|
432 |
public void actionPerformed(ActionEvent e) {
|
|
433 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
434 |
editingContext.activateService(CircleCREditingProviderFactory.PROVIDER_NAME);
|
|
435 |
}
|
|
436 |
};
|
|
433 | 437 |
|
434 |
circunferenceCr = new AbstractAction("CircunferenceCrAction") {
|
|
438 |
circunferenceCr = new AbstractAction("CircunferenceCrAction") {
|
|
435 | 439 |
|
436 |
public void actionPerformed(ActionEvent e) {
|
|
437 |
editingContext = swingManager.getEditingContext(mapControl); |
|
438 |
editingContext.activateService(CircumferenceCREditingProviderFactory.PROVIDER_NAME); |
|
439 |
}
|
|
440 |
};
|
|
440 |
public void actionPerformed(ActionEvent e) {
|
|
441 |
editingContext = swingManager.getEditingContext(mapControl);
|
|
442 |
editingContext.activateService(CircumferenceCREditingProviderFactory.PROVIDER_NAME);
|
|
443 |
}
|
|
444 |
};
|
|
441 | 445 |
|
442 |
|
|
443 |
polyline = new AbstractAction("PolylineAction") { |
|
446 |
polyline = new AbstractAction("PolylineAction") { |
|
444 | 447 |
|
445 |
public void actionPerformed(ActionEvent e) { |
|
446 |
editingContext = swingManager.getEditingContext(mapControl); |
|
447 |
editingContext.activateService(PolylineEditingProviderFactory.PROVIDER_NAME); |
|
448 |
} |
|
449 |
}; |
|
450 |
|
|
448 |
public void actionPerformed(ActionEvent e) { |
|
449 |
editingContext = swingManager.getEditingContext(mapControl); |
|
450 |
editingContext.activateService(PolylineEditingProviderFactory.PROVIDER_NAME); |
|
451 |
} |
|
452 |
}; |
|
451 | 453 |
|
452 |
symmetry = new AbstractAction("SymmetryAction") {
|
|
454 |
polygon = new AbstractAction("PolygonAction") {
|
|
453 | 455 |
|
454 |
public void actionPerformed(ActionEvent e) { |
|
455 |
editingContext = swingManager.getEditingContext(mapControl); |
|
456 |
editingContext.activateService(SymmetryEditingProviderFactory.PROVIDER_NAME); |
|
457 |
} |
|
458 |
}; |
|
459 |
|
|
460 |
internalPolygon = new AbstractAction("InternalPolygonAction") { |
|
461 |
|
|
462 |
public void actionPerformed(ActionEvent e) { |
|
463 |
editingContext = swingManager.getEditingContext(mapControl); |
|
464 |
editingContext.activateService(InternalPolygonEditingProviderFactory.PROVIDER_NAME); |
|
465 |
} |
|
466 |
}; |
|
456 |
public void actionPerformed(ActionEvent e) { |
|
457 |
editingContext = swingManager.getEditingContext(mapControl); |
|
458 |
editingContext.activateService(PolylineEditingProviderFactory.PROVIDER_NAME); |
|
459 |
} |
|
460 |
}; |
|
467 | 461 |
|
468 |
}
|
|
462 |
symmetry = new AbstractAction("SymmetryAction") {
|
|
469 | 463 |
|
470 |
public void addLayer(String shpPath) throws InitializeException, |
|
471 |
ProviderNotRegisteredException, ValidateDataParametersException, |
|
472 |
LoadLayerException { |
|
473 |
DataStoreParameters params; |
|
474 |
params = dataManager.createStoreParameters("Shape"); |
|
475 |
if (shpPath.isEmpty()){ |
|
464 |
public void actionPerformed(ActionEvent e) { |
|
465 |
editingContext = swingManager.getEditingContext(mapControl); |
|
466 |
editingContext.activateService(SymmetryEditingProviderFactory.PROVIDER_NAME); |
|
467 |
} |
|
468 |
}; |
|
469 |
|
|
470 |
internalPolygon = new AbstractAction("InternalPolygonAction") { |
|
471 |
|
|
472 |
public void actionPerformed(ActionEvent e) { |
|
473 |
editingContext = swingManager.getEditingContext(mapControl); |
|
474 |
editingContext.activateService(InternalPolygonEditingProviderFactory.PROVIDER_NAME); |
|
475 |
} |
|
476 |
}; |
|
477 |
|
|
478 |
} |
|
479 |
|
|
480 |
public void addLayer(String shpPath) throws InitializeException, |
|
481 |
ProviderNotRegisteredException, ValidateDataParametersException, |
|
482 |
LoadLayerException { |
|
483 |
DataStoreParameters params; |
|
484 |
params = dataManager.createStoreParameters("Shape"); |
|
485 |
if (shpPath.isEmpty()) { |
|
476 | 486 |
shpPath = "/home/lmarques/data/cartography/Andalucia/muni_andalucia.shp"; |
477 |
}
|
|
487 |
}
|
|
478 | 488 |
|
479 |
String dbfPath = shpPath.substring(0, shpPath.length() - 3).concat("dbf"); |
|
480 |
String shxPath = shpPath.substring(0, shpPath.length() - 3).concat("shx"); |
|
489 |
String dbfPath = shpPath.substring(0, shpPath.length() - 3).concat( |
|
490 |
"dbf"); |
|
491 |
String shxPath = shpPath.substring(0, shpPath.length() - 3).concat( |
|
492 |
"shx"); |
|
481 | 493 |
|
482 |
File shpFile = new File(shpPath);
|
|
483 |
File dbFile = new File(dbfPath);
|
|
484 |
File shxFile = new File(shxPath);
|
|
494 |
File shpFile = new File(shpPath);
|
|
495 |
File dbFile = new File(dbfPath);
|
|
496 |
File shxFile = new File(shxPath);
|
|
485 | 497 |
|
486 |
params.setDynValue("shpFile", shpFile.getPath());
|
|
487 |
params.setDynValue("dbfFile", dbFile.getPath());
|
|
488 |
params.setDynValue("shxFile", shxFile.getPath());
|
|
489 |
params.setDynValue("CRS", defaultProjection);
|
|
498 |
params.setDynValue("shpFile", shpFile.getPath());
|
|
499 |
params.setDynValue("dbfFile", dbFile.getPath());
|
|
500 |
params.setDynValue("shxFile", shxFile.getPath());
|
|
501 |
params.setDynValue("CRS", defaultProjection);
|
|
490 | 502 |
|
491 |
store = (FeatureStore) dataManager.openStore("Shape", params);
|
|
503 |
store = (FeatureStore) dataManager.openStore("Shape", params);
|
|
492 | 504 |
|
493 |
FLayer layer = mapContextManager.createLayer("prueba", store); |
|
494 |
mapControl.getMapContext().setOrderManager(layerOrderManager); |
|
495 |
mapControl.getMapContext().getLayers().addLayer(layer); |
|
496 |
mapControl.getMapContext().getLayers().setActive(true); |
|
497 |
try { |
|
498 |
currentLayer = (FLyrVect) layer; |
|
499 |
} |
|
500 |
catch (Exception e) { |
|
501 |
logger.error("Can't load layer " + e.getMessage()); |
|
502 |
} |
|
505 |
FLayer layer = mapContextManager.createLayer("prueba", store); |
|
506 |
mapControl.getMapContext().setOrderManager(layerOrderManager); |
|
507 |
mapControl.getMapContext().getLayers().addLayer(layer); |
|
508 |
mapControl.getMapContext().getLayers().setActive(true); |
|
509 |
try { |
|
510 |
currentLayer = (FLyrVect) layer; |
|
511 |
} catch (Exception e) { |
|
512 |
logger.error("Can't load layer " + e.getMessage()); |
|
513 |
} |
|
503 | 514 |
|
504 |
}
|
|
515 |
}
|
|
505 | 516 |
|
506 |
private void zoomAll() {
|
|
507 |
MapContext mapContext = mapControl.getMapContext();
|
|
508 |
Envelope all = mapContext.getLayers().getFullEnvelope();
|
|
509 |
logger.info("Full extdents " + all.toString());
|
|
510 |
mapContext.getViewPort().setEnvelope(all);
|
|
511 |
mapContext.invalidate();
|
|
512 |
}
|
|
517 |
private void zoomAll() {
|
|
518 |
MapContext mapContext = mapControl.getMapContext();
|
|
519 |
Envelope all = mapContext.getLayers().getFullEnvelope();
|
|
520 |
logger.info("Full extdents " + all.toString());
|
|
521 |
mapContext.getViewPort().setEnvelope(all);
|
|
522 |
mapContext.invalidate();
|
|
523 |
}
|
|
513 | 524 |
|
514 |
public JFrame getJFrame() {
|
|
515 |
return this.addLayerFrame;
|
|
516 |
}
|
|
525 |
public JFrame getJFrame() {
|
|
526 |
return this.addLayerFrame;
|
|
527 |
}
|
|
517 | 528 |
} |
Also available in: Unified diff