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