Revision 12 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.main/src/main/java/org/gvsig/vectorediting/main/Main.java
Main.java | ||
---|---|---|
26 | 26 |
import java.awt.BorderLayout; |
27 | 27 |
import java.awt.Dimension; |
28 | 28 |
import java.awt.event.ActionEvent; |
29 |
import java.util.Iterator; |
|
30 |
import java.util.Set; |
|
29 | 31 |
|
30 | 32 |
import javax.swing.AbstractAction; |
31 |
import javax.swing.Action; |
|
32 | 33 |
import javax.swing.JButton; |
33 | 34 |
import javax.swing.JFrame; |
34 | 35 |
import javax.swing.JMenu; |
... | ... | |
37 | 38 |
import javax.swing.JToolBar; |
38 | 39 |
import javax.swing.WindowConstants; |
39 | 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; |
|
40 | 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; |
|
41 | 69 |
import org.gvsig.vectorediting.lib.api.EditingLocator; |
42 | 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; |
|
43 | 74 |
import org.slf4j.Logger; |
44 | 75 |
import org.slf4j.LoggerFactory; |
45 | 76 |
|
46 | 77 |
/** |
47 |
* Main executable class for testing the FortuneCookie library.
|
|
78 |
* Main executable class for testing the VectorEditing library.
|
|
48 | 79 |
* |
49 | 80 |
* @author gvSIG Team |
50 | 81 |
* @version $Id$ |
51 | 82 |
*/ |
52 | 83 |
public class Main { |
53 | 84 |
|
54 |
private static final Logger logger = LoggerFactory.getLogger(Main.class);
|
|
85 |
private static final Logger logger = LoggerFactory.getLogger(Main.class); |
|
55 | 86 |
|
56 |
private EditingManager manager;
|
|
87 |
final EditingManager manager;
|
|
57 | 88 |
|
58 |
public static void main(String args[]) { |
|
59 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
60 |
Main main = new Main(); |
|
61 |
main.doMain(); |
|
62 |
} |
|
89 |
final EditingProviderManager providerManager; |
|
63 | 90 |
|
64 |
@SuppressWarnings("serial") |
|
65 |
public void doMain() { |
|
66 |
manager = EditingLocator.getManager(); |
|
91 |
final MapControlManager mapControlManager; |
|
67 | 92 |
|
68 |
Action showCookie = new AbstractAction("Show FortuneCookie") { |
|
69 |
public void actionPerformed(ActionEvent e) { |
|
70 |
// showFortuneCookie(manager); |
|
71 |
} |
|
72 |
}; |
|
93 |
EditingBehavior editingBehavior; |
|
73 | 94 |
|
74 |
Action exit = new AbstractAction("Exit") { |
|
75 |
public void actionPerformed(ActionEvent e) { |
|
76 |
System.exit(0); |
|
77 |
} |
|
78 |
}; |
|
95 |
MapControl mapControl; |
|
96 |
|
|
97 |
LayerFactory layerFactory; |
|
79 | 98 |
|
80 |
JFrame frame = new JFrame("VectorEditing test application"); |
|
81 |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
99 |
JFrame mainFrame; |
|
82 | 100 |
|
83 |
// Create the menu bar.
|
|
84 |
JMenuBar menuBar = new JMenuBar();
|
|
101 |
// Actions
|
|
102 |
AbstractAction editingExtensionAction;
|
|
85 | 103 |
|
86 |
// Build the menu. |
|
87 |
JMenu menuFile = new JMenu("File"); |
|
88 |
menuFile.add(new JMenuItem(showCookie)); |
|
89 |
menuFile.add(new JMenuItem(exit)); |
|
104 |
AbstractAction insertPointAction; |
|
90 | 105 |
|
91 |
menuBar.add(menuFile); |
|
106 |
AbstractAction exit; |
|
107 |
|
|
108 |
AbstractAction addLayer; |
|
92 | 109 |
|
93 |
JToolBar toolBar = new JToolBar(); |
|
94 |
toolBar.add(new JButton(showCookie)); |
|
95 |
toolBar.add(new JButton(exit)); |
|
110 |
final String DEFAULT_CRS_CODE = "EPSG:4326"; |
|
96 | 111 |
|
97 |
frame.setPreferredSize(new Dimension(300, 100)); |
|
98 |
frame.setJMenuBar(menuBar); |
|
99 |
frame.add(toolBar, BorderLayout.PAGE_START); |
|
112 |
public static void main(String args[]) { |
|
113 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
114 |
Main main = new Main(); |
|
115 |
main.doMain(); |
|
116 |
} |
|
100 | 117 |
|
101 |
// Display the window. |
|
102 |
frame.pack(); |
|
103 |
frame.setVisible(true); |
|
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(); |
|
104 | 130 |
} |
131 |
catch (MapControlCreationException e) { |
|
132 |
// TODO Auto-generated catch block |
|
133 |
e.printStackTrace(); |
|
134 |
} |
|
105 | 135 |
|
106 |
// public void showFortuneCookie(FortuneCookieManager manager) {
|
|
107 |
// try {
|
|
108 |
// FortuneCookie cookie = manager.getFortuneCookie();
|
|
109 |
// JFortuneCookiePanel panel = swingManager.createFortuneCookiePanel(cookie); |
|
110 |
//
|
|
111 |
// WindowManager wm = ToolsSwingLocator.getWindowManager();
|
|
112 |
// wm.showWindow(panel.asJComponent(), "FortuneCookie", WindowManager.MODE.WINDOW);
|
|
113 |
//
|
|
114 |
// } catch (ServiceException e) {
|
|
115 |
// logger.warn("Error showing a FortuneCookie", e);
|
|
116 |
// }
|
|
117 |
// }
|
|
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 |
} |
|
118 | 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 |
} |
|
119 | 239 |
} |
Also available in: Unified diff