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 @ 43213
History | View | Annotate | Download (4.51 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.app.gui.panels.crs.ISelectCrsPanel; |
36 |
import org.gvsig.proj.CoordinateReferenceSystem; |
37 |
import org.gvsig.proj.cts.DefaultIProjection; |
38 |
import org.gvsig.proj.swing.CoordinateReferenceSystemSelectorComponent; |
39 |
import org.gvsig.proj.swing.CoordinateReferenceSystemSwingLocator; |
40 |
import org.gvsig.tools.ToolsLocator; |
41 |
import org.gvsig.tools.i18n.I18nManager; |
42 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
43 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
44 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
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 |
ISelectCrsPanel { |
53 |
|
54 |
private static final long serialVersionUID = 810773451033764544L; |
55 |
private boolean okPressed = false; |
56 |
private IProjection lastProjection = null; |
57 |
private CoordinateReferenceSystemSelectorComponent component;
|
58 |
|
59 |
/**
|
60 |
* Constructor.
|
61 |
*/
|
62 |
public CoordinateReferenceSystemSelectionDialog() {
|
63 |
super();
|
64 |
this.setLayout(new BorderLayout()); |
65 |
|
66 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
67 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
68 |
final Dialog dialogPanel = windowManager.createDialog( |
69 |
getContentPanel(), |
70 |
i18nManager.getTranslation("selecciona_sistema_de_referencia"),
|
71 |
i18nManager.getTranslation("reference_system"),
|
72 |
WindowManager_v2.BUTTONS_OK_CANCEL |
73 |
); |
74 |
|
75 |
add(dialogPanel.asJComponent(), BorderLayout.CENTER);
|
76 |
dialogPanel.addActionListener(new ActionListener() { |
77 |
|
78 |
@Override
|
79 |
public void actionPerformed(ActionEvent ae) { |
80 |
switch( dialogPanel.getAction()) {
|
81 |
case WindowManager_v2.BUTTON_OK:
|
82 |
okPressed = true;
|
83 |
break;
|
84 |
case WindowManager_v2.BUTTON_CANCEL:
|
85 |
setProjection(lastProjection); |
86 |
okPressed = false;
|
87 |
break;
|
88 |
} |
89 |
setVisible(false);
|
90 |
} |
91 |
}); |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public boolean isOkPressed() { |
96 |
return okPressed;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* @return
|
101 |
*/
|
102 |
@Override
|
103 |
public IProjection getProjection() {
|
104 |
CoordinateReferenceSystem crs = |
105 |
component.getSelectedCoordinateReferenceSystem(); |
106 |
if (crs == null) { |
107 |
return lastProjection;
|
108 |
} |
109 |
return new DefaultIProjection(crs); |
110 |
} |
111 |
|
112 |
protected JComponent getContentPanel() { |
113 |
if (component == null) { |
114 |
|
115 |
component = |
116 |
CoordinateReferenceSystemSwingLocator.getSwingManager() |
117 |
.createCoordinateReferenceSystemSelectionComponent(); |
118 |
} |
119 |
|
120 |
return component.asJComponent();
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* @param proj
|
125 |
*/
|
126 |
@Override
|
127 |
public void setProjection(IProjection proj) { |
128 |
CoordinateReferenceSystem crs = null;
|
129 |
lastProjection = proj; |
130 |
if( proj != null ) { |
131 |
crs = ((DefaultIProjection) proj).getCoordinateReferenceSystem(); |
132 |
} |
133 |
component.setCoordinateReferenceSystem(crs); |
134 |
} |
135 |
|
136 |
@Override
|
137 |
public JComponent asJComponent() { |
138 |
return this; |
139 |
} |
140 |
} |