root / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / wizard / DefinirDatum.java @ 12202
History | View | Annotate | Download (34.9 KB)
1 |
package org.gvsig.crs.gui.panels.wizard; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.FlowLayout; |
6 |
import java.awt.GridLayout; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.awt.event.ItemEvent; |
10 |
import java.awt.event.ItemListener; |
11 |
import java.awt.event.KeyEvent; |
12 |
import java.awt.event.KeyListener; |
13 |
import java.sql.ResultSet; |
14 |
import java.sql.SQLException; |
15 |
import java.util.ArrayList; |
16 |
|
17 |
import javax.swing.BorderFactory; |
18 |
import javax.swing.ButtonGroup; |
19 |
import javax.swing.JButton; |
20 |
import javax.swing.JLabel; |
21 |
import javax.swing.JOptionPane; |
22 |
import javax.swing.JPanel; |
23 |
import javax.swing.JRadioButton; |
24 |
import javax.swing.JTextField; |
25 |
import javax.units.ConversionException; |
26 |
import javax.units.Unit; |
27 |
|
28 |
import org.geotools.referencing.crs.AbstractSingleCRS; |
29 |
import org.geotools.referencing.datum.DefaultEllipsoid; |
30 |
import org.geotools.referencing.datum.DefaultGeodeticDatum; |
31 |
import org.geotools.referencing.datum.DefaultPrimeMeridian; |
32 |
import org.gvsig.crs.CrsException; |
33 |
import org.gvsig.crs.CrsFactory; |
34 |
import org.gvsig.crs.ICrs; |
35 |
import org.gvsig.crs.gui.dialog.ImportNewCrsDialog; |
36 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
37 |
|
38 |
import com.iver.andami.PluginServices; |
39 |
import com.iver.utiles.swing.JComboBox; |
40 |
|
41 |
import es.idr.teledeteccion.connection.EpsgConnection; |
42 |
import es.idr.teledeteccion.connection.Query; |
43 |
|
44 |
/**
|
45 |
* Panel de definicin del Datum
|
46 |
*
|
47 |
* @author Luisa Marina Fernandez Ruiz (luisam.fernandez@uclm.es)
|
48 |
* @author Jose Luis Gomez Martinez (joseluis.gomez@uclm.es)
|
49 |
*
|
50 |
*
|
51 |
*/
|
52 |
public class DefinirDatum extends JPanel implements ActionListener, ItemListener, KeyListener{ |
53 |
|
54 |
private JTextField txtDatum; |
55 |
private JTextField txtElipsoide; |
56 |
private JTextField txtSemMay; |
57 |
private JTextField txtSemMen; |
58 |
private JTextField txtInvF; |
59 |
private JTextField txtMeridian; |
60 |
private JTextField txtLong; |
61 |
private JTextField txtNombreCrs; |
62 |
private JTextField txtCodigoCrs; |
63 |
|
64 |
private JLabel lblDatum; |
65 |
private JLabel lblElipsoide; |
66 |
private JLabel lblMeridian; |
67 |
private JLabel lblLong; |
68 |
private JLabel lblNombreCrs; |
69 |
private JLabel lblCodigoCrs; |
70 |
private JLabel lblSemiejeMayor; |
71 |
private JLabel lblSemiejeMenor; |
72 |
private JLabel lblInverseFlat; |
73 |
private JLabel lblDefinir; |
74 |
|
75 |
|
76 |
private JButton btnImportDatum; |
77 |
private JButton btnImportElipsoide; |
78 |
private JButton btnImportMeridian; |
79 |
|
80 |
private JComboBox cbSemMay; |
81 |
private JComboBox cbSemMen; |
82 |
private JComboBox cbInvF; |
83 |
private JComboBox cbLong; |
84 |
|
85 |
private JRadioButton rbA_Inv; |
86 |
private JRadioButton rbA_B; |
87 |
private ButtonGroup groupRadioButton; |
88 |
|
89 |
private Dimension bigSize; |
90 |
private Dimension smallSize; |
91 |
private Dimension dimLabels; |
92 |
// private ImageIcon imodify;
|
93 |
|
94 |
private static final long serialVersionUID = 1L; |
95 |
ICrs crs = null;
|
96 |
|
97 |
private String sourceUnitLong = null; |
98 |
private String sourceUnitSemMay = null; |
99 |
private String sourceUnitSemMen = null; |
100 |
|
101 |
int divider=10000; |
102 |
|
103 |
/**
|
104 |
* Small tolerance factor for rounding errors.
|
105 |
*/
|
106 |
private static final double EPS = 1E-8; |
107 |
|
108 |
public DefinirDatum() {
|
109 |
|
110 |
super();
|
111 |
//imodify = new ImageIcon(DefinirDatum.class.getClassLoader().getResource("images/search.png"));
|
112 |
dimLabels=new Dimension(110,15); |
113 |
this.setLayout(new BorderLayout()); |
114 |
this.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); |
115 |
bigSize=new Dimension(); |
116 |
bigSize.width=350;
|
117 |
smallSize=new Dimension(); |
118 |
smallSize.width=130;
|
119 |
inicializarNuevo(); |
120 |
|
121 |
} |
122 |
private void inicializarNuevo(){ |
123 |
JPanel pMain=new JPanel(); |
124 |
JPanel pDatum=new JPanel(); |
125 |
JPanel pElipsoide=new JPanel(); |
126 |
JPanel pMeridian=new JPanel(); |
127 |
JPanel pNorthis=new JPanel(new FlowLayout(FlowLayout.LEFT,10,5)); |
128 |
pMain.setLayout(new BorderLayout()); |
129 |
|
130 |
pMain.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this,"Dat_nDatum"))); |
131 |
pElipsoide.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this,"Dat_nElipsoide"))); |
132 |
pMeridian.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this,"Dat_nMeridian"))); |
133 |
|
134 |
/*Panel que contiene los datos del Datum*/
|
135 |
pDatum.setLayout(new GridLayout(2,1)); |
136 |
JPanel pD1=new JPanel(new FlowLayout(FlowLayout.LEFT,10,0)); |
137 |
pD1.add(getLblDatum()); |
138 |
JPanel pD2=new JPanel(new FlowLayout(FlowLayout.LEFT,10,0)); |
139 |
pD2.add(getTxtDatum()); |
140 |
pD2.add(getBtnImportDatum()); |
141 |
pDatum.add(pD1); |
142 |
pDatum.add(pD2); |
143 |
|
144 |
/*Panel que contiene los datos del Elipsoide*/
|
145 |
pElipsoide.setLayout(new GridLayout(6,1)); |
146 |
//Crear y agregar los componentes a los subpaneles que componen el panel de definicin del elipsoide
|
147 |
JPanel pE1=new JPanel(new FlowLayout(FlowLayout.LEFT,10,2)); |
148 |
pE1.add(getLblElipsoide()); |
149 |
JPanel pE2=new JPanel(new FlowLayout(FlowLayout.LEFT,10,2)); |
150 |
pE2.add(getTxtElipsoide()); |
151 |
pE2.add(getBtnImportElipsoide()); |
152 |
JPanel pE3=new JPanel(new FlowLayout(FlowLayout.LEFT,10,2)); |
153 |
pE3.add(getLblDefinir()); |
154 |
pE3.add(getRbA_Inv()); |
155 |
pE3.add(getRbA_B()); |
156 |
JPanel pE4=new JPanel(new FlowLayout(FlowLayout.LEFT,10,2)); |
157 |
//Semieje mayor
|
158 |
pE4.add(getLblSemiejeMayor()); |
159 |
pE4.add(getTxtSemMay()); |
160 |
pE4.add(getCbSemMay()); |
161 |
JPanel pE5=new JPanel(new FlowLayout(FlowLayout.LEFT,10,2)); |
162 |
pE5.add(getLblInverseFlat()); |
163 |
pE5.add(getTxtInvF()); |
164 |
JPanel pE6=new JPanel(new FlowLayout(FlowLayout.LEFT,10,2)); |
165 |
//Semieje menor
|
166 |
pE6.add(getLblSemiejeMenor()); |
167 |
pE6.add(getTxtSemMen()); |
168 |
pE6.add(getCbSemMen()); |
169 |
|
170 |
//Agregar los subpaneles al panel del Elipsoide
|
171 |
pElipsoide.add(pE1); |
172 |
pElipsoide.add(pE2); |
173 |
pElipsoide.add(pE3); |
174 |
pElipsoide.add(pE4); |
175 |
pElipsoide.add(pE5); |
176 |
pElipsoide.add(pE6); |
177 |
//Agrupar los Radio Buttoms
|
178 |
agruparRadioButtons(); |
179 |
|
180 |
/*Panel que contiene los datos del Meridiano*/
|
181 |
pMeridian.setLayout(new GridLayout(2,1)); |
182 |
JPanel pM1=new JPanel(new FlowLayout(FlowLayout.LEFT,10,3)); |
183 |
pM1.add(getLblMeridian()); |
184 |
pM1.add(getTxtMeridian()); |
185 |
pM1.add(getBtnImportMeridian()); |
186 |
JPanel pM2=new JPanel(new FlowLayout(FlowLayout.LEFT,10,3)); |
187 |
pM2.add(getLblLong()); |
188 |
pM2.add(getTxtLong()); |
189 |
pM2.add(getCbLong()); |
190 |
pMeridian.add(pM1); |
191 |
pMeridian.add(pM2); |
192 |
pMain.add(pDatum,BorderLayout.NORTH);
|
193 |
pMain.add(pElipsoide,BorderLayout.CENTER);
|
194 |
pMain.add(pMeridian,BorderLayout.SOUTH);
|
195 |
this.add(pMain,BorderLayout.CENTER); |
196 |
//Agregar en norte-this el nombre y el cdigo
|
197 |
pNorthis.add(getLblNombreCrs()); |
198 |
pNorthis.add(getTxtNombreCrs()); |
199 |
pNorthis.add(getLblCodigoCrs()); |
200 |
pNorthis.add(getTxtCodigoCrs()); |
201 |
this.add(pNorthis,BorderLayout.NORTH); |
202 |
|
203 |
} |
204 |
/**
|
205 |
* Inicializa el botn Importar del datum
|
206 |
* @return
|
207 |
*/
|
208 |
public JButton getBtnImportDatum() { |
209 |
if(btnImportDatum==null){ |
210 |
btnImportDatum=new JButton(); |
211 |
btnImportDatum.setText("...");
|
212 |
//btnImportDatum.setIcon(imodify);
|
213 |
btnImportDatum.addActionListener(this);
|
214 |
} |
215 |
return btnImportDatum;
|
216 |
} |
217 |
/**
|
218 |
* Inicializa el botn Importar del Elipsoide
|
219 |
* @return
|
220 |
*/
|
221 |
public JButton getBtnImportElipsoide() { |
222 |
if(btnImportElipsoide==null){ |
223 |
btnImportElipsoide=new JButton(); |
224 |
btnImportElipsoide.setText("...");
|
225 |
//btnImportElipsoide.setIcon(imodify);
|
226 |
btnImportElipsoide.addActionListener(this);
|
227 |
} |
228 |
return btnImportElipsoide;
|
229 |
} |
230 |
/**
|
231 |
* Inicializa el botn Importar del Meridiano
|
232 |
* @return
|
233 |
*/
|
234 |
public JButton getBtnImportMeridian() { |
235 |
if(btnImportMeridian==null){ |
236 |
btnImportMeridian=new JButton(); |
237 |
btnImportMeridian.setText("...");
|
238 |
//btnImportMeridian.setIcon(imodify);
|
239 |
btnImportMeridian.addActionListener(this);
|
240 |
} |
241 |
return btnImportMeridian;
|
242 |
} |
243 |
/**
|
244 |
* Inicializa el Combo box con las unidades de Inverse Flat
|
245 |
* @return
|
246 |
*/
|
247 |
public JComboBox getCbInvF() { |
248 |
if (cbInvF==null){ |
249 |
ArrayList units = obtenerItemsUnidades();
|
250 |
String[] items = new String[units.size()]; |
251 |
for (int i=0;i<units.size();i++){ |
252 |
items[i] = units.get(i).toString(); |
253 |
} |
254 |
cbInvF=new JComboBox(items); |
255 |
/*Seleccionar un item por defecto*/
|
256 |
cbInvF.setSelectedIndex(0);
|
257 |
cbInvF.addItemListener(this);
|
258 |
} |
259 |
return cbInvF;
|
260 |
} |
261 |
/**
|
262 |
* Inicializa el Combo box con las unidades de Longitud
|
263 |
* @return
|
264 |
*/
|
265 |
public JComboBox getCbLong() { |
266 |
if (cbLong==null){ |
267 |
ArrayList units = obtenerItemsUnidadesAngle();
|
268 |
String[] items = new String[units.size()]; |
269 |
for (int i=0;i<units.size();i++){ |
270 |
items[i] = units.get(i).toString(); |
271 |
} |
272 |
cbLong=new JComboBox(items); |
273 |
cbLong.setPreferredSize(new Dimension(230, 25)); |
274 |
/*Seleccionar un item por defecto*/
|
275 |
cbLong.setSelectedIndex(1);
|
276 |
cbLong.addItemListener(this);
|
277 |
sourceUnitLong = (String)cbLong.getSelectedItem();
|
278 |
} |
279 |
return cbLong;
|
280 |
} |
281 |
/**
|
282 |
* Inicializa el Combo box con las unidades de Semieje Mayor
|
283 |
* @return
|
284 |
*/
|
285 |
public JComboBox getCbSemMay() { |
286 |
if (cbSemMay==null){ |
287 |
ArrayList units = obtenerItemsUnidades();
|
288 |
String[] items = new String[units.size()]; |
289 |
for (int i=0;i<units.size();i++){ |
290 |
items[i] = units.get(i).toString(); |
291 |
} |
292 |
cbSemMay=new JComboBox(items); |
293 |
/*Seleccionar un item por defecto*/
|
294 |
cbSemMay.setSelectedIndex(0);
|
295 |
cbSemMay.addItemListener(this);
|
296 |
sourceUnitSemMay = (String)cbSemMay.getSelectedItem();
|
297 |
} |
298 |
return cbSemMay;
|
299 |
} |
300 |
/**
|
301 |
* Inicializa el Combo box con las unidades de Semieje Menor
|
302 |
* @return
|
303 |
*/
|
304 |
public JComboBox getCbSemMen() { |
305 |
if (cbSemMen==null){ |
306 |
ArrayList units = obtenerItemsUnidades();
|
307 |
String[] items = new String[units.size()]; |
308 |
for (int i=0;i<units.size();i++){ |
309 |
items[i] = units.get(i).toString(); |
310 |
} |
311 |
cbSemMen=new JComboBox(items); |
312 |
/*Seleccionar un item por defecto*/
|
313 |
cbSemMen.setSelectedIndex(0);
|
314 |
cbSemMen.addItemListener(this);
|
315 |
sourceUnitSemMen = (String)cbSemMen.getSelectedItem();
|
316 |
} |
317 |
return cbSemMen;
|
318 |
} |
319 |
/*
|
320 |
* Accede al la base de datos y obtiene los items de
|
321 |
* los combobox
|
322 |
* @return
|
323 |
*/
|
324 |
private ArrayList obtenerItemsUnidades(){ //unidades de longitud... |
325 |
//TODO: Obtener los items del combo de la base de datos
|
326 |
ArrayList items = new ArrayList(); |
327 |
|
328 |
String sentence = "SELECT unit_of_meas_name " + |
329 |
"FROM epsg_unitofmeasure " +
|
330 |
"WHERE unit_of_meas_type = 'length'";
|
331 |
EpsgConnection connect = new EpsgConnection();
|
332 |
connect.setConnectionEPSG(); |
333 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
334 |
try {
|
335 |
while (result.next()) {
|
336 |
String item = result.getString("unit_of_meas_name"); |
337 |
items.add(PluginServices.getText(this, item));
|
338 |
} |
339 |
} catch (SQLException e) { |
340 |
// TODO Auto-generated catch block
|
341 |
e.printStackTrace(); |
342 |
} |
343 |
return items;
|
344 |
} |
345 |
|
346 |
/*
|
347 |
* Accede al la base de datos y obtiene los items de
|
348 |
* los combobox
|
349 |
* @return
|
350 |
*/
|
351 |
private ArrayList obtenerItemsUnidadesAngle(){ //unidades angulares... |
352 |
//TODO: Obtener los items del combo de la base de datos
|
353 |
ArrayList items = new ArrayList(); |
354 |
|
355 |
String sentence = "SELECT unit_of_meas_name " + |
356 |
"FROM epsg_unitofmeasure " +
|
357 |
"WHERE unit_of_meas_type = 'angle'";
|
358 |
EpsgConnection connect = new EpsgConnection();
|
359 |
connect.setConnectionEPSG(); |
360 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
361 |
try {
|
362 |
while (result.next()) {
|
363 |
String item = result.getString("unit_of_meas_name"); |
364 |
items.add(PluginServices.getText(this, item));
|
365 |
} |
366 |
} catch (SQLException e) { |
367 |
// TODO Auto-generated catch block
|
368 |
e.printStackTrace(); |
369 |
} |
370 |
return items;
|
371 |
} |
372 |
/**
|
373 |
* Inicializa el JLabel Datum
|
374 |
* @return
|
375 |
*/
|
376 |
public JLabel getLblDatum() { |
377 |
if (lblDatum==null){ |
378 |
lblDatum=new JLabel(); |
379 |
lblDatum.setText(PluginServices.getText(this,"Dat_Datum")); |
380 |
} |
381 |
return lblDatum;
|
382 |
} |
383 |
/**
|
384 |
* Inicializa el JLabel Elipsoide
|
385 |
* @return
|
386 |
*/
|
387 |
public JLabel getLblElipsoide() { |
388 |
if (lblElipsoide==null){ |
389 |
lblElipsoide=new JLabel(); |
390 |
lblElipsoide.setText(PluginServices.getText(this,"Dat_Elips")); |
391 |
//lblElipsoide.setText("Introduce el Elipsoide");
|
392 |
} |
393 |
return lblElipsoide;
|
394 |
} |
395 |
|
396 |
/**
|
397 |
* Inicializa el JLabel Longitud
|
398 |
* @return
|
399 |
*/
|
400 |
public JLabel getLblLong() { |
401 |
if (lblLong==null){ |
402 |
lblLong=new JLabel(); |
403 |
lblLong.setText(PluginServices.getText(this,"Dat_Long")); |
404 |
lblLong.setMinimumSize(dimLabels); |
405 |
lblLong.setPreferredSize(dimLabels); |
406 |
} |
407 |
return lblLong;
|
408 |
} |
409 |
/**
|
410 |
* Inicializa el JLabel Meridiano
|
411 |
* @return
|
412 |
*/
|
413 |
public JLabel getLblMeridian() { |
414 |
if (lblMeridian==null){ |
415 |
lblMeridian=new JLabel(); |
416 |
lblMeridian.setText(PluginServices.getText(this,"Dat_Meridian")); |
417 |
lblMeridian.setMinimumSize(dimLabels); |
418 |
lblMeridian.setPreferredSize(dimLabels); |
419 |
} |
420 |
return lblMeridian;
|
421 |
} |
422 |
/**
|
423 |
* Inicializa el JLabel del Cdigo de Crs
|
424 |
* @return
|
425 |
*/
|
426 |
public JLabel getLblCodigoCrs() { |
427 |
if (lblCodigoCrs==null){ |
428 |
lblCodigoCrs=new JLabel(PluginServices.getText(this,"Dat_CodeCrs")+":"); |
429 |
} |
430 |
return lblCodigoCrs;
|
431 |
} |
432 |
/**
|
433 |
* Inicializa el JLabel del Nombre del Crs
|
434 |
* @return
|
435 |
*/
|
436 |
public JLabel getLblNombreCrs() { |
437 |
if (lblNombreCrs==null){ |
438 |
lblNombreCrs=new JLabel(PluginServices.getText(this,"Dat_NombreCrs")+":"); |
439 |
} |
440 |
return lblNombreCrs;
|
441 |
} |
442 |
public JLabel getLblInverseFlat() { |
443 |
if(lblInverseFlat==null){ |
444 |
lblInverseFlat=new JLabel(); |
445 |
lblInverseFlat.setText(PluginServices.getText(this,"Dat_InvF")+(" (inv_f)")); |
446 |
lblInverseFlat.setMinimumSize(dimLabels); |
447 |
lblInverseFlat.setPreferredSize(dimLabels); |
448 |
} |
449 |
return lblInverseFlat;
|
450 |
} |
451 |
public JLabel getLblSemiejeMayor() { |
452 |
if(lblSemiejeMayor==null){ |
453 |
lblSemiejeMayor=new JLabel(); |
454 |
lblSemiejeMayor.setText(PluginServices.getText(this,"Dat_SemMay")+(" (a)")); |
455 |
lblSemiejeMayor.setMinimumSize(dimLabels); |
456 |
lblSemiejeMayor.setPreferredSize(dimLabels); |
457 |
|
458 |
} |
459 |
return lblSemiejeMayor;
|
460 |
} |
461 |
public JLabel getLblSemiejeMenor() { |
462 |
if(lblSemiejeMenor==null){ |
463 |
lblSemiejeMenor=new JLabel(); |
464 |
lblSemiejeMenor.setText(PluginServices.getText(this,"Dat_SemMen")+(" (b)")); |
465 |
lblSemiejeMenor.setMinimumSize(dimLabels); |
466 |
lblSemiejeMenor.setPreferredSize(dimLabels); |
467 |
} |
468 |
return lblSemiejeMenor;
|
469 |
} |
470 |
public JLabel getLblDefinir() { |
471 |
if(lblDefinir==null){ |
472 |
lblDefinir=new JLabel(); |
473 |
lblDefinir.setText(PluginServices.getText(this,"Dat_DefinirPor")); |
474 |
Dimension d=new Dimension(200,15); |
475 |
lblDefinir.setMinimumSize(d); |
476 |
lblDefinir.setPreferredSize(d); |
477 |
} |
478 |
return lblDefinir;
|
479 |
} |
480 |
|
481 |
|
482 |
public JRadioButton getRbA_B() { |
483 |
if(rbA_B==null){ |
484 |
rbA_B=new JRadioButton(); |
485 |
rbA_B.setText("a, b");
|
486 |
rbA_B.addActionListener(this);
|
487 |
} |
488 |
return rbA_B;
|
489 |
} |
490 |
public JRadioButton getRbA_Inv() { |
491 |
if(rbA_Inv==null){ |
492 |
rbA_Inv=new JRadioButton(); |
493 |
rbA_Inv.setText("a, inv_f");
|
494 |
Dimension d=new Dimension(100,15); |
495 |
rbA_Inv.setMinimumSize(d); |
496 |
rbA_Inv.setPreferredSize(d); |
497 |
rbA_Inv.addActionListener(this);
|
498 |
} |
499 |
return rbA_Inv;
|
500 |
} |
501 |
|
502 |
/*
|
503 |
public JRadioButton getRbInvF() {
|
504 |
if(rbInvF==null){
|
505 |
rbInvF=new JRadioButton();
|
506 |
rbInvF.setToolTipText(PluginServices.getText(this,"Dat_InvFToolTipText"));
|
507 |
rbInvF.setText(PluginServices.getText(this,"Dat_InvF"));
|
508 |
rbInvF.addActionListener(this);
|
509 |
}
|
510 |
return rbInvF;
|
511 |
}
|
512 |
*/
|
513 |
/**
|
514 |
* Inicializa el radio button Semieje Mayor del elipsoide
|
515 |
* @return
|
516 |
*/
|
517 |
/*
|
518 |
public JRadioButton getRbSemMay() {
|
519 |
if(rbSemMay==null){
|
520 |
rbSemMay=new JRadioButton();
|
521 |
rbSemMay.setToolTipText(PluginServices.getText(this,"Dat_SemMayToolTipText"));
|
522 |
rbSemMay.setText(PluginServices.getText(this,"Dat_SemMay"));
|
523 |
rbSemMay.addActionListener(this);
|
524 |
}
|
525 |
return rbSemMay;
|
526 |
}*/
|
527 |
|
528 |
/**
|
529 |
* Inicializa el radio Button del Semieje Menor del elipsoide
|
530 |
* @return
|
531 |
*/
|
532 |
/*
|
533 |
public JRadioButton getRbSemMen() {
|
534 |
if(rbSemMen==null){
|
535 |
rbSemMen=new JRadioButton();
|
536 |
rbSemMen.setToolTipText(PluginServices.getText(this,"Dat_SemMenToolTipText"));
|
537 |
rbSemMen.setText(PluginServices.getText(this,"Dat_SemMen"));
|
538 |
rbSemMen.addActionListener(this);
|
539 |
}
|
540 |
return rbSemMen;
|
541 |
}
|
542 |
*/
|
543 |
|
544 |
/**
|
545 |
* Agrupa los Radio Button de los parmetros del elipsoide
|
546 |
*
|
547 |
*/
|
548 |
|
549 |
private void agruparRadioButtons() { |
550 |
if(groupRadioButton==null){ |
551 |
groupRadioButton=new ButtonGroup(); |
552 |
//Agrupar los radio Buttons
|
553 |
groupRadioButton.add(getRbA_B()); |
554 |
groupRadioButton.add(getRbA_Inv()); |
555 |
getRbA_Inv().setSelected(true);
|
556 |
getTxtSemMen().setEditable(false);
|
557 |
getCbSemMen().setEnabled(false);
|
558 |
|
559 |
} |
560 |
} |
561 |
|
562 |
/**
|
563 |
* Inicializa el cuadro de texto que contiene el datum
|
564 |
* @return
|
565 |
*/
|
566 |
public JTextField getTxtDatum() { |
567 |
if (txtDatum==null){ |
568 |
txtDatum=new JTextField(); |
569 |
bigSize.height=txtDatum.getPreferredSize().height; |
570 |
txtDatum.setPreferredSize(bigSize); |
571 |
txtDatum.addActionListener(this);
|
572 |
} |
573 |
return txtDatum;
|
574 |
} |
575 |
/**
|
576 |
* Inicializa el cuadro de texto que contiene el elipsoide
|
577 |
* @return
|
578 |
*/
|
579 |
public JTextField getTxtElipsoide() { |
580 |
if (txtElipsoide==null){ |
581 |
txtElipsoide=new JTextField(); |
582 |
bigSize.height=txtElipsoide.getPreferredSize().height; |
583 |
txtElipsoide.setPreferredSize(bigSize); |
584 |
txtElipsoide.addActionListener(this);
|
585 |
} |
586 |
return txtElipsoide;
|
587 |
} |
588 |
/**
|
589 |
* Inicializa el cuadro de texto que contiene el Inverse Flat del Elipsoide
|
590 |
* @return
|
591 |
*/
|
592 |
public JTextField getTxtInvF() { |
593 |
if (txtInvF==null){ |
594 |
txtInvF=new JTextField(); |
595 |
smallSize.height=txtInvF.getPreferredSize().height; |
596 |
txtInvF.setPreferredSize(smallSize); |
597 |
txtInvF.setMinimumSize(smallSize); |
598 |
txtInvF.addActionListener(this);
|
599 |
txtInvF.addKeyListener(this);
|
600 |
} |
601 |
return txtInvF;
|
602 |
} |
603 |
/**
|
604 |
* Inicializa el cuadro de texto que contiene el dato de longitud del
|
605 |
* meridiano
|
606 |
* @return
|
607 |
*/
|
608 |
public JTextField getTxtLong() { |
609 |
if (txtLong==null){ |
610 |
txtLong=new JTextField(); |
611 |
smallSize.height=txtLong.getPreferredSize().height; |
612 |
txtLong.setPreferredSize(smallSize); |
613 |
txtLong.addActionListener(this);
|
614 |
} |
615 |
return txtLong;
|
616 |
} |
617 |
/**
|
618 |
* Inicializa el cuadro de texto que contiene el meridiano
|
619 |
* @return
|
620 |
*/
|
621 |
public JTextField getTxtMeridian() { |
622 |
if (txtMeridian==null){ |
623 |
txtMeridian=new JTextField(); |
624 |
bigSize.height=txtMeridian.getPreferredSize().height; |
625 |
Dimension d=new Dimension(280,15); |
626 |
d.height=txtMeridian.getPreferredSize().height; |
627 |
txtMeridian.setPreferredSize(d); |
628 |
txtMeridian.addActionListener(this);
|
629 |
} |
630 |
return txtMeridian;
|
631 |
} |
632 |
/**
|
633 |
* Inicializa el cuadro de texto que contiene el Semieje Mayor
|
634 |
* del elipsoide
|
635 |
* @return
|
636 |
*/
|
637 |
public JTextField getTxtSemMay() { |
638 |
if (txtSemMay==null){ |
639 |
txtSemMay=new JTextField(); |
640 |
smallSize.height=txtSemMay.getPreferredSize().height; |
641 |
txtSemMay.setPreferredSize(smallSize); |
642 |
txtSemMay.setMinimumSize(smallSize); |
643 |
txtSemMay.addActionListener(this);
|
644 |
txtSemMay.addKeyListener(this);
|
645 |
} |
646 |
return txtSemMay;
|
647 |
} |
648 |
/**
|
649 |
* Inicializa el cuadro de texto que contiene el semieje
|
650 |
* menor del elipsoide
|
651 |
* @return
|
652 |
*/
|
653 |
public JTextField getTxtSemMen() { |
654 |
if (txtSemMen==null){ |
655 |
txtSemMen=new JTextField(); |
656 |
smallSize.height=txtSemMen.getPreferredSize().height; |
657 |
txtSemMen.setPreferredSize(smallSize); |
658 |
txtSemMen.setMinimumSize(smallSize); |
659 |
txtSemMen.addActionListener(this);
|
660 |
txtSemMen.addKeyListener(this);
|
661 |
} |
662 |
return txtSemMen;
|
663 |
} |
664 |
/**
|
665 |
* Inicializa el cuadro de texto que contiene el cdigo del Crs definido por el usuario
|
666 |
* @return
|
667 |
*/
|
668 |
public JTextField getTxtCodigoCrs() { |
669 |
if (txtCodigoCrs==null){ |
670 |
txtCodigoCrs=new JTextField(); |
671 |
smallSize.height=txtCodigoCrs.getPreferredSize().height; |
672 |
txtCodigoCrs.setPreferredSize(smallSize); |
673 |
txtCodigoCrs.addActionListener(this);
|
674 |
} |
675 |
return txtCodigoCrs;
|
676 |
} |
677 |
/**
|
678 |
* Inicializa el cuadro de texto que contiene el nombre del Crs
|
679 |
* @return
|
680 |
*/
|
681 |
public JTextField getTxtNombreCrs() { |
682 |
if (txtNombreCrs==null){ |
683 |
txtNombreCrs=new JTextField(); |
684 |
smallSize.height=txtNombreCrs.getPreferredSize().height; |
685 |
txtNombreCrs.setPreferredSize(smallSize); |
686 |
txtNombreCrs.addActionListener(this);
|
687 |
} |
688 |
return txtNombreCrs;
|
689 |
} |
690 |
/*
|
691 |
* Manejador de eventos de los controles
|
692 |
*/
|
693 |
public void actionPerformed(ActionEvent e) { |
694 |
|
695 |
if(e.getSource().equals(getTxtDatum())){
|
696 |
System.out.println("txt Datum"); |
697 |
}else if(e.getSource().equals(getTxtElipsoide())){ |
698 |
System.out.println("txt Elipsoide"); |
699 |
}else if(e.getSource().equals(getTxtInvF())){ |
700 |
System.out.println("txt Inverse Flat"); |
701 |
}else if(e.getSource().equals(getTxtSemMay())){ |
702 |
System.out.println("txt Semieje Mayor"); |
703 |
}else if(e.getSource().equals(getTxtSemMen())){ |
704 |
System.out.println("txt Semieje Menor"); |
705 |
}else if(e.getSource().equals(getTxtLong())){ |
706 |
System.out.println("txt Longitud"); |
707 |
}else if(e.getSource().equals(getTxtMeridian())){ |
708 |
System.out.println("txt Meridiano"); |
709 |
}else if(e.getSource().equals(getCbInvF())){ |
710 |
System.out.println("combo box Inverse Flat"); |
711 |
}else if(e.getSource().equals(getCbLong())){ |
712 |
System.out.println("combo box Longitud"); |
713 |
}else if(e.getSource().equals(getCbSemMay())){ |
714 |
System.out.println("combo box Semieje Mayor"); |
715 |
}else if(e.getSource().equals(getCbSemMen())){ |
716 |
System.out.println("combo box Semieje Menor"); |
717 |
}else if(e.getSource().equals(getRbA_B())){ |
718 |
System.out.println("radio button a,b"); |
719 |
getTxtSemMay().setEditable(true);
|
720 |
getTxtSemMen().setEditable(true);
|
721 |
getTxtInvF().setEditable(false);
|
722 |
getCbSemMen().setEnabled(true);
|
723 |
}else if(e.getSource().equals(getRbA_Inv())){ |
724 |
System.out.println("radio button a,inv_f"); |
725 |
getTxtSemMay().setEditable(true);
|
726 |
getTxtSemMen().setEditable(false);
|
727 |
getTxtInvF().setEditable(true);
|
728 |
getCbSemMen().setEnabled(false);
|
729 |
}else if(e.getSource().equals(getBtnImportDatum())){ |
730 |
System.out.println("Importar Datum"); |
731 |
ImportNewCrsDialog newCrs = new ImportNewCrsDialog(PluginServices.getText(this, "datum")); |
732 |
PluginServices.getMDIManager().addWindow(newCrs); |
733 |
if (newCrs.getCode() != -1) { |
734 |
setCrs(newCrs.getCode()); |
735 |
fillDatum(getCrs()); |
736 |
} |
737 |
}else if(e.getSource().equals(getBtnImportElipsoide())){ |
738 |
System.out.println("Importar Elipsoide"); |
739 |
ImportNewCrsDialog newCrs = new ImportNewCrsDialog(PluginServices.getText(this, "ellips")); |
740 |
PluginServices.getMDIManager().addWindow(newCrs); |
741 |
if (newCrs.getCode() != -1) { |
742 |
setCrs(newCrs.getCode()); |
743 |
fillEllipsoid(getCrs()); |
744 |
} |
745 |
}else if(e.getSource().equals(getBtnImportMeridian())){ |
746 |
System.out.println("Importar Meridiano"); |
747 |
ImportNewCrsDialog newCrs = new ImportNewCrsDialog(PluginServices.getText(this, "primem")); |
748 |
PluginServices.getMDIManager().addWindow(newCrs); |
749 |
if (newCrs.getCode() != -1) { |
750 |
setCrs(newCrs.getCode()); |
751 |
fillPrimeMeridian(getCrs()); |
752 |
}else if(e.getSource().equals(getRbA_Inv())){ |
753 |
|
754 |
}else if(e.getSource().equals(getRbA_B())){ |
755 |
|
756 |
} |
757 |
} |
758 |
} |
759 |
|
760 |
public void fillData(ICrs crs){ |
761 |
getTxtNombreCrs().setText(crs.getCrsWkt().getGeogcs()); |
762 |
getTxtCodigoCrs().setText(crs.getCrsWkt().getAuthority()[1]);
|
763 |
fillDatum(crs); |
764 |
} |
765 |
|
766 |
public void fillDatum(ICrs crs) { |
767 |
getTxtDatum().setText(crs.getCrsWkt().getDatumName()); |
768 |
fillEllipsoid(crs); |
769 |
fillPrimeMeridian(crs); |
770 |
} |
771 |
|
772 |
public void fillData(CoordinateReferenceSystem crsGT) { |
773 |
AbstractSingleCRS crs = (AbstractSingleCRS)crsGT; |
774 |
String authority = crs.getName().toString().split(":")[0]; |
775 |
//String code = crs.getName().toString().split(":")[1];
|
776 |
getTxtNombreCrs().setText(authority); |
777 |
getTxtCodigoCrs().setText(getMaxCode()); |
778 |
DefaultGeodeticDatum d = (DefaultGeodeticDatum) crs.getDatum(); |
779 |
String[] val = d.getName().toString().split(":"); |
780 |
if (val.length<2) |
781 |
getTxtDatum().setText(d.getName().toString().split(":")[0]); |
782 |
else
|
783 |
getTxtDatum().setText(d.getName().toString().split(":")[1]); |
784 |
DefaultEllipsoid ellips = (DefaultEllipsoid)d.getEllipsoid(); |
785 |
|
786 |
Unit u = ellips.getAxisUnit(); |
787 |
double semi_major = convert(ellips.getSemiMajorAxis(), u.toString());
|
788 |
double inv_f = ellips.getInverseFlattening();
|
789 |
val = ellips.getName().toString().split(":");
|
790 |
if (val.length<2) |
791 |
getTxtElipsoide().setText(val[0]);
|
792 |
else
|
793 |
getTxtElipsoide().setText(val[1]);
|
794 |
getTxtSemMay().setText(String.valueOf(semi_major));
|
795 |
getTxtInvF().setText(String.valueOf(inv_f));
|
796 |
getTxtSemMen().setText(String.valueOf(calcularSemMen()));
|
797 |
|
798 |
DefaultPrimeMeridian primem = (DefaultPrimeMeridian)d.getPrimeMeridian(); |
799 |
|
800 |
u = primem.getAngularUnit(); |
801 |
double longitude = convert(primem.getGreenwichLongitude(), u.toString());
|
802 |
val = primem.getName().toString().split(":");
|
803 |
if (val.length<2) |
804 |
getTxtMeridian().setText(val[0]);
|
805 |
else
|
806 |
getTxtMeridian().setText(val[1]);
|
807 |
|
808 |
getTxtLong().setText(""+longitude);
|
809 |
} |
810 |
|
811 |
public void fillEllipsoid(ICrs crs) { |
812 |
getTxtElipsoide().setText(crs.getCrsWkt().getSpheroid()[0]);
|
813 |
String semMay = crs.getCrsWkt().getSpheroid()[1]; |
814 |
String invF = crs.getCrsWkt().getSpheroid()[2]; |
815 |
getTxtSemMay().setText(semMay); |
816 |
getTxtInvF().setText(invF); |
817 |
double semMen = calcularSemMen();
|
818 |
getTxtSemMen().setText(String.valueOf(semMen));
|
819 |
} |
820 |
|
821 |
public void fillPrimeMeridian(ICrs crs) { |
822 |
getTxtMeridian().setText(crs.getCrsWkt().getPrimen()[0]);
|
823 |
getTxtLong().setText(crs.getCrsWkt().getPrimen()[1]);
|
824 |
} |
825 |
|
826 |
|
827 |
private double calcularSemMen() { |
828 |
String cadenaNumerica = getTxtSemMay().getText().replaceAll("[^0-9.E]", ""); |
829 |
|
830 |
if (getTxtSemMay().getText().length() != cadenaNumerica.length() || notANumber(cadenaNumerica)) {
|
831 |
JOptionPane.showMessageDialog(DefinirDatum.this,
|
832 |
PluginServices.getText(this,"numeric_format")+": Semieje Mayor", |
833 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
834 |
return 0; |
835 |
} |
836 |
else {
|
837 |
cadenaNumerica = getTxtInvF().getText().replaceAll("[^0-9.E-]", ""); |
838 |
|
839 |
if (getTxtInvF().getText().length() != cadenaNumerica.length() || notANumber(cadenaNumerica)) {
|
840 |
|
841 |
JOptionPane.showMessageDialog(DefinirDatum.this,
|
842 |
PluginServices.getText(this,"numeric_format"+": Inverse Flattening"), |
843 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
844 |
return 0; |
845 |
} |
846 |
} |
847 |
|
848 |
double semMay = Double.parseDouble((String)getTxtSemMay().getText()); |
849 |
double invF = Double.parseDouble((String)getTxtInvF().getText()); |
850 |
|
851 |
if (invF != 0) |
852 |
return semMay - (semMay / (invF));
|
853 |
return 0; |
854 |
} |
855 |
|
856 |
private double calcularInvF() { |
857 |
String cadenaNumerica = getTxtSemMay().getText().replaceAll("[^0-9.E]", ""); |
858 |
|
859 |
if (getTxtSemMay().getText().length() != cadenaNumerica.length() || notANumber(cadenaNumerica)) {
|
860 |
JOptionPane.showMessageDialog(DefinirDatum.this,
|
861 |
PluginServices.getText(this,"numeric_format")+": Semieje Mayor", |
862 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
863 |
return 0; |
864 |
} |
865 |
else {
|
866 |
cadenaNumerica = getTxtInvF().getText().replaceAll("[^0-9.E-]", ""); |
867 |
|
868 |
if (getTxtInvF().getText().length() != cadenaNumerica.length() || notANumber(cadenaNumerica)) {
|
869 |
|
870 |
JOptionPane.showMessageDialog(DefinirDatum.this,
|
871 |
PluginServices.getText(this,"numeric_format"+": Inverse Flattening"), |
872 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
873 |
return 0; |
874 |
} |
875 |
} |
876 |
|
877 |
double semMay = Double.parseDouble((String)getTxtSemMay().getText()); |
878 |
double semMen = Double.parseDouble((String)getTxtSemMen().getText()); |
879 |
|
880 |
|
881 |
if ((semMay - semMen) != 0) |
882 |
return (semMay ) / (semMay - semMen);
|
883 |
return 0; |
884 |
} |
885 |
|
886 |
public void setCrs(int code) { |
887 |
try {
|
888 |
crs = new CrsFactory().getCRS("EPSG:"+code); |
889 |
} catch (CrsException e) {
|
890 |
// TODO Auto-generated catch block
|
891 |
e.printStackTrace(); |
892 |
} |
893 |
|
894 |
} |
895 |
|
896 |
public ICrs getCrs() {
|
897 |
return crs;
|
898 |
} |
899 |
|
900 |
public void cleanData() { |
901 |
String max = getMaxCode();
|
902 |
getTxtCodigoCrs().setText(max); |
903 |
getTxtNombreCrs().setText("");
|
904 |
getTxtDatum().setText("");
|
905 |
getTxtElipsoide().setText("");
|
906 |
getTxtInvF().setText("");
|
907 |
getTxtLong().setText("");
|
908 |
getTxtMeridian().setText("");
|
909 |
getTxtSemMay().setText("");
|
910 |
getTxtSemMen().setText("");
|
911 |
} |
912 |
|
913 |
private String getMaxCode() { |
914 |
String sentence = "SELECT usr_code " + |
915 |
"FROM USR " +
|
916 |
"ORDER BY usr_code DESC";
|
917 |
EpsgConnection connect = new EpsgConnection();
|
918 |
connect.setConnectionUsr(); |
919 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
920 |
int max = 0; |
921 |
try {
|
922 |
result.next(); |
923 |
max = result.getInt("usr_code");
|
924 |
} catch (SQLException e) { |
925 |
// TODO Auto-generated catch block
|
926 |
e.printStackTrace(); |
927 |
} |
928 |
max++; |
929 |
return ""+max; |
930 |
} |
931 |
|
932 |
public double convert2Meters(String unit, double value) { |
933 |
double factor_b = 0; |
934 |
double factor_c = 0; |
935 |
String sentence = "SELECT factor_b, factor_c " + |
936 |
"FROM epsg_unitofmeasure " +
|
937 |
"WHERE unit_of_meas_name = '" +unit + "'"; |
938 |
EpsgConnection connect = new EpsgConnection();
|
939 |
connect.setConnectionEPSG(); |
940 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
941 |
try {
|
942 |
result.next(); |
943 |
factor_b = result.getDouble("factor_b");
|
944 |
factor_c = result.getDouble("factor_c");
|
945 |
} catch (SQLException e) { |
946 |
// TODO Auto-generated catch block
|
947 |
e.printStackTrace(); |
948 |
} |
949 |
return ((value*factor_b)/factor_c);
|
950 |
} |
951 |
|
952 |
public double convert2Degree(String unit, double value) { |
953 |
double factor_b = 0; |
954 |
double factor_c = 0; |
955 |
String sentence = "SELECT factor_b, factor_c " + |
956 |
"FROM epsg_unitofmeasure " +
|
957 |
"WHERE unit_of_meas_name = '" +unit + "'"; |
958 |
EpsgConnection connect = new EpsgConnection();
|
959 |
connect.setConnectionEPSG(); |
960 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
961 |
try {
|
962 |
result.next(); |
963 |
factor_b = result.getDouble("factor_b");
|
964 |
factor_c = result.getDouble("factor_c");
|
965 |
} catch (SQLException e) { |
966 |
// TODO Auto-generated catch block
|
967 |
e.printStackTrace(); |
968 |
} |
969 |
value = ((value*factor_b)/factor_c); |
970 |
return ((value * 180.0) / 200.0); |
971 |
} |
972 |
|
973 |
public double convert(double value, String measure) throws ConversionException { |
974 |
if (measure.equals("D.MS")) { |
975 |
value *= this.divider;
|
976 |
int deg,min;
|
977 |
deg = (int) (value/10000); value -= 10000*deg; |
978 |
min = (int) (value/ 100); value -= 100*min; |
979 |
if (min<=-60 || min>=60) { // Accepts NaN |
980 |
if (Math.abs(Math.abs(min) - 100) <= EPS) { |
981 |
if (min >= 0) deg++; else deg--; |
982 |
min = 0;
|
983 |
} else {
|
984 |
throw new ConversionException("Invalid minutes: "+min); |
985 |
} |
986 |
} |
987 |
if (value<=-60 || value>=60) { // Accepts NaN |
988 |
if (Math.abs(Math.abs(value) - 100) <= EPS) { |
989 |
if (value >= 0) min++; else min--; |
990 |
value = 0;
|
991 |
} else {
|
992 |
throw new ConversionException("Invalid secondes: "+value); |
993 |
} |
994 |
} |
995 |
value = ((value/60) + min)/60 + deg; |
996 |
return value;
|
997 |
} |
998 |
if (measure.equals("grad") || measure.equals("grade")) |
999 |
return ((value * 180.0) / 200.0); |
1000 |
if (measure.equals(""+(char)176)) |
1001 |
return value;
|
1002 |
if (measure.equals("DMS") ) |
1003 |
return value;
|
1004 |
if (measure.equals("m")) |
1005 |
return value;
|
1006 |
if (measure.equals("")) |
1007 |
return value;
|
1008 |
|
1009 |
throw new ConversionException("Conversion no contemplada: "+measure); |
1010 |
} |
1011 |
|
1012 |
public double convertFromDegree(String unitSource, String unitTarget, double value) { |
1013 |
double factor_b = 0; |
1014 |
double factor_c = 0; |
1015 |
String sentence = "SELECT factor_b, factor_c " + |
1016 |
"FROM epsg_unitofmeasure " +
|
1017 |
"WHERE unit_of_meas_name = '" +unitSource + "'"; |
1018 |
EpsgConnection connect = new EpsgConnection();
|
1019 |
connect.setConnectionEPSG(); |
1020 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
1021 |
try {
|
1022 |
result.next(); |
1023 |
factor_b = result.getDouble("factor_b");
|
1024 |
factor_c = result.getDouble("factor_c");
|
1025 |
} catch (SQLException e) { |
1026 |
// TODO Auto-generated catch block
|
1027 |
e.printStackTrace(); |
1028 |
} |
1029 |
value = ((value*factor_b)/factor_c); |
1030 |
|
1031 |
sentence = "SELECT factor_b, factor_c " +
|
1032 |
"FROM epsg_unitofmeasure " +
|
1033 |
"WHERE unit_of_meas_name = '" +unitTarget + "'"; |
1034 |
connect = new EpsgConnection();
|
1035 |
connect.setConnectionEPSG(); |
1036 |
result = Query.select(sentence,connect.getConnection());
|
1037 |
try {
|
1038 |
result.next(); |
1039 |
factor_b = result.getDouble("factor_b");
|
1040 |
factor_c = result.getDouble("factor_c");
|
1041 |
} catch (SQLException e) { |
1042 |
// TODO Auto-generated catch block
|
1043 |
e.printStackTrace(); |
1044 |
} |
1045 |
return ((value*factor_c)/factor_b);
|
1046 |
} |
1047 |
|
1048 |
public void itemStateChanged(ItemEvent e) { |
1049 |
if (e.getItemSelectable().equals(cbLong)) {
|
1050 |
double value = Double.valueOf(getTxtLong().getText()).doubleValue(); |
1051 |
value = convertFromDegree(sourceUnitLong, (String)e.getItem(), value);
|
1052 |
sourceUnitLong = (String)e.getItem();
|
1053 |
String val = String.valueOf(value); |
1054 |
getTxtLong().setText(val); |
1055 |
} |
1056 |
if (e.getItemSelectable().equals(cbSemMay) ) {
|
1057 |
double value = Double.valueOf(getTxtSemMay().getText()).doubleValue(); |
1058 |
value = convertFromMeters(sourceUnitSemMay, (String)e.getItem(), value);
|
1059 |
sourceUnitSemMay = (String)e.getItem();
|
1060 |
String val = String.valueOf(value); |
1061 |
getTxtSemMay().setText(val); |
1062 |
} |
1063 |
if (e.getItemSelectable().equals(cbSemMen) ) {
|
1064 |
double value = Double.valueOf(getTxtSemMen().getText()).doubleValue(); |
1065 |
value = convertFromMeters(sourceUnitSemMen, (String)e.getItem(), value);
|
1066 |
sourceUnitSemMen = (String)e.getItem();
|
1067 |
String val = String.valueOf(value); |
1068 |
getTxtSemMen().setText(val); |
1069 |
} |
1070 |
} |
1071 |
|
1072 |
private boolean notANumber(String cadenaNumerica) { |
1073 |
int puntos = 0; |
1074 |
int signos = 0; |
1075 |
int letras = 0; |
1076 |
for (int i = 0; i< cadenaNumerica.length(); i++) { |
1077 |
if (cadenaNumerica.charAt(i) == '.') |
1078 |
puntos++; |
1079 |
else if (cadenaNumerica.charAt(i) == '-') { |
1080 |
if (i==0) { |
1081 |
signos++; |
1082 |
} |
1083 |
else if (i!=0 && cadenaNumerica.charAt(i-1) != 'E') { |
1084 |
signos = 2;
|
1085 |
} |
1086 |
} |
1087 |
else if (cadenaNumerica.charAt(i) == 'E') { |
1088 |
if (i== 0) { |
1089 |
letras = 2;
|
1090 |
} |
1091 |
else letras ++;
|
1092 |
} |
1093 |
} |
1094 |
|
1095 |
if ((letras > 1) || (signos > 1) || (puntos > 1)) |
1096 |
return true; |
1097 |
return false; |
1098 |
} |
1099 |
|
1100 |
public double convertFromMeters(String unitSource, String unitTarget, double value) { |
1101 |
double factor_b = 0; |
1102 |
double factor_c = 0; |
1103 |
String sentence = "SELECT factor_b, factor_c " + |
1104 |
"FROM epsg_unitofmeasure " +
|
1105 |
"WHERE unit_of_meas_name = '" +unitSource + "'"; |
1106 |
EpsgConnection connect = new EpsgConnection();
|
1107 |
connect.setConnectionEPSG(); |
1108 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
1109 |
try {
|
1110 |
result.next(); |
1111 |
factor_b = result.getDouble("factor_b");
|
1112 |
factor_c = result.getDouble("factor_c");
|
1113 |
} catch (SQLException e) { |
1114 |
// TODO Auto-generated catch block
|
1115 |
e.printStackTrace(); |
1116 |
} |
1117 |
value = ((value*factor_b)/factor_c); |
1118 |
|
1119 |
sentence = "SELECT factor_b, factor_c " +
|
1120 |
"FROM epsg_unitofmeasure " +
|
1121 |
"WHERE unit_of_meas_name = '" +unitTarget + "'"; |
1122 |
connect = new EpsgConnection();
|
1123 |
connect.setConnectionEPSG(); |
1124 |
result = Query.select(sentence,connect.getConnection());
|
1125 |
try {
|
1126 |
result.next(); |
1127 |
factor_b = result.getDouble("factor_b");
|
1128 |
factor_c = result.getDouble("factor_c");
|
1129 |
} catch (SQLException e) { |
1130 |
// TODO Auto-generated catch block
|
1131 |
e.printStackTrace(); |
1132 |
} |
1133 |
return ((value*factor_c)/factor_b);
|
1134 |
} |
1135 |
|
1136 |
public void keyPressed(KeyEvent e) { |
1137 |
if (e.getSource() == this.getTxtSemMay()) { |
1138 |
String cadenaNumerica = getTxtSemMay().getText().replaceAll("[^0-9.E]", ""); |
1139 |
|
1140 |
if (getTxtSemMay().getText().length() != cadenaNumerica.length() || notANumber(cadenaNumerica)) {
|
1141 |
JOptionPane.showMessageDialog(DefinirDatum.this,
|
1142 |
PluginServices.getText(this,"numeric_format")+": Semieje Mayor", |
1143 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
1144 |
return;
|
1145 |
} |
1146 |
if (e.getKeyCode() == 10) { |
1147 |
if (getRbA_Inv().isSelected()) {
|
1148 |
getTxtSemMen().setText(String.valueOf(calcularSemMen()));
|
1149 |
} |
1150 |
else if (getRbA_B().isSelected()) { |
1151 |
getTxtInvF().setText(String.valueOf(calcularInvF()));
|
1152 |
} |
1153 |
} |
1154 |
} |
1155 |
if (e.getSource() == this.getTxtSemMen()) { |
1156 |
if (e.getKeyCode() == 10) { |
1157 |
getTxtInvF().setText(String.valueOf(calcularInvF()));
|
1158 |
} |
1159 |
} |
1160 |
if (e.getSource() == this.getTxtInvF()) { |
1161 |
if (e.getKeyCode() == 10) { |
1162 |
getTxtSemMen().setText(String.valueOf(calcularSemMen()));
|
1163 |
} |
1164 |
} |
1165 |
} |
1166 |
public void keyReleased(KeyEvent e) { |
1167 |
// TODO Auto-generated method stub
|
1168 |
|
1169 |
} |
1170 |
public void keyTyped(KeyEvent e) { |
1171 |
// TODO Auto-generated method stub
|
1172 |
|
1173 |
} |
1174 |
|
1175 |
} |