root / org.gvsig.projection.jcrs / trunk / org.gvsig.projection.jcrs / org.gvsig.projection.app.jcrs / org.gvsig.projection.app.jcrs.common / src / main / java / org / gvsig / crs / gui / panels / EPSGpanel.java @ 251
History | View | Annotate | Download (27 KB)
1 |
/* gvSIG. Sistema de Informacin Geogrfica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ibez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.crs.gui.panels; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Color; |
45 |
import java.awt.Dimension; |
46 |
import java.awt.FlowLayout; |
47 |
import java.awt.GridLayout; |
48 |
import java.awt.event.ActionEvent; |
49 |
import java.awt.event.ActionListener; |
50 |
import java.awt.event.KeyEvent; |
51 |
import java.awt.event.KeyListener; |
52 |
import java.sql.ResultSet; |
53 |
import java.sql.SQLException; |
54 |
|
55 |
import javax.swing.BorderFactory; |
56 |
import javax.swing.ButtonGroup; |
57 |
import javax.swing.JButton; |
58 |
import javax.swing.JLabel; |
59 |
import javax.swing.JOptionPane; |
60 |
import javax.swing.JPanel; |
61 |
import javax.swing.JRadioButton; |
62 |
import javax.swing.JScrollPane; |
63 |
import javax.swing.JTable; |
64 |
import javax.swing.JTextField; |
65 |
import javax.swing.ListSelectionModel; |
66 |
import javax.swing.table.DefaultTableModel; |
67 |
import javax.swing.table.TableColumn; |
68 |
|
69 |
import org.cresques.cts.IProjection; |
70 |
import org.gvsig.andami.PluginServices; |
71 |
import org.gvsig.app.gui.TableSorter; |
72 |
import org.gvsig.crs.CrsException; |
73 |
import org.gvsig.crs.CrsFactory; |
74 |
import org.gvsig.crs.ICrs; |
75 |
import org.gvsig.crs.ogr.Epsg2wkt; |
76 |
import org.gvsig.crs.ogr.CrsEPSG; |
77 |
|
78 |
|
79 |
import org.slf4j.Logger; |
80 |
import org.slf4j.LoggerFactory; |
81 |
|
82 |
import es.idr.teledeteccion.connection.EpsgConnection; |
83 |
import es.idr.teledeteccion.connection.Query; |
84 |
|
85 |
/**
|
86 |
* Clase perteneciente al panel de eleccin de CRS del repositorio de la
|
87 |
* EPSG, realiza la bsqueda y filtra los vlidos.
|
88 |
*
|
89 |
* @author Jos Luis Gmez Martnez (jolugomar@gmail.com)
|
90 |
* @author Luisa Marina Fernndez (luisam.fernandez@uclm.es)
|
91 |
*
|
92 |
*/
|
93 |
public class EPSGpanel extends JPanel implements KeyListener, ActionListener{ |
94 |
public static final Logger logger = LoggerFactory.getLogger(EPSGpanel.class); |
95 |
|
96 |
private static final long serialVersionUID = 1L; |
97 |
|
98 |
String cadWKT = ""; |
99 |
String cad_valida = ""; |
100 |
public String key; |
101 |
public String crs_kind = null; |
102 |
String[] soported_crs = {"projected","geographic 2D","geographic 3D", "engineering", "vertical", "compound", "geocentric"}; |
103 |
String[] not_soported_crs = {}; |
104 |
|
105 |
int iteracion = 0; |
106 |
int transf = 0; |
107 |
int source_cod = 0; |
108 |
int method_code = 0; |
109 |
int datum_code = 0; |
110 |
int projection_conv_code = 0; |
111 |
public int epsg_code = 0; |
112 |
public int selectedRowTable = -1; |
113 |
private int codeCRS = -1; |
114 |
int[] valid_method_code = { 1024, 9800, 9801, 9802, 9803, 9804, 9805, 9806, 9807, 9808, 9809, 9810, |
115 |
9811, 9812, 9813, 9814, 9815, 9816, 9817, 9602, 9659, 9818, 9819, 9820, 9822, |
116 |
9827};
|
117 |
|
118 |
|
119 |
boolean tecla_valida = false; |
120 |
boolean source_yn = false; |
121 |
|
122 |
|
123 |
private JRadioButton codeRadioButton = null; |
124 |
private JRadioButton nameRadioButton = null; |
125 |
private JRadioButton areaRadioButton = null; |
126 |
private ButtonGroup optGroup; |
127 |
private JPanel groupRadioButton = null; |
128 |
|
129 |
public EpsgConnection connect = null; |
130 |
public JPanel EPSGpanel = null; |
131 |
private JLabel lblCriterio; |
132 |
private JButton infoCrs = null; |
133 |
private JButton searchButton = null; |
134 |
private JTextField searchTextField = null; |
135 |
public JTable jTable = null; |
136 |
private JScrollPane jScrollPane = null; |
137 |
public DefaultTableModel dtm = null; |
138 |
public TableSorter sorter = null; |
139 |
|
140 |
private int projectionCode=-1; |
141 |
|
142 |
/**
|
143 |
* Construye el Objeto EpsgPanel
|
144 |
*
|
145 |
*/
|
146 |
public EPSGpanel(){
|
147 |
initialize(); |
148 |
} |
149 |
/*
|
150 |
* Define las propiedades y agrega los componentes del EPSGPanel
|
151 |
*/
|
152 |
private void initialize(){ |
153 |
this.setLayout(new BorderLayout()); |
154 |
JPanel pNorth=new JPanel(); |
155 |
pNorth.setLayout(new GridLayout(2,1)); |
156 |
pNorth.setBorder(BorderFactory.createEmptyBorder(3,3,3,3)); |
157 |
pNorth.add(getGroupRadioButton()); |
158 |
JPanel pInNorth = new JPanel(); |
159 |
pInNorth.setLayout(new FlowLayout(FlowLayout.LEFT,10,1)); |
160 |
pInNorth.add(getSearchButton()); |
161 |
pInNorth.add(getSearchTextField()); |
162 |
pNorth.add(pInNorth); |
163 |
this.add(pNorth,BorderLayout.NORTH); |
164 |
this.add(getJScrollPane(), BorderLayout.CENTER); |
165 |
JPanel pSouth=new JPanel(new FlowLayout(FlowLayout.RIGHT,10,3)); |
166 |
pSouth.add(getInfoCrs()); |
167 |
this.add(pSouth,BorderLayout.SOUTH); |
168 |
} |
169 |
/**
|
170 |
* Establece la conexin con la Base de Datos de la Epsg
|
171 |
*
|
172 |
*/
|
173 |
public void connection(){ |
174 |
connect = new EpsgConnection();
|
175 |
connect.setConnectionEPSG(); |
176 |
} |
177 |
/**
|
178 |
* Inicializa el botn de opcin 'cdigo'
|
179 |
* @return
|
180 |
*/
|
181 |
private JRadioButton getCodeRadioButton() { |
182 |
if (codeRadioButton == null) { |
183 |
codeRadioButton = new JRadioButton(); |
184 |
codeRadioButton.setText(PluginServices.getText(this,"por_codigo"));//setText("By Code EPSG"); |
185 |
codeRadioButton.setSelected(true);
|
186 |
codeRadioButton.addActionListener(this);
|
187 |
} |
188 |
return codeRadioButton;
|
189 |
} |
190 |
/**
|
191 |
* Inicializa el botn de opcin 'nombre'
|
192 |
* @return
|
193 |
*/
|
194 |
private JRadioButton getNameRadioButton() { |
195 |
if (nameRadioButton == null) { |
196 |
nameRadioButton = new JRadioButton(); |
197 |
nameRadioButton.setText(PluginServices.getText(this,"por_nombre")); |
198 |
nameRadioButton.addActionListener(this);
|
199 |
} |
200 |
return nameRadioButton;
|
201 |
} |
202 |
/**
|
203 |
* Inicializa el botn de opcin 'Area'
|
204 |
* @return
|
205 |
*/
|
206 |
private JRadioButton getAreaRadioButton() { |
207 |
if (areaRadioButton == null) { |
208 |
areaRadioButton = new JRadioButton(); |
209 |
areaRadioButton.setText(PluginServices.getText(this,"por_area")); |
210 |
areaRadioButton.addActionListener(this);
|
211 |
} |
212 |
return areaRadioButton;
|
213 |
} |
214 |
/**
|
215 |
* Obtiene el panel con todos los botones de opcin
|
216 |
* @return
|
217 |
*/
|
218 |
private JPanel getGroupRadioButton() { |
219 |
if (groupRadioButton == null) { |
220 |
groupRadioButton = new JPanel(); |
221 |
groupRadioButton.setLayout(new GridLayout(1,4)); |
222 |
groupRadioButton.add(getLblCriterio()); |
223 |
groupRadioButton.add(getCodeRadioButton()); |
224 |
groupRadioButton.add(getNameRadioButton()); |
225 |
groupRadioButton.add(getAreaRadioButton()); |
226 |
//agrupar los botones
|
227 |
getOptGroup(); |
228 |
} |
229 |
return groupRadioButton;
|
230 |
} |
231 |
/**
|
232 |
* Inicializa el laber 'Criterio de bsqueda'
|
233 |
* @return
|
234 |
*/
|
235 |
private JLabel getLblCriterio(){ |
236 |
lblCriterio = new JLabel(); |
237 |
lblCriterio.setText(PluginServices.getText(this, "criterio_busqueda")+":"); |
238 |
return lblCriterio;
|
239 |
} |
240 |
|
241 |
/**
|
242 |
* Mtodo que controla la bsqueda de los CRS siguiendo los criterios
|
243 |
* de bsqueda que le hemos definido. Tambin gestiona los casos en que
|
244 |
* no encuentre CRS, o que los parmetros de bsqueda sean errneos. Si
|
245 |
* encuentra algn CRS pero no es soportado por la aplicacin
|
246 |
* aparecer el mensaje de informacin correspondiente.
|
247 |
*
|
248 |
*/
|
249 |
private void searchButton() { |
250 |
boolean not_valid = false; |
251 |
boolean not_numeric = false; |
252 |
searchTextField.setBackground(Color.white);
|
253 |
|
254 |
if (searchTextField.getText().equals("")) { |
255 |
searchTextField.setBackground(new Color(255,204,204)); |
256 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this,"fill_name"), "Warning...", JOptionPane.WARNING_MESSAGE); |
257 |
} |
258 |
|
259 |
else {
|
260 |
//Eliminar filas en cada nueva bsqueda
|
261 |
int numRow = dtm.getRowCount();
|
262 |
while (numRow != 0) { |
263 |
numRow = numRow - 1;
|
264 |
dtm.removeRow(numRow); |
265 |
} |
266 |
|
267 |
if (codeRadioButton.isSelected() && (searchTextField.getText().length()!=searchTextField.getText().replaceAll("[^0-9]", "").length())){ |
268 |
not_numeric = true;
|
269 |
} |
270 |
|
271 |
//Dependiendo de la opcion se realizada una busqueda
|
272 |
ResultSet result = null; |
273 |
ResultSet result2 = null; |
274 |
/*
|
275 |
* variable que indicara si la busqueda se hace primero en epsg_coordinatereferencesystem
|
276 |
* o en epsg_area; esto es debido a que HSQLDB no soporta la bsqueda simultnea en ambas
|
277 |
* tablas, por lo cual hay que separar la bsqueda
|
278 |
*/
|
279 |
int bus = 2; |
280 |
if (codeRadioButton.isSelected() && !not_numeric) {
|
281 |
bus=0;
|
282 |
key = searchTextField.getText(); |
283 |
int code = Integer.parseInt(key); |
284 |
String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, area_of_use_code, " + |
285 |
"source_geogcrs_code, projection_conv_code " +
|
286 |
"FROM epsg_coordinatereferencesystem " +
|
287 |
"WHERE coord_ref_sys_code = " + code;
|
288 |
|
289 |
result = Query.select(sentence,connect.getConnection());
|
290 |
|
291 |
} |
292 |
|
293 |
else if (nameRadioButton.isSelected()) { |
294 |
bus=0;
|
295 |
key = searchTextField.getText(); |
296 |
key = key.toLowerCase(); |
297 |
String key2 = key.substring(0,1); |
298 |
String key3 = key.substring(1,key.length()); |
299 |
key2 = key2.toUpperCase(); |
300 |
|
301 |
String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, " + |
302 |
"area_of_use_code, source_geogcrs_code, projection_conv_code " +
|
303 |
"FROM epsg_coordinatereferencesystem " +
|
304 |
"WHERE (coord_ref_sys_name LIKE '%" + key + "%') OR (coord_ref_sys_name LIKE '%"+ |
305 |
key.toUpperCase() +"%') " +
|
306 |
"OR (coord_ref_sys_name LIKE '%" + key2+key3 +"%')"; |
307 |
result = Query.select(sentence,connect.getConnection());
|
308 |
} |
309 |
|
310 |
else if (areaRadioButton.isSelected()) { |
311 |
bus=1;
|
312 |
key = searchTextField.getText(); |
313 |
key = key.toLowerCase(); |
314 |
String key2 = key.substring(0,1); |
315 |
String key3 = key.substring(1,key.length()); |
316 |
key2 = key2.toUpperCase(); |
317 |
|
318 |
String sentence = "SELECT area_name, area_of_use, area_code " + |
319 |
"FROM epsg_area " +
|
320 |
"WHERE (area_name LIKE '%" + key + "%') OR (area_of_use LIKE '%" + key + "%') "+ |
321 |
"OR (area_name LIKE '%" + key.toUpperCase() + "%') OR (area_of_use LIKE '%" + key.toUpperCase() + "%') "+ |
322 |
"OR (area_name LIKE '%" + key2+key3 + "%') OR (area_of_use LIKE '%" + key2+key3 + "%') "; |
323 |
result = Query.select(sentence,connect.getConnection());
|
324 |
} |
325 |
|
326 |
if (bus==0){ |
327 |
try {
|
328 |
while(result.next()) {
|
329 |
Object[]data = new Object[5]; |
330 |
data[0] = String.valueOf(result.getInt("coord_ref_sys_code")); |
331 |
data[1] = result.getString("coord_ref_sys_name"); |
332 |
crs_kind = result.getString("coord_ref_sys_kind");
|
333 |
data[2] = crs_kind;
|
334 |
projection_conv_code = result.getInt("projection_conv_code");
|
335 |
setProjectionCode(projection_conv_code); |
336 |
|
337 |
int area_of_use_code = Integer.parseInt(result.getString("area_of_use_code")); |
338 |
|
339 |
String sentence = "SELECT area_name, area_of_use FROM epsg_area " + |
340 |
"WHERE area_code = "+ area_of_use_code ;
|
341 |
|
342 |
result2 = Query.select(sentence,connect.getConnection());
|
343 |
while(result2.next()){
|
344 |
data[3] = result2.getString("area_name"); |
345 |
data[4] = result2.getString("area_of_use"); |
346 |
} |
347 |
if (data[0]!=null /*&& validCRS(projection_conv_code)*/ && valid(crs_kind)){ |
348 |
dtm.addRow(data); |
349 |
} |
350 |
} |
351 |
} |
352 |
|
353 |
catch (SQLException e1) { |
354 |
logger.error("Can't get values from RecordSet.",e1);
|
355 |
} |
356 |
} |
357 |
else if (bus==1){ |
358 |
try {
|
359 |
while(result.next()) {
|
360 |
Object[]data = new Object[5]; |
361 |
data[3] = result.getString("area_name"); |
362 |
data[4] = result.getString("area_of_use"); |
363 |
|
364 |
int area_of_use_code = Integer.parseInt(result.getString("area_code")); |
365 |
|
366 |
String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, " + |
367 |
"coord_ref_sys_kind, source_geogcrs_code, projection_conv_code " +
|
368 |
"FROM epsg_coordinatereferencesystem " +
|
369 |
"WHERE area_of_use_code = "+ area_of_use_code ;
|
370 |
|
371 |
result2 = Query.select(sentence,connect.getConnection());
|
372 |
while(result2.next()){
|
373 |
data[0] = String.valueOf(result2.getInt("coord_ref_sys_code")); |
374 |
data[1] = result2.getString("coord_ref_sys_name"); |
375 |
data[2] = result2.getString("coord_ref_sys_kind"); |
376 |
crs_kind = (String)data[2]; |
377 |
projection_conv_code = result2.getInt("projection_conv_code");
|
378 |
setProjectionCode(projection_conv_code); |
379 |
} |
380 |
/*
|
381 |
* Buscaremos solo aquellos CRS cuyas proyecciones esten entre las
|
382 |
* 16 soportadas por proj4 para ello creamos un metodo para validar
|
383 |
* si esta entre estas proyecciones
|
384 |
*/
|
385 |
if (data[0]!=null /*&& validCRS(projection_conv_code)*/ && valid(crs_kind)){ |
386 |
dtm.addRow(data); |
387 |
} |
388 |
if (notValid(crs_kind)){
|
389 |
not_valid = true;
|
390 |
} |
391 |
} |
392 |
} |
393 |
|
394 |
catch (SQLException e1) { |
395 |
logger.error("Can't get values from RecordSet.",e1);
|
396 |
|
397 |
} |
398 |
} |
399 |
int numr = dtm.getRowCount();
|
400 |
if (not_valid){
|
401 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this,"crs_not_soported"), "Warning...", |
402 |
JOptionPane.WARNING_MESSAGE);
|
403 |
not_valid = false;
|
404 |
} |
405 |
else if (not_numeric) { |
406 |
JOptionPane.showMessageDialog(EPSGpanel.this,
|
407 |
PluginServices.getText(this,"numeric_format"), |
408 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
409 |
searchTextField.setText("");
|
410 |
} |
411 |
else if (numr == 0){ |
412 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this,"no_results"), "Warning...", |
413 |
JOptionPane.WARNING_MESSAGE);
|
414 |
} |
415 |
else{
|
416 |
this.getJTable().setRowSelectionInterval(0,0); |
417 |
} |
418 |
} |
419 |
} |
420 |
|
421 |
/**
|
422 |
* metodo auxiliar que hara la comprobacion de si el CRS buscado pertenecera
|
423 |
* a los no soportados por proj4
|
424 |
*/
|
425 |
private boolean notValid(String kind){ |
426 |
for (int i = 0; i< not_soported_crs.length; i++){ |
427 |
if (kind.equals(not_soported_crs[i])){
|
428 |
return true; |
429 |
} |
430 |
} |
431 |
return false; |
432 |
} |
433 |
|
434 |
/**
|
435 |
* Metodo que comprueba si el CRS buscado pertenece a algun tipo
|
436 |
* de los que soporta la aplicacion
|
437 |
*/
|
438 |
private boolean valid(String kind){ |
439 |
for (int i = 0; i< soported_crs.length; i++){ |
440 |
if (kind.equals(soported_crs[i])){
|
441 |
return true; |
442 |
} |
443 |
} |
444 |
return false; |
445 |
} |
446 |
|
447 |
/**
|
448 |
* metodo auxiliar que nos servira para comprobar si la proyeccion del CRS seleccionado
|
449 |
* esta entre las 16 con las que trabaja proj4
|
450 |
*/
|
451 |
private boolean validCRS(int projection_conv_code2) { |
452 |
if (projection_conv_code2 == 0) return true; |
453 |
String sentence = "SELECT coord_op_method_code " + |
454 |
"FROM epsg_coordoperation " +
|
455 |
"WHERE coord_op_code = " + projection_conv_code;
|
456 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
457 |
try {
|
458 |
while (result.next()){
|
459 |
method_code = result.getInt("coord_op_method_code");
|
460 |
} |
461 |
} catch (SQLException e) { |
462 |
logger.error("Can't get values from RecordSet (sentence='"+sentence+"').",e); |
463 |
} |
464 |
|
465 |
for (int i = 0; i< valid_method_code.length; i++){ |
466 |
if (method_code == valid_method_code[i] ){
|
467 |
return true; |
468 |
} |
469 |
} |
470 |
return false; |
471 |
} |
472 |
|
473 |
/**
|
474 |
* Inicializa el botn de bsqueda
|
475 |
* @return
|
476 |
*/
|
477 |
private JButton getSearchButton() { |
478 |
if (searchButton == null) { |
479 |
searchButton = new JButton(); |
480 |
searchButton.setPreferredSize(new Dimension(75,20)); |
481 |
searchButton.setText(PluginServices.getText(this,"buscar")); |
482 |
searchButton.setMnemonic('S');
|
483 |
searchButton.setToolTipText(PluginServices.getText(this,"buscar_por_criterio_seleccion")); |
484 |
searchButton.addActionListener(this);
|
485 |
} |
486 |
return searchButton;
|
487 |
} |
488 |
/**
|
489 |
* Inicializa el cuadro de texto en el que se introduce el dato a buscar
|
490 |
* @return
|
491 |
*/
|
492 |
private JTextField getSearchTextField() { |
493 |
if (searchTextField == null) { |
494 |
searchTextField = new JTextField(); |
495 |
searchTextField.setPreferredSize(new Dimension(350,20)); |
496 |
searchTextField.addKeyListener(this);
|
497 |
} |
498 |
return searchTextField;
|
499 |
} |
500 |
/**
|
501 |
* Inicializa la tabla que se utiliza para mostrar
|
502 |
* los resultados de la bsqueda
|
503 |
* @return
|
504 |
*/
|
505 |
public JTable getJTable() { |
506 |
if (jTable == null) { |
507 |
String[] columnNames= {PluginServices.getText(this,"codigo"), |
508 |
PluginServices.getText(this,"nombre"), |
509 |
PluginServices.getText(this,"tipo"), |
510 |
PluginServices.getText(this,"area"), |
511 |
PluginServices.getText(this,"descripcion")}; |
512 |
Object[][]data = {}; |
513 |
dtm = new DefaultTableModel(data, columnNames) |
514 |
{ |
515 |
private static final long serialVersionUID = 1L; |
516 |
public boolean isCellEditable(int row, int column) { |
517 |
return false; |
518 |
} |
519 |
/*
|
520 |
* metodo necesario para cuando utilizamos tablas ordenadas
|
521 |
* ya que sino al ordenar por algun campo no se queda con el orden
|
522 |
* actual al seleccionar una fila (non-Javadoc)
|
523 |
* @see javax.swing.table.TableModel#getColumnClass(int)
|
524 |
*/
|
525 |
public Class getColumnClass(int column) |
526 |
{ |
527 |
return getValueAt(0, column).getClass(); |
528 |
} |
529 |
}; |
530 |
sorter = new TableSorter(dtm);
|
531 |
|
532 |
jTable = new JTable(sorter); |
533 |
//jTable.setPreferredSize(new Dimension(800, 100));
|
534 |
sorter.setTableHeader(jTable.getTableHeader()); |
535 |
jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
536 |
jTable.setCellSelectionEnabled(false);
|
537 |
jTable.setRowSelectionAllowed(true);
|
538 |
jTable.setColumnSelectionAllowed(false);
|
539 |
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
540 |
TableColumn column = null; |
541 |
for (int i = 0; i < columnNames.length; i++) { |
542 |
column = jTable.getColumnModel().getColumn(i); |
543 |
if (i == 0) { |
544 |
column.setPreferredWidth(50); //code column is shorter |
545 |
} |
546 |
else if (i == 2) { |
547 |
column.setPreferredWidth(80);
|
548 |
} |
549 |
else if (i==4){ |
550 |
column.setPreferredWidth(300);
|
551 |
} |
552 |
else {
|
553 |
column.setPreferredWidth(140);
|
554 |
} |
555 |
} |
556 |
} |
557 |
|
558 |
return jTable;
|
559 |
|
560 |
} |
561 |
/**
|
562 |
* Establece el cdigo se CRS
|
563 |
* @param code
|
564 |
*/
|
565 |
public void setCodeCRS(int code) { |
566 |
codeCRS = code; |
567 |
} |
568 |
/**
|
569 |
* Obtiene el cdigo de CRS
|
570 |
* @return
|
571 |
*/
|
572 |
public int getCodeCRS() { |
573 |
return codeCRS;
|
574 |
} |
575 |
/**
|
576 |
* Inicializa el panel que contiene la tabla de resultados
|
577 |
* @return
|
578 |
*/
|
579 |
private JScrollPane getJScrollPane() { |
580 |
if (jScrollPane == null) { |
581 |
jScrollPane = new JScrollPane(getJTable(),JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); |
582 |
jScrollPane.setPreferredSize(new Dimension(500,150)); |
583 |
jScrollPane.setBorder( |
584 |
BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(3,3,3,3),jScrollPane.getBorder())); |
585 |
|
586 |
jScrollPane.setViewportView(getJTable()); |
587 |
} |
588 |
return jScrollPane;
|
589 |
} |
590 |
/**
|
591 |
* Inicializa el botn que muestra la informacin de CRS seleccionado
|
592 |
* @return
|
593 |
*/
|
594 |
public JButton getInfoCrs() { |
595 |
if(infoCrs == null) { |
596 |
infoCrs = new JButton(); |
597 |
infoCrs.setPreferredSize(new Dimension(85,20)); |
598 |
infoCrs.setText(PluginServices.getText(this,"infocrs")); |
599 |
infoCrs.setMnemonic('I');
|
600 |
infoCrs.setEnabled(false);
|
601 |
infoCrs.setToolTipText(PluginServices.getText(this,"more_info")); |
602 |
infoCrs.addActionListener(this);
|
603 |
} |
604 |
return infoCrs;
|
605 |
} |
606 |
|
607 |
|
608 |
public ICrs getProjection() {
|
609 |
try {
|
610 |
String txt = getWKT();
|
611 |
//ICrs crs = new CrsFactory().getCRS(epsg_code, txt);
|
612 |
ICrs crs = new CrsFactory().getCRS("EPSG:"+epsg_code); |
613 |
return crs ;
|
614 |
} catch (CrsException e) {
|
615 |
logger.error("Can't create EPSG CRS from code "+epsg_code+".",e); |
616 |
} |
617 |
return null; |
618 |
} |
619 |
|
620 |
/**
|
621 |
* Genera la cadena WKT una vez que escogemos el CRS de la tabla.
|
622 |
* Dicha cadena la generamos con los parmetros cogidos directamente
|
623 |
* del repositorio de la EPSG, y ms adelante volveremos a tratarla
|
624 |
* para pasarla a una cadena legible por la proj4.
|
625 |
*
|
626 |
*/
|
627 |
public void setWKT(){ |
628 |
Epsg2wkt wkt = null;
|
629 |
|
630 |
epsg_code = getCodeCRS(); |
631 |
if (epsg_code != -1){ |
632 |
/*
|
633 |
* ahora que he escogido, recojo toda la informacion que me va a hacer falta
|
634 |
*/
|
635 |
String sentence = "SELECT source_geogcrs_code, projection_conv_code, " + |
636 |
"coord_ref_sys_kind, datum_code " +
|
637 |
"FROM epsg_coordinatereferencesystem " +
|
638 |
"WHERE coord_ref_sys_code = "+ epsg_code ;
|
639 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
640 |
|
641 |
try {
|
642 |
result.next(); |
643 |
source_cod = result.getInt("source_geogcrs_code");
|
644 |
projection_conv_code = result.getInt("projection_conv_code");
|
645 |
crs_kind = result.getString("coord_ref_sys_kind");
|
646 |
datum_code = result.getInt("datum_code");
|
647 |
} catch (SQLException e1) { |
648 |
logger.error("Can't get values from RecordSet (sentence='"+sentence+"').",e1); |
649 |
} |
650 |
|
651 |
if (datum_code != 0){ |
652 |
source_yn = true;
|
653 |
} |
654 |
else if (source_cod != 0){ |
655 |
source_yn = false;
|
656 |
} |
657 |
else source_yn = true; |
658 |
|
659 |
CrsEPSG ep = new CrsEPSG(epsg_code, source_yn, source_cod, projection_conv_code, connect);
|
660 |
|
661 |
if (crs_kind.equals("geographic 2D") || crs_kind.equals("geographic 3D")){ |
662 |
wkt = new Epsg2wkt(ep , "geog"); |
663 |
} |
664 |
else if (crs_kind.equals("projected")){ |
665 |
wkt = new Epsg2wkt(ep, "proj"); |
666 |
} |
667 |
else if (crs_kind.equals("compound")){ |
668 |
wkt = new Epsg2wkt(ep,"comp"); |
669 |
} |
670 |
else if (crs_kind.equals("geocentric")){ |
671 |
wkt = new Epsg2wkt(ep,"geoc"); |
672 |
} |
673 |
} |
674 |
else {
|
675 |
JOptionPane.showMessageDialog(this, |
676 |
PluginServices.getText(this,"crs_no_selected."), |
677 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
678 |
|
679 |
} |
680 |
cadWKT = wkt.getWKT(); |
681 |
} |
682 |
|
683 |
public String getWKT(){ |
684 |
return cadWKT;
|
685 |
} |
686 |
|
687 |
public void setProjection(IProjection crs) { |
688 |
//setCrs((ICrs) crs);
|
689 |
} |
690 |
|
691 |
/**
|
692 |
* Metodo para cargar en el CRS de la capa el CRS de la vista.
|
693 |
* Se utilizar a la hora de arrancar la definicin del CRS de la nueva capa
|
694 |
*/
|
695 |
public void loadViewCRS(int code){ |
696 |
connection(); |
697 |
String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, area_of_use_code, " + |
698 |
"source_geogcrs_code, projection_conv_code " +
|
699 |
"FROM epsg_coordinatereferencesystem " +
|
700 |
"WHERE coord_ref_sys_code = " + code;
|
701 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
702 |
|
703 |
try {
|
704 |
result.next(); |
705 |
Object[]data = new Object[5]; |
706 |
data[0] = String.valueOf(result.getInt("coord_ref_sys_code")); |
707 |
data[1] = result.getString("coord_ref_sys_name"); |
708 |
crs_kind = result.getString("coord_ref_sys_kind");
|
709 |
data[2] = crs_kind;
|
710 |
projection_conv_code = result.getInt("projection_conv_code");
|
711 |
|
712 |
int area_of_use_code = Integer.parseInt(result.getString("area_of_use_code")); |
713 |
|
714 |
sentence = "SELECT area_name, area_of_use FROM epsg_area " +
|
715 |
"WHERE area_code = "+ area_of_use_code ;
|
716 |
|
717 |
ResultSet result2 = Query.select(sentence,connect.getConnection()); |
718 |
result2.next(); |
719 |
data[3] = result2.getString("area_name"); |
720 |
data[4] = result2.getString("area_of_use"); |
721 |
|
722 |
dtm.addRow(data); |
723 |
} |
724 |
|
725 |
catch (SQLException e1) { |
726 |
logger.error("Can't get values from RecordSet (sentence='"+sentence+"').",e1); |
727 |
} |
728 |
} |
729 |
/**
|
730 |
* Controla si se pulsa intro en el cuadro de texto,
|
731 |
* en ese caso se interpreta como si hubiese pulsado el botn 'Buscar'
|
732 |
*/
|
733 |
public void keyPressed(KeyEvent e) { |
734 |
if (e.getSource() == this.getSearchTextField()) { |
735 |
if (e.getKeyCode() == 10) { |
736 |
searchButton(); |
737 |
} |
738 |
} |
739 |
} |
740 |
|
741 |
public void keyReleased(KeyEvent e) { |
742 |
|
743 |
} |
744 |
|
745 |
public void keyTyped(KeyEvent e) { |
746 |
|
747 |
} |
748 |
|
749 |
/**
|
750 |
* Maneja los eventos de los botones y los radioButtons del panel
|
751 |
* de la EPSG.
|
752 |
*/
|
753 |
public void actionPerformed(ActionEvent e) { |
754 |
/*Si el objeto que genera el evento es el RadioButton 'Codigo'-->
|
755 |
resetea el texto de bsqueda*/
|
756 |
if (e.getSource() == this.getCodeRadioButton()) { |
757 |
searchTextField.setText("");
|
758 |
} |
759 |
/*Si el objeto que genera el evento es el RadioButton 'Nombre'-->
|
760 |
resetea el texto de bsqueda*/
|
761 |
if (e.getSource() == this.getNameRadioButton()) { |
762 |
searchTextField.setText("");
|
763 |
} |
764 |
/*Si el objeto que genera el evento es el RadioButton 'Area'-->
|
765 |
resetea el texto de bsqueda*/
|
766 |
if (e.getSource() == this.getAreaRadioButton()) { |
767 |
searchTextField.setText("");
|
768 |
} |
769 |
/*Si el objeto que genera el evento es el JButton 'Buscar'-->
|
770 |
Comprueba que no est vacio*/
|
771 |
if (e.getSource() == this.getSearchButton()) { |
772 |
searchTextField.setBackground(Color.white);
|
773 |
if (searchTextField.getText().equals("")) { |
774 |
searchTextField.setBackground(new Color(255,204,204)); |
775 |
JOptionPane.showMessageDialog(EPSGpanel.this,
|
776 |
PluginServices.getText(this,"fill_name"), |
777 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
778 |
} |
779 |
else {
|
780 |
searchButton(); |
781 |
} |
782 |
} |
783 |
/*Si el objeto que genera el evento es el JButton 'InfoCrs'
|
784 |
se muestra la informacin ralicionada con el Crs seleccionado en la tabla*/
|
785 |
if (e.getSource() == this.getInfoCrs()) { |
786 |
InfoCRSPanel info = new InfoCRSPanel("EPSG", getCodeCRS()); |
787 |
PluginServices.getMDIManager().addWindow(info); |
788 |
} |
789 |
} |
790 |
/**
|
791 |
* Agrupa los botones de opcin
|
792 |
* @return
|
793 |
*/
|
794 |
public ButtonGroup getOptGroup() { |
795 |
if (optGroup==null){ |
796 |
optGroup=new ButtonGroup(); |
797 |
optGroup.add(getCodeRadioButton()); |
798 |
optGroup.add(getNameRadioButton()); |
799 |
optGroup.add(getAreaRadioButton()); |
800 |
} |
801 |
return optGroup;
|
802 |
} |
803 |
|
804 |
public void setProjectionCode(int projCode) { |
805 |
String sentence = "SELECT coord_op_method_code " + |
806 |
"FROM epsg_coordoperation " +
|
807 |
"WHERE coord_op_code = " + projCode;
|
808 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
809 |
try {
|
810 |
while (result.next()){
|
811 |
projectionCode = result.getInt("coord_op_method_code");
|
812 |
} |
813 |
} catch (SQLException e) { |
814 |
logger.error("Can't get values from RecordSet (sentence='"+sentence+"').",e); |
815 |
} |
816 |
} |
817 |
|
818 |
public int getProjectionCode(String code) { |
819 |
int cod= Integer.parseInt(code); |
820 |
|
821 |
String sentence = "SELECT projection_conv_code " + |
822 |
"FROM epsg_coordinatereferencesystem " +
|
823 |
"WHERE coord_ref_sys_code = " + code;
|
824 |
|
825 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
826 |
int projCode = 0; |
827 |
try {
|
828 |
while (result.next()){
|
829 |
projCode = result.getInt("projection_conv_code");
|
830 |
} |
831 |
} catch (SQLException e1) { |
832 |
logger.error("Can't get values from RecordSet (sentence='"+sentence+"').",e1); |
833 |
} |
834 |
sentence = "SELECT coord_op_method_code " +
|
835 |
"FROM epsg_coordoperation " +
|
836 |
"WHERE coord_op_code = " + projCode;
|
837 |
|
838 |
result = Query.select(sentence,connect.getConnection());
|
839 |
try {
|
840 |
while (result.next()){
|
841 |
projectionCode = result.getInt("coord_op_method_code");
|
842 |
} |
843 |
} catch (SQLException e) { |
844 |
logger.error("Can't get values from RecordSet (sentence='"+sentence+"').",e); |
845 |
} |
846 |
return projectionCode;
|
847 |
} |
848 |
} |