svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.exportto / org.gvsig.exportto.main / src / main / java / org / gvsig / exportto / main / Main.java @ 34981
History | View | Annotate | Download (5.19 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 |
*/
|
22 |
package org.gvsig.exportto.main; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.awt.Dimension; |
26 |
import java.awt.event.ActionEvent; |
27 |
|
28 |
import javax.swing.AbstractAction; |
29 |
import javax.swing.Action; |
30 |
import javax.swing.JButton; |
31 |
import javax.swing.JFrame; |
32 |
import javax.swing.JMenu; |
33 |
import javax.swing.JMenuBar; |
34 |
import javax.swing.JMenuItem; |
35 |
import javax.swing.JToolBar; |
36 |
import javax.swing.WindowConstants; |
37 |
|
38 |
import org.slf4j.Logger; |
39 |
import org.slf4j.LoggerFactory; |
40 |
|
41 |
import org.gvsig.exportto.ExporttoLocator; |
42 |
import org.gvsig.exportto.ExporttoManager; |
43 |
import org.gvsig.exportto.swing.ExporttoSwingLocator; |
44 |
import org.gvsig.exportto.swing.ExporttoSwingManager; |
45 |
import org.gvsig.exportto.swing.ExporttoWindowManager; |
46 |
import org.gvsig.exportto.swing.JExporttoServicePanel; |
47 |
import org.gvsig.fmap.crs.CRSFactory; |
48 |
import org.gvsig.fmap.dal.DALLocator; |
49 |
import org.gvsig.fmap.dal.DataManager; |
50 |
import org.gvsig.fmap.dal.DataStoreParameters; |
51 |
import org.gvsig.fmap.dal.exception.InitializeException; |
52 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
53 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
54 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
55 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
56 |
|
57 |
/**
|
58 |
* Main executable class for testing the Exportto library.
|
59 |
*
|
60 |
* @author gvSIG Team
|
61 |
* @version $Id$
|
62 |
*/
|
63 |
public class Main { |
64 |
|
65 |
private static final Logger LOG = LoggerFactory.getLogger(Main.class); |
66 |
|
67 |
private ExporttoManager manager;
|
68 |
private ExporttoSwingManager swingManager;
|
69 |
private DataManager dataManager;
|
70 |
|
71 |
public static void main(String args[]) { |
72 |
new DefaultLibrariesInitializer().fullInitialize();
|
73 |
Main main = new Main();
|
74 |
main.show(); |
75 |
} |
76 |
|
77 |
@SuppressWarnings("serial") |
78 |
public void show() { |
79 |
manager = ExporttoLocator.getManager(); |
80 |
swingManager = ExporttoSwingLocator.getSwingManager(); |
81 |
dataManager = DALLocator.getDataManager(); |
82 |
|
83 |
Action showCookie = new AbstractAction("Get a Exportto") { |
84 |
|
85 |
public void actionPerformed(ActionEvent e) { |
86 |
showExportto(manager); |
87 |
} |
88 |
}; |
89 |
|
90 |
Action exit = new AbstractAction("Exit") { |
91 |
|
92 |
public void actionPerformed(ActionEvent e) { |
93 |
System.exit(0); |
94 |
} |
95 |
}; |
96 |
|
97 |
JFrame frame = new JFrame("Exportto example app"); |
98 |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
99 |
|
100 |
// Create the menu bar.
|
101 |
JMenuBar menuBar = new JMenuBar(); |
102 |
|
103 |
// Build the menu.
|
104 |
JMenu menuFile = new JMenu("File"); |
105 |
menuFile.add(new JMenuItem(showCookie)); |
106 |
menuFile.add(new JMenuItem(exit)); |
107 |
|
108 |
menuBar.add(menuFile); |
109 |
|
110 |
JToolBar toolBar = new JToolBar(); |
111 |
toolBar.add(new JButton(showCookie)); |
112 |
toolBar.add(new JButton(exit)); |
113 |
|
114 |
frame.setPreferredSize(new Dimension(200, 100)); |
115 |
frame.setJMenuBar(menuBar); |
116 |
frame.add(toolBar, BorderLayout.PAGE_START);
|
117 |
|
118 |
// Display the window.
|
119 |
frame.pack(); |
120 |
frame.setVisible(true);
|
121 |
} |
122 |
|
123 |
public void showExportto(ExporttoManager manager) { |
124 |
try {
|
125 |
JExporttoServicePanel panel = |
126 |
swingManager.createExportto(createFeatureStore(), CRSFactory.getCRS("EPSG:23030"));
|
127 |
panel.setPreferredSize(new Dimension(800, 400)); |
128 |
swingManager.getWindowManager().showWindow(panel, "Exportto",
|
129 |
ExporttoWindowManager.MODE_WINDOW); |
130 |
} catch (ValidateDataParametersException e) {
|
131 |
LOG.error("Error showing a Exportto", e);
|
132 |
} catch (InitializeException e) {
|
133 |
LOG.error("Error showing a Exportto", e);
|
134 |
} catch (ProviderNotRegisteredException e) {
|
135 |
LOG.error("Error showing a Exportto", e);
|
136 |
} |
137 |
} |
138 |
|
139 |
private FeatureStore createFeatureStore() throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException{ |
140 |
String sourceFileName = getClass().getClassLoader().getResource("org/gvsig/exportto/data/andalucia.shp").getFile(); |
141 |
DataStoreParameters sourceParameters = dataManager.createStoreParameters("Shape");
|
142 |
sourceParameters.setDynValue("shpfile", sourceFileName);
|
143 |
sourceParameters.setDynValue("crs", CRSFactory.getCRS("EPSG:23030")); |
144 |
return (FeatureStore) dataManager.openStore("Shape", sourceParameters); |
145 |
} |
146 |
} |