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