svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / exportto / swing / impl / panel / ExportTargetProjectionPanel.java @ 42676
History | View | Annotate | Download (7.76 KB)
1 | 42676 | dmartinezizquierdo | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
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 3
|
||
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 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | package org.gvsig.exportto.swing.impl.panel; |
||
25 | |||
26 | import java.awt.event.ActionEvent; |
||
27 | import java.awt.event.ActionListener; |
||
28 | |||
29 | import org.cresques.cts.ICoordTrans; |
||
30 | import org.cresques.cts.IProjection; |
||
31 | import org.gvsig.app.gui.panels.CRSSelectPanel; |
||
32 | import org.gvsig.app.gui.panels.CRSSelectPanelFactory; |
||
33 | import org.gvsig.exportto.swing.impl.DefaultJExporttoServicePanel; |
||
34 | import org.gvsig.fmap.dal.exception.DataException; |
||
35 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
36 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
37 | import org.gvsig.tools.ToolsLocator; |
||
38 | import org.gvsig.tools.i18n.I18nManager; |
||
39 | import org.slf4j.Logger; |
||
40 | import org.slf4j.LoggerFactory; |
||
41 | |||
42 | /**
|
||
43 | * @author gvSIG Team
|
||
44 | * @version $Id$
|
||
45 | *
|
||
46 | */
|
||
47 | public class ExportTargetProjectionPanel extends ExportTargetProjectionPanelLayout { |
||
48 | |||
49 | /**
|
||
50 | *
|
||
51 | */
|
||
52 | private static final long serialVersionUID = -2164424159712152267L; |
||
53 | |||
54 | private static final Logger logger = LoggerFactory.getLogger(ExportTargetProjectionPanel.class); |
||
55 | |||
56 | private IProjection originalProjection;
|
||
57 | private IProjection viewProjection;
|
||
58 | private IProjection userProjection;
|
||
59 | private IProjection selectedProjection;
|
||
60 | private CRSSelectPanel crsSelectPanel;
|
||
61 | |||
62 | /**
|
||
63 | * @param exporttoServicePanel
|
||
64 | * @param vectorLayer
|
||
65 | */
|
||
66 | public ExportTargetProjectionPanel(DefaultJExporttoServicePanel exporttoServicePanel) {
|
||
67 | viewProjection=null;
|
||
68 | originalProjection=null;
|
||
69 | if (originalProjection==null){ |
||
70 | FeatureStore store = exporttoServicePanel.getFeatureStore(); |
||
71 | try {
|
||
72 | this.originalProjection = store.getDefaultFeatureType().getDefaultSRS();
|
||
73 | } catch (DataException e) {
|
||
74 | logger.warn("Couldn't get original projection from feature store");
|
||
75 | } |
||
76 | } |
||
77 | this.initComponents();
|
||
78 | } |
||
79 | |||
80 | /**
|
||
81 | * Sets the vector layer and sets its projections
|
||
82 | * @param vectorLayer
|
||
83 | */
|
||
84 | public void setVectorLayer(FLyrVect vectorLayer){ |
||
85 | if (vectorLayer!=null){ |
||
86 | ICoordTrans ct = vectorLayer.getCoordTrans(); |
||
87 | if (ct!=null){ |
||
88 | viewProjection=ct.getPDest(); |
||
89 | originalProjection=ct.getPOrig(); |
||
90 | } |
||
91 | } |
||
92 | initComponents(); |
||
93 | } |
||
94 | |||
95 | private void initComponents() { |
||
96 | selectedProjection=null;
|
||
97 | |||
98 | if (originalProjection==null){ |
||
99 | rdbtnOriginalProjection.setEnabled(false);
|
||
100 | lblRdbtnOriginalProjection.setEnabled(false);
|
||
101 | lblOriginalProjection.setText("");
|
||
102 | }else{
|
||
103 | rdbtnOriginalProjection.setEnabled(true);
|
||
104 | lblRdbtnOriginalProjection.setEnabled(true);
|
||
105 | lblOriginalProjection.setText(originalProjection.getAbrev()); |
||
106 | this.rdbtnOriginalProjection.setSelected(true); |
||
107 | } |
||
108 | |||
109 | if (viewProjection==null){ |
||
110 | rdbtnViewProjection.setEnabled(false);
|
||
111 | lblRdbtnViewProjection.setEnabled(false);
|
||
112 | lblViewProjection.setText("");
|
||
113 | }else{
|
||
114 | rdbtnViewProjection.setEnabled(true);
|
||
115 | lblRdbtnViewProjection.setEnabled(true);
|
||
116 | lblViewProjection.setText(viewProjection.getAbrev()); |
||
117 | this.rdbtnViewProjection.setSelected(true); |
||
118 | } |
||
119 | |||
120 | ActionListener changeOptionAction = new ActionListener() { |
||
121 | public void actionPerformed(ActionEvent e) { |
||
122 | doChangeOption(); |
||
123 | } |
||
124 | }; |
||
125 | this.rdbtnViewProjection.addActionListener(changeOptionAction);
|
||
126 | this.rdbtnOriginalProjection.addActionListener(changeOptionAction);
|
||
127 | this.rdbtnUserProjection.addActionListener(changeOptionAction);
|
||
128 | |||
129 | this.crsSelectPanel=getJPanelProj();
|
||
130 | this.jPanelProj.add(crsSelectPanel);
|
||
131 | |||
132 | doChangeOption(); |
||
133 | this.translate();
|
||
134 | } |
||
135 | |||
136 | private void translate() { |
||
137 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
138 | |||
139 | this.lblSelectTargetProjection.setText(i18nManager.getTranslation(lblSelectTargetProjection.getText()));
|
||
140 | this.lblSelectTargetProjection.setToolTipText(i18nManager.getTranslation(lblSelectTargetProjection.getToolTipText()));
|
||
141 | |||
142 | this.lblRdbtnOriginalProjection.setText(i18nManager.getTranslation(lblRdbtnOriginalProjection.getText()));
|
||
143 | this.lblRdbtnOriginalProjection.setToolTipText(i18nManager.getTranslation(lblRdbtnOriginalProjection.getToolTipText()));
|
||
144 | this.rdbtnOriginalProjection.setToolTipText(i18nManager.getTranslation(rdbtnOriginalProjection.getToolTipText()));
|
||
145 | |||
146 | this.lblRdbtnViewProjection.setText(i18nManager.getTranslation(lblRdbtnViewProjection.getText()));
|
||
147 | this.lblRdbtnViewProjection.setToolTipText(i18nManager.getTranslation(lblRdbtnViewProjection.getToolTipText()));
|
||
148 | this.rdbtnViewProjection.setToolTipText(i18nManager.getTranslation(rdbtnViewProjection.getToolTipText()));
|
||
149 | |||
150 | this.lblRdbtnUserProjection.setText(i18nManager.getTranslation(lblRdbtnUserProjection.getText()));
|
||
151 | this.lblRdbtnUserProjection.setToolTipText(i18nManager.getTranslation(lblRdbtnUserProjection.getToolTipText()));
|
||
152 | this.rdbtnUserProjection.setToolTipText(i18nManager.getTranslation(rdbtnUserProjection.getToolTipText()));
|
||
153 | |||
154 | this.jPanelProj.setToolTipText(i18nManager.getTranslation(jPanelProj.getToolTipText()));
|
||
155 | this.crsSelectPanel.getJLabel().setText(i18nManager.getTranslation("selected_projection")); |
||
156 | } |
||
157 | |||
158 | protected void doChangeOption(){ |
||
159 | if( this.rdbtnOriginalProjection.isSelected() ) { |
||
160 | this.jPanelProj.setEnabled(false); |
||
161 | selectedProjection=originalProjection; |
||
162 | |||
163 | } else if( this.rdbtnViewProjection.isSelected() ) { |
||
164 | this.jPanelProj.setEnabled(false); |
||
165 | selectedProjection=viewProjection; |
||
166 | |||
167 | } else if( this.rdbtnUserProjection.isSelected() ) { |
||
168 | this.jPanelProj.setEnabled(true); |
||
169 | selectedProjection=userProjection; |
||
170 | } |
||
171 | } |
||
172 | |||
173 | protected boolean checkPanel(){ |
||
174 | return selectedProjection!=null; |
||
175 | } |
||
176 | |||
177 | private CRSSelectPanel getJPanelProj() {
|
||
178 | if (crsSelectPanel == null) { |
||
179 | if (viewProjection!=null){ |
||
180 | crsSelectPanel = CRSSelectPanelFactory.getPanel(viewProjection); |
||
181 | }else{
|
||
182 | crsSelectPanel = CRSSelectPanelFactory.getPanel(originalProjection); |
||
183 | } |
||
184 | crsSelectPanel.addActionListener(new java.awt.event.ActionListener() {
|
||
185 | |||
186 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
187 | if (crsSelectPanel.isOkPressed()) {
|
||
188 | userProjection=crsSelectPanel.getCurProj(); |
||
189 | selectedProjection=userProjection; |
||
190 | rdbtnUserProjection.setSelected(true);
|
||
191 | } |
||
192 | } |
||
193 | }); |
||
194 | } |
||
195 | return crsSelectPanel;
|
||
196 | } |
||
197 | |||
198 | /**
|
||
199 | * Returns the target projection to export
|
||
200 | * @return
|
||
201 | */
|
||
202 | public IProjection getTargetProjection(){
|
||
203 | return selectedProjection;
|
||
204 | } |
||
205 | |||
206 | } |