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