svn-gvsig-desktop / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / wizard / DefSistCoordenadas.java @ 11862
History | View | Annotate | Download (28.1 KB)
1 |
package org.gvsig.crs.gui.panels.wizard; |
---|---|
2 |
import java.awt.BorderLayout; |
3 |
import java.awt.CardLayout; |
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.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.DefaultCellEditor; |
18 |
import javax.swing.JButton; |
19 |
import javax.swing.JComboBox; |
20 |
import javax.swing.JLabel; |
21 |
import javax.swing.JPanel; |
22 |
import javax.swing.JRadioButton; |
23 |
import javax.swing.JScrollPane; |
24 |
import javax.swing.JTable; |
25 |
import javax.swing.JTextField; |
26 |
import javax.swing.border.TitledBorder; |
27 |
import javax.swing.table.DefaultTableCellRenderer; |
28 |
import javax.swing.table.DefaultTableModel; |
29 |
import javax.swing.table.TableColumn; |
30 |
import javax.units.ConversionException; |
31 |
import javax.units.Unit; |
32 |
|
33 |
import org.geotools.referencing.crs.DefaultProjectedCRS; |
34 |
import org.gvsig.crs.CrsException; |
35 |
import org.gvsig.crs.ICrs; |
36 |
import org.gvsig.crs.Proj4; |
37 |
import org.gvsig.crs.ogr.CrsEPSG; |
38 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
39 |
|
40 |
import sun.net.www.content.image.png; |
41 |
|
42 |
import com.iver.andami.PluginServices; |
43 |
|
44 |
import es.idr.teledeteccion.connection.EpsgConnection; |
45 |
import es.idr.teledeteccion.connection.Query; |
46 |
|
47 |
|
48 |
|
49 |
/**
|
50 |
* Panel de Definicion del Sistema de Coordenadas
|
51 |
*
|
52 |
* @author Luisa Marina Fernandez Ruiz (luisam.fernandez@uclm.es)
|
53 |
* @author Jose Luis Gomez Martinez (joseluis.gomez@uclm.es)
|
54 |
*
|
55 |
*/
|
56 |
public class DefSistCoordenadas extends JPanel implements ActionListener, ItemListener{ |
57 |
|
58 |
private static final long serialVersionUID = 1L; |
59 |
private JPanel top; |
60 |
private JPanel proyectadoPanel; |
61 |
private JPanel geograficoPanel; |
62 |
private JPanel cardPanel; |
63 |
private JRadioButton rbGeografico; |
64 |
private JRadioButton rbProyectado; |
65 |
private ButtonGroup coordGroup; |
66 |
|
67 |
private JLabel lblProyeccion; |
68 |
private JLabel lblNombreProy; |
69 |
private JTextField txtNombreProy; |
70 |
private JComboBox cbProyeccion; |
71 |
private JComboBox cbUnits; |
72 |
private JTable tableParametros; |
73 |
private JScrollPane scrollTable; |
74 |
|
75 |
private DefaultTableModel model = null; |
76 |
|
77 |
private int theigth=140; |
78 |
private int twidth=300; |
79 |
|
80 |
final static String PROYECTADOPANEL = "Proyectado"; |
81 |
final static String GEOGRAFICOPANEL = "Geografico"; |
82 |
private String sourceUnit = null; |
83 |
|
84 |
Proj4 proj4 = null;
|
85 |
private int pos; |
86 |
int divider=10000; |
87 |
|
88 |
/**
|
89 |
* Small tolerance factor for rounding errors.
|
90 |
*/
|
91 |
private static final double EPS = 1E-8; |
92 |
|
93 |
|
94 |
public DefSistCoordenadas() {
|
95 |
super();
|
96 |
BorderLayout bl=new BorderLayout(); |
97 |
try {
|
98 |
proj4 = new Proj4();
|
99 |
} catch (CrsException e) {
|
100 |
// TODO Auto-generated catch block
|
101 |
e.printStackTrace(); |
102 |
} |
103 |
bl.setVgap(5);
|
104 |
bl.setHgap(5);
|
105 |
this.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); |
106 |
this.setLayout(bl);
|
107 |
this.add(getTop(),BorderLayout.NORTH); |
108 |
cardPanel=new JPanel(); |
109 |
cardPanel.setLayout(new CardLayout()); |
110 |
//agregar los elementos correspondientes en el cardPanel
|
111 |
cardPanel.add(PROYECTADOPANEL,getProyectadoPanel()); |
112 |
cardPanel.add(GEOGRAFICOPANEL,getGeograficoPanel()); |
113 |
//agregar cardPanel en el this
|
114 |
this.add(cardPanel,BorderLayout.CENTER); |
115 |
|
116 |
} |
117 |
/**
|
118 |
* Inicializa el radio button Geogr�fico 2D
|
119 |
* @return
|
120 |
*/
|
121 |
public JRadioButton getRbGeografico() { |
122 |
if (rbGeografico==null){ |
123 |
rbGeografico=new JRadioButton(PluginServices.getText(this,"SistCoor_Geografico2D")); |
124 |
rbGeografico.addActionListener(this);
|
125 |
} |
126 |
return rbGeografico;
|
127 |
} |
128 |
/**
|
129 |
* Inicializa el radio button Proyectado
|
130 |
* @return
|
131 |
*/
|
132 |
public JRadioButton getRbProyectado() { |
133 |
if (rbProyectado==null){ |
134 |
rbProyectado=new JRadioButton(PluginServices.getText(this,"SistCoor_Proyactado")); |
135 |
rbProyectado.addActionListener(this);
|
136 |
} |
137 |
return rbProyectado;
|
138 |
} |
139 |
/**
|
140 |
* Inicializa el panel que contiene las opciones
|
141 |
* si el crs seleccionado es proyectado
|
142 |
*
|
143 |
*/
|
144 |
public JPanel getProyectadoPanel() { |
145 |
if(proyectadoPanel==null){ |
146 |
proyectadoPanel=new JPanel(new BorderLayout(5,5)); |
147 |
proyectadoPanel.setBorder(BorderFactory.createEmptyBorder(0,3,0,3)); |
148 |
//Tendra que alinearlo todo a la izquierda
|
149 |
JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT,3,5)); |
150 |
p1.add(getLblNombreProy()); |
151 |
p1.add(getTxtNombreProy()); |
152 |
JPanel p2=new JPanel(new FlowLayout(FlowLayout.RIGHT,3,5)); |
153 |
p2.add(getLblProyeccion()); |
154 |
p2.add(getCbProyeccion()); |
155 |
JPanel pNorth=new JPanel(new GridLayout(2,1)); |
156 |
pNorth.add(p1); |
157 |
pNorth.add(p2); |
158 |
proyectadoPanel.add(pNorth,BorderLayout.NORTH);
|
159 |
proyectadoPanel.add(getScrollTable(),BorderLayout.CENTER);
|
160 |
} |
161 |
return proyectadoPanel;
|
162 |
} |
163 |
/**
|
164 |
* Inicializa el panel superior donde se define el sistema
|
165 |
* de coordenadas
|
166 |
*
|
167 |
*/
|
168 |
public JPanel getTop() { |
169 |
if(top==null){ |
170 |
top=new JPanel(); |
171 |
top.add(getRbGeografico()); |
172 |
top.add(getRbProyectado()); |
173 |
//Agrupar las opciones
|
174 |
agruparRadioButtons(); |
175 |
top.setBorder(new TitledBorder(PluginServices.getText(this,"SistCoor_titmarco"))); |
176 |
} |
177 |
return top;
|
178 |
} |
179 |
/**
|
180 |
* Agrupa los radio button
|
181 |
*
|
182 |
*/
|
183 |
private void agruparRadioButtons() { |
184 |
if (coordGroup==null){ |
185 |
coordGroup=new ButtonGroup(); |
186 |
//Agrupar los botones de opcion
|
187 |
coordGroup.add(getRbProyectado()); |
188 |
coordGroup.add(getRbGeografico()); |
189 |
getRbProyectado().setSelected(true);
|
190 |
} |
191 |
} |
192 |
/**
|
193 |
* Inicializa el label Proyecci�n
|
194 |
* @return
|
195 |
*/
|
196 |
public JLabel getLblProyeccion() { |
197 |
if (lblProyeccion==null){ |
198 |
lblProyeccion=new JLabel(); |
199 |
lblProyeccion.setText(PluginServices.getText(this,"SistCoor_Proyeccion")); |
200 |
} |
201 |
return lblProyeccion;
|
202 |
} |
203 |
/**
|
204 |
* Crea la tabla donde se definen los par�metros de la
|
205 |
* proyecci�n seleccionada en el combobox
|
206 |
* @return
|
207 |
*/
|
208 |
public JTable getTableParametros() { |
209 |
|
210 |
if(tableParametros==null){ |
211 |
tableParametros = new JTable(); |
212 |
model = (DefaultTableModel)tableParametros.getModel();
|
213 |
//Crea la tabla con 7 filas
|
214 |
Object[][] data = { |
215 |
{"", "", "Metros"}, |
216 |
{"", "", "Metros"}, |
217 |
{"", "", "Metros"}, |
218 |
{"", "", "Metros"}, |
219 |
{"", "", "Metros"}, |
220 |
{"", "", "Metros"}, |
221 |
{"", "", "Metros"}}; |
222 |
|
223 |
String col1=PluginServices.getText(this,"SistCoor_Parametro"); |
224 |
String col2=PluginServices.getText(this,"SistCoor_Valor"); |
225 |
String col3=PluginServices.getText(this,"SistCoor_Unidades"); |
226 |
Object[] headers = {col1, col2, col3}; |
227 |
|
228 |
/*Agrega otra fila
|
229 |
model.addRow(new Object[]{"fila","","Metros"});*/
|
230 |
//TODO: Agregar los items "Unidades" al combo
|
231 |
//define los items del combo
|
232 |
ArrayList units = obtenerItemsUnidades();
|
233 |
String[] items = new String[units.size()]; |
234 |
for (int i=0;i<units.size();i++){ |
235 |
items[i] = units.get(i).toString(); |
236 |
} |
237 |
|
238 |
model = new DefaultTableModel(data, headers) { |
239 |
private static final long serialVersionUID = 1L; |
240 |
public boolean isCellEditable(int row, int column) { |
241 |
if (column == 0) |
242 |
return false; |
243 |
else return true; |
244 |
} |
245 |
}; |
246 |
tableParametros.setModel(model); |
247 |
//String[] items = new String[] { "Metros", "Grados", "Kilometros", "Decimetros", "Hect�metros" };
|
248 |
TableColumn col = tableParametros.getColumnModel().getColumn(2); |
249 |
|
250 |
//ComboBoxEditor editor = new ComboBoxEditor(items);
|
251 |
col.setCellEditor(new DefaultCellEditor(getCbUnits())); |
252 |
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); |
253 |
|
254 |
col.setCellRenderer(renderer); |
255 |
|
256 |
|
257 |
//Define el tama�o de la tabla
|
258 |
tableParametros.setPreferredScrollableViewportSize(new Dimension(twidth,theigth)); |
259 |
//la posicion de las columnas es fija
|
260 |
tableParametros.getTableHeader().setReorderingAllowed( false );
|
261 |
//Ajustar ancho y alto de las filas y columnas
|
262 |
ajustarTamanoTabla(); |
263 |
fillTable(cbProyeccion.getItemAt(0).toString());
|
264 |
} |
265 |
|
266 |
return tableParametros;
|
267 |
} |
268 |
|
269 |
/**
|
270 |
* Contiene los nombres de las distintas unidades
|
271 |
* @return
|
272 |
*/
|
273 |
public JComboBox getCbUnits() { |
274 |
if (cbUnits==null){ |
275 |
ArrayList units = obtenerItemsUnidades();
|
276 |
String[] items = new String[units.size()]; |
277 |
for (int i=0;i<units.size();i++){ |
278 |
items[i] = units.get(i).toString(); |
279 |
} |
280 |
cbUnits=new JComboBox(items); |
281 |
cbUnits.setEditable(false);
|
282 |
cbUnits.setToolTipText(PluginServices.getText(this,"SistCoor_cbToolTip")); |
283 |
sourceUnit = (String)cbUnits.getItemAt(0); |
284 |
cbUnits.addItemListener(this);
|
285 |
} |
286 |
return cbUnits;
|
287 |
} |
288 |
|
289 |
/**
|
290 |
* Accede al la base de datos y obtiene los items de
|
291 |
* los combobox
|
292 |
* @return
|
293 |
*/
|
294 |
private ArrayList obtenerItemsUnidades(){ //unidades de longitud... |
295 |
//TODO: Obtener los items del combo de la base de datos
|
296 |
ArrayList items = new ArrayList(); |
297 |
|
298 |
String sentence = "SELECT unit_of_meas_name " + |
299 |
"FROM epsg_unitofmeasure ";// + |
300 |
//"WHERE unit_of_meas_type = 'length'";
|
301 |
EpsgConnection connect = new EpsgConnection();
|
302 |
connect.setConnectionEPSG(); |
303 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
304 |
try {
|
305 |
while (result.next()) {
|
306 |
items.add(result.getString("unit_of_meas_name"));
|
307 |
} |
308 |
} catch (SQLException e) { |
309 |
// TODO Auto-generated catch block
|
310 |
e.printStackTrace(); |
311 |
} |
312 |
return items;
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* Accede al la base de datos y obtiene los items de
|
317 |
* los combobox
|
318 |
* @return
|
319 |
*/
|
320 |
private ArrayList obtenerItemsUnidadesAngular(){ //unidades angulares... |
321 |
//TODO: Obtener los items del combo de la base de datos
|
322 |
ArrayList items = new ArrayList(); |
323 |
|
324 |
String sentence = "SELECT unit_of_meas_name " + |
325 |
"FROM epsg_unitofmeasure " +
|
326 |
"WHERE unit_of_meas_type = 'angle'";
|
327 |
EpsgConnection connect = new EpsgConnection();
|
328 |
connect.setConnectionEPSG(); |
329 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
330 |
try {
|
331 |
while (result.next()) {
|
332 |
items.add(result.getString("unit_of_meas_name"));
|
333 |
} |
334 |
} catch (SQLException e) { |
335 |
// TODO Auto-generated catch block
|
336 |
e.printStackTrace(); |
337 |
} |
338 |
return items;
|
339 |
} |
340 |
|
341 |
/**
|
342 |
* Accede al la base de datos y obtiene los items de
|
343 |
* los combobox
|
344 |
* @return
|
345 |
*/
|
346 |
private ArrayList obtenerItemsUnidadesScale(){ //unidades angulares... |
347 |
//TODO: Obtener los items del combo de la base de datos
|
348 |
ArrayList items = new ArrayList(); |
349 |
|
350 |
String sentence = "SELECT unit_of_meas_name " + |
351 |
"FROM epsg_unitofmeasure " +
|
352 |
"WHERE unit_of_meas_type = 'scale'";
|
353 |
EpsgConnection connect = new EpsgConnection();
|
354 |
connect.setConnectionEPSG(); |
355 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
356 |
try {
|
357 |
while (result.next()) {
|
358 |
items.add(result.getString("unit_of_meas_name"));
|
359 |
} |
360 |
} catch (SQLException e) { |
361 |
// TODO Auto-generated catch block
|
362 |
e.printStackTrace(); |
363 |
} |
364 |
return items;
|
365 |
} |
366 |
|
367 |
/**
|
368 |
* Crear scrollPane y agregar la tabla en �l
|
369 |
*/
|
370 |
public JScrollPane getScrollTable() { |
371 |
if(scrollTable==null){ |
372 |
scrollTable = new JScrollPane(getTableParametros()); |
373 |
scrollTable.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
374 |
} |
375 |
return scrollTable;
|
376 |
} |
377 |
/**
|
378 |
* Contiene los nombres de las distintas proyecciones
|
379 |
* @return
|
380 |
*/
|
381 |
public JComboBox getCbProyeccion() { |
382 |
if (cbProyeccion==null){ |
383 |
ArrayList projections = obtainProjections();
|
384 |
String[] items = new String[projections.size()]; |
385 |
for (int i=0;i<projections.size();i++){ |
386 |
items[i] = projections.get(i).toString(); |
387 |
} |
388 |
cbProyeccion=new JComboBox(items); |
389 |
cbProyeccion.setEditable(false);
|
390 |
cbProyeccion.setToolTipText(PluginServices.getText(this,"SistCoor_cbToolTip")); |
391 |
cbProyeccion.addItemListener(this);
|
392 |
} |
393 |
return cbProyeccion;
|
394 |
} |
395 |
/**
|
396 |
* Inicializa el label que contiene el Nombre de la Proyeccin
|
397 |
* @return
|
398 |
*/
|
399 |
public JLabel getLblNombreProy() { |
400 |
if(lblNombreProy==null){ |
401 |
lblNombreProy=new JLabel(PluginServices.getText(this,"nombre_proyeccion")); |
402 |
} |
403 |
return lblNombreProy;
|
404 |
} |
405 |
/**
|
406 |
* Inicializa el cuadro de texto que contiene el nombre de la proyeccin
|
407 |
* @return
|
408 |
*/
|
409 |
public JTextField getTxtNombreProy() { |
410 |
if(txtNombreProy==null){ |
411 |
txtNombreProy=new JTextField(); |
412 |
Dimension d=new Dimension(340,20); |
413 |
txtNombreProy.setPreferredSize(d); |
414 |
txtNombreProy.setMinimumSize(d); |
415 |
} |
416 |
return txtNombreProy;
|
417 |
} |
418 |
private ArrayList obtainProjections() { |
419 |
ArrayList items = new ArrayList(); |
420 |
|
421 |
String sentence = "SELECT coord_op_method_name " + |
422 |
"FROM epsg_coordoperationmethod " +
|
423 |
"WHERE coord_op_method_code > 9800";
|
424 |
EpsgConnection connect = new EpsgConnection();
|
425 |
connect.setConnectionEPSG(); |
426 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
427 |
try {
|
428 |
while (result.next()) {
|
429 |
items.add(result.getString("coord_op_method_name"));
|
430 |
} |
431 |
} catch (SQLException e) { |
432 |
// TODO Auto-generated catch block
|
433 |
e.printStackTrace(); |
434 |
} |
435 |
return items;
|
436 |
} |
437 |
/*
|
438 |
* Redimensiona el tama�o de las filas y columnas de la tabla
|
439 |
*
|
440 |
*/
|
441 |
public void ajustarTamanoTabla(){ |
442 |
TableColumn column = null; |
443 |
//Fijar el alto de las filas
|
444 |
getTableParametros().setRowHeight(20);
|
445 |
//Fijar el ancho de las columnas
|
446 |
column = getTableParametros().getColumnModel().getColumn(0);
|
447 |
column.setPreferredWidth(30);
|
448 |
column = getTableParametros().getColumnModel().getColumn(1);
|
449 |
column.setPreferredWidth(90);
|
450 |
column = getTableParametros().getColumnModel().getColumn(2);
|
451 |
column.setPreferredWidth(120);
|
452 |
|
453 |
} |
454 |
|
455 |
/**
|
456 |
* Fija los eventos de los RadioButtons y dem�s controles
|
457 |
*/
|
458 |
public void actionPerformed(ActionEvent e) { |
459 |
//MOSTRAR UN PANEL U OTRO
|
460 |
CardLayout cl = (CardLayout)(cardPanel.getLayout()); |
461 |
if (e.getSource().equals(getRbProyectado())){
|
462 |
/*Si est� seleccionada la opci�n de Proyectado
|
463 |
se muestra el panel de selecci�n de la proyecci�n con sus par�metros*/
|
464 |
cl.show(cardPanel, PROYECTADOPANEL); |
465 |
}else if(e.getSource().equals(getRbGeografico())){ |
466 |
/*Se muestra el panel de Sistema de Coordenadas Geografico*/
|
467 |
cl.show(cardPanel, GEOGRAFICOPANEL); |
468 |
} |
469 |
} |
470 |
|
471 |
/*
|
472 |
* Crear el panel que contiene los componentes de
|
473 |
* un sistema de coordenadas geografico
|
474 |
* */
|
475 |
public JPanel getGeograficoPanel() { |
476 |
if(geograficoPanel==null){ |
477 |
BorderLayout b=new BorderLayout(); |
478 |
b.setVgap(5);
|
479 |
b.setHgap(5);
|
480 |
geograficoPanel=new JPanel(b); |
481 |
geograficoPanel.add(new JButton("Crear panel Geogr�fico 2D")); |
482 |
} |
483 |
return geograficoPanel;
|
484 |
} |
485 |
|
486 |
public void fillData(ICrs crs) { |
487 |
if (!crs.getCrsWkt().getProjcs().equals("")) { |
488 |
for (int i = 0; i < getCbProyeccion().getItemCount(); i++) { |
489 |
if (getCbProyeccion().getItemAt(i).toString().replaceAll(" ", "_").equals(crs.getCrsWkt().getProjection().replaceAll(" ", "_"))) { |
490 |
getCbProyeccion().setSelectedIndex(i); |
491 |
break;
|
492 |
} |
493 |
} |
494 |
getTxtNombreProy().setText(crs.getCrsWkt().getProjcs()); |
495 |
setPos(proj4.findProjection(crs.getCrsWkt().getProjection())); |
496 |
int numRow = model.getRowCount();
|
497 |
while (numRow != 0) { |
498 |
numRow = numRow - 1;
|
499 |
model.removeRow(numRow); |
500 |
} |
501 |
Object[] data = new Object[3]; |
502 |
data[2] = "Metros"; |
503 |
|
504 |
try {
|
505 |
|
506 |
for (int i = 0; i < crs.getCrsWkt().getParam_name().length; i++) { |
507 |
data[0] = crs.getCrsWkt().getParam_name()[i];
|
508 |
data[1] = crs.getCrsWkt().getParam_value()[i];
|
509 |
int pos = proj4.findProjectionParameter((String)data[0]); |
510 |
String unit = proj4.getProjectionParameterUnitList(pos);
|
511 |
if (unit.equals("Angular")) |
512 |
data[2] = "Degree"; |
513 |
else if (unit.equals("Unitless")) |
514 |
data[2] = "Unitless"; |
515 |
else if (unit.equals("Linear")) |
516 |
data[2] = "Meters"; |
517 |
model.addRow(data); |
518 |
} |
519 |
} catch (CrsException e) {
|
520 |
// TODO Auto-generated catch block
|
521 |
e.printStackTrace(); |
522 |
} |
523 |
} else {
|
524 |
getRbGeografico().setSelected(true);
|
525 |
CardLayout cl = (CardLayout)(cardPanel.getLayout()); |
526 |
cl.show(cardPanel, GEOGRAFICOPANEL); |
527 |
} |
528 |
} |
529 |
|
530 |
public void fillData(CoordinateReferenceSystem crs) { |
531 |
if (crs instanceof DefaultProjectedCRS) { |
532 |
DefaultProjectedCRS sour = (DefaultProjectedCRS) crs; |
533 |
String[] val = sour.getName().toString().split(":"); |
534 |
|
535 |
if (val.length<2) |
536 |
getTxtNombreProy().setText(val[0]);
|
537 |
else
|
538 |
getTxtNombreProy().setText(val[1]);
|
539 |
|
540 |
val = sour.getConversionFromBase().getMethod().getName().toString().split(":");
|
541 |
String proj;
|
542 |
if (val.length<2) |
543 |
proj=val[0];
|
544 |
else
|
545 |
proj=val[1];
|
546 |
|
547 |
for (int i = 0; i < getCbProyeccion().getItemCount(); i++) { |
548 |
if (getCbProyeccion().getItemAt(i).toString().replaceAll(" ", "_").equals(proj.replaceAll(" ", "_"))) { |
549 |
getCbProyeccion().setSelectedIndex(i); |
550 |
break;
|
551 |
} |
552 |
} |
553 |
String[] param_name = new String[sour.getConversionFromBase().getParameterValues().values().size()]; |
554 |
String[] param_value= new String[sour.getConversionFromBase().getParameterValues().values().size()]; |
555 |
for (int i=0; i< sour.getConversionFromBase().getParameterValues().values().size();i++) { |
556 |
String str = sour.getConversionFromBase().getParameterValues().values().get(i).toString();
|
557 |
Unit u = sour.getConversionFromBase().getParameterValues().parameter(str.split("=")[0]).getUnit(); |
558 |
double value = sour.getConversionFromBase().getParameterValues().parameter(str.split("=")[0]).doubleValue(); |
559 |
value = convert(value, u.toString()); |
560 |
param_name[i] = str.split("=")[0]; |
561 |
param_value [i] = String.valueOf(value);
|
562 |
} |
563 |
|
564 |
setPos(proj4.findProjection(proj)); |
565 |
int numRow = model.getRowCount();
|
566 |
while (numRow != 0) { |
567 |
numRow = numRow - 1;
|
568 |
model.removeRow(numRow); |
569 |
} |
570 |
|
571 |
Object[] data = new Object[3]; |
572 |
|
573 |
try {
|
574 |
|
575 |
for (int i = 0; i < param_name.length; i++) { |
576 |
data[0] = param_name[i];
|
577 |
data[1] = param_value[i];
|
578 |
int pos = proj4.findProjectionParameter((String)data[0]); |
579 |
String unit = proj4.getProjectionParameterUnitList(pos);
|
580 |
if (unit.equals("Angular")) |
581 |
data[2] = "Degree"; |
582 |
else if (unit.equals("Unitless")) |
583 |
data[2] = "Unitless"; |
584 |
else if (unit.equals("Linear")) |
585 |
data[2] = "Meters"; |
586 |
model.addRow(data); |
587 |
} |
588 |
} catch (CrsException e) {
|
589 |
// TODO Auto-generated catch block
|
590 |
e.printStackTrace(); |
591 |
} |
592 |
} |
593 |
else {
|
594 |
getRbGeografico().setSelected(true);
|
595 |
CardLayout cl = (CardLayout)(cardPanel.getLayout()); |
596 |
cl.show(cardPanel, GEOGRAFICOPANEL); |
597 |
} |
598 |
} |
599 |
|
600 |
public void fillTable(String projection) { |
601 |
try {
|
602 |
int index = proj4.findProjection(projection);
|
603 |
ArrayList params = proj4.getProj4ProjectionParameters(index);
|
604 |
setPos(index); |
605 |
String[] parameters = new String[params.size()]; |
606 |
String[] units = new String[params.size()]; |
607 |
for (int i = 0; i < params.size(); i++) { |
608 |
parameters[i] = params.get(i).toString(); |
609 |
int pos = proj4.findProjectionParameter(parameters[i]);
|
610 |
units[i] = proj4.getProjectionParameterUnitList(pos); |
611 |
|
612 |
} |
613 |
int numRow = model.getRowCount();
|
614 |
while (numRow != 0) { |
615 |
numRow = numRow - 1;
|
616 |
model.removeRow(numRow); |
617 |
} |
618 |
Object[] data = new Object[3]; |
619 |
data[1] = ""+0; |
620 |
data[2] = "Metros"; |
621 |
String[] items = null; |
622 |
//Estas 5 lineas se eliminaran cuando se pueda utilizar el codigo
|
623 |
//del siguiente comentario
|
624 |
ArrayList unit = obtenerItemsUnidades();
|
625 |
items = new String[unit.size()]; |
626 |
for (int j=0;j<unit.size();j++){ |
627 |
items[j] = unit.get(j).toString(); |
628 |
} |
629 |
/**
|
630 |
* Esto debera ser utilizado cuando podamos distinguir
|
631 |
* entre las unidades. De momento vamos a coger todas
|
632 |
*/
|
633 |
for (int i = 0; i < parameters.length; i++) { |
634 |
data[0] = parameters[i];
|
635 |
if (units[i].equals("Angular")) { |
636 |
data[2] = "Degree"; |
637 |
//define los items del combo
|
638 |
unit = obtenerItemsUnidadesAngular(); |
639 |
items = new String[unit.size()]; |
640 |
for (int j=0;j<unit.size();j++){ |
641 |
items[j] = unit.get(j).toString(); |
642 |
} |
643 |
} |
644 |
else if (units[i].equals("Unitless")) { |
645 |
data[2] = "Unitless"; |
646 |
//define los items del combo
|
647 |
unit = obtenerItemsUnidadesScale(); |
648 |
items = new String[unit.size()]; |
649 |
for (int j=0;j<unit.size();j++){ |
650 |
items[j] = unit.get(j).toString(); |
651 |
} |
652 |
} |
653 |
else {
|
654 |
data[2] = "Meters"; |
655 |
//define los items del combo
|
656 |
unit = obtenerItemsUnidades(); |
657 |
items = new String[unit.size()]; |
658 |
for (int j=0;j<unit.size();j++){ |
659 |
items[j] = unit.get(j).toString(); |
660 |
} |
661 |
} |
662 |
model.addRow(data); |
663 |
TableColumn col = getTableParametros().getColumnModel().getColumn(2); |
664 |
|
665 |
col.setCellEditor(new DefaultCellEditor(getCbUnits())); |
666 |
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); |
667 |
|
668 |
col.setCellRenderer(renderer); |
669 |
getTableParametros().setCellEditor(new DefaultCellEditor(getCbUnits())); |
670 |
|
671 |
} |
672 |
|
673 |
} catch (CrsException e) {
|
674 |
// TODO Auto-generated catch block
|
675 |
e.printStackTrace(); |
676 |
} |
677 |
} |
678 |
public void itemStateChanged(ItemEvent e) { |
679 |
if (e.getItemSelectable().equals(cbProyeccion) ) {
|
680 |
String op = (String)e.getItem(); |
681 |
fillTable(op); |
682 |
} |
683 |
|
684 |
if (e.getItemSelectable().equals(cbUnits) ) {
|
685 |
System.out.println( (String)e.getItem()); |
686 |
double value = Double.valueOf((String)getTableParametros().getValueAt(0, 1)).doubleValue(); |
687 |
value = convertFromMeters(sourceUnit, (String)e.getItem(), value);
|
688 |
sourceUnit = (String)e.getItem();
|
689 |
String val = String.valueOf(value); |
690 |
getTableParametros().setValueAt(val, 0, 1); |
691 |
} |
692 |
} |
693 |
|
694 |
public void cleanData() { |
695 |
getTxtNombreProy().setText("");
|
696 |
getCbProyeccion().setSelectedIndex(0);
|
697 |
} |
698 |
|
699 |
public double convert(double value, String measure) throws ConversionException { |
700 |
if (measure.equals("D.MS")) { |
701 |
value *= this.divider;
|
702 |
int deg,min;
|
703 |
deg = (int) (value/10000); value -= 10000*deg; |
704 |
min = (int) (value/ 100); value -= 100*min; |
705 |
if (min<=-60 || min>=60) { // Accepts NaN |
706 |
if (Math.abs(Math.abs(min) - 100) <= EPS) { |
707 |
if (min >= 0) deg++; else deg--; |
708 |
min = 0;
|
709 |
} else {
|
710 |
throw new ConversionException("Invalid minutes: "+min); |
711 |
} |
712 |
} |
713 |
if (value<=-60 || value>=60) { // Accepts NaN |
714 |
if (Math.abs(Math.abs(value) - 100) <= EPS) { |
715 |
if (value >= 0) min++; else min--; |
716 |
value = 0;
|
717 |
} else {
|
718 |
throw new ConversionException("Invalid secondes: "+value); |
719 |
} |
720 |
} |
721 |
value = ((value/60) + min)/60 + deg; |
722 |
return value;
|
723 |
} |
724 |
if (measure.equals("grad") || measure.equals("grade")) |
725 |
return ((value * 180.0) / 200.0); |
726 |
if (measure.equals(""+(char)176)) |
727 |
return value;
|
728 |
if (measure.equals("DMS") ) |
729 |
return value;
|
730 |
if (measure.equals("m")) |
731 |
return value;
|
732 |
if (measure.equals("")) |
733 |
return value;
|
734 |
|
735 |
throw new ConversionException("Conversion no contemplada: "+measure); |
736 |
} |
737 |
|
738 |
public double convert2Meters(String unit, double value) { |
739 |
double factor_b = 0; |
740 |
double factor_c = 0; |
741 |
String sentence = "SELECT factor_b, factor_c " + |
742 |
"FROM epsg_unitofmeasure " +
|
743 |
"WHERE unit_of_meas_name = '" +unit + "'"; |
744 |
EpsgConnection connect = new EpsgConnection();
|
745 |
connect.setConnectionEPSG(); |
746 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
747 |
try {
|
748 |
result.next(); |
749 |
factor_b = result.getDouble("factor_b");
|
750 |
factor_c = result.getDouble("factor_c");
|
751 |
} catch (SQLException e) { |
752 |
// TODO Auto-generated catch block
|
753 |
e.printStackTrace(); |
754 |
} |
755 |
return ((value*factor_b)/factor_c);
|
756 |
} |
757 |
|
758 |
public double convert2Unitless(String unit, double value) { |
759 |
double factor_b = 0; |
760 |
double factor_c = 0; |
761 |
String sentence = "SELECT factor_b, factor_c " + |
762 |
"FROM epsg_unitofmeasure " +
|
763 |
"WHERE unit_of_meas_name = '" +unit + "'"; |
764 |
EpsgConnection connect = new EpsgConnection();
|
765 |
connect.setConnectionEPSG(); |
766 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
767 |
try {
|
768 |
result.next(); |
769 |
factor_b = result.getDouble("factor_b");
|
770 |
factor_c = result.getDouble("factor_c");
|
771 |
} catch (SQLException e) { |
772 |
// TODO Auto-generated catch block
|
773 |
e.printStackTrace(); |
774 |
} |
775 |
return ((value*factor_b)/factor_c);
|
776 |
} |
777 |
|
778 |
public double convert2Degree(String unit, double value) { |
779 |
double factor_b = 0; |
780 |
double factor_c = 0; |
781 |
String sentence = "SELECT factor_b, factor_c " + |
782 |
"FROM epsg_unitofmeasure " +
|
783 |
"WHERE unit_of_meas_name = '" +unit + "'"; |
784 |
EpsgConnection connect = new EpsgConnection();
|
785 |
connect.setConnectionEPSG(); |
786 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
787 |
try {
|
788 |
result.next(); |
789 |
factor_b = result.getDouble("factor_b");
|
790 |
factor_c = result.getDouble("factor_c");
|
791 |
} catch (SQLException e) { |
792 |
// TODO Auto-generated catch block
|
793 |
e.printStackTrace(); |
794 |
} |
795 |
value = ((value*factor_b)/factor_c); |
796 |
return ((value * 180.0) / 200.0); |
797 |
} |
798 |
|
799 |
public double convertFromMeters(String unitSource, String unitTarget, double value) { |
800 |
double factor_b = 0; |
801 |
double factor_c = 0; |
802 |
String sentence = "SELECT factor_b, factor_c " + |
803 |
"FROM epsg_unitofmeasure " +
|
804 |
"WHERE unit_of_meas_name = '" +unitSource + "'"; |
805 |
EpsgConnection connect = new EpsgConnection();
|
806 |
connect.setConnectionEPSG(); |
807 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
808 |
try {
|
809 |
result.next(); |
810 |
factor_b = result.getDouble("factor_b");
|
811 |
factor_c = result.getDouble("factor_c");
|
812 |
} catch (SQLException e) { |
813 |
// TODO Auto-generated catch block
|
814 |
e.printStackTrace(); |
815 |
} |
816 |
value = ((value*factor_b)/factor_c); |
817 |
|
818 |
sentence = "SELECT factor_b, factor_c " +
|
819 |
"FROM epsg_unitofmeasure " +
|
820 |
"WHERE unit_of_meas_name = '" +unitTarget + "'"; |
821 |
connect = new EpsgConnection();
|
822 |
connect.setConnectionEPSG(); |
823 |
result = Query.select(sentence,connect.getConnection());
|
824 |
try {
|
825 |
result.next(); |
826 |
factor_b = result.getDouble("factor_b");
|
827 |
factor_c = result.getDouble("factor_c");
|
828 |
} catch (SQLException e) { |
829 |
// TODO Auto-generated catch block
|
830 |
e.printStackTrace(); |
831 |
} |
832 |
return ((value*factor_c)/factor_b);
|
833 |
} |
834 |
|
835 |
public double convertFromUnitless(String unitSource, String unitTarget, double value) { |
836 |
double factor_b = 0; |
837 |
double factor_c = 0; |
838 |
String sentence = "SELECT factor_b, factor_c " + |
839 |
"FROM epsg_unitofmeasure " +
|
840 |
"WHERE unit_of_meas_name = '" +unitSource + "'"; |
841 |
EpsgConnection connect = new EpsgConnection();
|
842 |
connect.setConnectionEPSG(); |
843 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
844 |
try {
|
845 |
result.next(); |
846 |
factor_b = result.getDouble("factor_b");
|
847 |
factor_c = result.getDouble("factor_c");
|
848 |
} catch (SQLException e) { |
849 |
// TODO Auto-generated catch block
|
850 |
e.printStackTrace(); |
851 |
} |
852 |
value = ((value*factor_b)/factor_c); |
853 |
|
854 |
sentence = "SELECT factor_b, factor_c " +
|
855 |
"FROM epsg_unitofmeasure " +
|
856 |
"WHERE unit_of_meas_name = '" +unitSource + "'"; |
857 |
connect = new EpsgConnection();
|
858 |
connect.setConnectionEPSG(); |
859 |
result = Query.select(sentence,connect.getConnection());
|
860 |
try {
|
861 |
result.next(); |
862 |
factor_b = result.getDouble("factor_b");
|
863 |
factor_c = result.getDouble("factor_c");
|
864 |
} catch (SQLException e) { |
865 |
// TODO Auto-generated catch block
|
866 |
e.printStackTrace(); |
867 |
} |
868 |
return ((value*factor_c)/factor_b);
|
869 |
} |
870 |
|
871 |
public double convertFromDegree(String unitSource, String unitTarget, double value) { |
872 |
double factor_b = 0; |
873 |
double factor_c = 0; |
874 |
String sentence = "SELECT factor_b, factor_c " + |
875 |
"FROM epsg_unitofmeasure " +
|
876 |
"WHERE unit_of_meas_name = '" +unitSource + "'"; |
877 |
EpsgConnection connect = new EpsgConnection();
|
878 |
connect.setConnectionEPSG(); |
879 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
880 |
try {
|
881 |
result.next(); |
882 |
factor_b = result.getDouble("factor_b");
|
883 |
factor_c = result.getDouble("factor_c");
|
884 |
} catch (SQLException e) { |
885 |
// TODO Auto-generated catch block
|
886 |
e.printStackTrace(); |
887 |
} |
888 |
value = ((value*factor_b)/factor_c); |
889 |
|
890 |
sentence = "SELECT factor_b, factor_c " +
|
891 |
"FROM epsg_unitofmeasure " +
|
892 |
"WHERE unit_of_meas_name = '" +unitSource + "'"; |
893 |
connect = new EpsgConnection();
|
894 |
connect.setConnectionEPSG(); |
895 |
result = Query.select(sentence,connect.getConnection());
|
896 |
try {
|
897 |
result.next(); |
898 |
factor_b = result.getDouble("factor_b");
|
899 |
factor_c = result.getDouble("factor_c");
|
900 |
} catch (SQLException e) { |
901 |
// TODO Auto-generated catch block
|
902 |
e.printStackTrace(); |
903 |
} |
904 |
return ((value*factor_c)/factor_b);
|
905 |
} |
906 |
|
907 |
public Proj4 getProj4() {
|
908 |
return proj4;
|
909 |
} |
910 |
|
911 |
public void setPos(int pos) { |
912 |
this.pos = pos;
|
913 |
} |
914 |
|
915 |
public int getPos() { |
916 |
return this.pos; |
917 |
} |
918 |
|
919 |
|
920 |
} |
921 |
|