root / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / TransformationVistaPanel.java @ 18259
History | View | Annotate | Download (14.9 KB)
1 |
/* gvSIG. Sistema de Informacin Geogrfica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ibez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
package org.gvsig.crs.gui.panels; |
41 |
|
42 |
import java.awt.BorderLayout; |
43 |
import java.awt.CardLayout; |
44 |
import java.awt.Dimension; |
45 |
import java.awt.FlowLayout; |
46 |
import java.awt.GridLayout; |
47 |
import java.awt.event.ActionEvent; |
48 |
import java.awt.event.ActionListener; |
49 |
|
50 |
import javax.swing.JComboBox; |
51 |
import javax.swing.JLabel; |
52 |
import javax.swing.JPanel; |
53 |
import javax.swing.ListSelectionModel; |
54 |
|
55 |
import org.gvsig.crs.CrsFactory; |
56 |
import org.gvsig.crs.ICrs; |
57 |
import org.gvsig.crs.gui.CRSMainTrPanel; |
58 |
import org.gvsig.crs.gui.listeners.TransformationCompuestaPanelListener; |
59 |
import org.gvsig.crs.persistence.CompTrData; |
60 |
import org.gvsig.crs.persistence.RecentTrsPersistence; |
61 |
import org.gvsig.crs.persistence.TrData; |
62 |
|
63 |
import com.iver.andami.PluginServices; |
64 |
|
65 |
/**
|
66 |
* Clase que define la transformacion de la vista en una transformacion compuesta
|
67 |
*
|
68 |
* @author Jose Luis Gomez Martinez (JoseLuis.Gomez@uclm.es)
|
69 |
* @author Luisa Marina Fernandez (luisam.fernandez@uclm.es)
|
70 |
*
|
71 |
*/
|
72 |
public class TransformationVistaPanel extends JPanel implements ActionListener { |
73 |
private static final long serialVersionUID = 1L; |
74 |
private JLabel lblTransVista=null; |
75 |
private JComboBox jComboOptions=null; |
76 |
private JPanel pNorth=null; |
77 |
private JPanel pCenter=null; |
78 |
private TransformationManualPanel manualTrPanel = null; |
79 |
private TransformationEpsgPanel epsgTrPanel = null; |
80 |
private TransformationNadgridsPanel nadsTrPanel = null; |
81 |
private TransformationRecentsPanel recentsTrPanel = null; |
82 |
private JLabel lblCrsView = null; |
83 |
private JLabel lblCrsViewCode = null; |
84 |
|
85 |
String crs_target = null; |
86 |
String crs_source = null; |
87 |
String sourceAbrev = ""; |
88 |
String sourceTransformation = null; |
89 |
String targetTransformation = null; |
90 |
CRSMainTrPanel crsMainTrPanel = null;
|
91 |
|
92 |
boolean recentCompTransformation = false; |
93 |
|
94 |
/**
|
95 |
* Inicializa this
|
96 |
*
|
97 |
*/
|
98 |
public TransformationVistaPanel(String target, CRSMainTrPanel p) { |
99 |
super();
|
100 |
crsMainTrPanel = p; |
101 |
setCrs_target(target); |
102 |
manualTrPanel = new TransformationManualPanel();
|
103 |
epsgTrPanel = new TransformationEpsgPanel(getCrs_target());
|
104 |
nadsTrPanel = new TransformationNadgridsPanel(false); |
105 |
recentsTrPanel = new TransformationRecentsPanel();
|
106 |
|
107 |
this.setLayout(new BorderLayout()); |
108 |
//Aadir al norte el panel que contiene las diferentes opciones de transformacin
|
109 |
this.add(getPNorth(),BorderLayout.NORTH); |
110 |
this.add(getPCenter(),BorderLayout.CENTER); |
111 |
|
112 |
setListeners(); |
113 |
|
114 |
} |
115 |
|
116 |
public JPanel getPCenter() { |
117 |
if (pCenter == null) { |
118 |
pCenter = new JPanel(); |
119 |
pCenter.setLayout(new CardLayout()); |
120 |
|
121 |
pCenter.add("recents", recentsTrPanel);
|
122 |
pCenter.add("manual", manualTrPanel);
|
123 |
pCenter.add("epsg", epsgTrPanel);
|
124 |
pCenter.add("nad", nadsTrPanel);
|
125 |
} |
126 |
|
127 |
return pCenter;
|
128 |
} |
129 |
|
130 |
public JLabel getLblTransVista() { |
131 |
if(lblTransVista==null){ |
132 |
lblTransVista=new JLabel(PluginServices.getText(this,"transformacion_vista")+":"); |
133 |
} |
134 |
return lblTransVista;
|
135 |
} |
136 |
|
137 |
public JLabel getLblCrsVista() { |
138 |
if(lblCrsView==null){ |
139 |
lblCrsView=new JLabel(PluginServices.getText(this,"crs_view")+":"); |
140 |
} |
141 |
return lblCrsView;
|
142 |
} |
143 |
|
144 |
public JLabel getLblCrsVistaCode() { |
145 |
if(lblCrsViewCode==null){ |
146 |
lblCrsViewCode=new JLabel(); |
147 |
} |
148 |
return lblCrsViewCode;
|
149 |
} |
150 |
/**
|
151 |
* Definicion del panel que contiene el Label y el Combo de
|
152 |
* las transformaciones de la vista
|
153 |
* @return
|
154 |
*/
|
155 |
public JPanel getPNorth() { |
156 |
if (pNorth==null){ |
157 |
pNorth=new JPanel(); |
158 |
pNorth.setLayout(new GridLayout(2,1)); |
159 |
JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT,10,3)); |
160 |
p1.add(getLblCrsVista()); |
161 |
p1.add(getLblCrsVistaCode()); |
162 |
JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT,10,3)); |
163 |
p2.add(getLblTransVista()); |
164 |
p2.add(getJComboOptions()); |
165 |
|
166 |
pNorth.add(p1); |
167 |
pNorth.add(p2); |
168 |
} |
169 |
return pNorth;
|
170 |
} |
171 |
/**
|
172 |
* Definicin del ComboBox que contiene las diferentes transformaciones
|
173 |
* aplicables a la vista
|
174 |
* @return
|
175 |
*/
|
176 |
|
177 |
public JComboBox getJComboOptions() { |
178 |
if (jComboOptions == null){ |
179 |
String[] selection = {PluginServices.getText(this, "recents_transformation"), |
180 |
PluginServices.getText(this, "transformacion_epsg"), |
181 |
PluginServices.getText(this, "transformacion_manual"), |
182 |
PluginServices.getText(this, "nadgrids")}; |
183 |
jComboOptions = new JComboBox(selection); |
184 |
//jComboOptions=new JComboBox();
|
185 |
jComboOptions.setPreferredSize(new Dimension(180,25)); |
186 |
jComboOptions.setSelectedIndex(0);
|
187 |
jComboOptions.addActionListener(this);
|
188 |
} |
189 |
|
190 |
return jComboOptions;
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* Mtodo para aplicarle los eventos necesarios en el panel actual. La
|
195 |
* definicin de estos listeners estarn en la clase CRSMainTrPanelListener
|
196 |
*
|
197 |
*/
|
198 |
private void setListeners(){ |
199 |
|
200 |
TransformationCompuestaPanelListener listener = new TransformationCompuestaPanelListener(this, crsMainTrPanel); |
201 |
|
202 |
getJComboOptions().addActionListener(listener); |
203 |
getRecentsTrPanel().getJButtonInfo().addActionListener(listener); |
204 |
|
205 |
ListSelectionModel rowSMEpsgTr = getEpsgTrPanel().getJTable().getSelectionModel();
|
206 |
rowSMEpsgTr.addListSelectionListener(listener); |
207 |
|
208 |
ListSelectionModel rowSMRecentsTr = getRecentsTrPanel().getJTable().getSelectionModel();
|
209 |
rowSMRecentsTr.addListSelectionListener(listener); |
210 |
|
211 |
getNadsTrPanel().getJComboNadFile().addItemListener(listener); |
212 |
|
213 |
getManualTrPanel().getTx_Translation().addKeyListener(listener); |
214 |
getManualTrPanel().getTy_Translation().addKeyListener(listener); |
215 |
getManualTrPanel().getTz_Translation().addKeyListener(listener); |
216 |
getManualTrPanel().getTx_Rotation().addKeyListener(listener); |
217 |
getManualTrPanel().getTy_Rotation().addKeyListener(listener); |
218 |
getManualTrPanel().getTz_Rotation().addKeyListener(listener); |
219 |
getManualTrPanel().getTscale().addKeyListener(listener); |
220 |
} |
221 |
|
222 |
|
223 |
public void actionPerformed(ActionEvent e) { |
224 |
//Al cambiar el item seleccionado del combo
|
225 |
if(e.getSource().equals(getJComboOptions())){
|
226 |
CardLayout cl = (CardLayout)(pCenter.getLayout()); |
227 |
if(getJComboOptions().getSelectedItem().equals(PluginServices.getText(this,"recents_transformation"))){ |
228 |
//Mostrar el panel de transformacin reciente
|
229 |
cl.show(pCenter, "recents");
|
230 |
} |
231 |
else if(getJComboOptions().getSelectedItem().equals(PluginServices.getText(this,"transformacion_epsg"))){ |
232 |
|
233 |
//mostrar el panel de transformacin epsg
|
234 |
cl.show(pCenter, "epsg");
|
235 |
} |
236 |
else if(getJComboOptions().getSelectedItem().equals(PluginServices.getText(this,"transformacion_manual"))){ |
237 |
|
238 |
|
239 |
//mostrar el panel de transformacin manual
|
240 |
cl.show(pCenter, "manual");
|
241 |
} |
242 |
else if(getJComboOptions().getSelectedItem().equals(PluginServices.getText(this,"nadgrids"))){ |
243 |
//mostrar el panel de nadgrids
|
244 |
cl.show(pCenter, "nad");
|
245 |
} |
246 |
} |
247 |
|
248 |
} |
249 |
|
250 |
public TransformationEpsgPanel getEpsgTrPanel() {
|
251 |
return epsgTrPanel;
|
252 |
} |
253 |
|
254 |
public TransformationManualPanel getManualTrPanel() {
|
255 |
return manualTrPanel;
|
256 |
} |
257 |
|
258 |
public TransformationNadgridsPanel getNadsTrPanel() {
|
259 |
return nadsTrPanel;
|
260 |
} |
261 |
|
262 |
public TransformationRecentsPanel getRecentsTrPanel() {
|
263 |
return recentsTrPanel;
|
264 |
} |
265 |
|
266 |
public void setCrs_target(String authTarget) { |
267 |
crs_target = authTarget; |
268 |
getLblCrsVistaCode().setText(authTarget); |
269 |
} |
270 |
|
271 |
public String getCrs_target() { |
272 |
return crs_target;
|
273 |
} |
274 |
|
275 |
public void setCrs_source(String authority) { |
276 |
crs_source = authority; |
277 |
setSourceAbrev(authority); |
278 |
} |
279 |
|
280 |
public String getCrs_source() { |
281 |
return crs_source;
|
282 |
} |
283 |
|
284 |
public void fillData() { |
285 |
String[] source = getCrs_source().split(":"); |
286 |
String[] target = getCrs_target().split(":"); |
287 |
recentsTrPanel.loadRecentsCompuesta(getCrs_target()); |
288 |
epsgTrPanel.setSourceCompuesta(getCrs_target()); |
289 |
nadsTrPanel.setCode(Integer.parseInt(source[1])); |
290 |
nadsTrPanel.setSourceAbrev(source[0], source[1]); |
291 |
nadsTrPanel.setTargetAbrev(target[0], target[1]); |
292 |
nadsTrPanel.getJComboNadFile().setSelectedIndex(0);
|
293 |
manualTrPanel.setCode(Integer.parseInt(source[1])); |
294 |
manualTrPanel.setSourceAbrev(source[0], source[1]); |
295 |
manualTrPanel.setTargetAbrev(target[0], target[1]); |
296 |
getJComboOptions().setSelectedIndex(0);
|
297 |
/*
|
298 |
* Se dice que no es una transformacion cogida de las recientes compuestas
|
299 |
* para un correcto funcionamiento de los botones.
|
300 |
*/
|
301 |
setRecentCompTransformation(false);
|
302 |
} |
303 |
|
304 |
public void setSourceAbrev(String fuente){ |
305 |
sourceAbrev = fuente; |
306 |
} |
307 |
|
308 |
public String getSourceAbrev(){ |
309 |
return sourceAbrev;
|
310 |
} |
311 |
|
312 |
public ICrs getProjection() {
|
313 |
ICrs crs; |
314 |
try {
|
315 |
crs = new CrsFactory().getCRS(getSourceAbrev());
|
316 |
crs.setTransformationParams(getSourceTransformation(),getTargetTransformation());//nadFile);
|
317 |
return crs;
|
318 |
} catch (org.gvsig.crs.CrsException e) {
|
319 |
e.printStackTrace(); |
320 |
} |
321 |
return null; |
322 |
} |
323 |
|
324 |
public void setSourceTransformation(String trans) { |
325 |
sourceTransformation = trans; |
326 |
} |
327 |
|
328 |
public String getSourceTransformation() { |
329 |
return sourceTransformation;
|
330 |
} |
331 |
|
332 |
public void setTargetTransformation(String trans) { |
333 |
targetTransformation = trans; |
334 |
} |
335 |
|
336 |
public String getTargetTransformation() { |
337 |
return targetTransformation;
|
338 |
} |
339 |
|
340 |
public String getParamsEpsg(String [] values) { |
341 |
String params = "+towgs84="; |
342 |
params += values[0];
|
343 |
for(int i = 1; i < values.length; i++) |
344 |
params +=","+values[i];
|
345 |
return params;
|
346 |
} |
347 |
|
348 |
public String getManualParams() { |
349 |
if(getManualTrPanel().getTx_Translation().getText().equals("")){ |
350 |
getManualTrPanel().getTx_Translation().setText("0");
|
351 |
} |
352 |
else if (getManualTrPanel().getTy_Translation().getText().equals("")){ |
353 |
getManualTrPanel().getTy_Translation().setText("0");
|
354 |
} |
355 |
else if (getManualTrPanel().getTz_Translation().getText().equals("")){ |
356 |
getManualTrPanel().getTz_Translation().setText("0");
|
357 |
} |
358 |
else if (getManualTrPanel().getTx_Rotation().getText().equals("")){ |
359 |
getManualTrPanel().getTx_Rotation().setText("0");
|
360 |
} |
361 |
else if (getManualTrPanel().getTy_Rotation().getText().equals("")){ |
362 |
getManualTrPanel().getTy_Rotation().setText("0");
|
363 |
} |
364 |
else if (getManualTrPanel().getTz_Rotation().getText().equals("")){ |
365 |
getManualTrPanel().getTz_Rotation().setText("0");
|
366 |
} |
367 |
else if (getManualTrPanel().getTscale().getText().equals("")){ |
368 |
getManualTrPanel().getTscale().setText("0");
|
369 |
} |
370 |
String param = "+towgs84="+ getManualTrPanel().getTx_Translation().getText()+","+ |
371 |
getManualTrPanel().getTy_Translation().getText()+","+
|
372 |
getManualTrPanel().getTz_Translation().getText()+","+
|
373 |
getManualTrPanel().getTx_Rotation().getText()+","+
|
374 |
getManualTrPanel().getTy_Rotation().getText()+","+
|
375 |
getManualTrPanel().getTz_Rotation().getText()+","+
|
376 |
getManualTrPanel().getTscale().getText() + " ";
|
377 |
return param;
|
378 |
} |
379 |
|
380 |
public String getNadsParams(String info) { |
381 |
String[] partes = info.split("\\("); |
382 |
String nadFile = partes[0]; |
383 |
return "+nadgrids="+nadFile; |
384 |
} |
385 |
|
386 |
/**
|
387 |
* cuando utilizamos crs+transformacion, cargamos los paneles para que
|
388 |
* el usuario pueda consultar la transformacion utilizada...
|
389 |
* @param details
|
390 |
*/
|
391 |
public void fillData(String details) { |
392 |
RecentTrsPersistence trPersistence = new RecentTrsPersistence();
|
393 |
TrData crsTrDataArray[] = trPersistence.getArrayOfTrData();
|
394 |
CompTrData comp = null;
|
395 |
|
396 |
for (int iRow = crsTrDataArray.length-1; iRow >= 0; iRow--) { |
397 |
if (details.equals(crsTrDataArray[iRow].getAuthority()+":"+crsTrDataArray[iRow].getCode()+" <--> "+crsTrDataArray[iRow].getDetails()) && crsTrDataArray[iRow].getAuthority().equals(PluginServices.getText(this, "COMP"))) { |
398 |
comp = (CompTrData) crsTrDataArray[iRow]; |
399 |
break;
|
400 |
} |
401 |
} |
402 |
if (comp.getSecondTr().getAuthority().equals(PluginServices.getText(this, "EPSG"))) { |
403 |
getJComboOptions().setSelectedIndex(1);
|
404 |
int cod =Integer.parseInt(comp.getFirstTr().getCrsSource().split(":")[1]); |
405 |
String code = String.valueOf(comp.getSecondTr().getCode()); |
406 |
//getEpsgTrPanel().setSource(PluginServices.getText(this, "EPSG"), cod);
|
407 |
for (int i=0; i< getEpsgTrPanel().getJTable().getRowCount(); i++) { |
408 |
if (code.equals((String)getEpsgTrPanel().getJTable().getValueAt(i, 0))) { |
409 |
//seleccionarlo
|
410 |
getEpsgTrPanel().getJTable().setRowSelectionInterval(i,i); |
411 |
break;
|
412 |
} |
413 |
} |
414 |
} else if (comp.getSecondTr().getAuthority().equals(PluginServices.getText(this, "USR"))) { |
415 |
getJComboOptions().setSelectedIndex(2);
|
416 |
String data = comp.getSecondTr().getDetails();
|
417 |
data = data.trim().substring(1, data.length()-1); |
418 |
String values[] = data.split(","); |
419 |
getManualTrPanel().getTx_Translation().setText(values[0]);
|
420 |
getManualTrPanel().getTy_Translation().setText(values[1]);
|
421 |
getManualTrPanel().getTz_Translation().setText(values[2]);
|
422 |
getManualTrPanel().getTx_Rotation().setText(values[3]);
|
423 |
getManualTrPanel().getTy_Rotation().setText(values[4]);
|
424 |
getManualTrPanel().getTz_Rotation().setText(values[5]);
|
425 |
getManualTrPanel().getTscale().setText(values[6]);
|
426 |
|
427 |
} else if (comp.getSecondTr().getAuthority().equals(PluginServices.getText(this, "NADGR"))) { |
428 |
getJComboOptions().setSelectedIndex(3);
|
429 |
String data[] = comp.getSecondTr().getDetails().split(" "); |
430 |
String fichero = data[0]; |
431 |
String[] authority = data[1].substring(1,data[1].length()-1).split(":"); |
432 |
//Mirar como indicarle el CRS al que se le aplica...
|
433 |
getNadsTrPanel().setSourceAbrev(authority[0], authority[1]); |
434 |
|
435 |
for (int i = 0; i< getNadsTrPanel().getJComboNadFile().getItemCount(); i++) { |
436 |
if (fichero.equals((String)getNadsTrPanel().getJComboNadFile().getItemAt(i))) { |
437 |
getNadsTrPanel().getJComboNadFile().setSelectedIndex(i); |
438 |
break;
|
439 |
} |
440 |
} |
441 |
} |
442 |
/*
|
443 |
* Por aquí solo pasa cuando se ha seleccionado una transformación compuesta de recientes.
|
444 |
* Pondremos el valor de que es un crs compuesto reciente a true para que el botón de siguiente
|
445 |
* salga habilitado.
|
446 |
*/
|
447 |
setRecentCompTransformation(true);
|
448 |
} |
449 |
|
450 |
public void setRecentCompTransformation(boolean state) { |
451 |
recentCompTransformation = state; |
452 |
} |
453 |
|
454 |
public boolean getRecentCompTransformation() { |
455 |
return recentCompTransformation;
|
456 |
} |
457 |
|
458 |
public void resetData() { |
459 |
fillData(); |
460 |
} |
461 |
|
462 |
public boolean isSthSelected() { |
463 |
if (getRecentsTrPanel().selectedRowTable == -1) |
464 |
return false; |
465 |
return true; |
466 |
} |
467 |
|
468 |
} |