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