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