root / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / wizard / DefinirDatum.java @ 11709
History | View | Annotate | Download (21.1 KB)
1 |
package org.gvsig.crs.gui.panels.wizard; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.GridBagConstraints; |
6 |
import java.awt.GridBagLayout; |
7 |
import java.awt.Insets; |
8 |
import java.awt.event.ActionEvent; |
9 |
import java.awt.event.ActionListener; |
10 |
import java.awt.event.ItemEvent; |
11 |
import java.sql.ResultSet; |
12 |
import java.sql.SQLException; |
13 |
import java.util.ArrayList; |
14 |
|
15 |
import javax.swing.BorderFactory; |
16 |
import javax.swing.ButtonGroup; |
17 |
import javax.swing.ImageIcon; |
18 |
import javax.swing.JButton; |
19 |
import javax.swing.JLabel; |
20 |
import javax.swing.JPanel; |
21 |
import javax.swing.JRadioButton; |
22 |
import javax.swing.JTextField; |
23 |
|
24 |
import org.gvsig.crs.CrsException; |
25 |
import org.gvsig.crs.CrsFactory; |
26 |
import org.gvsig.crs.ICrs; |
27 |
import org.gvsig.crs.gui.dialog.ImportNewCrsDialog; |
28 |
|
29 |
import com.iver.andami.PluginServices; |
30 |
import com.iver.utiles.swing.JComboBox; |
31 |
|
32 |
import es.idr.teledeteccion.connection.EpsgConnection; |
33 |
import es.idr.teledeteccion.connection.Query; |
34 |
|
35 |
/**
|
36 |
* Panel de definicin del Datum
|
37 |
*
|
38 |
* @author Luisa Marina Fernandez Ruiz (luisam.fernandez@uclm.es)
|
39 |
*
|
40 |
*
|
41 |
*/
|
42 |
public class DefinirDatum extends JPanel implements ActionListener{ |
43 |
|
44 |
private JTextField txtDatum; |
45 |
private JTextField txtElipsoide; |
46 |
private JTextField txtSemMay; |
47 |
private JTextField txtSemMen; |
48 |
private JTextField txtInvF; |
49 |
private JTextField txtMeridian; |
50 |
private JTextField txtLong; |
51 |
|
52 |
private JLabel lblDatum; |
53 |
private JLabel lblElipsoide; |
54 |
private JLabel lblMeridian; |
55 |
private JLabel lblLong; |
56 |
|
57 |
private JButton btnImportDatum; |
58 |
private JButton btnImportElipsoide; |
59 |
private JButton btnImportMeridian; |
60 |
|
61 |
private JComboBox cbSemMay; |
62 |
private JComboBox cbSemMen; |
63 |
private JComboBox cbInvF; |
64 |
private JComboBox cbLong; |
65 |
|
66 |
private JRadioButton rbSemMay; |
67 |
private JRadioButton rbSemMen; |
68 |
private JRadioButton rbInvF; |
69 |
private ButtonGroup groupRadioButton; |
70 |
|
71 |
private Dimension bigSize; |
72 |
private Dimension smallSize; |
73 |
|
74 |
private ImageIcon imodify; |
75 |
|
76 |
private static final long serialVersionUID = 1L; |
77 |
ICrs crs = null;
|
78 |
|
79 |
private String sourceUnitLong = null; |
80 |
private String sourceUnitSemMay = null; |
81 |
private String sourceUnitSemMen = null; |
82 |
|
83 |
public DefinirDatum() {
|
84 |
|
85 |
super();
|
86 |
imodify = new ImageIcon(DefinirDatum.class.getClassLoader().getResource("images/search.png")); |
87 |
this.setLayout(new BorderLayout()); |
88 |
this.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); |
89 |
bigSize=new Dimension(); |
90 |
bigSize.width=200;
|
91 |
smallSize=new Dimension(); |
92 |
smallSize.width=130;
|
93 |
inicializarNuevo(); |
94 |
|
95 |
} |
96 |
private void inicializarNuevo(){ |
97 |
JPanel pMain=new JPanel(); |
98 |
JPanel pDatum=new JPanel(); |
99 |
JPanel pElipsoide=new JPanel(); |
100 |
JPanel pMeridian=new JPanel(); |
101 |
pMain.setLayout(new BorderLayout()); |
102 |
|
103 |
pMain.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this,"Dat_nDatum"))); |
104 |
pElipsoide.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this,"Dat_nElipsoide"))); |
105 |
pMeridian.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this,"Dat_nMeridian"))); |
106 |
/*Panel que contiene los datos del Datum*/
|
107 |
pDatum.setLayout(new GridBagLayout()); |
108 |
GridBagConstraints z=new GridBagConstraints(); |
109 |
z.fill=GridBagConstraints.BOTH;
|
110 |
z.anchor=GridBagConstraints.WEST;
|
111 |
z.insets=new Insets(3,3,3,3); |
112 |
z.gridx=0;
|
113 |
z.gridy=0;
|
114 |
pDatum.add(getLblDatum(),z); |
115 |
z.gridwidth=3;
|
116 |
z.gridx=0;
|
117 |
z.gridy=1;
|
118 |
pDatum.add(getTxtDatum(),z); |
119 |
z.gridwidth=1;
|
120 |
z.gridx=3;
|
121 |
z.gridy=1;
|
122 |
pDatum.add(getBtnImportDatum(),z); |
123 |
|
124 |
/*Panel que contiene los datos del Elipsoide*/
|
125 |
pElipsoide.setLayout(new GridBagLayout()); |
126 |
GridBagConstraints b=new GridBagConstraints(); |
127 |
b.fill=GridBagConstraints.BOTH;
|
128 |
b.anchor=GridBagConstraints.WEST;
|
129 |
b.insets=new Insets(3,3,3,3); |
130 |
|
131 |
b.gridx=0;
|
132 |
b.gridy=0;
|
133 |
b.gridwidth=2;
|
134 |
pElipsoide.add(getLblElipsoide(),b); |
135 |
|
136 |
b.gridx=0;
|
137 |
b.gridwidth=3;
|
138 |
b.gridy=1;
|
139 |
pElipsoide.add(getTxtElipsoide(),b); |
140 |
b.gridwidth=1;
|
141 |
b.gridx=3;
|
142 |
b.gridy=1;
|
143 |
pElipsoide.add(getBtnImportElipsoide(),b); |
144 |
b.gridx=1;
|
145 |
b.gridy=2;
|
146 |
pElipsoide.add(getRbSemMay(),b); |
147 |
b.gridx=2;
|
148 |
b.gridy=2;
|
149 |
pElipsoide.add(getTxtSemMay(),b); |
150 |
b.gridx=3;
|
151 |
b.gridy=2;
|
152 |
pElipsoide.add(getCbSemMay(),b); |
153 |
b.gridx=1;
|
154 |
b.gridy=3;
|
155 |
pElipsoide.add(getRbSemMen(),b); |
156 |
b.gridx=2;
|
157 |
b.gridy=3;
|
158 |
pElipsoide.add(getTxtSemMen(),b); |
159 |
b.gridx=3;
|
160 |
b.gridy=3;
|
161 |
pElipsoide.add(getCbSemMen(),b); |
162 |
b.gridx=1;
|
163 |
b.gridy=4;
|
164 |
pElipsoide.add(getRbInvF(),b); |
165 |
b.gridx=2;
|
166 |
b.gridy=4;
|
167 |
pElipsoide.add(getTxtInvF(),b); |
168 |
b.gridx=3;
|
169 |
b.gridy=4;
|
170 |
//pElipsoide.add(getCbInvF(),b);
|
171 |
/*Agrupar los Radio Buttoms*/
|
172 |
agruparRadioButtons(); |
173 |
|
174 |
|
175 |
/*Panel que contiene los datos del Meridiano*/
|
176 |
pMeridian.setLayout(new GridBagLayout()); |
177 |
GridBagConstraints c=new GridBagConstraints(); |
178 |
c.fill=GridBagConstraints.BOTH;
|
179 |
c.insets=new Insets(3,3,3,3); |
180 |
c.anchor=GridBagConstraints.WEST;
|
181 |
c.gridx=0;
|
182 |
c.gridy=0;
|
183 |
pMeridian.add(getLblMeridian(),c); |
184 |
c.gridx=0;
|
185 |
c.gridwidth=3;
|
186 |
c.gridy=1;
|
187 |
pMeridian.add(getTxtMeridian(),c); |
188 |
c.gridwidth=1;
|
189 |
c.gridx=3;
|
190 |
c.gridy=1;
|
191 |
pMeridian.add(getBtnImportMeridian(),c); |
192 |
c.gridx=0;
|
193 |
c.gridy=2;
|
194 |
pMeridian.add(getLblLong(),c); |
195 |
c.gridx=1;
|
196 |
c.gridy=2;
|
197 |
c.gridwidth=2;
|
198 |
pMeridian.add(getTxtLong(),c); |
199 |
c.gridwidth=1;
|
200 |
c.gridx=3;
|
201 |
c.gridy=2;
|
202 |
pMeridian.add(getCbLong(),c); |
203 |
|
204 |
pMain.add(pDatum,BorderLayout.NORTH);
|
205 |
pMain.add(pElipsoide,BorderLayout.CENTER);
|
206 |
pMain.add(pMeridian,BorderLayout.SOUTH);
|
207 |
this.add(pMain,BorderLayout.CENTER); |
208 |
|
209 |
} |
210 |
/**
|
211 |
* Inicializa el botn Importar del datum
|
212 |
* @return
|
213 |
*/
|
214 |
public JButton getBtnImportDatum() { |
215 |
if(btnImportDatum==null){ |
216 |
btnImportDatum=new JButton(); |
217 |
btnImportDatum.setText(PluginServices.getText(this, "Dat_Importar")); |
218 |
btnImportDatum.setIcon(imodify); |
219 |
btnImportDatum.addActionListener(this);
|
220 |
} |
221 |
return btnImportDatum;
|
222 |
} |
223 |
/**
|
224 |
* Inicializa el botn Importar del Elipsoide
|
225 |
* @return
|
226 |
*/
|
227 |
public JButton getBtnImportElipsoide() { |
228 |
if(btnImportElipsoide==null){ |
229 |
btnImportElipsoide=new JButton(); |
230 |
btnImportElipsoide.setText(PluginServices.getText(this, "Dat_Importar")); |
231 |
btnImportElipsoide.setIcon(imodify); |
232 |
btnImportElipsoide.addActionListener(this);
|
233 |
} |
234 |
return btnImportElipsoide;
|
235 |
} |
236 |
/**
|
237 |
* Inicializa el botn Importar del Meridiano
|
238 |
* @return
|
239 |
*/
|
240 |
public JButton getBtnImportMeridian() { |
241 |
if(btnImportMeridian==null){ |
242 |
btnImportMeridian=new JButton(); |
243 |
btnImportMeridian.setText(PluginServices.getText(this, "Dat_Importar")); |
244 |
btnImportMeridian.setIcon(imodify); |
245 |
btnImportMeridian.addActionListener(this);
|
246 |
} |
247 |
return btnImportMeridian;
|
248 |
} |
249 |
/**
|
250 |
* Inicializa el Combo box con las unidades de Inverse Flat
|
251 |
* @return
|
252 |
*/
|
253 |
public JComboBox getCbInvF() { |
254 |
if (cbInvF==null){ |
255 |
ArrayList units = obtenerItemsUnidades();
|
256 |
String[] items = new String[units.size()]; |
257 |
for (int i=0;i<units.size();i++){ |
258 |
items[i] = units.get(i).toString(); |
259 |
} |
260 |
cbInvF=new JComboBox(items); |
261 |
/*Seleccionar un item por defecto*/
|
262 |
cbInvF.setSelectedIndex(0);
|
263 |
cbInvF.addActionListener(this);
|
264 |
} |
265 |
return cbInvF;
|
266 |
} |
267 |
/**
|
268 |
* Inicializa el Combo box con las unidades de Longitud
|
269 |
* @return
|
270 |
*/
|
271 |
public JComboBox getCbLong() { |
272 |
if (cbLong==null){ |
273 |
ArrayList units = obtenerItemsUnidades();
|
274 |
String[] items = new String[units.size()]; |
275 |
for (int i=0;i<units.size();i++){ |
276 |
items[i] = units.get(i).toString(); |
277 |
} |
278 |
cbLong=new JComboBox(items); |
279 |
/*Seleccionar un item por defecto*/
|
280 |
cbLong.setSelectedIndex(0);
|
281 |
cbLong.addActionListener(this);
|
282 |
sourceUnitLong = (String)cbLong.getSelectedItem();
|
283 |
} |
284 |
return cbLong;
|
285 |
} |
286 |
/**
|
287 |
* Inicializa el Combo box con las unidades de Semieje Mayor
|
288 |
* @return
|
289 |
*/
|
290 |
public JComboBox getCbSemMay() { |
291 |
if (cbSemMay==null){ |
292 |
ArrayList units = obtenerItemsUnidades();
|
293 |
String[] items = new String[units.size()]; |
294 |
for (int i=0;i<units.size();i++){ |
295 |
items[i] = units.get(i).toString(); |
296 |
} |
297 |
cbSemMay=new JComboBox(items); |
298 |
/*Seleccionar un item por defecto*/
|
299 |
cbSemMay.setSelectedIndex(0);
|
300 |
cbSemMay.addActionListener(this);
|
301 |
sourceUnitSemMay = (String)cbSemMay.getSelectedItem();
|
302 |
} |
303 |
return cbSemMay;
|
304 |
} |
305 |
/**
|
306 |
* Inicializa el Combo box con las unidades de Semieje Menor
|
307 |
* @return
|
308 |
*/
|
309 |
public JComboBox getCbSemMen() { |
310 |
if (cbSemMen==null){ |
311 |
ArrayList units = obtenerItemsUnidades();
|
312 |
String[] items = new String[units.size()]; |
313 |
for (int i=0;i<units.size();i++){ |
314 |
items[i] = units.get(i).toString(); |
315 |
} |
316 |
cbSemMen=new JComboBox(items); |
317 |
/*Seleccionar un item por defecto*/
|
318 |
cbSemMen.setSelectedIndex(0);
|
319 |
cbSemMen.addActionListener(this);
|
320 |
sourceUnitSemMen = (String)cbSemMen.getSelectedItem();
|
321 |
} |
322 |
return cbSemMen;
|
323 |
} |
324 |
/*
|
325 |
* Accede al la base de datos y obtiene los items de
|
326 |
* los combobox
|
327 |
* @return
|
328 |
*/
|
329 |
private ArrayList obtenerItemsUnidades(){ //unidades de longitud... |
330 |
//TODO: Obtener los items del combo de la base de datos
|
331 |
ArrayList items = new ArrayList(); |
332 |
|
333 |
String sentence = "SELECT unit_of_meas_name " + |
334 |
"FROM epsg_unitofmeasure " +
|
335 |
"WHERE unit_of_meas_type = 'length'";
|
336 |
EpsgConnection connect = new EpsgConnection();
|
337 |
connect.setConnectionEPSG(); |
338 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
339 |
try {
|
340 |
while (result.next()) {
|
341 |
items.add(result.getString("unit_of_meas_name"));
|
342 |
} |
343 |
} catch (SQLException e) { |
344 |
// TODO Auto-generated catch block
|
345 |
e.printStackTrace(); |
346 |
} |
347 |
return items;
|
348 |
} |
349 |
/**
|
350 |
* Inicializa el JLabel Datum
|
351 |
* @return
|
352 |
*/
|
353 |
public JLabel getLblDatum() { |
354 |
if (lblDatum==null){ |
355 |
lblDatum=new JLabel(); |
356 |
lblDatum.setText(PluginServices.getText(this,"Dat_Datum")); |
357 |
} |
358 |
return lblDatum;
|
359 |
} |
360 |
/**
|
361 |
* Inicializa el JLabel Elipsoide
|
362 |
* @return
|
363 |
*/
|
364 |
public JLabel getLblElipsoide() { |
365 |
if (lblElipsoide==null){ |
366 |
lblElipsoide=new JLabel(); |
367 |
lblElipsoide.setText(PluginServices.getText(this,"Dat_Elips")); |
368 |
//lblElipsoide.setText("Introduce el Elipsoide");
|
369 |
} |
370 |
return lblElipsoide;
|
371 |
} |
372 |
|
373 |
/**
|
374 |
* Inicializa el JLabel Longitud
|
375 |
* @return
|
376 |
*/
|
377 |
public JLabel getLblLong() { |
378 |
if (lblLong==null){ |
379 |
lblLong=new JLabel(); |
380 |
lblLong.setText(PluginServices.getText(this,"Dat_Long")); |
381 |
} |
382 |
return lblLong;
|
383 |
} |
384 |
/**
|
385 |
* Inicializa el JLabel Meridiano
|
386 |
* @return
|
387 |
*/
|
388 |
public JLabel getLblMeridian() { |
389 |
if (lblMeridian==null){ |
390 |
lblMeridian=new JLabel(); |
391 |
lblMeridian.setText(PluginServices.getText(this,"Dat_Meridian")); |
392 |
} |
393 |
return lblMeridian;
|
394 |
} |
395 |
|
396 |
|
397 |
/**
|
398 |
* Inicializa el radio button Inverse Flat del elipsoide
|
399 |
* @return
|
400 |
*/
|
401 |
public JRadioButton getRbInvF() { |
402 |
if(rbInvF==null){ |
403 |
rbInvF=new JRadioButton(); |
404 |
rbInvF.setToolTipText(PluginServices.getText(this,"Dat_InvFToolTipText")); |
405 |
rbInvF.setText(PluginServices.getText(this,"Dat_InvF")); |
406 |
rbInvF.addActionListener(this);
|
407 |
} |
408 |
return rbInvF;
|
409 |
} |
410 |
|
411 |
/**
|
412 |
* Inicializa el radio button Semieje Mayor del elipsoide
|
413 |
* @return
|
414 |
*/
|
415 |
public JRadioButton getRbSemMay() { |
416 |
if(rbSemMay==null){ |
417 |
rbSemMay=new JRadioButton(); |
418 |
rbSemMay.setToolTipText(PluginServices.getText(this,"Dat_SemMayToolTipText")); |
419 |
rbSemMay.setText(PluginServices.getText(this,"Dat_SemMay")); |
420 |
rbSemMay.addActionListener(this);
|
421 |
} |
422 |
return rbSemMay;
|
423 |
} |
424 |
|
425 |
/**
|
426 |
* Inicializa el radio Button del Semieje Menor del elipsoide
|
427 |
* @return
|
428 |
*/
|
429 |
public JRadioButton getRbSemMen() { |
430 |
if(rbSemMen==null){ |
431 |
rbSemMen=new JRadioButton(); |
432 |
rbSemMen.setToolTipText(PluginServices.getText(this,"Dat_SemMenToolTipText")); |
433 |
rbSemMen.setText(PluginServices.getText(this,"Dat_SemMen")); |
434 |
rbSemMen.addActionListener(this);
|
435 |
} |
436 |
return rbSemMen;
|
437 |
} |
438 |
|
439 |
/**
|
440 |
* Agrupa los Radio Button de los parmetros del elipsoide
|
441 |
*
|
442 |
*/
|
443 |
private void agruparRadioButtons() { |
444 |
if(groupRadioButton==null){ |
445 |
groupRadioButton=new ButtonGroup(); |
446 |
/*Agrupar los radio Buttons*/
|
447 |
groupRadioButton.add(getRbSemMay()); |
448 |
groupRadioButton.add(getRbSemMen()); |
449 |
groupRadioButton.add(getRbInvF()); |
450 |
/*Selecciona por defecto el semieje mayor*/
|
451 |
getRbSemMay().setSelected(true);
|
452 |
} |
453 |
} |
454 |
/**
|
455 |
* Inicializa el cuadro de texto que contiene el datum
|
456 |
* @return
|
457 |
*/
|
458 |
public JTextField getTxtDatum() { |
459 |
if (txtDatum==null){ |
460 |
txtDatum=new JTextField(); |
461 |
bigSize.height=txtDatum.getPreferredSize().height; |
462 |
txtDatum.setPreferredSize(bigSize); |
463 |
txtDatum.addActionListener(this);
|
464 |
} |
465 |
return txtDatum;
|
466 |
} |
467 |
/**
|
468 |
* Inicializa el cuadro de texto que contiene el elipsoide
|
469 |
* @return
|
470 |
*/
|
471 |
public JTextField getTxtElipsoide() { |
472 |
if (txtElipsoide==null){ |
473 |
txtElipsoide=new JTextField(); |
474 |
bigSize.height=txtElipsoide.getPreferredSize().height; |
475 |
txtElipsoide.setPreferredSize(bigSize); |
476 |
txtElipsoide.addActionListener(this);
|
477 |
} |
478 |
return txtElipsoide;
|
479 |
} |
480 |
/**
|
481 |
* Inicializa el cuadro de texto que contiene el Inverse Flat del Elipsoide
|
482 |
* @return
|
483 |
*/
|
484 |
public JTextField getTxtInvF() { |
485 |
if (txtInvF==null){ |
486 |
txtInvF=new JTextField(); |
487 |
smallSize.height=txtInvF.getPreferredSize().height; |
488 |
txtInvF.setPreferredSize(smallSize); |
489 |
txtInvF.addActionListener(this);
|
490 |
} |
491 |
return txtInvF;
|
492 |
} |
493 |
/**
|
494 |
* Inicializa el cuadro de texto que contiene el dato de longitud del
|
495 |
* meridiano
|
496 |
* @return
|
497 |
*/
|
498 |
public JTextField getTxtLong() { |
499 |
if (txtLong==null){ |
500 |
txtLong=new JTextField(); |
501 |
smallSize.height=txtLong.getPreferredSize().height; |
502 |
txtLong.setPreferredSize(smallSize); |
503 |
txtLong.addActionListener(this);
|
504 |
} |
505 |
return txtLong;
|
506 |
} |
507 |
/**
|
508 |
* Inicializa el cuadro de texto que contiene el meridiano
|
509 |
* @return
|
510 |
*/
|
511 |
public JTextField getTxtMeridian() { |
512 |
if (txtMeridian==null){ |
513 |
txtMeridian=new JTextField(); |
514 |
bigSize.height=txtMeridian.getPreferredSize().height; |
515 |
txtMeridian.setPreferredSize(bigSize); |
516 |
txtMeridian.addActionListener(this);
|
517 |
} |
518 |
return txtMeridian;
|
519 |
} |
520 |
/**
|
521 |
* Inicializa el cuadro de texto que contiene el Semieje Mayor
|
522 |
* del elipsoide
|
523 |
* @return
|
524 |
*/
|
525 |
public JTextField getTxtSemMay() { |
526 |
if (txtSemMay==null){ |
527 |
txtSemMay=new JTextField(); |
528 |
smallSize.height=txtSemMay.getPreferredSize().height; |
529 |
txtSemMay.setPreferredSize(smallSize); |
530 |
txtSemMay.addActionListener(this);
|
531 |
} |
532 |
return txtSemMay;
|
533 |
} |
534 |
/**
|
535 |
* Inicializa el cuadro de texto que contiene el semieje
|
536 |
* menor del elipsoide
|
537 |
* @return
|
538 |
*/
|
539 |
public JTextField getTxtSemMen() { |
540 |
if (txtSemMen==null){ |
541 |
txtSemMen=new JTextField(); |
542 |
smallSize.height=txtSemMen.getPreferredSize().height; |
543 |
txtSemMen.setPreferredSize(smallSize); |
544 |
txtSemMen.addActionListener(this);
|
545 |
} |
546 |
return txtSemMen;
|
547 |
} |
548 |
/*
|
549 |
* Manejador de eventos de los controles
|
550 |
*/
|
551 |
public void actionPerformed(ActionEvent e) { |
552 |
|
553 |
if(e.getSource().equals(getTxtDatum())){
|
554 |
System.out.println("txt Datum"); |
555 |
}else if(e.getSource().equals(getTxtElipsoide())){ |
556 |
System.out.println("txt Elipsoide"); |
557 |
}else if(e.getSource().equals(getTxtInvF())){ |
558 |
System.out.println("txt Inverse Flat"); |
559 |
}else if(e.getSource().equals(getTxtSemMay())){ |
560 |
System.out.println("txt Semieje Mayor"); |
561 |
}else if(e.getSource().equals(getTxtSemMen())){ |
562 |
System.out.println("txt Semieje Menor"); |
563 |
}else if(e.getSource().equals(getTxtLong())){ |
564 |
System.out.println("txt Longitud"); |
565 |
}else if(e.getSource().equals(getTxtMeridian())){ |
566 |
System.out.println("txt Meridiano"); |
567 |
}else if(e.getSource().equals(getCbInvF())){ |
568 |
System.out.println("combo box Inverse Flat"); |
569 |
}else if(e.getSource().equals(getCbLong())){ |
570 |
System.out.println("combo box Longitud"); |
571 |
}else if(e.getSource().equals(getCbSemMay())){ |
572 |
System.out.println("combo box Semieje Mayor"); |
573 |
}else if(e.getSource().equals(getCbSemMen())){ |
574 |
System.out.println("combo box Semieje Menor"); |
575 |
}else if(e.getSource().equals(getBtnImportDatum())){ |
576 |
System.out.println("Importar Datum"); |
577 |
ImportNewCrsDialog newCrs = new ImportNewCrsDialog("datum"); |
578 |
PluginServices.getMDIManager().addWindow(newCrs); |
579 |
if (newCrs.getCode() != -1) { |
580 |
setCrs(newCrs.getCode()); |
581 |
fillData(getCrs()); |
582 |
} |
583 |
}else if(e.getSource().equals(getBtnImportElipsoide())){ |
584 |
System.out.println("Importar Elipsoide"); |
585 |
ImportNewCrsDialog newCrs = new ImportNewCrsDialog("ellips"); |
586 |
PluginServices.getMDIManager().addWindow(newCrs); |
587 |
if (newCrs.getCode() != -1) { |
588 |
setCrs(newCrs.getCode()); |
589 |
fillEllipsoid(getCrs()); |
590 |
} |
591 |
}else if(e.getSource().equals(getBtnImportMeridian())){ |
592 |
System.out.println("Importar Meridiano"); |
593 |
ImportNewCrsDialog newCrs = new ImportNewCrsDialog("primem"); |
594 |
PluginServices.getMDIManager().addWindow(newCrs); |
595 |
if (newCrs.getCode() != -1) { |
596 |
setCrs(newCrs.getCode()); |
597 |
fillPrimeMeridian(getCrs()); |
598 |
} |
599 |
}else if(e.getSource().equals(getRbInvF())){ |
600 |
System.out.println("opcion Inverse Flat"); |
601 |
/*Si selecciona esta opcin se fija este
|
602 |
parmetro y no se puede modificar el txt*/
|
603 |
getTxtSemMay().setEditable(true);
|
604 |
getTxtSemMen().setEditable(true);
|
605 |
getTxtInvF().setEditable(false);
|
606 |
|
607 |
}else if(e.getSource().equals(getRbSemMay())){ |
608 |
System.out.println("opcion Semieje Mayor"); |
609 |
/*Si selecciona esta opcin se fija este
|
610 |
parmetro y no se puede modificar el txt*/
|
611 |
getTxtSemMay().setEditable(false);
|
612 |
getTxtSemMen().setEditable(true);
|
613 |
getTxtInvF().setEditable(true);
|
614 |
}else if(e.getSource().equals(getRbSemMen())){ |
615 |
System.out.println("opcion Semieje Menor"); |
616 |
/*Si selecciona esta opcin se fija este
|
617 |
parmetro y no se puede modificar el txt*/
|
618 |
getTxtSemMay().setEditable(true);
|
619 |
getTxtSemMen().setEditable(false);
|
620 |
getTxtInvF().setEditable(true);
|
621 |
} |
622 |
|
623 |
} |
624 |
|
625 |
public void fillData(ICrs crs){ |
626 |
getTxtDatum().setText(crs.getCrsWkt().getDatumName()); |
627 |
fillEllipsoid(crs); |
628 |
fillPrimeMeridian(crs); |
629 |
} |
630 |
|
631 |
public void fillEllipsoid(ICrs crs) { |
632 |
getTxtElipsoide().setText(crs.getCrsWkt().getSpheroid()[0]);
|
633 |
String semMay = crs.getCrsWkt().getSpheroid()[1]; |
634 |
String invF = crs.getCrsWkt().getSpheroid()[2]; |
635 |
getTxtSemMay().setText(semMay); |
636 |
getTxtInvF().setText(invF); |
637 |
double semMen = calcularSemMen(Double.parseDouble(semMay), Double.parseDouble(invF)); |
638 |
getTxtSemMen().setText(String.valueOf(semMen));
|
639 |
} |
640 |
|
641 |
public void fillPrimeMeridian(ICrs crs) { |
642 |
getTxtMeridian().setText(crs.getCrsWkt().getPrimen()[0]);
|
643 |
getTxtLong().setText(crs.getCrsWkt().getPrimen()[1]);
|
644 |
} |
645 |
|
646 |
|
647 |
private double calcularSemMen(double semMay, double invF) { |
648 |
if (invF != 0) |
649 |
return (semMay) / (invF);
|
650 |
return 0; |
651 |
} |
652 |
|
653 |
public void setCrs(int code) { |
654 |
try {
|
655 |
crs = new CrsFactory().getCRS("EPSG:"+code); |
656 |
} catch (CrsException e) {
|
657 |
// TODO Auto-generated catch block
|
658 |
e.printStackTrace(); |
659 |
} |
660 |
|
661 |
} |
662 |
|
663 |
public ICrs getCrs() {
|
664 |
return crs;
|
665 |
} |
666 |
|
667 |
public void cleanData() { |
668 |
txtDatum.setText("");
|
669 |
txtElipsoide.setText("");
|
670 |
txtInvF.setText("");
|
671 |
txtLong.setText("");
|
672 |
txtMeridian.setText("");
|
673 |
txtSemMay.setText("");
|
674 |
txtSemMen.setText("");
|
675 |
} |
676 |
|
677 |
public double convert2Meters(String unit, double value) { |
678 |
double factor_b = 0; |
679 |
double factor_c = 0; |
680 |
String sentence = "SELECT factor_b, factor_c " + |
681 |
"FROM epsg_unitofmeasure " +
|
682 |
"WHERE unit_of_meas_name = '" +unit + "'"; |
683 |
EpsgConnection connect = new EpsgConnection();
|
684 |
connect.setConnectionEPSG(); |
685 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
686 |
try {
|
687 |
result.next(); |
688 |
factor_b = result.getDouble("factor_b");
|
689 |
factor_c = result.getDouble("factor_c");
|
690 |
} catch (SQLException e) { |
691 |
// TODO Auto-generated catch block
|
692 |
e.printStackTrace(); |
693 |
} |
694 |
return ((value*factor_b)/factor_c);
|
695 |
} |
696 |
|
697 |
public void itemStateChanged(ItemEvent e) { |
698 |
if (e.getItemSelectable().equals(getCbLong()) ) {
|
699 |
double value = Double.valueOf(getTxtLong().getText()).doubleValue(); |
700 |
value = convertFromMeters(sourceUnitLong, (String)e.getItem(), value);
|
701 |
sourceUnitLong = (String)e.getItem();
|
702 |
String val = String.valueOf(value); |
703 |
getTxtLong().setText(val); |
704 |
} |
705 |
if (e.getItemSelectable().equals(getCbSemMay()) ) {
|
706 |
double value = Double.valueOf(getTxtSemMay().getText()).doubleValue(); |
707 |
value = convertFromMeters(sourceUnitSemMay, (String)e.getItem(), value);
|
708 |
sourceUnitSemMay = (String)e.getItem();
|
709 |
String val = String.valueOf(value); |
710 |
getTxtSemMay().setText(val); |
711 |
} |
712 |
if (e.getItemSelectable().equals(getCbSemMen()) ) {
|
713 |
double value = Double.valueOf(getTxtSemMen().getText()).doubleValue(); |
714 |
value = convertFromMeters(sourceUnitSemMen, (String)e.getItem(), value);
|
715 |
sourceUnitSemMen = (String)e.getItem();
|
716 |
String val = String.valueOf(value); |
717 |
getTxtSemMen().setText(val); |
718 |
} |
719 |
} |
720 |
|
721 |
public double convertFromMeters(String unitSource, String unitTarget, double value) { |
722 |
double factor_b = 0; |
723 |
double factor_c = 0; |
724 |
String sentence = "SELECT factor_b, factor_c " + |
725 |
"FROM epsg_unitofmeasure " +
|
726 |
"WHERE unit_of_meas_name = '" +unitSource + "'"; |
727 |
EpsgConnection connect = new EpsgConnection();
|
728 |
connect.setConnectionEPSG(); |
729 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
730 |
try {
|
731 |
result.next(); |
732 |
factor_b = result.getDouble("factor_b");
|
733 |
factor_c = result.getDouble("factor_c");
|
734 |
} catch (SQLException e) { |
735 |
// TODO Auto-generated catch block
|
736 |
e.printStackTrace(); |
737 |
} |
738 |
value = ((value*factor_b)/factor_c); |
739 |
|
740 |
sentence = "SELECT factor_b, factor_c " +
|
741 |
"FROM epsg_unitofmeasure " +
|
742 |
"WHERE unit_of_meas_name = '" +unitTarget + "'"; |
743 |
connect = new EpsgConnection();
|
744 |
connect.setConnectionEPSG(); |
745 |
result = Query.select(sentence,connect.getConnection());
|
746 |
try {
|
747 |
result.next(); |
748 |
factor_b = result.getDouble("factor_b");
|
749 |
factor_c = result.getDouble("factor_c");
|
750 |
} catch (SQLException e) { |
751 |
// TODO Auto-generated catch block
|
752 |
e.printStackTrace(); |
753 |
} |
754 |
return ((value*factor_c)/factor_b);
|
755 |
} |
756 |
|
757 |
} |