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