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

History | View | Annotate | Download (5.24 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(),
127
                    CRSFactory.getCRS("EPSG:23030"));
128
            panel.setPreferredSize(new Dimension(800, 400));
129
            swingManager.getWindowManager().showWindow(panel, "Exportto",
130
                ExporttoWindowManager.MODE_WINDOW);
131
        } catch (ValidateDataParametersException e) {
132
            LOG.error("Error showing a Exportto", e);
133
        } catch (InitializeException e) {
134
            LOG.error("Error showing a Exportto", e);
135
        } catch (ProviderNotRegisteredException e) {
136
            LOG.error("Error showing a Exportto", e);
137
        }
138
    }
139

    
140
    private FeatureStore createFeatureStore() throws InitializeException,
141
        ProviderNotRegisteredException, ValidateDataParametersException {
142
        String sourceFileName =
143
            getClass().getClassLoader()
144
                .getResource("org/gvsig/exportto/data/andalucia.shp").getFile();
145
        DataStoreParameters sourceParameters =
146
            dataManager.createStoreParameters("Shape");
147
        sourceParameters.setDynValue("shpfile", sourceFileName);
148
        sourceParameters.setDynValue("crs", CRSFactory.getCRS("EPSG:23030"));
149
        return (FeatureStore) dataManager.openStore("Shape", sourceParameters);
150
    }
151
}