svn-gvsig-desktop / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / panels / IAU2000panel.java @ 8304
History | View | Annotate | Download (13.4 KB)
1 |
package org.gvsig.crs.gui.panels; |
---|---|
2 |
|
3 |
import java.awt.Color; |
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.sql.ResultSet; |
12 |
import java.sql.SQLException; |
13 |
|
14 |
import javax.swing.BorderFactory; |
15 |
import javax.swing.JButton; |
16 |
import javax.swing.JLabel; |
17 |
import javax.swing.JOptionPane; |
18 |
import javax.swing.JPanel; |
19 |
import javax.swing.JRadioButton; |
20 |
import javax.swing.JScrollPane; |
21 |
import javax.swing.JTable; |
22 |
import javax.swing.JTextField; |
23 |
import javax.swing.ListSelectionModel; |
24 |
import javax.swing.table.DefaultTableModel; |
25 |
import javax.swing.table.TableColumn; |
26 |
|
27 |
import org.cresques.cts.IProjection; |
28 |
import org.gvsig.crs.CrsException; |
29 |
import org.gvsig.crs.CrsFactory; |
30 |
import org.gvsig.crs.EpsgConnection; |
31 |
import org.gvsig.crs.ICrs; |
32 |
import org.gvsig.crs.Query; |
33 |
|
34 |
import com.iver.andami.PluginServices; |
35 |
import com.iver.cit.gvsig.gui.TableSorter; |
36 |
|
37 |
public class IAU2000panel extends JPanel implements KeyListener, ActionListener { |
38 |
|
39 |
/**
|
40 |
*
|
41 |
*/
|
42 |
private static final long serialVersionUID = 1L; |
43 |
public JPanel IAU2000panel = null; |
44 |
|
45 |
private JRadioButton codeRadioButton = null; |
46 |
private JRadioButton nameRadioButton = null; |
47 |
private JPanel groupRadioButton = null; |
48 |
|
49 |
JLabel jLabel = null; |
50 |
JTextField crsTextFld = null; |
51 |
|
52 |
String cadWKT = ""; |
53 |
|
54 |
int transf = 0; |
55 |
boolean source_yn = false; |
56 |
int source_cod = 0; |
57 |
int method_code = 0; |
58 |
int datum_code = 0; |
59 |
int projection_conv_code = 0; |
60 |
public String crs_kind = null; |
61 |
|
62 |
public TableSorter sorter = null; |
63 |
|
64 |
public EpsgConnection connect = null; |
65 |
|
66 |
private JButton searchButton = null; |
67 |
private JTextField searchTextField = null; |
68 |
public JTable jTable = null; |
69 |
private JScrollPane jScrollPane = null; |
70 |
public DefaultTableModel dtm = null; |
71 |
public String key; |
72 |
public int selectedRowTable = -1; |
73 |
|
74 |
private int codeCRS = -1; |
75 |
|
76 |
public IAU2000panel() {
|
77 |
initialize(); |
78 |
} |
79 |
|
80 |
private void initialize(){ |
81 |
this.setLayout(new GridLayout(2,3)); |
82 |
this.setLayout(new FlowLayout(FlowLayout.LEFT,10,10)); |
83 |
this.add(getGroupRadioButton(), null); |
84 |
this.add(getSearchButton(), null); |
85 |
this.add(getSearchTextField(), null); |
86 |
this.add(getJScrollPane(), null); |
87 |
} |
88 |
|
89 |
public void connection(){ |
90 |
connect = new EpsgConnection();
|
91 |
|
92 |
|
93 |
} |
94 |
|
95 |
private JRadioButton getCodeRadioButton() { |
96 |
if (codeRadioButton == null) { |
97 |
codeRadioButton = new JRadioButton(); |
98 |
codeRadioButton.setText(PluginServices.getText(this,"por_codigo"));//setText("By Code EPSG"); |
99 |
codeRadioButton.setSelected(true);
|
100 |
codeRadioButton.addActionListener(this);
|
101 |
} |
102 |
return codeRadioButton;
|
103 |
} |
104 |
|
105 |
private JRadioButton getNameRadioButton() { |
106 |
if (nameRadioButton == null) { |
107 |
nameRadioButton = new JRadioButton(); |
108 |
nameRadioButton.setText(PluginServices.getText(this,"por_nombre")); |
109 |
nameRadioButton.addActionListener(this);
|
110 |
} |
111 |
return nameRadioButton;
|
112 |
} |
113 |
|
114 |
private JPanel getGroupRadioButton() { |
115 |
if (groupRadioButton == null) { |
116 |
groupRadioButton = new JPanel(); |
117 |
groupRadioButton.setLayout(new GridLayout(1,0)); |
118 |
groupRadioButton.setPreferredSize(new Dimension(500,30)); |
119 |
groupRadioButton.add(getLabel()); |
120 |
groupRadioButton.add(getCodeRadioButton()); |
121 |
groupRadioButton.add(getNameRadioButton()); |
122 |
} |
123 |
return groupRadioButton;
|
124 |
} |
125 |
|
126 |
private JLabel getLabel(){ |
127 |
JLabel criterio = new JLabel(); |
128 |
criterio.setPreferredSize(new Dimension(100, 20)); |
129 |
criterio.setText(PluginServices.getText(this, "criterio_busqueda")); |
130 |
return criterio;
|
131 |
} |
132 |
|
133 |
private void searchButton() { |
134 |
searchTextField.setBackground(Color.white);
|
135 |
|
136 |
if (searchTextField.getText().equals("")) { |
137 |
searchTextField.setBackground(new Color(255,204,204)); |
138 |
JOptionPane.showMessageDialog(this, "Fill the name of CRS.", "Warning...", JOptionPane.WARNING_MESSAGE); |
139 |
} |
140 |
|
141 |
else {
|
142 |
//Eliminar filas en cada nueva bsqueda
|
143 |
int numRow = dtm.getRowCount();
|
144 |
while (numRow != 0) { |
145 |
numRow = numRow - 1;
|
146 |
dtm.removeRow(numRow); |
147 |
} |
148 |
|
149 |
//Dependiendo de la opcion se realizada una busqueda
|
150 |
ResultSet result = null; |
151 |
|
152 |
if (codeRadioButton.isSelected()) {
|
153 |
|
154 |
key = searchTextField.getText(); |
155 |
int code = Integer.parseInt(key); |
156 |
String sentence = "SELECT iau_code, iau_wkt, iau_proj, iau_geog, iau_datum " + |
157 |
"FROM IAU2000 " +
|
158 |
"WHERE iau_code = " + code;
|
159 |
|
160 |
connect.setConnectionIAU2000(); |
161 |
result = Query.select(sentence,connect.getConnection());
|
162 |
try {
|
163 |
connect.shutdown(); |
164 |
} catch (SQLException e) { |
165 |
// TODO Auto-generated catch block
|
166 |
e.printStackTrace(); |
167 |
} |
168 |
|
169 |
Object[] data = new Object[4]; |
170 |
try {
|
171 |
while (result.next()){
|
172 |
data[0] = result.getString("iau_code"); |
173 |
data[1] = result.getString("iau_wkt"); |
174 |
String proj = result.getString("iau_proj"); |
175 |
if (!proj.equals("")){ |
176 |
data[1] = proj;
|
177 |
data[2] = PluginServices.getText(this,"si"); |
178 |
} |
179 |
else
|
180 |
{ |
181 |
data[1] = result.getString("iau_geog"); |
182 |
data[2] = PluginServices.getText(this,"no"); |
183 |
} |
184 |
|
185 |
data[3] = result.getString("iau_datum"); |
186 |
dtm.addRow(data); |
187 |
} |
188 |
} catch (SQLException e1) { |
189 |
e1.printStackTrace(); |
190 |
} |
191 |
} |
192 |
else if (nameRadioButton.isSelected()) { |
193 |
key = searchTextField.getText(); |
194 |
String key2 = key.substring(0,1); |
195 |
String key3 = key.substring(1,key.length()); |
196 |
key2 = key2.toUpperCase(); |
197 |
|
198 |
String sentence = "SELECT iau_code, iau_wkt, iau_proj, iau_geog, iau_datum " + |
199 |
"FROM IAU2000 " +
|
200 |
"WHERE (iau_proj LIKE '%" + key + "%') OR (iau_proj LIKE '%"+ |
201 |
key.toUpperCase() +"%') " +
|
202 |
"OR (iau_proj LIKE '%" + key2+key3 +"%') OR " + |
203 |
"(iau_geog LIKE '%" + key + "%') OR (iau_geog LIKE '%"+ |
204 |
key.toUpperCase() +"%') " +
|
205 |
"OR (iau_geog LIKE '%" + key2+key3 +"%')"; |
206 |
|
207 |
connect.setConnectionIAU2000(); |
208 |
result = Query.select(sentence,connect.getConnection());
|
209 |
try {
|
210 |
connect.shutdown(); |
211 |
} catch (SQLException e) { |
212 |
// TODO Auto-generated catch block
|
213 |
e.printStackTrace(); |
214 |
} |
215 |
|
216 |
Object[] data = new Object[4]; |
217 |
try {
|
218 |
while (result.next()){
|
219 |
data[0] = result.getString("iau_code"); |
220 |
data[1] = result.getString("iau_wkt"); |
221 |
String proj = result.getString("iau_proj"); |
222 |
if (!proj.equals("")){ |
223 |
data[1] = proj;
|
224 |
data[2] = PluginServices.getText(this,"si"); |
225 |
} |
226 |
else
|
227 |
{ |
228 |
data[1] = result.getString("iau_geog"); |
229 |
data[2] = PluginServices.getText(this,"no"); |
230 |
} |
231 |
|
232 |
data[3] = result.getString("iau_datum"); |
233 |
dtm.addRow(data); |
234 |
} |
235 |
} catch (SQLException e1) { |
236 |
e1.printStackTrace(); |
237 |
} |
238 |
} |
239 |
|
240 |
int numr = dtm.getRowCount();
|
241 |
|
242 |
if (numr == 0 ){ |
243 |
JOptionPane.showMessageDialog(this, "Not Results found.", "Warning...", |
244 |
JOptionPane.WARNING_MESSAGE);
|
245 |
} |
246 |
else{
|
247 |
this.getJTable().setRowSelectionInterval(0,0); |
248 |
} |
249 |
} |
250 |
} |
251 |
|
252 |
private JButton getSearchButton() { |
253 |
if (searchButton == null) { |
254 |
searchButton = new JButton(); |
255 |
searchButton.setPreferredSize(new Dimension(75,20)); |
256 |
searchButton.setText(PluginServices.getText(this,"buscar")); |
257 |
searchButton.setMnemonic('S');
|
258 |
searchButton.addActionListener(this);
|
259 |
} |
260 |
return searchButton;
|
261 |
} |
262 |
|
263 |
private JTextField getSearchTextField() { |
264 |
if (searchTextField == null) { |
265 |
searchTextField = new JTextField(); |
266 |
searchTextField.setPreferredSize(new Dimension(300,20)); |
267 |
searchTextField.addKeyListener(this);
|
268 |
} |
269 |
return searchTextField;
|
270 |
} |
271 |
|
272 |
public JTable getJTable() { |
273 |
if (jTable == null) { |
274 |
String[] columnNames= {PluginServices.getText(this,"codigo"), |
275 |
PluginServices.getText(this,"nombre"), |
276 |
PluginServices.getText(this,"projected"), |
277 |
PluginServices.getText(this,"datum")}; |
278 |
Object[][]data = {}; |
279 |
dtm = new DefaultTableModel(data, columnNames) |
280 |
{ |
281 |
public boolean isCellEditable(int row, int column) { |
282 |
return false; |
283 |
} |
284 |
/*
|
285 |
* metodo necesario para cuando utilizamos tablas ordenadas
|
286 |
* ya que sino al ordenar por algun campo no se queda con el orden
|
287 |
* actual al seleccionar una fila (non-Javadoc)
|
288 |
* @see javax.swing.table.TableModel#getColumnClass(int)
|
289 |
*/
|
290 |
public Class getColumnClass(int column) |
291 |
{ |
292 |
return getValueAt(0, column).getClass(); |
293 |
} |
294 |
}; |
295 |
sorter = new TableSorter(dtm);
|
296 |
|
297 |
jTable = new JTable(sorter); |
298 |
sorter.setTableHeader(jTable.getTableHeader()); |
299 |
jTable.setCellSelectionEnabled(false);
|
300 |
jTable.setRowSelectionAllowed(true);
|
301 |
jTable.setColumnSelectionAllowed(false);
|
302 |
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
303 |
TableColumn column = null; |
304 |
for (int i = 0; i < 4; i++) { |
305 |
column = jTable.getColumnModel().getColumn(i); |
306 |
if (i == 0) { |
307 |
column.setPreferredWidth(80); //code column is shorter |
308 |
}else if (i ==2) { |
309 |
column.setPreferredWidth(50);
|
310 |
} else {
|
311 |
column.setPreferredWidth(175);
|
312 |
} |
313 |
|
314 |
} |
315 |
} |
316 |
return jTable;
|
317 |
|
318 |
} |
319 |
|
320 |
public void setCodeCRS(int code) { |
321 |
codeCRS = code; |
322 |
} |
323 |
|
324 |
public int getCodeCRS() { |
325 |
return codeCRS;
|
326 |
} |
327 |
|
328 |
private JScrollPane getJScrollPane() { |
329 |
if (jScrollPane == null) { |
330 |
jScrollPane = new JScrollPane(); |
331 |
jScrollPane.setPreferredSize(new Dimension(500,150)); |
332 |
jScrollPane.setBorder( |
333 |
BorderFactory.createCompoundBorder(
|
334 |
BorderFactory.createCompoundBorder(
|
335 |
BorderFactory.createTitledBorder(PluginServices.getText(this,"IAU2000")), |
336 |
BorderFactory.createEmptyBorder(5,5,5,5)), |
337 |
jScrollPane.getBorder())); |
338 |
jScrollPane.setViewportView(getJTable()); |
339 |
} |
340 |
return jScrollPane;
|
341 |
} |
342 |
|
343 |
public ICrs getProjection() {
|
344 |
try {
|
345 |
String txt = getWKT();
|
346 |
ICrs crs = new CrsFactory().getCRS(getCodeCRS(), txt);
|
347 |
return crs ;
|
348 |
} catch (CrsException e) {
|
349 |
e.printStackTrace(); |
350 |
} |
351 |
return null; |
352 |
} |
353 |
|
354 |
public void setWKT(){ |
355 |
int code = getCodeCRS();
|
356 |
String sentence = "SELECT iau_code, iau_wkt, iau_proj, iau_geog, iau_datum " + |
357 |
"FROM IAU2000 " +
|
358 |
"WHERE iau_code = " + code;
|
359 |
|
360 |
connect.setConnectionIAU2000(); |
361 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
362 |
try {
|
363 |
connect.shutdown(); |
364 |
} catch (SQLException e) { |
365 |
// TODO Auto-generated catch block
|
366 |
e.printStackTrace(); |
367 |
} |
368 |
try {
|
369 |
result.next(); |
370 |
cadWKT = result.getString("iau_wkt");
|
371 |
} catch (SQLException e1) { |
372 |
e1.printStackTrace(); |
373 |
} |
374 |
|
375 |
cadWKT = cadWKT.substring(0, cadWKT.length()-1) + ", AUTHORITY[\"IAU2000\","+ getCodeCRS()+"]]"; |
376 |
} |
377 |
|
378 |
public String getWKT(){ |
379 |
return cadWKT;
|
380 |
} |
381 |
|
382 |
public void setProjection(IProjection crs) { |
383 |
//setCrs((ICrs) crs);
|
384 |
} |
385 |
|
386 |
public void loadViewCRS(int code){ |
387 |
connection(); |
388 |
String sentence = "SELECT iau_code, iau_wkt, iau_proj, iau_geog, iau_datum " + |
389 |
"FROM IAU2000 " +
|
390 |
"WHERE iau_code = " + code;
|
391 |
|
392 |
connect.setConnectionIAU2000(); |
393 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
394 |
try {
|
395 |
connect.shutdown(); |
396 |
} catch (SQLException e) { |
397 |
// TODO Auto-generated catch block
|
398 |
e.printStackTrace(); |
399 |
} |
400 |
|
401 |
Object[] data = new Object[4]; |
402 |
try {
|
403 |
while (result.next()){
|
404 |
data[0] = result.getString("iau_code"); |
405 |
data[1] = result.getString("iau_wkt"); |
406 |
String proj = result.getString("iau_proj"); |
407 |
if (!proj.equals("")){ |
408 |
data[1] = proj;
|
409 |
data[2] = PluginServices.getText(this,"si"); |
410 |
} |
411 |
else
|
412 |
{ |
413 |
data[1] = result.getString("iau_geog"); |
414 |
data[2] = PluginServices.getText(this,"no"); |
415 |
} |
416 |
|
417 |
data[3] = result.getString("iau_datum"); |
418 |
dtm.addRow(data); |
419 |
} |
420 |
} catch (SQLException e1) { |
421 |
e1.printStackTrace(); |
422 |
} |
423 |
} |
424 |
|
425 |
public void keyPressed(KeyEvent e) { |
426 |
if (e.getSource() == this.getSearchTextField()){ |
427 |
if (e.getKeyCode() == 10) { |
428 |
searchButton(); |
429 |
} |
430 |
if (codeRadioButton.isSelected()) {
|
431 |
|
432 |
if ((e.getKeyCode() >= 48 && e.getKeyCode() <= 57) || e.getKeyCode() >= 96 && e.getKeyCode() <= 105 || |
433 |
(e.getKeyCode() >= 0 && e.getKeyCode()<= 31) || e.getKeyCode() == 127){ |
434 |
} |
435 |
else {
|
436 |
JOptionPane.showMessageDialog(IAU2000panel.this,
|
437 |
"Only number format.",
|
438 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
439 |
String aux = searchTextField.getText();
|
440 |
if (aux.length() == 1 || aux.length() == 0){ |
441 |
searchTextField.setText("");
|
442 |
} |
443 |
else {
|
444 |
searchTextField.setText(aux.substring(0, aux.length()-1)); |
445 |
} |
446 |
} |
447 |
} |
448 |
} |
449 |
|
450 |
} |
451 |
|
452 |
public void keyReleased(KeyEvent arg0) { |
453 |
// TODO Auto-generated method stub
|
454 |
|
455 |
} |
456 |
|
457 |
public void keyTyped(KeyEvent arg0) { |
458 |
// TODO Auto-generated method stub
|
459 |
|
460 |
} |
461 |
|
462 |
public void actionPerformed(ActionEvent e) { |
463 |
// TODO Auto-generated method stub
|
464 |
if (e.getSource() == this.getSearchButton()){ |
465 |
searchTextField.setBackground(Color.white);
|
466 |
if (searchTextField.getText().equals("")) { |
467 |
searchTextField.setBackground(new Color(255,204,204)); |
468 |
JOptionPane.showMessageDialog(IAU2000panel.this,
|
469 |
"Fill the key-word of the search.",
|
470 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
471 |
} |
472 |
else {
|
473 |
searchButton(); |
474 |
} |
475 |
} |
476 |
if (e.getSource() == this.getCodeRadioButton()) { |
477 |
searchTextField.setText("");
|
478 |
codeRadioButton.setSelected(true);
|
479 |
nameRadioButton.setSelected(false);
|
480 |
} |
481 |
|
482 |
if (e.getSource() == this.getNameRadioButton()) { |
483 |
searchTextField.setText("");
|
484 |
nameRadioButton.setSelected(true);
|
485 |
codeRadioButton.setSelected(false);
|
486 |
} |
487 |
} |
488 |
|
489 |
} |