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 @ 42614
History | View | Annotate | Download (5.09 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.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
import javax.swing.JComponent; |
30 |
|
31 |
import javax.swing.JPanel; |
32 |
|
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.ToolsLocator; |
44 |
import org.gvsig.tools.i18n.I18nManager; |
45 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
46 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
47 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
48 |
|
49 |
/**
|
50 |
* ISelectCrsPanel implementation based on the org.gvsig.proj library.
|
51 |
*
|
52 |
* @author gvSIG Team
|
53 |
*/
|
54 |
public class CoordinateReferenceSystemSelectionDialog extends JPanel implements |
55 |
IWindow, ISelectCrsPanel { |
56 |
|
57 |
private static final long serialVersionUID = 810773451033764544L; |
58 |
private boolean okPressed = false; |
59 |
private IProjection lastProjection = null; |
60 |
private CoordinateReferenceSystemSelectorComponent component;
|
61 |
|
62 |
/**
|
63 |
* Constructor.
|
64 |
*/
|
65 |
public CoordinateReferenceSystemSelectionDialog() {
|
66 |
super();
|
67 |
this.setLayout(new BorderLayout()); |
68 |
|
69 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
70 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
71 |
final Dialog dialogPanel = windowManager.createDialog( |
72 |
getContentPanel(), |
73 |
i18nManager.getTranslation("selecciona_sistema_de_referencia"),
|
74 |
i18nManager.getTranslation("reference_system"),
|
75 |
WindowManager_v2.BUTTONS_OK_CANCEL |
76 |
); |
77 |
|
78 |
add(dialogPanel.asJComponent(), BorderLayout.CENTER);
|
79 |
dialogPanel.addActionListener(new ActionListener() { |
80 |
|
81 |
@Override
|
82 |
public void actionPerformed(ActionEvent ae) { |
83 |
switch( dialogPanel.getAction()) {
|
84 |
case WindowManager_v2.BUTTON_OK:
|
85 |
okPressed = true;
|
86 |
break;
|
87 |
case WindowManager_v2.BUTTON_CANCEL:
|
88 |
setProjection(lastProjection); |
89 |
okPressed = false;
|
90 |
break;
|
91 |
} |
92 |
setVisible(false);
|
93 |
} |
94 |
}); |
95 |
} |
96 |
|
97 |
@Override
|
98 |
public WindowInfo getWindowInfo() {
|
99 |
WindowInfo m_viewinfo = |
100 |
new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
101 |
m_viewinfo.setTitle(PluginServices.getText(this,
|
102 |
"selecciona_sistema_de_referencia"));
|
103 |
Dimension dim = getPreferredSize();
|
104 |
m_viewinfo.setWidth(dim.width); |
105 |
m_viewinfo.setHeight(dim.height); |
106 |
return m_viewinfo;
|
107 |
} |
108 |
|
109 |
@Override
|
110 |
public boolean isOkPressed() { |
111 |
return okPressed;
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* @return
|
116 |
*/
|
117 |
@Override
|
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 JComponent getContentPanel() { |
128 |
if (component == null) { |
129 |
|
130 |
component = |
131 |
CoordinateReferenceSystemSwingLocator.getSwingManager() |
132 |
.createCoordinateReferenceSystemSelectionComponent(); |
133 |
} |
134 |
|
135 |
return component.asJComponent();
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* @param proj
|
140 |
*/
|
141 |
@Override
|
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 |
@Override
|
152 |
public Object getWindowProfile() { |
153 |
return WindowInfo.DIALOG_PROFILE;
|
154 |
} |
155 |
} |