Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.projection.app / org.gvsig.projection.app.proj4j / src / main / java / org / gvsig / proj / app / mainplugin / CoordinateReferenceSystemSelectionDialog.java @ 41204

History | View | Annotate | Download (5.13 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2012 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.proj.app.mainplugin;
24

    
25
import java.awt.BorderLayout;
26
import java.awt.Dimension;
27
import java.awt.FlowLayout;
28

    
29
import javax.swing.JButton;
30
import javax.swing.JPanel;
31

    
32
import org.cresques.Messages;
33
import org.cresques.cts.IProjection;
34

    
35
import org.gvsig.andami.PluginServices;
36
import org.gvsig.andami.ui.mdiManager.IWindow;
37
import org.gvsig.andami.ui.mdiManager.WindowInfo;
38
import org.gvsig.app.gui.panels.crs.ISelectCrsPanel;
39
import org.gvsig.proj.CoordinateReferenceSystem;
40
import org.gvsig.proj.cts.DefaultIProjection;
41
import org.gvsig.proj.swing.CoordinateReferenceSystemSelectorComponent;
42
import org.gvsig.proj.swing.CoordinateReferenceSystemSwingLocator;
43
import org.gvsig.tools.swing.api.ToolsSwingLocator;
44
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
45

    
46
/**
47
 * ISelectCrsPanel implementation based on the org.gvsig.proj library.
48
 * 
49
 * @author gvSIG Team
50
 */
51
public class CoordinateReferenceSystemSelectionDialog extends JPanel implements
52
    IWindow, ISelectCrsPanel {
53

    
54
    private static final long serialVersionUID = 810773451033764544L;
55
    private boolean okPressed = false;
56
    private IProjection lastProjection = null;
57
    private CoordinateReferenceSystemSelectorComponent component;
58
    private JPanel panel;
59

    
60
    /**
61
     * Constructor.
62
     */
63
    public CoordinateReferenceSystemSelectionDialog() {
64
        super(new BorderLayout(4, 0));
65

    
66
        add(getContentPanel(), BorderLayout.CENTER);
67

    
68
        JPanel buttonsPanel =
69
            new JPanel(new FlowLayout(FlowLayout.RIGHT, 4, 4));
70
        add(buttonsPanel, BorderLayout.SOUTH);
71

    
72
        UsabilitySwingManager usabilitySwingManager =
73
            ToolsSwingLocator.getUsabilitySwingManager();
74
        JButton acceptButton =
75
            usabilitySwingManager.createJButton(Messages.getText("Aceptar"));
76
        buttonsPanel.add(acceptButton);
77
        JButton cancelButton =
78
            usabilitySwingManager.createJButton(Messages.getText("Cancelar"));
79
        buttonsPanel.add(cancelButton);
80

    
81
        acceptButton.addActionListener(new java.awt.event.ActionListener() {
82

    
83
            public void actionPerformed(java.awt.event.ActionEvent e) {
84
                PluginServices.getMDIManager().closeWindow(
85
                    CoordinateReferenceSystemSelectionDialog.this);
86
                okPressed = true;
87
            }
88
        });
89
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
90

    
91
            public void actionPerformed(java.awt.event.ActionEvent e) {
92
                setProjection(lastProjection);
93
                PluginServices.getMDIManager().closeWindow(
94
                    CoordinateReferenceSystemSelectionDialog.this);
95
                okPressed = false;
96
            }
97
        });
98
    }
99

    
100
    public WindowInfo getWindowInfo() {
101
        WindowInfo m_viewinfo =
102
            new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
103
        m_viewinfo.setTitle(PluginServices.getText(this,
104
            "selecciona_sistema_de_referencia"));
105
        Dimension dim = getPreferredSize();
106
        m_viewinfo.setWidth(dim.width);
107
        m_viewinfo.setHeight(dim.height);
108
        return m_viewinfo;
109
    }
110

    
111
    public boolean isOkPressed() {
112
        return okPressed;
113
    }
114

    
115
    /**
116
     * @return
117
     */
118
    public IProjection getProjection() {
119
        CoordinateReferenceSystem crs =
120
            component.getSelectedCoordinateReferenceSystem();
121
        if (crs == null) {
122
            return lastProjection;
123
        }
124
        return new DefaultIProjection(crs);
125
    }
126

    
127
    protected JPanel getContentPanel() {
128
        if (panel == null) {
129
            panel = new JPanel();
130
            component =
131
                CoordinateReferenceSystemSwingLocator.getSwingManager()
132
                    .createCoordinateReferenceSystemSelectionComponent();
133
            panel.add(component.asJComponent());
134
        }
135

    
136
        return panel;
137
    }
138

    
139
    /**
140
     * @param proj
141
     */
142
    public void setProjection(IProjection proj) {
143
        CoordinateReferenceSystem crs = null;
144
        lastProjection = proj;
145
        if( proj != null ) {
146
            crs = ((DefaultIProjection) proj).getCoordinateReferenceSystem();
147
        }
148
        component.setCoordinateReferenceSystem(crs);
149
    }
150

    
151
    public Object getWindowProfile() {
152
        return WindowInfo.DIALOG_PROFILE;
153
    }
154
}