root / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / panels / EPSGpanel.java @ 8146
History | View | Annotate | Download (20.4 KB)
1 |
package org.gvsig.crs.gui.panels; |
---|---|
2 |
import java.awt.Color; |
3 |
import java.awt.Dimension; |
4 |
import java.awt.FlowLayout; |
5 |
import java.awt.GridLayout; |
6 |
import java.awt.event.ActionEvent; |
7 |
import java.awt.event.ActionListener; |
8 |
import java.awt.event.KeyEvent; |
9 |
import java.awt.event.KeyListener; |
10 |
import java.sql.ResultSet; |
11 |
import java.sql.SQLException; |
12 |
|
13 |
import javax.swing.BorderFactory; |
14 |
import javax.swing.JButton; |
15 |
import javax.swing.JLabel; |
16 |
import javax.swing.JOptionPane; |
17 |
import javax.swing.JPanel; |
18 |
import javax.swing.JRadioButton; |
19 |
import javax.swing.JScrollPane; |
20 |
import javax.swing.JTable; |
21 |
import javax.swing.JTextField; |
22 |
import javax.swing.ListSelectionModel; |
23 |
import javax.swing.table.DefaultTableModel; |
24 |
import javax.swing.table.TableColumn; |
25 |
|
26 |
import org.cresques.cts.IProjection; |
27 |
import org.gvsig.crs.CrsException; |
28 |
import org.gvsig.crs.CrsFactory; |
29 |
import org.gvsig.crs.EpsgConnection; |
30 |
import org.gvsig.crs.ICrs; |
31 |
import org.gvsig.crs.Query; |
32 |
import org.gvsig.crs.gui.InfoCRSPanel; |
33 |
import org.gvsig.crs.ogr.Epsg2wkt; |
34 |
import org.gvsig.crs.ogr.GetCRSepsg; |
35 |
|
36 |
import com.iver.andami.PluginServices; |
37 |
import com.iver.cit.gvsig.gui.TableSorter; |
38 |
|
39 |
public class EPSGpanel extends JPanel implements KeyListener, ActionListener{ |
40 |
|
41 |
/**
|
42 |
*
|
43 |
*/
|
44 |
private static final long serialVersionUID = 1L; |
45 |
public JPanel EPSGpanel = null; |
46 |
|
47 |
String cadWKT = ""; |
48 |
|
49 |
int transf = 0; |
50 |
public int epsg_code = 0; |
51 |
boolean source_yn = false; |
52 |
int source_cod = 0; |
53 |
int method_code = 0; |
54 |
int datum_code = 0; |
55 |
int projection_conv_code = 0; |
56 |
public String crs_kind = null; |
57 |
int[] valid_method_code = {9800, 9801, 9802, 9803, 9804, 9805, 9806, 9807, 9808, 9809, 9810, |
58 |
9811, 9812, 9813, 9814, 9815, 9816, 9817, 9602, 9659}; |
59 |
|
60 |
String[] soported_crs = {"projected","geographic 2D","geographic 3D", "engineering", "vertical", "compound", "geocentric"}; |
61 |
String[] not_soported_crs = {}; |
62 |
|
63 |
private JRadioButton codeRadioButton = null; |
64 |
private JRadioButton nameRadioButton = null; |
65 |
private JRadioButton areaRadioButton = null; |
66 |
private JPanel groupRadioButton = null; |
67 |
|
68 |
public EpsgConnection connect = null; |
69 |
|
70 |
private JButton infoCrs = null; |
71 |
private JButton searchButton = null; |
72 |
private JTextField searchTextField = null; |
73 |
public JTable jTable = null; |
74 |
private JScrollPane jScrollPane = null; |
75 |
public DefaultTableModel dtm = null; |
76 |
public String key; |
77 |
public int selectedRowTable = -1; |
78 |
|
79 |
private int codeCRS = -1; |
80 |
|
81 |
public EPSGpanel(){
|
82 |
initialize(); |
83 |
} |
84 |
|
85 |
private void initialize(){ |
86 |
this.setLayout(new GridLayout(3,3)); |
87 |
this.setLayout(new FlowLayout(FlowLayout.LEFT,10,10)); |
88 |
|
89 |
this.add(getGroupRadioButton(), null); |
90 |
this.add(getSearchButton(), null); |
91 |
this.add(getSearchTextField(), null); |
92 |
this.add(getInfoCrs(), null); |
93 |
this.add(getJScrollPane(), null); |
94 |
} |
95 |
|
96 |
public void connection(){ |
97 |
connect = new EpsgConnection();
|
98 |
connect.setConnectionEPSG(); |
99 |
} |
100 |
|
101 |
/* public JPanel getJPanelEPSG() { //TODO Eliminar esta funci?n.
|
102 |
if (EPSGpanel == null){
|
103 |
EPSGpanel = new JPanel();
|
104 |
EPSGpanel.setLayout(new GridLayout(3,3));
|
105 |
EPSGpanel.setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
|
106 |
|
107 |
EPSGpanel.add(getGroupRadioButton(), null);
|
108 |
EPSGpanel.add(getSearchButton(), null);
|
109 |
EPSGpanel.add(getSearchTextField(), null);
|
110 |
EPSGpanel.add(getInfoCrs(), null);
|
111 |
EPSGpanel.add(getJScrollPane(), null);
|
112 |
}
|
113 |
return EPSGpanel;
|
114 |
}*/
|
115 |
|
116 |
|
117 |
|
118 |
private JRadioButton getCodeRadioButton() { |
119 |
if (codeRadioButton == null) { |
120 |
codeRadioButton = new JRadioButton(); |
121 |
codeRadioButton.setText(PluginServices.getText(this,"Por c?digo"));//setText("By Code EPSG"); |
122 |
codeRadioButton.setSelected(true);
|
123 |
codeRadioButton.addActionListener(this);
|
124 |
} |
125 |
return codeRadioButton;
|
126 |
} |
127 |
|
128 |
private JRadioButton getNameRadioButton() { |
129 |
if (nameRadioButton == null) { |
130 |
nameRadioButton = new JRadioButton(); |
131 |
nameRadioButton.setText(PluginServices.getText(this,"Por nombre")); |
132 |
nameRadioButton.addActionListener(this);
|
133 |
} |
134 |
return nameRadioButton;
|
135 |
} |
136 |
|
137 |
private JRadioButton getAreaRadioButton() { |
138 |
if (areaRadioButton == null) { |
139 |
areaRadioButton = new JRadioButton(); |
140 |
areaRadioButton.setText(PluginServices.getText(this,"Por ?rea")); |
141 |
areaRadioButton.addActionListener(this);
|
142 |
} |
143 |
return areaRadioButton;
|
144 |
} |
145 |
|
146 |
private JPanel getGroupRadioButton() { |
147 |
if (groupRadioButton == null) { |
148 |
groupRadioButton = new JPanel(); |
149 |
groupRadioButton.setLayout(new GridLayout(1,0)); |
150 |
groupRadioButton.setPreferredSize(new Dimension(500,30)); |
151 |
groupRadioButton.add(getLabel()); |
152 |
groupRadioButton.add(getCodeRadioButton()); |
153 |
groupRadioButton.add(getNameRadioButton()); |
154 |
groupRadioButton.add(getAreaRadioButton()); |
155 |
} |
156 |
return groupRadioButton;
|
157 |
} |
158 |
|
159 |
private JLabel getLabel(){ |
160 |
JLabel criterio = new JLabel(); |
161 |
criterio.setPreferredSize(new Dimension(100, 20)); |
162 |
criterio.setText(PluginServices.getText(this, "Criterio de b?squeda: ")); |
163 |
return criterio;
|
164 |
} |
165 |
|
166 |
private void searchButton() { |
167 |
boolean not_valid = false; |
168 |
searchTextField.setBackground(Color.white);
|
169 |
|
170 |
if (searchTextField.getText().equals("")) { |
171 |
searchTextField.setBackground(new Color(255,204,204)); |
172 |
JOptionPane.showMessageDialog(this, "Fill the name of CRS.", "Warning...", JOptionPane.WARNING_MESSAGE); |
173 |
} |
174 |
|
175 |
else {
|
176 |
//Eliminar filas en cada nueva bsqueda
|
177 |
int numRow = dtm.getRowCount();
|
178 |
while (numRow != 0) { |
179 |
numRow = numRow - 1;
|
180 |
dtm.removeRow(numRow); |
181 |
} |
182 |
|
183 |
//Dependiendo de la opcion se realizada una busqueda
|
184 |
ResultSet result = null; |
185 |
ResultSet result2 = null; |
186 |
/*
|
187 |
* variable que indicara si la busqueda se hace primero en epsg_coordinatereferencesystem
|
188 |
* o en epsg_area; esto es debido a que HSQLDB no soporta la b?squeda simult?nea en ambas
|
189 |
* tablas, por lo cual hay que separar la b?squeda
|
190 |
*/
|
191 |
int bus = 2; |
192 |
if (codeRadioButton.isSelected()) {
|
193 |
bus=0;
|
194 |
key = searchTextField.getText(); |
195 |
int code = Integer.parseInt(key); |
196 |
String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, area_of_use_code, " + |
197 |
"source_geogcrs_code, projection_conv_code " +
|
198 |
"FROM epsg_coordinatereferencesystem " +
|
199 |
"WHERE coord_ref_sys_code = " + code;
|
200 |
|
201 |
result = Query.select(sentence,connect.getConnection());
|
202 |
|
203 |
} |
204 |
|
205 |
else if (nameRadioButton.isSelected()) { |
206 |
bus=0;
|
207 |
key = searchTextField.getText(); |
208 |
String key2 = key.substring(0,1); |
209 |
String key3 = key.substring(1,key.length()); |
210 |
key2 = key2.toUpperCase(); |
211 |
|
212 |
String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, " + |
213 |
"area_of_use_code, source_geogcrs_code, projection_conv_code " +
|
214 |
"FROM epsg_coordinatereferencesystem " +
|
215 |
"WHERE (coord_ref_sys_name LIKE '%" + key + "%') OR (coord_ref_sys_name LIKE '%"+ |
216 |
key.toUpperCase() +"%') " +
|
217 |
"OR (coord_ref_sys_name LIKE '%" + key2+key3 +"%')"; |
218 |
result = Query.select(sentence,connect.getConnection());
|
219 |
} |
220 |
|
221 |
else {
|
222 |
bus=1;
|
223 |
key = searchTextField.getText(); |
224 |
String key2 = key.substring(0,1); |
225 |
String key3 = key.substring(1,key.length()); |
226 |
key2 = key2.toUpperCase(); |
227 |
|
228 |
String sentence = "SELECT area_name, area_of_use, area_code " + |
229 |
"FROM epsg_area " +
|
230 |
"WHERE (area_name LIKE '%" + key + "%') OR (area_of_use LIKE '%" + key + "%') "+ |
231 |
"OR (area_name LIKE '%" + key.toUpperCase() + "%') OR (area_of_use LIKE '%" + key.toUpperCase() + "%') "+ |
232 |
"OR (area_name LIKE '%" + key2+key3 + "%') OR (area_of_use LIKE '%" + key2+key3 + "%') "; |
233 |
result = Query.select(sentence,connect.getConnection());
|
234 |
} |
235 |
|
236 |
if (bus==0){ |
237 |
try {
|
238 |
while(result.next()) {
|
239 |
Object[]data = new Object[5]; |
240 |
data[0] = String.valueOf(result.getInt("coord_ref_sys_code")); |
241 |
data[1] = result.getString("coord_ref_sys_name"); |
242 |
crs_kind = result.getString("coord_ref_sys_kind");
|
243 |
data[2] = crs_kind;
|
244 |
projection_conv_code = result.getInt("projection_conv_code");
|
245 |
|
246 |
int area_of_use_code = Integer.parseInt(result.getString("area_of_use_code")); |
247 |
|
248 |
String sentence = "SELECT area_name, area_of_use FROM epsg_area " + |
249 |
"WHERE area_code = "+ area_of_use_code ;
|
250 |
|
251 |
result2 = Query.select(sentence,connect.getConnection());
|
252 |
while(result2.next()){
|
253 |
data[3] = result2.getString("area_name"); |
254 |
data[4] = result2.getString("area_of_use"); |
255 |
} |
256 |
if (data[0]!=null && validCRS(projection_conv_code) && valid(crs_kind)){ |
257 |
dtm.addRow(data); |
258 |
} |
259 |
} |
260 |
} |
261 |
|
262 |
catch (SQLException e1) { |
263 |
e1.printStackTrace(); |
264 |
} |
265 |
} |
266 |
else if (bus==1){ |
267 |
try {
|
268 |
while(result.next()) {
|
269 |
Object[]data = new Object[5]; |
270 |
data[3] = result.getString("area_name"); |
271 |
data[4] = result.getString("area_of_use"); |
272 |
|
273 |
int area_of_use_code = Integer.parseInt(result.getString("area_code")); |
274 |
|
275 |
String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, " + |
276 |
"coord_ref_sys_kind, source_geogcrs_code, projection_conv_code " +
|
277 |
"FROM epsg_coordinatereferencesystem " +
|
278 |
"WHERE area_of_use_code = "+ area_of_use_code ;
|
279 |
|
280 |
result2 = Query.select(sentence,connect.getConnection());
|
281 |
while(result2.next()){
|
282 |
data[0] = String.valueOf(result2.getInt("coord_ref_sys_code")); |
283 |
data[1] = result2.getString("coord_ref_sys_name"); |
284 |
data[2] = result2.getString("coord_ref_sys_kind"); |
285 |
crs_kind = (String)data[2]; |
286 |
projection_conv_code = result2.getInt("projection_conv_code");
|
287 |
|
288 |
} |
289 |
/*
|
290 |
* Buscaremos solo aquellos CRS cuyas proyecciones esten entre las
|
291 |
* 16 soportadas por proj4 para ello creamos un metodo para validar
|
292 |
* si esta entre estas proyecciones
|
293 |
*/
|
294 |
if (data[0]!=null && validCRS(projection_conv_code) && valid(crs_kind)){ |
295 |
dtm.addRow(data); |
296 |
} |
297 |
if (notValid(crs_kind)){
|
298 |
not_valid = true;
|
299 |
} |
300 |
} |
301 |
} |
302 |
|
303 |
catch (SQLException e1) { |
304 |
e1.printStackTrace(); |
305 |
} |
306 |
} |
307 |
int numr = dtm.getRowCount();
|
308 |
if (not_valid){
|
309 |
JOptionPane.showMessageDialog(this, "CRS no soportado.", "Warning...", |
310 |
JOptionPane.WARNING_MESSAGE);
|
311 |
not_valid = false;
|
312 |
} |
313 |
else if (numr == 0 ){ |
314 |
JOptionPane.showMessageDialog(this, "Not Results found.", "Warning...", |
315 |
JOptionPane.WARNING_MESSAGE);
|
316 |
} |
317 |
else{
|
318 |
this.getJTable().setRowSelectionInterval(0,0); |
319 |
} |
320 |
} |
321 |
} |
322 |
|
323 |
/*
|
324 |
* metodo auxiliar que hara la comprobacion de si el CRS buscado pertenecera
|
325 |
* a los no soportados por proj4
|
326 |
*/
|
327 |
private boolean notValid(String kind){ |
328 |
for (int i = 0; i< not_soported_crs.length; i++){ |
329 |
if (kind.equals(not_soported_crs[i])){
|
330 |
return true; |
331 |
} |
332 |
} |
333 |
return false; |
334 |
} |
335 |
|
336 |
/*
|
337 |
* Metodo que comprueba si el CRS buscado pertenece a algun tipo de los que soporta
|
338 |
* la aplicacion
|
339 |
*/
|
340 |
private boolean valid(String kind){ |
341 |
for (int i = 0; i< soported_crs.length; i++){ |
342 |
if (kind.equals(soported_crs[i])){
|
343 |
return true; |
344 |
} |
345 |
} |
346 |
return false; |
347 |
} |
348 |
|
349 |
/*
|
350 |
* metodo auxiliar que nos servira para comprobar si la proyeccion del CRS seleccionado
|
351 |
* esta entre las 16 con las que trabaja proj4
|
352 |
*/
|
353 |
private boolean validCRS(int projection_conv_code2) { |
354 |
if (projection_conv_code2 == 0) return true; |
355 |
String sentence = "SELECT coord_op_method_code " + |
356 |
"FROM epsg_coordoperation " +
|
357 |
"WHERE coord_op_code = " + projection_conv_code;
|
358 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
359 |
try {
|
360 |
while (result.next()){
|
361 |
method_code = result.getInt("coord_op_method_code");
|
362 |
} |
363 |
} catch (SQLException e) { |
364 |
e.printStackTrace(); |
365 |
} |
366 |
|
367 |
for (int i = 0; i< valid_method_code.length; i++){ |
368 |
if (method_code == valid_method_code[i] ){
|
369 |
return true; |
370 |
} |
371 |
} |
372 |
return false; |
373 |
} |
374 |
|
375 |
|
376 |
private JButton getSearchButton() { |
377 |
if (searchButton == null) { |
378 |
searchButton = new JButton(); |
379 |
searchButton.setPreferredSize(new Dimension(75,20)); |
380 |
searchButton.setText(PluginServices.getText(this,"Buscar")); |
381 |
searchButton.setMnemonic('S');
|
382 |
searchButton.setToolTipText("Search of a CRS by selected criterion");
|
383 |
searchButton.addActionListener(this);
|
384 |
} |
385 |
return searchButton;
|
386 |
} |
387 |
|
388 |
private JTextField getSearchTextField() { |
389 |
if (searchTextField == null) { |
390 |
searchTextField = new JTextField(); |
391 |
searchTextField.setPreferredSize(new Dimension(300,20)); |
392 |
searchTextField.addKeyListener(this);
|
393 |
} |
394 |
|
395 |
return searchTextField;
|
396 |
} |
397 |
|
398 |
public JTable getJTable() { |
399 |
if (jTable == null) { |
400 |
String[] columnNames= {"Code of CRS","Name of CRS","Type of CRS","Name of Area","Description of Area"}; |
401 |
Object[][]data = {}; |
402 |
dtm = new DefaultTableModel(data, columnNames) |
403 |
{ |
404 |
public boolean isCellEditable(int row, int column) { |
405 |
return false; |
406 |
} |
407 |
/*
|
408 |
* metodo necesario para cuando utilizamos tablas ordenadas
|
409 |
* ya que sino al ordenar por algun campo no se queda con el orden
|
410 |
* actual al seleccionar una fila (non-Javadoc)
|
411 |
* @see javax.swing.table.TableModel#getColumnClass(int)
|
412 |
*/
|
413 |
public Class getColumnClass(int column) |
414 |
{ |
415 |
return getValueAt(0, column).getClass(); |
416 |
} |
417 |
}; |
418 |
TableSorter sorter = new TableSorter(dtm);
|
419 |
|
420 |
jTable = new JTable(sorter); |
421 |
sorter.setTableHeader(jTable.getTableHeader()); |
422 |
jTable.setCellSelectionEnabled(false);
|
423 |
jTable.setRowSelectionAllowed(true);
|
424 |
jTable.setColumnSelectionAllowed(false);
|
425 |
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
426 |
TableColumn column = null; |
427 |
for (int i = 0; i < 5; i++) { |
428 |
column = jTable.getColumnModel().getColumn(i); |
429 |
if (i == 0) { |
430 |
column.setPreferredWidth(40); //code column is shorter |
431 |
}else if (i == 2) { |
432 |
column.setPreferredWidth(80);
|
433 |
} |
434 |
else {
|
435 |
column.setPreferredWidth(160);
|
436 |
} |
437 |
} |
438 |
} |
439 |
return jTable;
|
440 |
|
441 |
} |
442 |
|
443 |
public void setCodeCRS(int code) { |
444 |
codeCRS = code; |
445 |
} |
446 |
|
447 |
public int getCodeCRS() { |
448 |
return codeCRS;
|
449 |
} |
450 |
|
451 |
private JScrollPane getJScrollPane() { |
452 |
if (jScrollPane == null) { |
453 |
jScrollPane = new JScrollPane(); |
454 |
jScrollPane.setPreferredSize(new Dimension(500,150)); |
455 |
jScrollPane.setBorder( |
456 |
BorderFactory.createCompoundBorder(
|
457 |
BorderFactory.createCompoundBorder(
|
458 |
BorderFactory.createTitledBorder(PluginServices.getText(this,"Coordinate Reference Systems")), |
459 |
BorderFactory.createEmptyBorder(5,5,5,5)), |
460 |
jScrollPane.getBorder())); |
461 |
jScrollPane.setViewportView(getJTable()); |
462 |
} |
463 |
return jScrollPane;
|
464 |
} |
465 |
|
466 |
public JButton getInfoCrs() { |
467 |
if(infoCrs == null) { |
468 |
infoCrs = new JButton(); |
469 |
infoCrs.setPreferredSize(new Dimension(75,20)); |
470 |
infoCrs.setText(PluginServices.getText(this,"InfoCrs")); |
471 |
infoCrs.setMnemonic('I');
|
472 |
infoCrs.setEnabled(false);
|
473 |
infoCrs.setToolTipText("Mostrar la informacion del Crs selecionado");
|
474 |
infoCrs.addActionListener(this);
|
475 |
} |
476 |
return infoCrs;
|
477 |
} |
478 |
|
479 |
|
480 |
public ICrs getProjection() {
|
481 |
try {
|
482 |
String txt = getWKT();
|
483 |
ICrs crs = new CrsFactory().getCRS(epsg_code, txt);
|
484 |
return crs ;
|
485 |
} catch (CrsException e) {
|
486 |
e.printStackTrace(); |
487 |
} |
488 |
return null; |
489 |
} |
490 |
|
491 |
|
492 |
public void setWKT(){ |
493 |
Epsg2wkt wkt = null;
|
494 |
|
495 |
epsg_code = getCodeCRS(); |
496 |
if (epsg_code != -1){ |
497 |
/*
|
498 |
* ahora que he escogido, recojo toda la informacion que me va a hacer falta
|
499 |
*/
|
500 |
String sentence = "SELECT source_geogcrs_code, projection_conv_code, " + |
501 |
"coord_ref_sys_kind, datum_code " +
|
502 |
"FROM epsg_coordinatereferencesystem " +
|
503 |
"WHERE coord_ref_sys_code = "+ epsg_code ;
|
504 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
505 |
|
506 |
try {
|
507 |
result.next(); |
508 |
source_cod = result.getInt("source_geogcrs_code");
|
509 |
projection_conv_code = result.getInt("projection_conv_code");
|
510 |
crs_kind = result.getString("coord_ref_sys_kind");
|
511 |
datum_code = result.getInt("datum_code");
|
512 |
} catch (SQLException e1) { |
513 |
e1.printStackTrace(); |
514 |
} |
515 |
|
516 |
if (datum_code != 0){ |
517 |
source_yn = true;
|
518 |
GetCRSepsg ep = new GetCRSepsg(epsg_code, source_yn, source_cod, projection_conv_code, connect);
|
519 |
ep.Getepsgdata(); |
520 |
} |
521 |
else if (source_cod != 0){ |
522 |
source_yn = false;
|
523 |
} |
524 |
else source_yn = true; |
525 |
|
526 |
GetCRSepsg ep = new GetCRSepsg(epsg_code, source_yn, source_cod, projection_conv_code, connect);
|
527 |
ep.Getepsgdata(); |
528 |
|
529 |
if (crs_kind.equals("geographic 2D") || crs_kind.equals("geographic 3D")){ |
530 |
wkt = new Epsg2wkt(ep , "geog"); |
531 |
} |
532 |
else if (crs_kind.equals("projected")){ |
533 |
wkt = new Epsg2wkt(ep, "proj"); |
534 |
} |
535 |
else if (crs_kind.equals("compound")){ |
536 |
wkt = new Epsg2wkt(ep,"comp"); |
537 |
} |
538 |
else if (crs_kind.equals("geocentric")){ |
539 |
wkt = new Epsg2wkt(ep,"geoc"); |
540 |
} |
541 |
} |
542 |
else {
|
543 |
JOptionPane.showMessageDialog(this, |
544 |
"No CRS selected.",
|
545 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
546 |
|
547 |
} |
548 |
cadWKT = wkt.getWKT(); |
549 |
} |
550 |
|
551 |
public String getWKT(){ |
552 |
return cadWKT;
|
553 |
} |
554 |
|
555 |
public void setProjection(IProjection crs) { |
556 |
//setCrs((ICrs) crs);
|
557 |
} |
558 |
|
559 |
/*
|
560 |
* Metodo para cargar en el CRS de la capa el CRS de la vista.
|
561 |
* Se utilizar? a la hora de arrancar la definici?n del CRS de la nueva capa
|
562 |
*/
|
563 |
public void loadViewCRS(int code){ |
564 |
connection(); |
565 |
String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, area_of_use_code, " + |
566 |
"source_geogcrs_code, projection_conv_code " +
|
567 |
"FROM epsg_coordinatereferencesystem " +
|
568 |
"WHERE coord_ref_sys_code = " + code;
|
569 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
570 |
|
571 |
try {
|
572 |
result.next(); |
573 |
Object[]data = new Object[5]; |
574 |
data[0] = String.valueOf(result.getInt("coord_ref_sys_code")); |
575 |
data[1] = result.getString("coord_ref_sys_name"); |
576 |
crs_kind = result.getString("coord_ref_sys_kind");
|
577 |
data[2] = crs_kind;
|
578 |
projection_conv_code = result.getInt("projection_conv_code");
|
579 |
|
580 |
int area_of_use_code = Integer.parseInt(result.getString("area_of_use_code")); |
581 |
|
582 |
sentence = "SELECT area_name, area_of_use FROM epsg_area " +
|
583 |
"WHERE area_code = "+ area_of_use_code ;
|
584 |
|
585 |
ResultSet result2 = Query.select(sentence,connect.getConnection()); |
586 |
result2.next(); |
587 |
data[3] = result2.getString("area_name"); |
588 |
data[4] = result2.getString("area_of_use"); |
589 |
|
590 |
dtm.addRow(data); |
591 |
} |
592 |
|
593 |
catch (SQLException e1) { |
594 |
e1.printStackTrace(); |
595 |
} |
596 |
} |
597 |
|
598 |
public void keyPressed(KeyEvent e) { |
599 |
// TODO Auto-generated method stub
|
600 |
if (e.getSource() == this.getSearchTextField()) { |
601 |
if (e.getKeyCode() == 10) { |
602 |
searchButton(); |
603 |
} |
604 |
if (codeRadioButton.isSelected()){
|
605 |
if ((e.getKeyCode() >= 48 && e.getKeyCode() <= 57) || e.getKeyCode() >= 96 && e.getKeyCode() <= 105 || |
606 |
(e.getKeyCode() >= 0 && e.getKeyCode()<= 31) || e.getKeyCode() == 127){ |
607 |
} |
608 |
else {
|
609 |
JOptionPane.showMessageDialog(EPSGpanel.this,
|
610 |
"Only number format.",
|
611 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
612 |
String aux = searchTextField.getText();
|
613 |
if (aux.length() == 1 || aux.length() == 0){ |
614 |
searchTextField.setText("");
|
615 |
} |
616 |
else {
|
617 |
searchTextField.setText(aux.substring(0, aux.length()-1)); |
618 |
} |
619 |
} |
620 |
} |
621 |
} |
622 |
|
623 |
} |
624 |
|
625 |
public void keyReleased(KeyEvent e) { |
626 |
// TODO Auto-generated method stub
|
627 |
|
628 |
} |
629 |
|
630 |
public void keyTyped(KeyEvent e) { |
631 |
// TODO Auto-generated method stub
|
632 |
|
633 |
} |
634 |
|
635 |
public void actionPerformed(ActionEvent e) { |
636 |
// TODO Auto-generated method stub
|
637 |
if (e.getSource() == this.getCodeRadioButton()) { |
638 |
searchTextField.setText("");
|
639 |
codeRadioButton.setSelected(true);
|
640 |
nameRadioButton.setSelected(false);
|
641 |
areaRadioButton.setSelected(false);
|
642 |
} |
643 |
|
644 |
if (e.getSource() == this.getNameRadioButton()) { |
645 |
searchTextField.setText("");
|
646 |
nameRadioButton.setSelected(true);
|
647 |
codeRadioButton.setSelected(false);
|
648 |
areaRadioButton.setSelected(false);
|
649 |
} |
650 |
|
651 |
if (e.getSource() == this.getAreaRadioButton()) { |
652 |
searchTextField.setText("");
|
653 |
areaRadioButton.setSelected(true);
|
654 |
codeRadioButton.setSelected(false);
|
655 |
nameRadioButton.setSelected(false);
|
656 |
} |
657 |
|
658 |
if (e.getSource() == this.getSearchButton()) { |
659 |
searchTextField.setBackground(Color.white);
|
660 |
if (searchTextField.getText().equals("")) { |
661 |
searchTextField.setBackground(new Color(255,204,204)); |
662 |
JOptionPane.showMessageDialog(EPSGpanel.this,
|
663 |
"Fill the key-word of the search.",
|
664 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
665 |
} |
666 |
else {
|
667 |
searchButton(); |
668 |
} |
669 |
} |
670 |
|
671 |
if (e.getSource() == this.getInfoCrs()) { |
672 |
InfoCRSPanel info = new InfoCRSPanel(getProjection());
|
673 |
info.setSize(new Dimension(550,350)); |
674 |
info.setLayout(new GridLayout(0,1)); |
675 |
info.setLayout(new FlowLayout(FlowLayout.LEFT,10,5)); |
676 |
PluginServices.getMDIManager().addWindow(info); |
677 |
} |
678 |
} |
679 |
|
680 |
} |