root / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / EPSGpanel.java @ 12202
History | View | Annotate | Download (24.2 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.crs.CrsException; |
71 |
import org.gvsig.crs.CrsFactory; |
72 |
import org.gvsig.crs.ICrs; |
73 |
import org.gvsig.crs.ogr.Epsg2wkt; |
74 |
import org.gvsig.crs.ogr.CrsEPSG; |
75 |
|
76 |
import com.iver.andami.PluginServices; |
77 |
import com.iver.cit.gvsig.gui.TableSorter; |
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 |
/**
|
137 |
* Construye el Objeto EpsgPanel
|
138 |
*
|
139 |
*/
|
140 |
public EPSGpanel(){
|
141 |
initialize(); |
142 |
} |
143 |
/*
|
144 |
* Define las propiedades y agrega los componentes del EPSGPanel
|
145 |
*/
|
146 |
private void initialize(){ |
147 |
this.setLayout(new BorderLayout()); |
148 |
JPanel pNorth=new JPanel(); |
149 |
pNorth.setLayout(new GridLayout(2,1)); |
150 |
pNorth.setBorder(BorderFactory.createEmptyBorder(3,3,3,3)); |
151 |
pNorth.add(getGroupRadioButton()); |
152 |
JPanel pInNorth = new JPanel(); |
153 |
pInNorth.setLayout(new FlowLayout(FlowLayout.LEFT,10,1)); |
154 |
pInNorth.add(getSearchButton()); |
155 |
pInNorth.add(getSearchTextField()); |
156 |
pNorth.add(pInNorth); |
157 |
this.add(pNorth,BorderLayout.NORTH); |
158 |
this.add(getJScrollPane(), BorderLayout.CENTER); |
159 |
JPanel pSouth=new JPanel(new FlowLayout(FlowLayout.RIGHT,10,3)); |
160 |
pSouth.add(getInfoCrs()); |
161 |
this.add(pSouth,BorderLayout.SOUTH); |
162 |
} |
163 |
/**
|
164 |
* Establece la conexin con la Base de Datos de la Epsg
|
165 |
*
|
166 |
*/
|
167 |
public void connection(){ |
168 |
connect = new EpsgConnection();
|
169 |
connect.setConnectionEPSG(); |
170 |
} |
171 |
/**
|
172 |
* Inicializa el botn de opcin 'cdigo'
|
173 |
* @return
|
174 |
*/
|
175 |
private JRadioButton getCodeRadioButton() { |
176 |
if (codeRadioButton == null) { |
177 |
codeRadioButton = new JRadioButton(); |
178 |
codeRadioButton.setText(PluginServices.getText(this,"por_codigo"));//setText("By Code EPSG"); |
179 |
codeRadioButton.setSelected(true);
|
180 |
codeRadioButton.addActionListener(this);
|
181 |
} |
182 |
return codeRadioButton;
|
183 |
} |
184 |
/**
|
185 |
* Inicializa el botn de opcin 'nombre'
|
186 |
* @return
|
187 |
*/
|
188 |
private JRadioButton getNameRadioButton() { |
189 |
if (nameRadioButton == null) { |
190 |
nameRadioButton = new JRadioButton(); |
191 |
nameRadioButton.setText(PluginServices.getText(this,"por_nombre")); |
192 |
nameRadioButton.addActionListener(this);
|
193 |
} |
194 |
return nameRadioButton;
|
195 |
} |
196 |
/**
|
197 |
* Inicializa el botn de opcin 'Area'
|
198 |
* @return
|
199 |
*/
|
200 |
private JRadioButton getAreaRadioButton() { |
201 |
if (areaRadioButton == null) { |
202 |
areaRadioButton = new JRadioButton(); |
203 |
areaRadioButton.setText(PluginServices.getText(this,"por_area")); |
204 |
areaRadioButton.addActionListener(this);
|
205 |
} |
206 |
return areaRadioButton;
|
207 |
} |
208 |
/**
|
209 |
* Obtiene el panel con todos los botones de opcin
|
210 |
* @return
|
211 |
*/
|
212 |
private JPanel getGroupRadioButton() { |
213 |
if (groupRadioButton == null) { |
214 |
groupRadioButton = new JPanel(); |
215 |
groupRadioButton.setLayout(new GridLayout(1,4)); |
216 |
groupRadioButton.add(getLblCriterio()); |
217 |
groupRadioButton.add(getCodeRadioButton()); |
218 |
groupRadioButton.add(getNameRadioButton()); |
219 |
groupRadioButton.add(getAreaRadioButton()); |
220 |
//agrupar los botones
|
221 |
getOptGroup(); |
222 |
} |
223 |
return groupRadioButton;
|
224 |
} |
225 |
/**
|
226 |
* Inicializa el laber 'Criterio de bsqueda'
|
227 |
* @return
|
228 |
*/
|
229 |
private JLabel getLblCriterio(){ |
230 |
lblCriterio = new JLabel(); |
231 |
lblCriterio.setText(PluginServices.getText(this, "criterio_busqueda")+":"); |
232 |
return lblCriterio;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* Mtodo que controla la bsqueda de los CRS siguiendo los criterios
|
237 |
* de bsqueda que le hemos definido. Tambin gestiona los casos en que
|
238 |
* no encuentre CRS, o que los parmetros de bsqueda sean errneos. Si
|
239 |
* encuentra algn CRS pero no es soportado por la aplicacin
|
240 |
* aparecer el mensaje de informacin correspondiente.
|
241 |
*
|
242 |
*/
|
243 |
private void searchButton() { |
244 |
boolean not_valid = false; |
245 |
boolean not_numeric = false; |
246 |
searchTextField.setBackground(Color.white);
|
247 |
|
248 |
if (searchTextField.getText().equals("")) { |
249 |
searchTextField.setBackground(new Color(255,204,204)); |
250 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this,"fill_name"), "Warning...", JOptionPane.WARNING_MESSAGE); |
251 |
} |
252 |
|
253 |
else {
|
254 |
//Eliminar filas en cada nueva bsqueda
|
255 |
int numRow = dtm.getRowCount();
|
256 |
while (numRow != 0) { |
257 |
numRow = numRow - 1;
|
258 |
dtm.removeRow(numRow); |
259 |
} |
260 |
|
261 |
if (codeRadioButton.isSelected() && (searchTextField.getText().length()!=searchTextField.getText().replaceAll("[^0-9]", "").length())){ |
262 |
not_numeric = true;
|
263 |
} |
264 |
|
265 |
//Dependiendo de la opcion se realizada una busqueda
|
266 |
ResultSet result = null; |
267 |
ResultSet result2 = null; |
268 |
/*
|
269 |
* variable que indicara si la busqueda se hace primero en epsg_coordinatereferencesystem
|
270 |
* o en epsg_area; esto es debido a que HSQLDB no soporta la bsqueda simultnea en ambas
|
271 |
* tablas, por lo cual hay que separar la bsqueda
|
272 |
*/
|
273 |
int bus = 2; |
274 |
if (codeRadioButton.isSelected() && !not_numeric) {
|
275 |
bus=0;
|
276 |
key = searchTextField.getText(); |
277 |
int code = Integer.parseInt(key); |
278 |
String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, area_of_use_code, " + |
279 |
"source_geogcrs_code, projection_conv_code " +
|
280 |
"FROM epsg_coordinatereferencesystem " +
|
281 |
"WHERE coord_ref_sys_code = " + code;
|
282 |
|
283 |
result = Query.select(sentence,connect.getConnection());
|
284 |
|
285 |
} |
286 |
|
287 |
else if (nameRadioButton.isSelected()) { |
288 |
bus=0;
|
289 |
key = searchTextField.getText(); |
290 |
String key2 = key.substring(0,1); |
291 |
String key3 = key.substring(1,key.length()); |
292 |
key2 = key2.toUpperCase(); |
293 |
|
294 |
String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, " + |
295 |
"area_of_use_code, source_geogcrs_code, projection_conv_code " +
|
296 |
"FROM epsg_coordinatereferencesystem " +
|
297 |
"WHERE (coord_ref_sys_name LIKE '%" + key + "%') OR (coord_ref_sys_name LIKE '%"+ |
298 |
key.toUpperCase() +"%') " +
|
299 |
"OR (coord_ref_sys_name LIKE '%" + key2+key3 +"%')"; |
300 |
result = Query.select(sentence,connect.getConnection());
|
301 |
} |
302 |
|
303 |
else if (areaRadioButton.isSelected()) { |
304 |
bus=1;
|
305 |
key = searchTextField.getText(); |
306 |
String key2 = key.substring(0,1); |
307 |
String key3 = key.substring(1,key.length()); |
308 |
key2 = key2.toUpperCase(); |
309 |
|
310 |
String sentence = "SELECT area_name, area_of_use, area_code " + |
311 |
"FROM epsg_area " +
|
312 |
"WHERE (area_name LIKE '%" + key + "%') OR (area_of_use LIKE '%" + key + "%') "+ |
313 |
"OR (area_name LIKE '%" + key.toUpperCase() + "%') OR (area_of_use LIKE '%" + key.toUpperCase() + "%') "+ |
314 |
"OR (area_name LIKE '%" + key2+key3 + "%') OR (area_of_use LIKE '%" + key2+key3 + "%') "; |
315 |
result = Query.select(sentence,connect.getConnection());
|
316 |
} |
317 |
|
318 |
if (bus==0){ |
319 |
try {
|
320 |
while(result.next()) {
|
321 |
Object[]data = new Object[5]; |
322 |
data[0] = String.valueOf(result.getInt("coord_ref_sys_code")); |
323 |
data[1] = result.getString("coord_ref_sys_name"); |
324 |
crs_kind = result.getString("coord_ref_sys_kind");
|
325 |
data[2] = crs_kind;
|
326 |
projection_conv_code = result.getInt("projection_conv_code");
|
327 |
|
328 |
int area_of_use_code = Integer.parseInt(result.getString("area_of_use_code")); |
329 |
|
330 |
String sentence = "SELECT area_name, area_of_use FROM epsg_area " + |
331 |
"WHERE area_code = "+ area_of_use_code ;
|
332 |
|
333 |
result2 = Query.select(sentence,connect.getConnection());
|
334 |
while(result2.next()){
|
335 |
data[3] = result2.getString("area_name"); |
336 |
data[4] = result2.getString("area_of_use"); |
337 |
} |
338 |
if (data[0]!=null && validCRS(projection_conv_code) && valid(crs_kind)){ |
339 |
dtm.addRow(data); |
340 |
} |
341 |
} |
342 |
} |
343 |
|
344 |
catch (SQLException e1) { |
345 |
e1.printStackTrace(); |
346 |
} |
347 |
} |
348 |
else if (bus==1){ |
349 |
try {
|
350 |
while(result.next()) {
|
351 |
Object[]data = new Object[5]; |
352 |
data[3] = result.getString("area_name"); |
353 |
data[4] = result.getString("area_of_use"); |
354 |
|
355 |
int area_of_use_code = Integer.parseInt(result.getString("area_code")); |
356 |
|
357 |
String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, " + |
358 |
"coord_ref_sys_kind, source_geogcrs_code, projection_conv_code " +
|
359 |
"FROM epsg_coordinatereferencesystem " +
|
360 |
"WHERE area_of_use_code = "+ area_of_use_code ;
|
361 |
|
362 |
result2 = Query.select(sentence,connect.getConnection());
|
363 |
while(result2.next()){
|
364 |
data[0] = String.valueOf(result2.getInt("coord_ref_sys_code")); |
365 |
data[1] = result2.getString("coord_ref_sys_name"); |
366 |
data[2] = result2.getString("coord_ref_sys_kind"); |
367 |
crs_kind = (String)data[2]; |
368 |
projection_conv_code = result2.getInt("projection_conv_code");
|
369 |
|
370 |
} |
371 |
/*
|
372 |
* Buscaremos solo aquellos CRS cuyas proyecciones esten entre las
|
373 |
* 16 soportadas por proj4 para ello creamos un metodo para validar
|
374 |
* si esta entre estas proyecciones
|
375 |
*/
|
376 |
if (data[0]!=null && validCRS(projection_conv_code) && valid(crs_kind)){ |
377 |
dtm.addRow(data); |
378 |
} |
379 |
if (notValid(crs_kind)){
|
380 |
not_valid = true;
|
381 |
} |
382 |
} |
383 |
} |
384 |
|
385 |
catch (SQLException e1) { |
386 |
e1.printStackTrace(); |
387 |
} |
388 |
} |
389 |
int numr = dtm.getRowCount();
|
390 |
if (not_valid){
|
391 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this,"crs_not_soported"), "Warning...", |
392 |
JOptionPane.WARNING_MESSAGE);
|
393 |
not_valid = false;
|
394 |
} |
395 |
else if (not_numeric) { |
396 |
JOptionPane.showMessageDialog(EPSGpanel.this,
|
397 |
PluginServices.getText(this,"numeric_format"), |
398 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
399 |
searchTextField.setText("");
|
400 |
} |
401 |
else if (numr == 0){ |
402 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this,"no_results"), "Warning...", |
403 |
JOptionPane.WARNING_MESSAGE);
|
404 |
} |
405 |
else{
|
406 |
this.getJTable().setRowSelectionInterval(0,0); |
407 |
} |
408 |
} |
409 |
} |
410 |
|
411 |
/**
|
412 |
* metodo auxiliar que hara la comprobacion de si el CRS buscado pertenecera
|
413 |
* a los no soportados por proj4
|
414 |
*/
|
415 |
private boolean notValid(String kind){ |
416 |
for (int i = 0; i< not_soported_crs.length; i++){ |
417 |
if (kind.equals(not_soported_crs[i])){
|
418 |
return true; |
419 |
} |
420 |
} |
421 |
return false; |
422 |
} |
423 |
|
424 |
/**
|
425 |
* Metodo que comprueba si el CRS buscado pertenece a algun tipo
|
426 |
* de los que soporta la aplicacion
|
427 |
*/
|
428 |
private boolean valid(String kind){ |
429 |
for (int i = 0; i< soported_crs.length; i++){ |
430 |
if (kind.equals(soported_crs[i])){
|
431 |
return true; |
432 |
} |
433 |
} |
434 |
return false; |
435 |
} |
436 |
|
437 |
/**
|
438 |
* metodo auxiliar que nos servira para comprobar si la proyeccion del CRS seleccionado
|
439 |
* esta entre las 16 con las que trabaja proj4
|
440 |
*/
|
441 |
private boolean validCRS(int projection_conv_code2) { |
442 |
if (projection_conv_code2 == 0) return true; |
443 |
String sentence = "SELECT coord_op_method_code " + |
444 |
"FROM epsg_coordoperation " +
|
445 |
"WHERE coord_op_code = " + projection_conv_code;
|
446 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
447 |
try {
|
448 |
while (result.next()){
|
449 |
method_code = result.getInt("coord_op_method_code");
|
450 |
} |
451 |
} catch (SQLException e) { |
452 |
e.printStackTrace(); |
453 |
} |
454 |
|
455 |
for (int i = 0; i< valid_method_code.length; i++){ |
456 |
if (method_code == valid_method_code[i] ){
|
457 |
return true; |
458 |
} |
459 |
} |
460 |
return false; |
461 |
} |
462 |
|
463 |
/**
|
464 |
* Inicializa el botn de bsqueda
|
465 |
* @return
|
466 |
*/
|
467 |
private JButton getSearchButton() { |
468 |
if (searchButton == null) { |
469 |
searchButton = new JButton(); |
470 |
searchButton.setPreferredSize(new Dimension(75,20)); |
471 |
searchButton.setText(PluginServices.getText(this,"buscar")); |
472 |
searchButton.setMnemonic('S');
|
473 |
searchButton.setToolTipText(PluginServices.getText(this,"buscar_por_criterio_seleccion")); |
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 bsqueda
|
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 cdigo se CRS
|
553 |
* @param code
|
554 |
*/
|
555 |
public void setCodeCRS(int code) { |
556 |
codeCRS = code; |
557 |
} |
558 |
/**
|
559 |
* Obtiene el cdigo 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 botn que muestra la informacin 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 |
infoCrs.setToolTipText(PluginServices.getText(this,"more_info")); |
592 |
infoCrs.addActionListener(this);
|
593 |
} |
594 |
return infoCrs;
|
595 |
} |
596 |
|
597 |
|
598 |
public ICrs getProjection() {
|
599 |
try {
|
600 |
String txt = getWKT();
|
601 |
//ICrs crs = new CrsFactory().getCRS(epsg_code, txt);
|
602 |
ICrs crs = new CrsFactory().getCRS("EPSG:"+epsg_code); |
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 parmetros cogidos directamente
|
613 |
* del repositorio de la EPSG, y ms adelante volveremos a tratarla
|
614 |
* para pasarla a una cadena 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 |
} |
644 |
else if (source_cod != 0){ |
645 |
source_yn = false;
|
646 |
} |
647 |
else source_yn = true; |
648 |
|
649 |
CrsEPSG ep = new CrsEPSG(epsg_code, source_yn, source_cod, projection_conv_code, connect);
|
650 |
|
651 |
if (crs_kind.equals("geographic 2D") || crs_kind.equals("geographic 3D")){ |
652 |
wkt = new Epsg2wkt(ep , "geog"); |
653 |
} |
654 |
else if (crs_kind.equals("projected")){ |
655 |
wkt = new Epsg2wkt(ep, "proj"); |
656 |
} |
657 |
else if (crs_kind.equals("compound")){ |
658 |
wkt = new Epsg2wkt(ep,"comp"); |
659 |
} |
660 |
else if (crs_kind.equals("geocentric")){ |
661 |
wkt = new Epsg2wkt(ep,"geoc"); |
662 |
} |
663 |
} |
664 |
else {
|
665 |
JOptionPane.showMessageDialog(this, |
666 |
PluginServices.getText(this,"crs_no_selected."), |
667 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
668 |
|
669 |
} |
670 |
cadWKT = wkt.getWKT(); |
671 |
} |
672 |
|
673 |
public String getWKT(){ |
674 |
return cadWKT;
|
675 |
} |
676 |
|
677 |
public void setProjection(IProjection crs) { |
678 |
//setCrs((ICrs) crs);
|
679 |
} |
680 |
|
681 |
/**
|
682 |
* Metodo para cargar en el CRS de la capa el CRS de la vista.
|
683 |
* Se utilizar a la hora de arrancar la definicin del CRS de la nueva capa
|
684 |
*/
|
685 |
public void loadViewCRS(int code){ |
686 |
connection(); |
687 |
String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, area_of_use_code, " + |
688 |
"source_geogcrs_code, projection_conv_code " +
|
689 |
"FROM epsg_coordinatereferencesystem " +
|
690 |
"WHERE coord_ref_sys_code = " + code;
|
691 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
692 |
|
693 |
try {
|
694 |
result.next(); |
695 |
Object[]data = new Object[5]; |
696 |
data[0] = String.valueOf(result.getInt("coord_ref_sys_code")); |
697 |
data[1] = result.getString("coord_ref_sys_name"); |
698 |
crs_kind = result.getString("coord_ref_sys_kind");
|
699 |
data[2] = crs_kind;
|
700 |
projection_conv_code = result.getInt("projection_conv_code");
|
701 |
|
702 |
int area_of_use_code = Integer.parseInt(result.getString("area_of_use_code")); |
703 |
|
704 |
sentence = "SELECT area_name, area_of_use FROM epsg_area " +
|
705 |
"WHERE area_code = "+ area_of_use_code ;
|
706 |
|
707 |
ResultSet result2 = Query.select(sentence,connect.getConnection()); |
708 |
result2.next(); |
709 |
data[3] = result2.getString("area_name"); |
710 |
data[4] = result2.getString("area_of_use"); |
711 |
|
712 |
dtm.addRow(data); |
713 |
} |
714 |
|
715 |
catch (SQLException e1) { |
716 |
e1.printStackTrace(); |
717 |
} |
718 |
} |
719 |
/**
|
720 |
* Controla si se pulsa intro en el cuadro de texto,
|
721 |
* en ese caso se interpreta como si hubiese pulsado el botn 'Buscar'
|
722 |
*/
|
723 |
public void keyPressed(KeyEvent e) { |
724 |
if (e.getSource() == this.getSearchTextField()) { |
725 |
if (e.getKeyCode() == 10) { |
726 |
searchButton(); |
727 |
} |
728 |
} |
729 |
} |
730 |
|
731 |
public void keyReleased(KeyEvent e) { |
732 |
|
733 |
} |
734 |
|
735 |
public void keyTyped(KeyEvent e) { |
736 |
|
737 |
} |
738 |
|
739 |
/**
|
740 |
* Maneja los eventos de los botones y los radioButtons del panel
|
741 |
* de la EPSG.
|
742 |
*/
|
743 |
public void actionPerformed(ActionEvent e) { |
744 |
/*Si el objeto que genera el evento es el RadioButton 'Codigo'-->
|
745 |
resetea el texto de bsqueda*/
|
746 |
if (e.getSource() == this.getCodeRadioButton()) { |
747 |
searchTextField.setText("");
|
748 |
} |
749 |
/*Si el objeto que genera el evento es el RadioButton 'Nombre'-->
|
750 |
resetea el texto de bsqueda*/
|
751 |
if (e.getSource() == this.getNameRadioButton()) { |
752 |
searchTextField.setText("");
|
753 |
} |
754 |
/*Si el objeto que genera el evento es el RadioButton 'Area'-->
|
755 |
resetea el texto de bsqueda*/
|
756 |
if (e.getSource() == this.getAreaRadioButton()) { |
757 |
searchTextField.setText("");
|
758 |
} |
759 |
/*Si el objeto que genera el evento es el JButton 'Buscar'-->
|
760 |
Comprueba que no est vacio*/
|
761 |
if (e.getSource() == this.getSearchButton()) { |
762 |
searchTextField.setBackground(Color.white);
|
763 |
if (searchTextField.getText().equals("")) { |
764 |
searchTextField.setBackground(new Color(255,204,204)); |
765 |
JOptionPane.showMessageDialog(EPSGpanel.this,
|
766 |
PluginServices.getText(this,"fill_name"), |
767 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
768 |
} |
769 |
else {
|
770 |
searchButton(); |
771 |
} |
772 |
} |
773 |
/*Si el objeto que genera el evento es el JButton 'InfoCrs'
|
774 |
se muestra la informacin ralicionada con el Crs seleccionado en la tabla*/
|
775 |
if (e.getSource() == this.getInfoCrs()) { |
776 |
InfoCRSPanel info = new InfoCRSPanel("EPSG", getCodeCRS()); |
777 |
PluginServices.getMDIManager().addWindow(info); |
778 |
} |
779 |
} |
780 |
/**
|
781 |
* Agrupa los botones de opcin
|
782 |
* @return
|
783 |
*/
|
784 |
public ButtonGroup getOptGroup() { |
785 |
if (optGroup==null){ |
786 |
optGroup=new ButtonGroup(); |
787 |
optGroup.add(getCodeRadioButton()); |
788 |
optGroup.add(getNameRadioButton()); |
789 |
optGroup.add(getAreaRadioButton()); |
790 |
} |
791 |
return optGroup;
|
792 |
} |
793 |
} |