gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.main / src / main / java / org / gvsig / vectorediting / main / Main.java @ 12
History | View | Annotate | Download (6.91 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 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 |
package org.gvsig.vectorediting.main; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.util.Iterator; |
30 |
import java.util.Set; |
31 |
|
32 |
import javax.swing.AbstractAction; |
33 |
import javax.swing.JButton; |
34 |
import javax.swing.JFrame; |
35 |
import javax.swing.JMenu; |
36 |
import javax.swing.JMenuBar; |
37 |
import javax.swing.JMenuItem; |
38 |
import javax.swing.JToolBar; |
39 |
import javax.swing.WindowConstants; |
40 |
|
41 |
import org.cresques.cts.IProjection; |
42 |
import org.gvsig.fmap.crs.CRSFactory; |
43 |
import org.gvsig.fmap.dal.DataQuery; |
44 |
import org.gvsig.fmap.dal.DataServerExplorer; |
45 |
import org.gvsig.fmap.dal.DataSet; |
46 |
import org.gvsig.fmap.dal.DataStore; |
47 |
import org.gvsig.fmap.dal.DataStoreParameters; |
48 |
import org.gvsig.fmap.dal.exception.DataException; |
49 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
50 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
51 |
import org.gvsig.fmap.mapcontrol.MapControl; |
52 |
import org.gvsig.fmap.mapcontrol.MapControlCreationException; |
53 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
54 |
import org.gvsig.fmap.mapcontrol.MapControlManager; |
55 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
56 |
import org.gvsig.metadata.exceptions.MetadataException; |
57 |
import org.gvsig.timesupport.Interval; |
58 |
import org.gvsig.tools.dynobject.DynClass; |
59 |
import org.gvsig.tools.dynobject.DynObject; |
60 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
61 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
62 |
import org.gvsig.tools.exception.BaseException; |
63 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
64 |
import org.gvsig.tools.observer.Observer; |
65 |
import org.gvsig.tools.persistence.PersistentState; |
66 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
67 |
import org.gvsig.tools.visitor.Visitor; |
68 |
import org.gvsig.vectorediting.lib.api.EditingBehavior; |
69 |
import org.gvsig.vectorediting.lib.api.EditingLocator; |
70 |
import org.gvsig.vectorediting.lib.api.EditingManager; |
71 |
import org.gvsig.vectorediting.lib.impl.DefaultEditingBehavior; |
72 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
73 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
74 |
import org.slf4j.Logger; |
75 |
import org.slf4j.LoggerFactory; |
76 |
|
77 |
/**
|
78 |
* Main executable class for testing the VectorEditing library.
|
79 |
*
|
80 |
* @author gvSIG Team
|
81 |
* @version $Id$
|
82 |
*/
|
83 |
public class Main { |
84 |
|
85 |
private static final Logger logger = LoggerFactory.getLogger(Main.class); |
86 |
|
87 |
final EditingManager manager;
|
88 |
|
89 |
final EditingProviderManager providerManager;
|
90 |
|
91 |
final MapControlManager mapControlManager;
|
92 |
|
93 |
EditingBehavior editingBehavior; |
94 |
|
95 |
MapControl mapControl; |
96 |
|
97 |
LayerFactory layerFactory; |
98 |
|
99 |
JFrame mainFrame;
|
100 |
|
101 |
// Actions
|
102 |
AbstractAction editingExtensionAction;
|
103 |
|
104 |
AbstractAction insertPointAction;
|
105 |
|
106 |
AbstractAction exit;
|
107 |
|
108 |
AbstractAction addLayer;
|
109 |
|
110 |
final String DEFAULT_CRS_CODE = "EPSG:4326"; |
111 |
|
112 |
public static void main(String args[]) { |
113 |
new DefaultLibrariesInitializer().fullInitialize();
|
114 |
Main main = new Main();
|
115 |
main.doMain(); |
116 |
} |
117 |
|
118 |
public Main() {
|
119 |
manager = EditingLocator.getManager(); |
120 |
providerManager = EditingProviderLocator.getProviderManager(); |
121 |
mapControlManager = MapControlLocator.getMapControlManager(); |
122 |
} |
123 |
|
124 |
public void doMain() { |
125 |
|
126 |
try {
|
127 |
mapControl = mapControlManager.createJMapControlPanel(); |
128 |
editingBehavior = new DefaultEditingBehavior(mapControl);
|
129 |
layerFactory = LayerFactory.getInstance(); |
130 |
} |
131 |
catch (MapControlCreationException e) {
|
132 |
// TODO Auto-generated catch block
|
133 |
e.printStackTrace(); |
134 |
} |
135 |
|
136 |
IProjection defaultProjection = CRSFactory.getCRS(DEFAULT_CRS_CODE); |
137 |
mapControl.getViewPort().setProjection(defaultProjection); |
138 |
mapControl.addBehavior("VectorEditing", (Behavior) editingBehavior);
|
139 |
|
140 |
// Create actions
|
141 |
try {
|
142 |
createActions(); |
143 |
} |
144 |
catch (MapControlCreationException e) {
|
145 |
// TODO Auto-generated catch block
|
146 |
e.printStackTrace(); |
147 |
} |
148 |
|
149 |
// Create JFrame to show data
|
150 |
mainFrame = new JFrame("Editing test app"); |
151 |
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
152 |
mainFrame.setPreferredSize(new Dimension(600, 480)); |
153 |
mainFrame.add(mapControl, BorderLayout.CENTER);
|
154 |
|
155 |
// Create menu bar
|
156 |
createMenu(); |
157 |
|
158 |
// Create tools bar
|
159 |
createToolBar(); |
160 |
|
161 |
// Display the window.
|
162 |
mainFrame.pack(); |
163 |
mainFrame.setLocation(100, 100); |
164 |
mainFrame.setVisible(true);
|
165 |
} |
166 |
|
167 |
private void createToolBar() { |
168 |
JToolBar toolBar = new JToolBar(); |
169 |
|
170 |
toolBar.add(new JButton(editingExtensionAction)); |
171 |
toolBar.add(new JButton(insertPointAction)); |
172 |
|
173 |
mainFrame.add(toolBar, BorderLayout.PAGE_START);
|
174 |
} |
175 |
|
176 |
private void createMenu() { |
177 |
// Create the menu bar.
|
178 |
JMenuBar menuBar = new JMenuBar(); |
179 |
|
180 |
// Build the menu.
|
181 |
JMenu menuFile = new JMenu("File"); |
182 |
menuFile.add(new JMenuItem(addLayer)); |
183 |
menuFile.add(new JMenuItem(exit)); |
184 |
|
185 |
JMenu menuTool = new JMenu("Tools"); |
186 |
menuTool.add(new JMenuItem(editingExtensionAction)); |
187 |
menuTool.addSeparator(); |
188 |
menuTool.add(new JMenuItem(insertPointAction)); |
189 |
|
190 |
|
191 |
menuBar.add(menuFile); |
192 |
|
193 |
mainFrame.setJMenuBar(menuBar); |
194 |
} |
195 |
|
196 |
@SuppressWarnings("serial") |
197 |
private void createActions() throws MapControlCreationException { |
198 |
|
199 |
addLayer = new AbstractAction("Add layer"){ |
200 |
public void actionPerformed(ActionEvent e) { |
201 |
//Do Nothing
|
202 |
} |
203 |
}; |
204 |
|
205 |
exit = new AbstractAction("Exit") { |
206 |
|
207 |
public void actionPerformed(ActionEvent e) { |
208 |
System.exit(0); |
209 |
} |
210 |
}; |
211 |
|
212 |
editingExtensionAction = new AbstractAction("EditingExtension") { |
213 |
|
214 |
public void actionPerformed(ActionEvent e) { |
215 |
mapControl.setTool("VectorEditing");
|
216 |
|
217 |
updateControls(); |
218 |
} |
219 |
}; |
220 |
|
221 |
insertPointAction = new AbstractAction("InsertPointAction") { |
222 |
|
223 |
public void actionPerformed(ActionEvent e) { |
224 |
activateTool("InsertPoint");
|
225 |
} |
226 |
|
227 |
}; |
228 |
insertPointAction.setEnabled(false);
|
229 |
|
230 |
} |
231 |
|
232 |
private void updateControls() { |
233 |
insertPointAction.setEnabled(true);
|
234 |
} |
235 |
|
236 |
private void activateTool(String name) { |
237 |
manager.activateTool(name, mapControl); |
238 |
} |
239 |
} |