root / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / ESRIpanel.java @ 12202
History | View | Annotate | Download (14.7 KB)
1 |
/* gvSIG. Sistema de Informacin Geogrfica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ibez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.crs.gui.panels; |
42 |
import java.awt.BorderLayout; |
43 |
import java.awt.Color; |
44 |
import java.awt.Dimension; |
45 |
import java.awt.FlowLayout; |
46 |
import java.awt.GridLayout; |
47 |
import java.awt.event.ActionEvent; |
48 |
import java.awt.event.ActionListener; |
49 |
import java.awt.event.KeyEvent; |
50 |
import java.awt.event.KeyListener; |
51 |
import java.sql.ResultSet; |
52 |
import java.sql.SQLException; |
53 |
|
54 |
import javax.swing.BorderFactory; |
55 |
import javax.swing.JButton; |
56 |
import javax.swing.JLabel; |
57 |
import javax.swing.JOptionPane; |
58 |
import javax.swing.JPanel; |
59 |
import javax.swing.JRadioButton; |
60 |
import javax.swing.JScrollPane; |
61 |
import javax.swing.JTable; |
62 |
import javax.swing.JTextField; |
63 |
import javax.swing.ListSelectionModel; |
64 |
import javax.swing.table.DefaultTableModel; |
65 |
import javax.swing.table.TableColumn; |
66 |
|
67 |
import org.cresques.cts.IProjection; |
68 |
import org.gvsig.crs.CrsException; |
69 |
import org.gvsig.crs.CrsFactory; |
70 |
import org.gvsig.crs.ICrs; |
71 |
|
72 |
import com.iver.andami.PluginServices; |
73 |
import com.iver.cit.gvsig.gui.TableSorter; |
74 |
|
75 |
import es.idr.teledeteccion.connection.EpsgConnection; |
76 |
import es.idr.teledeteccion.connection.Query; |
77 |
|
78 |
|
79 |
/**
|
80 |
* Clase que genera el panel para el repositorio ESRI
|
81 |
*
|
82 |
* @author Jos Luis Gmez Martnez (jolugomar@gmail.com)
|
83 |
*
|
84 |
*/
|
85 |
public class ESRIpanel extends JPanel implements ActionListener, KeyListener { |
86 |
|
87 |
/**
|
88 |
*
|
89 |
*/
|
90 |
private static final long serialVersionUID = 1L; |
91 |
|
92 |
|
93 |
private JRadioButton codeRadioButton = null; |
94 |
private JRadioButton nameRadioButton = null; |
95 |
private JPanel groupRadioButton = null; |
96 |
public TableSorter sorter = null; |
97 |
public JTable jTable = null; |
98 |
private JScrollPane jScrollPane = null; |
99 |
private JButton searchButton = null; |
100 |
private JButton infoCrs=null; |
101 |
private JTextField searchTextField = null; |
102 |
public DefaultTableModel dtm = null; |
103 |
private int codeCRS = -1; |
104 |
public String key; |
105 |
String cadWKT;
|
106 |
public int selectedRowTable = -1; |
107 |
|
108 |
public EpsgConnection connect = null; |
109 |
|
110 |
public ESRIpanel() {
|
111 |
initialize(); |
112 |
} |
113 |
|
114 |
private void initialize(){ |
115 |
this.setLayout(new BorderLayout()); |
116 |
JPanel pNorth=new JPanel(); |
117 |
pNorth.setLayout(new GridLayout(2,1)); |
118 |
pNorth.setBorder(BorderFactory.createEmptyBorder(3,3,3,3)); |
119 |
pNorth.add(getGroupRadioButton()); |
120 |
JPanel pInNorth = new JPanel(); |
121 |
pInNorth.setLayout(new FlowLayout(FlowLayout.LEFT,10,1)); |
122 |
pInNorth.add(getSearchButton()); |
123 |
pInNorth.add(getSearchTextField()); |
124 |
pNorth.add(pInNorth); |
125 |
this.add(pNorth,BorderLayout.NORTH); |
126 |
this.add(getJScrollPane(), BorderLayout.CENTER); |
127 |
JPanel pSouth=new JPanel(new FlowLayout(FlowLayout.RIGHT,10,3)); |
128 |
pSouth.add(getInfoCrs()); |
129 |
this.add(pSouth,BorderLayout.SOUTH); |
130 |
|
131 |
//probar asi y ver el resultado
|
132 |
/*this.setLayout(new GridLayout(2,3));
|
133 |
this.setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
|
134 |
this.add(getGroupRadioButton(), null);
|
135 |
this.add(getSearchButton(), null);
|
136 |
this.add(getSearchTextField(), null);
|
137 |
this.add(getJScrollPane(), null); */
|
138 |
} |
139 |
|
140 |
public void connection(){ |
141 |
connect = new EpsgConnection();
|
142 |
connect.setConnectionEsri(); |
143 |
} |
144 |
|
145 |
private JRadioButton getCodeRadioButton() { |
146 |
if (codeRadioButton == null) { |
147 |
codeRadioButton = new JRadioButton(); |
148 |
codeRadioButton.setText(PluginServices.getText(this,"por_codigo"));//setText("By Code EPSG"); |
149 |
codeRadioButton.setSelected(true);
|
150 |
codeRadioButton.addActionListener(this);
|
151 |
} |
152 |
return codeRadioButton;
|
153 |
} |
154 |
|
155 |
private JRadioButton getNameRadioButton() { |
156 |
if (nameRadioButton == null) { |
157 |
nameRadioButton = new JRadioButton(); |
158 |
nameRadioButton.setText(PluginServices.getText(this,"por_nombre")); |
159 |
nameRadioButton.addActionListener(this);
|
160 |
} |
161 |
return nameRadioButton;
|
162 |
} |
163 |
|
164 |
private JPanel getGroupRadioButton() { |
165 |
if (groupRadioButton == null) { |
166 |
groupRadioButton = new JPanel(); |
167 |
groupRadioButton.setLayout(new GridLayout(1,0)); |
168 |
groupRadioButton.setPreferredSize(new Dimension(500,30)); |
169 |
groupRadioButton.add(getLabel()); |
170 |
groupRadioButton.add(getCodeRadioButton()); |
171 |
groupRadioButton.add(getNameRadioButton()); |
172 |
} |
173 |
return groupRadioButton;
|
174 |
} |
175 |
|
176 |
private JLabel getLabel(){ |
177 |
JLabel criterio = new JLabel(); |
178 |
criterio.setPreferredSize(new Dimension(100, 20)); |
179 |
criterio.setText(PluginServices.getText(this, "criterio_busqueda")); |
180 |
return criterio;
|
181 |
} |
182 |
|
183 |
public JButton getInfoCrs() { |
184 |
if(infoCrs == null) { |
185 |
infoCrs = new JButton(); |
186 |
infoCrs.setPreferredSize(new Dimension(85,20)); |
187 |
infoCrs.setText(PluginServices.getText(this,"infocrs")); |
188 |
infoCrs.setMnemonic('I');
|
189 |
infoCrs.setEnabled(false);
|
190 |
infoCrs.setToolTipText(PluginServices.getText(this,"more_info")); |
191 |
infoCrs.addActionListener(this);
|
192 |
} |
193 |
return infoCrs;
|
194 |
} |
195 |
private JButton getSearchButton() { |
196 |
if (searchButton == null) { |
197 |
searchButton = new JButton(); |
198 |
searchButton.setPreferredSize(new Dimension(75,20)); |
199 |
searchButton.setText(PluginServices.getText(this,"buscar")); |
200 |
searchButton.setMnemonic('S');
|
201 |
searchButton.addActionListener(this);
|
202 |
} |
203 |
return searchButton;
|
204 |
} |
205 |
|
206 |
private JTextField getSearchTextField() { |
207 |
if (searchTextField == null) { |
208 |
searchTextField = new JTextField(); |
209 |
searchTextField.setPreferredSize(new Dimension(300,20)); |
210 |
searchTextField.addKeyListener(this);
|
211 |
} |
212 |
return searchTextField;
|
213 |
} |
214 |
|
215 |
public JTable getJTable() { |
216 |
if (jTable == null) { |
217 |
String[] columnNames= {PluginServices.getText(this,"codigo"), |
218 |
PluginServices.getText(this,"nombre"), |
219 |
PluginServices.getText(this,"projected"), |
220 |
PluginServices.getText(this,"datum")}; |
221 |
|
222 |
Object[][]data = {}; |
223 |
dtm = new DefaultTableModel(data, columnNames) |
224 |
{ |
225 |
private static final long serialVersionUID = 1L; |
226 |
public boolean isCellEditable(int row, int column) { |
227 |
return false; |
228 |
} |
229 |
/*
|
230 |
* metodo necesario para cuando utilizamos tablas ordenadas
|
231 |
* ya que sino al ordenar por algun campo no se queda con el orden
|
232 |
* actual al seleccionar una fila (non-Javadoc)
|
233 |
* @see javax.swing.table.TableModel#getColumnClass(int)
|
234 |
*/
|
235 |
public Class getColumnClass(int column) |
236 |
{ |
237 |
return getValueAt(0, column).getClass(); |
238 |
} |
239 |
}; |
240 |
sorter = new TableSorter(dtm);
|
241 |
|
242 |
jTable = new JTable(sorter); |
243 |
sorter.setTableHeader(jTable.getTableHeader()); |
244 |
jTable.setCellSelectionEnabled(false);
|
245 |
jTable.setRowSelectionAllowed(true);
|
246 |
jTable.setColumnSelectionAllowed(false);
|
247 |
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
248 |
TableColumn column = null; |
249 |
for (int i = 0; i < 4; i++) { |
250 |
column = jTable.getColumnModel().getColumn(i); |
251 |
if (i == 0) { |
252 |
column.setPreferredWidth(80); //code column is shorter |
253 |
}else if (i ==2) { |
254 |
column.setPreferredWidth(50);
|
255 |
} else {
|
256 |
column.setPreferredWidth(175);
|
257 |
} |
258 |
|
259 |
} |
260 |
} |
261 |
return jTable;
|
262 |
|
263 |
} |
264 |
|
265 |
public void setCodeCRS(int code) { |
266 |
codeCRS = code; |
267 |
} |
268 |
|
269 |
public int getCodeCRS() { |
270 |
return codeCRS;
|
271 |
} |
272 |
|
273 |
private JScrollPane getJScrollPane() { |
274 |
if (jScrollPane == null) { |
275 |
jScrollPane = new JScrollPane(); |
276 |
jScrollPane.setPreferredSize(new Dimension(500,150)); |
277 |
jScrollPane.setBorder( |
278 |
BorderFactory.createCompoundBorder(
|
279 |
BorderFactory.createCompoundBorder(
|
280 |
BorderFactory.createTitledBorder(PluginServices.getText(this,"ESRI")), |
281 |
BorderFactory.createEmptyBorder(5,5,5,5)), |
282 |
jScrollPane.getBorder())); |
283 |
jScrollPane.setViewportView(getJTable()); |
284 |
} |
285 |
return jScrollPane;
|
286 |
} |
287 |
|
288 |
public void keyPressed(KeyEvent e) { |
289 |
if (e.getSource() == this.getSearchTextField()){ |
290 |
if (e.getKeyCode() == 10) { |
291 |
searchButton(); |
292 |
} |
293 |
} |
294 |
} |
295 |
|
296 |
/**
|
297 |
* Mtodo que controla la bsqueda de CRS del repositorio de ESRI.
|
298 |
* Tambin maneja los errores en caso de que los parmetros de bsqueda
|
299 |
* sean errneos, o que no se encuentren resultados.
|
300 |
*
|
301 |
*/
|
302 |
private void searchButton() { |
303 |
searchTextField.setBackground(Color.white);
|
304 |
boolean not_numeric = false; |
305 |
|
306 |
if (searchTextField.getText().equals("")) { |
307 |
searchTextField.setBackground(new Color(255,204,204)); |
308 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this,"fill_name"), "Warning...", JOptionPane.WARNING_MESSAGE); |
309 |
} |
310 |
|
311 |
else {
|
312 |
//Eliminar filas en cada nueva bsqueda
|
313 |
int numRow = dtm.getRowCount();
|
314 |
while (numRow != 0) { |
315 |
numRow = numRow - 1;
|
316 |
dtm.removeRow(numRow); |
317 |
} |
318 |
|
319 |
if (codeRadioButton.isSelected() && (searchTextField.getText().length()!=searchTextField.getText().replaceAll("[^0-9]", "").length())){ |
320 |
not_numeric = true;
|
321 |
} |
322 |
|
323 |
//Dependiendo de la opcion se realizada una busqueda
|
324 |
ResultSet result = null; |
325 |
|
326 |
if (codeRadioButton.isSelected() && !not_numeric) {
|
327 |
|
328 |
key = searchTextField.getText(); |
329 |
int code = Integer.parseInt(key); |
330 |
String sentence = "SELECT esri_code, esri_wkt, esri_proj, esri_geog, esri_datum " + |
331 |
"FROM ESRI " +
|
332 |
"WHERE esri_code = " + code;
|
333 |
|
334 |
result = Query.select(sentence,connect.getConnection());
|
335 |
|
336 |
|
337 |
Object[] data = new Object[4]; |
338 |
try {
|
339 |
while (result.next()){
|
340 |
data[0] = result.getString("esri_code"); |
341 |
data[1] = result.getString("esri_wkt"); |
342 |
String proj = result.getString("esri_proj"); |
343 |
if (!proj.equals("")){ |
344 |
data[1] = proj;
|
345 |
data[2] = PluginServices.getText(this,"si"); |
346 |
} |
347 |
else
|
348 |
{ |
349 |
data[1] = result.getString("esri_geog"); |
350 |
data[2] = PluginServices.getText(this,"no"); |
351 |
} |
352 |
|
353 |
data[3] = result.getString("esri_datum"); |
354 |
dtm.addRow(data); |
355 |
} |
356 |
} catch (SQLException e1) { |
357 |
e1.printStackTrace(); |
358 |
} |
359 |
} |
360 |
else if (nameRadioButton.isSelected()) { |
361 |
key = searchTextField.getText(); |
362 |
String key2 = key.substring(0,1); |
363 |
String key3 = key.substring(1,key.length()); |
364 |
key2 = key2.toUpperCase(); |
365 |
|
366 |
String sentence = "SELECT esri_code, esri_wkt, esri_proj, esri_geog, esri_datum " + |
367 |
"FROM ESRI " +
|
368 |
"WHERE (esri_proj LIKE '%" + key + "%') OR (esri_proj LIKE '%"+ |
369 |
key.toUpperCase() +"%') " +
|
370 |
"OR (esri_proj LIKE '%" + key2+key3 +"%') OR " + |
371 |
"(esri_geog LIKE '%" + key + "%') OR (esri_geog LIKE '%"+ |
372 |
key.toUpperCase() +"%') " +
|
373 |
"OR (esri_geog LIKE '%" + key2+key3 +"%')"; |
374 |
|
375 |
result = Query.select(sentence,connect.getConnection());
|
376 |
|
377 |
Object[] data = new Object[4]; |
378 |
try {
|
379 |
while (result.next()){
|
380 |
data[0] = result.getString("esri_code"); |
381 |
data[1] = result.getString("esri_wkt"); |
382 |
String proj = result.getString("esri_proj"); |
383 |
if (!proj.equals("")){ |
384 |
data[1] = proj;
|
385 |
data[2] = PluginServices.getText(this,"si"); |
386 |
} |
387 |
else
|
388 |
{ |
389 |
data[1] = result.getString("esri_geog"); |
390 |
data[2] = PluginServices.getText(this,"no"); |
391 |
} |
392 |
|
393 |
data[3] = result.getString("esri_datum"); |
394 |
dtm.addRow(data); |
395 |
} |
396 |
} catch (SQLException e1) { |
397 |
e1.printStackTrace(); |
398 |
} |
399 |
} |
400 |
|
401 |
int numr = dtm.getRowCount();
|
402 |
if (not_numeric) {
|
403 |
JOptionPane.showMessageDialog(ESRIpanel.this,
|
404 |
PluginServices.getText(this,"numeric_format"), |
405 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
406 |
searchTextField.setText("");
|
407 |
} |
408 |
else if (numr == 0){ |
409 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this,"no_results"), "Warning...", |
410 |
JOptionPane.WARNING_MESSAGE);
|
411 |
} |
412 |
else{
|
413 |
this.getJTable().setRowSelectionInterval(0,0); |
414 |
} |
415 |
} |
416 |
} |
417 |
|
418 |
public void keyReleased(KeyEvent arg0) { |
419 |
|
420 |
} |
421 |
|
422 |
public void keyTyped(KeyEvent arg0) { |
423 |
|
424 |
} |
425 |
|
426 |
/**
|
427 |
* Maneja los eventos de los botones y los radioButtons del panel
|
428 |
* del repositorio ESRI.
|
429 |
*/
|
430 |
public void actionPerformed(ActionEvent e) { |
431 |
if (e.getSource() == this.getSearchButton()){ |
432 |
searchTextField.setBackground(Color.white);
|
433 |
if (searchTextField.getText().equals("")) { |
434 |
searchTextField.setBackground(new Color(255,204,204)); |
435 |
JOptionPane.showMessageDialog(ESRIpanel.this,
|
436 |
PluginServices.getText(this,"fill_name"), |
437 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
438 |
} |
439 |
else {
|
440 |
searchButton(); |
441 |
} |
442 |
} |
443 |
if (e.getSource() == this.getCodeRadioButton()) { |
444 |
searchTextField.setText("");
|
445 |
codeRadioButton.setSelected(true);
|
446 |
nameRadioButton.setSelected(false);
|
447 |
} |
448 |
|
449 |
if (e.getSource() == this.getNameRadioButton()) { |
450 |
searchTextField.setText("");
|
451 |
nameRadioButton.setSelected(true);
|
452 |
codeRadioButton.setSelected(false);
|
453 |
} |
454 |
|
455 |
/*Si el objeto que genera el evento es el JButton 'InfoCrs'
|
456 |
se muestra la informacin ralicionada con el Crs seleccionado en la tabla*/
|
457 |
if (e.getSource() == this.getInfoCrs()) { |
458 |
InfoCRSPanel info = new InfoCRSPanel("ESRI", getCodeCRS()); |
459 |
PluginServices.getMDIManager().addWindow(info); |
460 |
} |
461 |
} |
462 |
|
463 |
public ICrs getProjection() {
|
464 |
try {
|
465 |
String txt = getWKT();
|
466 |
//ICrs crs = new CrsFactory().getCRS("ESRI:"+getCodeCRS(), txt);
|
467 |
ICrs crs = new CrsFactory().getCRS("ESRI:"+getCodeCRS()); |
468 |
return crs ;
|
469 |
} catch (CrsException e) {
|
470 |
e.printStackTrace(); |
471 |
} |
472 |
return null; |
473 |
} |
474 |
|
475 |
/**
|
476 |
* Consigue la cadena wkt del CRS seleccionado, y genera la cadena que ms
|
477 |
* tarde volver a ser tratada para la consecucin de una cadena wkt
|
478 |
* legible por la proj4.
|
479 |
*
|
480 |
*/
|
481 |
public void setWKT(){ |
482 |
int code = getCodeCRS();
|
483 |
String sentence = "SELECT esri_wkt " + |
484 |
"FROM ESRI " +
|
485 |
"WHERE esri_code = " + code;
|
486 |
|
487 |
|
488 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
489 |
|
490 |
try {
|
491 |
result.next(); |
492 |
cadWKT = result.getString("esri_wkt");
|
493 |
} catch (SQLException e1) { |
494 |
e1.printStackTrace(); |
495 |
} |
496 |
cadWKT = cadWKT.substring(0, cadWKT.length()-1) + ", AUTHORITY[\"ESRI\","+ getCodeCRS()+"]]"; |
497 |
|
498 |
} |
499 |
|
500 |
public String getWKT(){ |
501 |
return cadWKT;
|
502 |
} |
503 |
|
504 |
public void setProjection(IProjection crs) { |
505 |
//setCrs((ICrs) crs);
|
506 |
} |
507 |
|
508 |
|
509 |
|
510 |
|
511 |
} |