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