root / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / NewCRSPanel.java @ 18259
History | View | Annotate | Download (23.6 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.BorderLayout; |
44 |
import java.awt.Color; |
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.sql.ResultSet; |
53 |
import java.sql.SQLException; |
54 |
|
55 |
import javax.swing.ButtonGroup; |
56 |
import javax.swing.JButton; |
57 |
import javax.swing.JDialog; |
58 |
import javax.swing.JLabel; |
59 |
import javax.swing.JOptionPane; |
60 |
import javax.swing.JPanel; |
61 |
import javax.swing.JRadioButton; |
62 |
import javax.swing.JScrollPane; |
63 |
import javax.swing.JTable; |
64 |
import javax.swing.JTextField; |
65 |
import javax.swing.ListSelectionModel; |
66 |
import javax.swing.border.CompoundBorder; |
67 |
import javax.swing.border.EmptyBorder; |
68 |
import javax.swing.table.DefaultTableModel; |
69 |
import javax.swing.table.TableColumn; |
70 |
|
71 |
import org.gvsig.crs.CrsException; |
72 |
import org.gvsig.crs.CrsFactory; |
73 |
import org.gvsig.crs.ICrs; |
74 |
import org.gvsig.crs.gui.panels.wizard.MainPanel; |
75 |
import org.gvsig.crs.ogr.Iau2wkt; |
76 |
import org.gvsig.crs.persistence.CrsData; |
77 |
import org.gvsig.crs.persistence.RecentCRSsPersistence; |
78 |
|
79 |
import com.iver.andami.PluginServices; |
80 |
import com.iver.cit.gvsig.gui.TableSorter; |
81 |
|
82 |
import es.idr.teledeteccion.connection.EpsgConnection; |
83 |
import es.idr.teledeteccion.connection.Query; |
84 |
|
85 |
/**
|
86 |
* Crea la interfaz de definicin de un nuevo crs por el usuario
|
87 |
* @author Luisa Marina Fernandez Ruiz (luisam.fernandez@uclm.es)
|
88 |
* @author Jose Luis Gomez Martinez (joseluis.gomez@uclm.es)
|
89 |
*
|
90 |
*/
|
91 |
public class NewCRSPanel extends JPanel implements ActionListener,KeyListener{ |
92 |
private static final long serialVersionUID = 1L; |
93 |
|
94 |
private JRadioButton codeRadioButton = null; |
95 |
private JRadioButton nameRadioButton = null; |
96 |
private JLabel lblCriterio=null; |
97 |
private JButton searchButton = null; |
98 |
private JTextField searchTextField = null; |
99 |
private JButton infoCrs; |
100 |
private JButton btnNuevo; |
101 |
private JButton btnEditar; |
102 |
private JButton btnEliminar; |
103 |
private JScrollPane jScrollPane=null; |
104 |
private JTable jTable; |
105 |
public TableSorter sorter = null; |
106 |
public DefaultTableModel dtm = null; |
107 |
|
108 |
public String key; |
109 |
public EpsgConnection connect = null; |
110 |
public int selectedRowTable = -1; |
111 |
String cadWkt = ""; |
112 |
private int codeCRS = -1; |
113 |
private ICrs currentCrs;
|
114 |
|
115 |
public NewCRSPanel(){}
|
116 |
|
117 |
public NewCRSPanel(ICrs crs) {
|
118 |
super();
|
119 |
currentCrs = crs; |
120 |
initialize(); |
121 |
//fijar los listener de todos los componentes
|
122 |
setListener(); |
123 |
habilitarJbuttons(false);
|
124 |
} |
125 |
/**
|
126 |
* Inicializa this
|
127 |
*
|
128 |
*/
|
129 |
private void initialize(){ |
130 |
this.setLayout(new BorderLayout()); |
131 |
this.setBorder(new EmptyBorder(1,1,1,1)); |
132 |
//Este panel contiene los componentes de radio button
|
133 |
JPanel radio=new JPanel(); |
134 |
radio.setLayout(new GridLayout(1,4,10,0)); |
135 |
radio.add(getLblCriterio()); |
136 |
radio.add(getCodeRadioButton()); |
137 |
radio.add(getNameRadioButton()); |
138 |
//Agrupar los radioButtons
|
139 |
agruparRadioButtons(); |
140 |
//Este panel contiene los componentes relacionados con la bsqueda
|
141 |
JPanel busqueda=new JPanel(); |
142 |
busqueda.setLayout(new FlowLayout(FlowLayout.LEFT,10,1)); |
143 |
busqueda.add(getSearchButton()); |
144 |
busqueda.add(getSearchTextField()); |
145 |
//busqueda.setBackground(Color.red);
|
146 |
JPanel pNorth=new JPanel(); |
147 |
pNorth.setLayout(new GridLayout(2,1)); |
148 |
pNorth.add(radio); |
149 |
pNorth.add(busqueda); |
150 |
this.add(pNorth,BorderLayout.NORTH); |
151 |
//agregar los botones de la tabla
|
152 |
JPanel pInSouth=new JPanel(); |
153 |
pInSouth.setLayout(new FlowLayout(FlowLayout.LEFT,10,0)); |
154 |
pInSouth.add(getInfoCrs()); |
155 |
pInSouth.add(getBtnNuevo()); |
156 |
pInSouth.add(getBtnEditar()); |
157 |
pInSouth.add(getBtnEliminar()); |
158 |
JPanel pCenter=new JPanel(); |
159 |
pCenter.setLayout(new BorderLayout()); |
160 |
pCenter.add(getJScrollPane(),BorderLayout.CENTER);
|
161 |
pCenter.add(pInSouth,BorderLayout.SOUTH);
|
162 |
this.add(pCenter,BorderLayout.CENTER); |
163 |
|
164 |
} |
165 |
|
166 |
public void connection(){ |
167 |
connect = new EpsgConnection();
|
168 |
connect.setConnectionUsr(); |
169 |
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* Inicializa el botn que muestra la informacin de CRS seleccionado
|
174 |
* @return
|
175 |
*/
|
176 |
public JButton getInfoCrs() { |
177 |
if(infoCrs == null) { |
178 |
infoCrs = new JButton(); |
179 |
infoCrs.setPreferredSize(new Dimension(85,23)); |
180 |
infoCrs.setText(PluginServices.getText(this,"infocrs")); |
181 |
infoCrs.setMnemonic('I');
|
182 |
infoCrs.setToolTipText(PluginServices.getText(this,"more_info")); |
183 |
|
184 |
} |
185 |
return infoCrs;
|
186 |
} |
187 |
/**
|
188 |
* Inicializa el panel que contiene la tabla de resultados
|
189 |
* @return
|
190 |
*/
|
191 |
private JScrollPane getJScrollPane() { |
192 |
if (jScrollPane == null) { |
193 |
jScrollPane = new JScrollPane(getJTable(),JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); |
194 |
jScrollPane.setPreferredSize(new Dimension(500,150)); |
195 |
jScrollPane.setBorder(new CompoundBorder(new EmptyBorder(3,10,3,10),jScrollPane.getBorder())); |
196 |
jScrollPane.setViewportView(getJTable()); |
197 |
} |
198 |
return jScrollPane;
|
199 |
} |
200 |
/**
|
201 |
* Inicializa la tabla que se utiliza para mostrar
|
202 |
* los resultados de la bsqueda
|
203 |
* @return
|
204 |
*/
|
205 |
public JTable getJTable() { |
206 |
if (jTable == null) { |
207 |
//TODO: Poner los titulos de las columnas correspondientes
|
208 |
String[] columnNames= {PluginServices.getText(this,"codigo"), |
209 |
PluginServices.getText(this,"nombre"), |
210 |
PluginServices.getText(this,"projected"), |
211 |
PluginServices.getText(this,"datum")}; |
212 |
Object[][]data = {}; |
213 |
dtm = new DefaultTableModel(data, columnNames) |
214 |
{ |
215 |
private static final long serialVersionUID = 1L; |
216 |
public boolean isCellEditable(int row, int column) { |
217 |
return false; |
218 |
} |
219 |
/*
|
220 |
* metodo necesario para cuando utilizamos tablas ordenadas
|
221 |
* ya que sino al ordenar por algun campo no se queda con el orden
|
222 |
* actual al seleccionar una fila (non-Javadoc)
|
223 |
* @see javax.swing.table.TableModel#getColumnClass(int)
|
224 |
*/
|
225 |
public Class getColumnClass(int column) |
226 |
{ |
227 |
return getValueAt(0, column).getClass(); |
228 |
} |
229 |
}; |
230 |
sorter = new TableSorter(dtm);
|
231 |
|
232 |
jTable = new JTable(sorter); |
233 |
sorter.setTableHeader(jTable.getTableHeader()); |
234 |
jTable.setCellSelectionEnabled(false);
|
235 |
jTable.setRowSelectionAllowed(true);
|
236 |
jTable.setColumnSelectionAllowed(false);
|
237 |
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
238 |
TableColumn column = null; |
239 |
for (int i = 0; i < columnNames.length; i++) { |
240 |
column = jTable.getColumnModel().getColumn(i); |
241 |
if (i == 0) { |
242 |
column.setPreferredWidth(80); //code column is shorter |
243 |
}else if (i ==2) { |
244 |
column.setPreferredWidth(50);
|
245 |
} else {
|
246 |
column.setPreferredWidth(175);
|
247 |
} |
248 |
|
249 |
} |
250 |
initializeTable(); |
251 |
} |
252 |
|
253 |
return jTable;
|
254 |
|
255 |
} |
256 |
|
257 |
public void initializeTable() { |
258 |
// Eliminar filas en cada nueva bsqueda
|
259 |
int numRow = dtm.getRowCount();
|
260 |
while (numRow != 0) { |
261 |
numRow = numRow - 1;
|
262 |
dtm.removeRow(numRow); |
263 |
} |
264 |
|
265 |
String sentence = "SELECT usr_code, usr_wkt, usr_proj, usr_geog, usr_datum " + |
266 |
"FROM USR ORDER BY usr_code ASC";
|
267 |
|
268 |
connect = new EpsgConnection();
|
269 |
connect.setConnectionUsr(); |
270 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
271 |
try {
|
272 |
connect.shutdown(); |
273 |
} catch (SQLException e) { |
274 |
// TODO Auto-generated catch block
|
275 |
e.printStackTrace(); |
276 |
} |
277 |
|
278 |
Object[] data = new Object[4]; |
279 |
try {
|
280 |
while (result.next()){
|
281 |
data[0] = result.getString("usr_code"); |
282 |
data[1] = result.getString("usr_wkt"); |
283 |
String proj = result.getString("usr_proj"); |
284 |
if (!proj.equals("")){ |
285 |
data[1] = proj;
|
286 |
data[2] = PluginServices.getText(this,"si"); |
287 |
} |
288 |
else
|
289 |
{ |
290 |
data[1] = result.getString("usr_geog"); |
291 |
data[2] = PluginServices.getText(this,"no"); |
292 |
} |
293 |
|
294 |
data[3] = result.getString("usr_datum"); |
295 |
dtm.addRow(data); |
296 |
} |
297 |
} catch (SQLException e1) { |
298 |
e1.printStackTrace(); |
299 |
} |
300 |
|
301 |
int numr = dtm.getRowCount();
|
302 |
if (numr > 0){ |
303 |
this.getJTable().setRowSelectionInterval(0,0); |
304 |
//getBtnEditar().setEnabled(true);
|
305 |
//getBtnEliminar().setEnabled(true);
|
306 |
} |
307 |
|
308 |
} |
309 |
/**
|
310 |
* Inicializa el radioButton 'Codigo'
|
311 |
* @return jRadioButton
|
312 |
*/
|
313 |
public JRadioButton getCodeRadioButton() { |
314 |
if (codeRadioButton == null) { |
315 |
codeRadioButton = new JRadioButton(); |
316 |
codeRadioButton.setText(PluginServices.getText(this,"por_codigo")); |
317 |
codeRadioButton.setSelected(true);
|
318 |
codeRadioButton.addActionListener(this);
|
319 |
} |
320 |
return codeRadioButton;
|
321 |
} |
322 |
/**
|
323 |
* Inicializa el radioButton 'Name'
|
324 |
* @return jRadioButton
|
325 |
*/
|
326 |
public JRadioButton getNameRadioButton() { |
327 |
if (nameRadioButton == null) { |
328 |
nameRadioButton = new JRadioButton(); |
329 |
nameRadioButton.setText(PluginServices.getText(this,"por_nombre")); |
330 |
nameRadioButton.addActionListener(this);
|
331 |
} |
332 |
return nameRadioButton;
|
333 |
} |
334 |
|
335 |
/**
|
336 |
* Agrupa los radioButtons
|
337 |
*/
|
338 |
private void agruparRadioButtons(){ |
339 |
ButtonGroup group= new ButtonGroup(); |
340 |
group.add(getCodeRadioButton()); |
341 |
group.add(getNameRadioButton()); |
342 |
} |
343 |
/**
|
344 |
* Inicializa el label 'Criterio de Bsqueda'
|
345 |
* @return jLabel
|
346 |
*/
|
347 |
public JLabel getLblCriterio() { |
348 |
lblCriterio = new JLabel(); |
349 |
lblCriterio.setText(PluginServices.getText(this, "criterio_busqueda")+":"); |
350 |
return lblCriterio;
|
351 |
} |
352 |
/**
|
353 |
* Inicializa el botn 'Buscar'
|
354 |
* @return jButton
|
355 |
*/
|
356 |
public JButton getSearchButton() { |
357 |
if (searchButton == null) { |
358 |
searchButton = new JButton(); |
359 |
searchButton.setPreferredSize(new Dimension(75,20)); |
360 |
searchButton.setText(PluginServices.getText(this,"buscar")); |
361 |
searchButton.setMnemonic('S');
|
362 |
searchButton.setToolTipText(PluginServices.getText(this,"buscar_por_criterio_seleccion")); |
363 |
|
364 |
} |
365 |
return searchButton;
|
366 |
} |
367 |
/**
|
368 |
* Inicializa el TextField
|
369 |
* en el que se incluye el texto a buscar
|
370 |
* @return jTextField
|
371 |
*/
|
372 |
public JTextField getSearchTextField() { |
373 |
if (searchTextField == null) { |
374 |
searchTextField = new JTextField(); |
375 |
searchTextField.setPreferredSize(new Dimension(340,20)); |
376 |
|
377 |
} |
378 |
return searchTextField;
|
379 |
} |
380 |
/**
|
381 |
* Manejador de eventos
|
382 |
*/
|
383 |
public void actionPerformed(ActionEvent e) { |
384 |
if (e.getSource().equals(getCodeRadioButton())){
|
385 |
getSearchTextField().setText("");
|
386 |
}else if (e.getSource().equals(getNameRadioButton())){ |
387 |
getSearchTextField().setText("");
|
388 |
}else if (e.getSource().equals(getBtnEditar())){ |
389 |
//editar la fila seleccionada de la tabla (si hay)
|
390 |
ICrs crs = null;
|
391 |
try {
|
392 |
crs = new CrsFactory().getCRS("USR:"+getCodeCRS()); |
393 |
} catch (CrsException e1) {
|
394 |
// TODO Auto-generated catch block
|
395 |
e1.printStackTrace(); |
396 |
} |
397 |
MainPanel wizard = new MainPanel(crs);
|
398 |
wizard.setEditing(true);
|
399 |
wizard.setEditingPanel(); |
400 |
PluginServices.getMDIManager().addWindow(wizard); |
401 |
getNewCrs(wizard.getNewCrsCode()); |
402 |
|
403 |
/**
|
404 |
* Actualizamos recientes para que coja los cambios del crs
|
405 |
*/
|
406 |
/*
|
407 |
* Actualizar recientes...
|
408 |
*/
|
409 |
String authority = "USR"; |
410 |
String name = ""; |
411 |
if (wizard.getPSistCoord().getTxtNombreProy().getText().equals("")) { |
412 |
name = wizard.getPDatum().getTxtNombreCrs().getText(); |
413 |
} else {
|
414 |
name = wizard.getPSistCoord().getTxtNombreProy().getText(); |
415 |
} |
416 |
int code = getCodeCRS();
|
417 |
CrsData crsData = new CrsData(authority,code,name);
|
418 |
RecentCRSsPersistence persistence = new RecentCRSsPersistence(RecentCRSsPersistence.pluginClassInstance);
|
419 |
persistence.addCrsData(crsData); |
420 |
|
421 |
}else if (e.getSource().equals(getBtnEliminar())){ |
422 |
//eliminar la fila seleccionada de la tabla
|
423 |
int i = JOptionPane.showConfirmDialog(NewCRSPanel.this, "¿"+PluginServices.getText(this, "deleteUsr")+"?"); |
424 |
if (i==0) { |
425 |
connect = new EpsgConnection();
|
426 |
connect.setConnectionUsr(); |
427 |
String sentence = "DELETE FROM USR WHERE usr_code =" + getCodeCRS(); |
428 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
429 |
try {
|
430 |
connect.shutdown(); |
431 |
} catch (SQLException arg0) { |
432 |
// TODO Auto-generated catch block
|
433 |
arg0.printStackTrace(); |
434 |
} |
435 |
dtm.removeRow(getJTable().getSelectedRow()); |
436 |
} |
437 |
//searchButton();
|
438 |
}else if (e.getSource().equals(getBtnNuevo())){ |
439 |
//mostrar el asistente de nuevo crs
|
440 |
|
441 |
MainPanel wizard = new MainPanel(currentCrs);
|
442 |
if ((wizard.getPCard().getSelectedIndex() == 0) && wizard.getPCrsUsr().getRbCrsExistente().isSelected() ){ |
443 |
ICrs crs = wizard.getPCrsUsr().getCrs(); |
444 |
if (crs != null){ |
445 |
wizard.fillData(crs); |
446 |
} |
447 |
else wizard.fillData(wizard.getCrs());
|
448 |
} |
449 |
else if ((wizard.getPCard().getSelectedIndex() == 0) && wizard.getPCrsUsr().getRbNuevoCrs().isSelected() ){ |
450 |
wizard.cleanData(); |
451 |
} |
452 |
PluginServices.getMDIManager().addWindow(wizard); |
453 |
getNewCrs(wizard.getNewCrsCode()); |
454 |
|
455 |
}else if (e.getSource().equals(getSearchButton())){ |
456 |
searchButton(); |
457 |
} |
458 |
/*Si el objeto que genera el evento es el JButton 'InfoCrs'
|
459 |
se muestra la informacin ralicionada con el Crs seleccionado en la tabla*/
|
460 |
else if (e.getSource().equals(getInfoCrs())) { |
461 |
InfoCRSPanel info = new InfoCRSPanel("USR", getCodeCRS()); |
462 |
PluginServices.getMDIManager().addWindow(info); |
463 |
} |
464 |
} |
465 |
public void keyPressed(KeyEvent e) { |
466 |
//Si se pulsa intro-->Buscar
|
467 |
if (e.getSource() == this.getSearchTextField()) { |
468 |
if (e.getKeyCode() == 10) { |
469 |
searchTextField.setBackground(Color.white);
|
470 |
if (searchTextField.getText().equals("")) { |
471 |
initializeTable(); |
472 |
} |
473 |
else {
|
474 |
searchButton(); |
475 |
} |
476 |
} |
477 |
} |
478 |
} |
479 |
public void keyReleased(KeyEvent e) { |
480 |
|
481 |
} |
482 |
public void keyTyped(KeyEvent e) { |
483 |
|
484 |
} |
485 |
/**
|
486 |
* Inicializa el botn 'Editar' una fila de la tabla
|
487 |
* @return jButton
|
488 |
*/
|
489 |
public JButton getBtnEditar() { |
490 |
if (btnEditar==null){ |
491 |
btnEditar=new JButton(); |
492 |
btnEditar.setText(PluginServices.getText(this,"editar")); |
493 |
} |
494 |
return btnEditar;
|
495 |
} |
496 |
/**
|
497 |
* Inicializa el botn 'Eliminar' una fila de la tabla
|
498 |
* @return
|
499 |
*/
|
500 |
public JButton getBtnEliminar() { |
501 |
if (btnEliminar==null){ |
502 |
btnEliminar=new JButton(); |
503 |
btnEliminar.setText(PluginServices.getText(this,"eliminar")); |
504 |
} |
505 |
return btnEliminar;
|
506 |
} |
507 |
/**
|
508 |
* Inicializa el botn 'Nuevo' para la creacin de un nuevo Crs
|
509 |
* @return
|
510 |
*/
|
511 |
public JButton getBtnNuevo() { |
512 |
if (btnNuevo==null){ |
513 |
btnNuevo=new JButton(); |
514 |
btnNuevo.setText(PluginServices.getText(this,"nuevo")); |
515 |
} |
516 |
return btnNuevo;
|
517 |
} |
518 |
/**
|
519 |
* Establece los listener de todos los componentes
|
520 |
*/
|
521 |
private void setListener(){ |
522 |
getBtnEditar().addActionListener(this);
|
523 |
getBtnEliminar().addActionListener(this);
|
524 |
getBtnNuevo().addActionListener(this);
|
525 |
getInfoCrs().addActionListener(this);
|
526 |
getCodeRadioButton().addActionListener(this);
|
527 |
getNameRadioButton().addActionListener(this);
|
528 |
getSearchButton().addActionListener(this);
|
529 |
getSearchTextField().addKeyListener(this);
|
530 |
|
531 |
} |
532 |
private void habilitarJbuttons(boolean b){ |
533 |
getInfoCrs().setEnabled(b); |
534 |
getBtnEditar().setEnabled(b); |
535 |
getBtnEliminar().setEnabled(b); |
536 |
} |
537 |
|
538 |
/**
|
539 |
* Mtodo que controla la bsqueda de los CRS siguiendo los criterios
|
540 |
* de bsqueda que le hemos definido. Tambin gestiona los casos en que
|
541 |
* no encuentre CRS, o que los parmetros de bsqueda sean errneos. Si
|
542 |
* encuentra algn CRS pero no es soportado por la aplicacin
|
543 |
* aparecer el mensaje de informacin correspondiente.
|
544 |
*
|
545 |
*/
|
546 |
private void searchButton() { |
547 |
searchTextField.setBackground(Color.white);
|
548 |
|
549 |
if (codeRadioButton.isSelected() && (searchTextField.getText().length()!=searchTextField.getText().replaceAll("[^0-9]", "").length())){ |
550 |
JOptionPane.showMessageDialog(NewCRSPanel.this,
|
551 |
PluginServices.getText(this,"numeric_format"), |
552 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
553 |
searchTextField.setText("");
|
554 |
return;
|
555 |
} |
556 |
|
557 |
//Eliminar filas en cada nueva bsqueda
|
558 |
int numRow = dtm.getRowCount();
|
559 |
while (numRow != 0) { |
560 |
numRow = numRow - 1;
|
561 |
dtm.removeRow(numRow); |
562 |
} |
563 |
// Dependiendo de la opcion se realizada una busqueda
|
564 |
ResultSet result = null; |
565 |
|
566 |
if (searchTextField.getText().equals("")) { |
567 |
String sentence = "SELECT usr_code, usr_wkt, usr_proj, usr_geog, usr_datum " + |
568 |
"FROM USR ";
|
569 |
connect = new EpsgConnection();
|
570 |
connect.setConnectionUsr(); |
571 |
result = Query.select(sentence,connect.getConnection());
|
572 |
try {
|
573 |
connect.shutdown(); |
574 |
} catch (SQLException e) { |
575 |
// TODO Auto-generated catch block
|
576 |
e.printStackTrace(); |
577 |
} |
578 |
Object[] data = new Object[4]; |
579 |
try {
|
580 |
while (result.next()){
|
581 |
data[0] = result.getString("usr_code"); |
582 |
data[1] = result.getString("usr_wkt"); |
583 |
String proj = result.getString("usr_proj"); |
584 |
if (!proj.equals("")){ |
585 |
data[1] = proj;
|
586 |
data[2] = PluginServices.getText(this,"si"); |
587 |
} |
588 |
else
|
589 |
{ |
590 |
data[1] = result.getString("usr_geog"); |
591 |
data[2] = PluginServices.getText(this,"no"); |
592 |
} |
593 |
|
594 |
data[3] = result.getString("usr_datum"); |
595 |
dtm.addRow(data); |
596 |
} |
597 |
} catch (SQLException e1) { |
598 |
e1.printStackTrace(); |
599 |
} |
600 |
} |
601 |
|
602 |
else if (codeRadioButton.isSelected()) { |
603 |
|
604 |
key = searchTextField.getText(); |
605 |
int code = Integer.parseInt(key); |
606 |
String sentence = "SELECT usr_code, usr_wkt, usr_proj, usr_geog, usr_datum " + |
607 |
"FROM USR " +
|
608 |
"WHERE usr_code = " + code;
|
609 |
connect = new EpsgConnection();
|
610 |
connect.setConnectionUsr(); |
611 |
result = Query.select(sentence,connect.getConnection());
|
612 |
try {
|
613 |
connect.shutdown(); |
614 |
} catch (SQLException e) { |
615 |
// TODO Auto-generated catch block
|
616 |
e.printStackTrace(); |
617 |
} |
618 |
|
619 |
Object[] data = new Object[4]; |
620 |
try {
|
621 |
while (result.next()){
|
622 |
data[0] = result.getString("usr_code"); |
623 |
data[1] = result.getString("usr_wkt"); |
624 |
String proj = result.getString("usr_proj"); |
625 |
if (!proj.equals("")){ |
626 |
data[1] = proj;
|
627 |
data[2] = PluginServices.getText(this,"si"); |
628 |
} |
629 |
else
|
630 |
{ |
631 |
data[1] = result.getString("usr_geog"); |
632 |
data[2] = PluginServices.getText(this,"no"); |
633 |
} |
634 |
|
635 |
data[3] = result.getString("usr_datum"); |
636 |
dtm.addRow(data); |
637 |
} |
638 |
} catch (SQLException e1) { |
639 |
e1.printStackTrace(); |
640 |
} |
641 |
} |
642 |
else if (nameRadioButton.isSelected()) { |
643 |
key = searchTextField.getText(); |
644 |
String key2 = key.substring(0,1); |
645 |
String key3 = key.substring(1,key.length()); |
646 |
key2 = key2.toUpperCase(); |
647 |
|
648 |
String sentence = "SELECT usr_code, usr_wkt, usr_proj, usr_geog, usr_datum " + |
649 |
"FROM USR " +
|
650 |
"WHERE (usr_proj LIKE '%" + key + "%') OR (usr_proj LIKE '%"+ |
651 |
key.toUpperCase() +"%') " +
|
652 |
"OR (usr_proj LIKE '%" + key2+key3 +"%') OR " + |
653 |
"(usr_geog LIKE '%" + key + "%') OR (usr_geog LIKE '%"+ |
654 |
key.toUpperCase() +"%') " +
|
655 |
"OR (usr_geog LIKE '%" + key2+key3 +"%')"; |
656 |
|
657 |
connect = new EpsgConnection();
|
658 |
connect.setConnectionUsr(); |
659 |
result = Query.select(sentence,connect.getConnection());
|
660 |
try {
|
661 |
connect.shutdown(); |
662 |
} catch (SQLException e) { |
663 |
// TODO Auto-generated catch block
|
664 |
e.printStackTrace(); |
665 |
} |
666 |
|
667 |
Object[] data = new Object[4]; |
668 |
try {
|
669 |
while (result.next()){
|
670 |
data[0] = result.getString("usr_code"); |
671 |
data[1] = result.getString("usr_wkt"); |
672 |
String proj = result.getString("usr_proj"); |
673 |
if (!proj.equals("")){ |
674 |
data[1] = proj;
|
675 |
data[2] = PluginServices.getText(this,"si"); |
676 |
} |
677 |
else
|
678 |
{ |
679 |
data[1] = result.getString("usr_geog"); |
680 |
data[2] = PluginServices.getText(this,"no"); |
681 |
} |
682 |
|
683 |
data[3] = result.getString("usr_datum"); |
684 |
dtm.addRow(data); |
685 |
} |
686 |
} catch (SQLException e1) { |
687 |
e1.printStackTrace(); |
688 |
} |
689 |
} |
690 |
|
691 |
int numr = dtm.getRowCount();
|
692 |
if (numr == 0){ |
693 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this,"no_results"), "Warning...", |
694 |
JOptionPane.WARNING_MESSAGE);
|
695 |
} |
696 |
else {
|
697 |
this.getJTable().setRowSelectionInterval(0,0); |
698 |
} |
699 |
} |
700 |
|
701 |
public void setCodeCRS(int code) { |
702 |
codeCRS = code; |
703 |
} |
704 |
|
705 |
public int getCodeCRS() { |
706 |
return codeCRS;
|
707 |
} |
708 |
|
709 |
/**
|
710 |
* Consigue la cadena wkt del CRS seleccionado, y genera la cadena que ms
|
711 |
* tarde volver a ser tratada para la consecucin de una cadena wkt
|
712 |
* legible por la proj4.
|
713 |
*
|
714 |
*/
|
715 |
public void setWKT(){ |
716 |
int code = getCodeCRS();
|
717 |
String sentence = "SELECT usr_wkt " + |
718 |
"FROM USR " +
|
719 |
"WHERE usr_code = " + code;
|
720 |
|
721 |
|
722 |
connect = new EpsgConnection();
|
723 |
connect.setConnectionUsr(); |
724 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
725 |
try {
|
726 |
connect.shutdown(); |
727 |
} catch (SQLException e) { |
728 |
// TODO Auto-generated catch block
|
729 |
e.printStackTrace(); |
730 |
} |
731 |
try {
|
732 |
result.next(); |
733 |
cadWkt = result.getString("usr_wkt");
|
734 |
} catch (SQLException e1) { |
735 |
e1.printStackTrace(); |
736 |
} |
737 |
cadWkt = cadWkt.substring(0, cadWkt.length()-1) + ", AUTHORITY[\"USR\","+ getCodeCRS()+"]]"; |
738 |
|
739 |
} |
740 |
|
741 |
public String getWKT(){ |
742 |
return cadWkt;
|
743 |
} |
744 |
|
745 |
public ICrs getProjection() {
|
746 |
try {
|
747 |
ICrs crs = new CrsFactory().getCRS("USR:"+getCodeCRS()); |
748 |
return crs ;
|
749 |
} catch (CrsException e) {
|
750 |
e.printStackTrace(); |
751 |
} |
752 |
return null; |
753 |
} |
754 |
|
755 |
private void getNewCrs(int code) { |
756 |
if (code != -1) { |
757 |
// Eliminar filas en cada nueva bsqueda
|
758 |
int numRow = dtm.getRowCount();
|
759 |
while (numRow != 0) { |
760 |
numRow = numRow - 1;
|
761 |
dtm.removeRow(numRow); |
762 |
} |
763 |
String sentence = "SELECT usr_code, usr_wkt, usr_proj, usr_geog, usr_datum " + |
764 |
"FROM USR " +
|
765 |
"WHERE usr_code = " + code;
|
766 |
connect = new EpsgConnection();
|
767 |
connect.setConnectionUsr(); |
768 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
769 |
try {
|
770 |
connect.shutdown(); |
771 |
} catch (SQLException e) { |
772 |
// TODO Auto-generated catch block
|
773 |
e.printStackTrace(); |
774 |
} |
775 |
|
776 |
Object[] data = new Object[4]; |
777 |
try {
|
778 |
while (result.next()){
|
779 |
data[0] = result.getString("usr_code"); |
780 |
data[1] = result.getString("usr_wkt"); |
781 |
String proj = result.getString("usr_proj"); |
782 |
if (!proj.equals("")){ |
783 |
data[1] = proj;
|
784 |
data[2] = PluginServices.getText(this,"si"); |
785 |
} |
786 |
else
|
787 |
{ |
788 |
data[1] = result.getString("usr_geog"); |
789 |
data[2] = PluginServices.getText(this,"no"); |
790 |
} |
791 |
|
792 |
data[3] = result.getString("usr_datum"); |
793 |
dtm.addRow(data); |
794 |
} |
795 |
} catch (SQLException e1) { |
796 |
e1.printStackTrace(); |
797 |
} |
798 |
this.getJTable().setRowSelectionInterval(0,0); |
799 |
} |
800 |
} |
801 |
|
802 |
public boolean isInBD (int code) { |
803 |
String sentence = "SELECT usr_code " + |
804 |
"FROM USR " +
|
805 |
"WHERE usr_code ="+code;
|
806 |
|
807 |
connect = new EpsgConnection();
|
808 |
connect.setConnectionUsr(); |
809 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
810 |
try {
|
811 |
connect.shutdown(); |
812 |
} catch (SQLException e) { |
813 |
// TODO Auto-generated catch block
|
814 |
e.printStackTrace(); |
815 |
} |
816 |
try {
|
817 |
if (result.next()) {
|
818 |
return true; |
819 |
} |
820 |
} catch (SQLException e) { |
821 |
// TODO Auto-generated catch block
|
822 |
e.printStackTrace(); |
823 |
} |
824 |
return false; |
825 |
} |
826 |
|
827 |
} |