Statistics
| Revision:

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 @ 37887

History | View | Annotate | Download (6.04 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.exportto.swing.preferences.ExporttoSwingPreferencesComponent;
48
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderLocator;
49
import org.gvsig.fmap.crs.CRSFactory;
50
import org.gvsig.fmap.dal.DALLocator;
51
import org.gvsig.fmap.dal.DataManager;
52
import org.gvsig.fmap.dal.DataStoreParameters;
53
import org.gvsig.fmap.dal.exception.InitializeException;
54
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
55
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
56
import org.gvsig.fmap.dal.feature.FeatureStore;
57
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
58

    
59
/**
60
 * Main executable class for testing the Exportto library.
61
 * 
62
 * @author gvSIG Team
63
 * @version $Id$
64
 */
65
public class Main {
66

    
67
    private static final Logger LOG = LoggerFactory.getLogger(Main.class);
68

    
69
    private ExporttoManager manager;
70
    private ExporttoSwingManager swingManager;
71
    private DataManager dataManager;
72

    
73
    public static void main(String args[]) {
74
        new DefaultLibrariesInitializer().fullInitialize();
75
        Main main = new Main();
76
        main.show();
77
    }
78

    
79
    @SuppressWarnings("serial")
80
    public void show() {
81
        manager = ExporttoLocator.getManager();
82
        swingManager = ExporttoSwingLocator.getSwingManager();
83
        dataManager = DALLocator.getDataManager();
84

    
85
        Action showCookie = new AbstractAction("Get a Exportto") {
86

    
87
            public void actionPerformed(ActionEvent e) {
88
                showExportto(manager);
89
            }
90
        };
91

    
92
        Action preferences = new AbstractAction("Exportto preferences") {
93

    
94
            public void actionPerformed(ActionEvent e) {
95
                showExporttoPreferences();
96
            }
97

    
98
        };
99

    
100
        Action exit = new AbstractAction("Exit") {
101

    
102
            public void actionPerformed(ActionEvent e) {
103
                System.exit(0);
104
            }
105
        };
106

    
107
        JFrame frame = new JFrame("Exportto example app");
108
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
109

    
110
        // Create the menu bar.
111
        JMenuBar menuBar = new JMenuBar();
112

    
113
        // Build the menu.
114
        JMenu menuFile = new JMenu("File");
115
        menuFile.add(new JMenuItem(showCookie));
116
        menuFile.add(new JMenuItem(preferences));
117
        menuFile.add(new JMenuItem(exit));
118

    
119
        menuBar.add(menuFile);
120

    
121
        JToolBar toolBar = new JToolBar();
122
        toolBar.add(new JButton(showCookie));
123
        toolBar.add(new JButton(exit));
124

    
125
        frame.setPreferredSize(new Dimension(200, 100));
126
        frame.setJMenuBar(menuBar);
127
        frame.add(toolBar, BorderLayout.PAGE_START);
128

    
129
        // Display the window.
130
        frame.pack();
131
        frame.setVisible(true);
132
    }
133

    
134
    private void showExporttoPreferences() {
135
        ExporttoSwingPreferencesComponent preferences =
136
            ExporttoSwingProviderLocator.getManager()
137
                .createExporttoSwingProvidersPreferences();
138

    
139
        JFrame preferencesFrame = new JFrame("Export to preferences");
140
        preferencesFrame.add(preferences.asJComponent());
141

    
142
        preferencesFrame.pack();
143
        preferencesFrame.setVisible(true);
144
    }
145

    
146
    public void showExportto(ExporttoManager manager) {
147
        try {
148
            JExporttoServicePanel panel =
149
                swingManager.createExportto(createFeatureStore(),
150
                    CRSFactory.getCRS("EPSG:23030"));
151
            panel.setPreferredSize(new Dimension(800, 400));
152
            swingManager.getWindowManager().showWindow(panel, "Exportto",
153
                ExporttoWindowManager.MODE_WINDOW);
154
        } catch (ValidateDataParametersException e) {
155
            LOG.error("Error showing a Exportto", e);
156
        } catch (InitializeException e) {
157
            LOG.error("Error showing a Exportto", e);
158
        } catch (ProviderNotRegisteredException e) {
159
            LOG.error("Error showing a Exportto", e);
160
        }
161
    }
162

    
163
    private FeatureStore createFeatureStore() throws InitializeException,
164
        ProviderNotRegisteredException, ValidateDataParametersException {
165
        String sourceFileName =
166
            getClass().getClassLoader()
167
                .getResource("org/gvsig/exportto/data/andalucia.shp").getFile();
168
        DataStoreParameters sourceParameters =
169
            dataManager.createStoreParameters("Shape");
170
        sourceParameters.setDynValue("shpfile", sourceFileName);
171
        sourceParameters.setDynValue("crs", CRSFactory.getCRS("EPSG:23030"));
172
        return (FeatureStore) dataManager.openStore("Shape", sourceParameters);
173
    }
174
}