root / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / wizard / DefSistCoordenadas.java @ 11629
History | View | Annotate | Download (14.9 KB)
1 |
package org.gvsig.crs.gui.panels.wizard; |
---|---|
2 |
import java.awt.BorderLayout; |
3 |
import java.awt.CardLayout; |
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.ItemEvent; |
10 |
import java.awt.event.ItemListener; |
11 |
import java.sql.ResultSet; |
12 |
import java.sql.SQLException; |
13 |
import java.util.ArrayList; |
14 |
|
15 |
import javax.swing.BorderFactory; |
16 |
import javax.swing.ButtonGroup; |
17 |
import javax.swing.JButton; |
18 |
import javax.swing.JComboBox; |
19 |
import javax.swing.JLabel; |
20 |
import javax.swing.JPanel; |
21 |
import javax.swing.JRadioButton; |
22 |
import javax.swing.JScrollPane; |
23 |
import javax.swing.JTable; |
24 |
import javax.swing.border.TitledBorder; |
25 |
import javax.swing.table.DefaultTableModel; |
26 |
import javax.swing.table.TableColumn; |
27 |
|
28 |
import org.gvsig.crs.CrsException; |
29 |
import org.gvsig.crs.ICrs; |
30 |
import org.gvsig.crs.Proj4; |
31 |
|
32 |
import com.iver.andami.PluginServices; |
33 |
|
34 |
import es.idr.teledeteccion.connection.EpsgConnection; |
35 |
import es.idr.teledeteccion.connection.Query; |
36 |
|
37 |
|
38 |
|
39 |
/**
|
40 |
* Panel de Definici�n del Sistema de Coordenadas
|
41 |
*
|
42 |
* @author Luisa Marina Fernandez Ruiz (luisam.fernandez@uclm.es)
|
43 |
*
|
44 |
*/
|
45 |
public class DefSistCoordenadas extends JPanel implements ActionListener, ItemListener{ |
46 |
|
47 |
private static final long serialVersionUID = 1L; |
48 |
private JPanel top; |
49 |
private JPanel proyectadoPanel; |
50 |
private JPanel geograficoPanel; |
51 |
private JPanel cardPanel; |
52 |
private JRadioButton rbGeografico; |
53 |
private JRadioButton rbProyectado; |
54 |
private ButtonGroup coordGroup; |
55 |
|
56 |
private JLabel lblProyeccion; |
57 |
private JComboBox cbProyeccion; |
58 |
private JTable tableParametros; |
59 |
private JScrollPane scrollTable; |
60 |
|
61 |
private DefaultTableModel model = null; |
62 |
|
63 |
private int theigth=140; |
64 |
private int twidth=300; |
65 |
|
66 |
final static String PROYECTADOPANEL = "Proyectado"; |
67 |
final static String GEOGRAFICOPANEL = "Geogr�fico"; |
68 |
|
69 |
|
70 |
public DefSistCoordenadas() {
|
71 |
super();
|
72 |
BorderLayout bl=new BorderLayout(); |
73 |
bl.setVgap(5);
|
74 |
bl.setHgap(5);
|
75 |
this.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); |
76 |
this.setLayout(bl);
|
77 |
this.add(getTop(),BorderLayout.NORTH); |
78 |
cardPanel=new JPanel(); |
79 |
cardPanel.setLayout(new CardLayout()); |
80 |
//agregar los elementos correspondientes en el cardPanel
|
81 |
cardPanel.add(PROYECTADOPANEL,getProyectadoPanel()); |
82 |
cardPanel.add(GEOGRAFICOPANEL,getGeograficoPanel()); |
83 |
//agregar cardPanel en el this
|
84 |
this.add(cardPanel,BorderLayout.CENTER); |
85 |
|
86 |
|
87 |
} |
88 |
/**
|
89 |
* Inicializa el radio button Geogr�fico 2D
|
90 |
* @return
|
91 |
*/
|
92 |
public JRadioButton getRbGeografico() { |
93 |
if (rbGeografico==null){ |
94 |
rbGeografico=new JRadioButton(PluginServices.getText(this,"SistCoor_Geografico2D")); |
95 |
rbGeografico.addActionListener(this);
|
96 |
} |
97 |
return rbGeografico;
|
98 |
} |
99 |
/**
|
100 |
* Inicializa el radio button Proyectado
|
101 |
* @return
|
102 |
*/
|
103 |
public JRadioButton getRbProyectado() { |
104 |
if (rbProyectado==null){ |
105 |
rbProyectado=new JRadioButton(PluginServices.getText(this,"SistCoor_Proyactado")); |
106 |
rbProyectado.addActionListener(this);
|
107 |
} |
108 |
return rbProyectado;
|
109 |
} |
110 |
/**
|
111 |
* Inicializa el panel que contiene las opciones
|
112 |
* si el crs seleccionado es proyectado
|
113 |
*
|
114 |
*/
|
115 |
public JPanel getProyectadoPanel() { |
116 |
if(proyectadoPanel==null){ |
117 |
BorderLayout b=new BorderLayout(); |
118 |
b.setVgap(5);
|
119 |
b.setHgap(5);
|
120 |
proyectadoPanel=new JPanel(b); |
121 |
proyectadoPanel.setBorder(BorderFactory.createEmptyBorder(0,3,0,3)); |
122 |
JPanel p=new JPanel(new GridLayout(1,0,10,10)); |
123 |
JPanel in=new JPanel(new FlowLayout(FlowLayout.RIGHT,3,5)); |
124 |
in.add(getLblProyeccion()); |
125 |
p.add(in); |
126 |
p.add(getCbProyeccion()); |
127 |
proyectadoPanel.add(p,BorderLayout.NORTH);
|
128 |
//JPanel center=new JPanel();
|
129 |
//center.add(parametrosJtable);
|
130 |
//center.add(new JButton("agregar la tabla con los parametros"));
|
131 |
proyectadoPanel.add(getScrollTable(),BorderLayout.CENTER);
|
132 |
//CREAR TODOS LOS ELEMENTOS
|
133 |
} |
134 |
return proyectadoPanel;
|
135 |
} |
136 |
/**
|
137 |
* Inicializa el panel superior donde se define el sistema
|
138 |
* de coordenadas
|
139 |
*
|
140 |
*/
|
141 |
public JPanel getTop() { |
142 |
if(top==null){ |
143 |
top=new JPanel(); |
144 |
top.add(getRbGeografico()); |
145 |
top.add(getRbProyectado()); |
146 |
//Agrupar las opciones
|
147 |
agruparRadioButtons(); |
148 |
top.setBorder(new TitledBorder(PluginServices.getText(this,"SistCoor_titmarco"))); |
149 |
} |
150 |
return top;
|
151 |
} |
152 |
/**
|
153 |
* Agrupa los radio button
|
154 |
*
|
155 |
*/
|
156 |
private void agruparRadioButtons() { |
157 |
if (coordGroup==null){ |
158 |
coordGroup=new ButtonGroup(); |
159 |
//Agrupar los botones de opcion
|
160 |
coordGroup.add(getRbProyectado()); |
161 |
coordGroup.add(getRbGeografico()); |
162 |
getRbProyectado().setSelected(true);
|
163 |
} |
164 |
} |
165 |
/**
|
166 |
* Inicializa el label Proyecci�n
|
167 |
* @return
|
168 |
*/
|
169 |
public JLabel getLblProyeccion() { |
170 |
if (lblProyeccion==null){ |
171 |
lblProyeccion=new JLabel(); |
172 |
lblProyeccion.setText(PluginServices.getText(this,"SistCoor_Proyeccion")); |
173 |
} |
174 |
return lblProyeccion;
|
175 |
} |
176 |
/**
|
177 |
* Crea la tabla donde se definen los par�metros de la
|
178 |
* proyecci�n seleccionada en el combobox
|
179 |
* @return
|
180 |
*/
|
181 |
public JTable getTableParametros() { |
182 |
|
183 |
if(tableParametros==null){ |
184 |
tableParametros = new JTable(); |
185 |
model = (DefaultTableModel)tableParametros.getModel();
|
186 |
//Crea la tabla con 7 filas
|
187 |
Object[][] data = { |
188 |
{"", "", "Metros"}, |
189 |
{"", "", "Metros"}, |
190 |
{"", "", "Metros"}, |
191 |
{"", "", "Metros"}, |
192 |
{"", "", "Metros"}, |
193 |
{"", "", "Metros"}, |
194 |
{"", "", "Metros"}}; |
195 |
|
196 |
String col1=PluginServices.getText(this,"SistCoor_Parametro"); |
197 |
String col2=PluginServices.getText(this,"SistCoor_Valor"); |
198 |
String col3=PluginServices.getText(this,"SistCoor_Unidades"); |
199 |
Object[] headers = {col1, col2, col3}; |
200 |
model.setDataVector(data,headers); |
201 |
/*Agrega otra fila
|
202 |
model.addRow(new Object[]{"fila","","Metros"});*/
|
203 |
//TODO: Agregar los items "Unidades" al combo
|
204 |
//define los items del combo
|
205 |
ArrayList units = obtenerItemsUnidades();
|
206 |
String[] items = new String[units.size()]; |
207 |
for (int i=0;i<units.size();i++){ |
208 |
items[i] = units.get(i).toString(); |
209 |
} |
210 |
//String[] items = new String[] { "Metros", "Grados", "Kilometros", "Decimetros", "Hect�metros" };
|
211 |
TableColumn col = tableParametros.getColumnModel().getColumn(2); |
212 |
ComboBoxEditor editor = new ComboBoxEditor(items); |
213 |
col.setCellEditor(editor); |
214 |
col.setCellRenderer(new ComboBoxRenderer(items));
|
215 |
//Define el tama�o de la tabla
|
216 |
tableParametros.setPreferredScrollableViewportSize(new Dimension(twidth,theigth)); |
217 |
//la posicion de las columnas es fija
|
218 |
tableParametros.getTableHeader().setReorderingAllowed( false );
|
219 |
//Ajustar ancho y alto de las filas y columnas
|
220 |
ajustarTamanoTabla(); |
221 |
fillTable(cbProyeccion.getItemAt(0).toString());
|
222 |
} |
223 |
|
224 |
return tableParametros;
|
225 |
} |
226 |
|
227 |
/**
|
228 |
* Accede al la base de datos y obtiene los items de
|
229 |
* los combobox
|
230 |
* @return
|
231 |
*/
|
232 |
private ArrayList obtenerItemsUnidades(){ //unidades de longitud... |
233 |
//TODO: Obtener los items del combo de la base de datos
|
234 |
ArrayList items = new ArrayList(); |
235 |
|
236 |
String sentence = "SELECT unit_of_meas_name " + |
237 |
"FROM epsg_unitofmeasure " +
|
238 |
"WHERE unit_of_meas_type = 'length'";
|
239 |
EpsgConnection connect = new EpsgConnection();
|
240 |
connect.setConnectionEPSG(); |
241 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
242 |
try {
|
243 |
while (result.next()) {
|
244 |
items.add(result.getString("unit_of_meas_name"));
|
245 |
} |
246 |
} catch (SQLException e) { |
247 |
// TODO Auto-generated catch block
|
248 |
e.printStackTrace(); |
249 |
} |
250 |
return items;
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* Accede al la base de datos y obtiene los items de
|
255 |
* los combobox
|
256 |
* @return
|
257 |
*/
|
258 |
private ArrayList obtenerItemsUnidadesAngular(){ //unidades angulares... |
259 |
//TODO: Obtener los items del combo de la base de datos
|
260 |
ArrayList items = new ArrayList(); |
261 |
|
262 |
String sentence = "SELECT unit_of_meas_name " + |
263 |
"FROM epsg_unitofmeasure " +
|
264 |
"WHERE unit_of_meas_type = 'angle'";
|
265 |
EpsgConnection connect = new EpsgConnection();
|
266 |
connect.setConnectionEPSG(); |
267 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
268 |
try {
|
269 |
while (result.next()) {
|
270 |
items.add(result.getString("unit_of_meas_name"));
|
271 |
} |
272 |
} catch (SQLException e) { |
273 |
// TODO Auto-generated catch block
|
274 |
e.printStackTrace(); |
275 |
} |
276 |
return items;
|
277 |
} |
278 |
|
279 |
/**
|
280 |
* Accede al la base de datos y obtiene los items de
|
281 |
* los combobox
|
282 |
* @return
|
283 |
*/
|
284 |
private ArrayList obtenerItemsUnidadesScale(){ //unidades angulares... |
285 |
//TODO: Obtener los items del combo de la base de datos
|
286 |
ArrayList items = new ArrayList(); |
287 |
|
288 |
String sentence = "SELECT unit_of_meas_name " + |
289 |
"FROM epsg_unitofmeasure " +
|
290 |
"WHERE unit_of_meas_type = 'scale'";
|
291 |
EpsgConnection connect = new EpsgConnection();
|
292 |
connect.setConnectionEPSG(); |
293 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
294 |
try {
|
295 |
while (result.next()) {
|
296 |
items.add(result.getString("unit_of_meas_name"));
|
297 |
} |
298 |
} catch (SQLException e) { |
299 |
// TODO Auto-generated catch block
|
300 |
e.printStackTrace(); |
301 |
} |
302 |
return items;
|
303 |
} |
304 |
|
305 |
/**
|
306 |
* Crear scrollPane y agregar la tabla en �l
|
307 |
*/
|
308 |
public JScrollPane getScrollTable() { |
309 |
if(scrollTable==null){ |
310 |
scrollTable = new JScrollPane(getTableParametros()); |
311 |
scrollTable.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
312 |
} |
313 |
return scrollTable;
|
314 |
} |
315 |
/**
|
316 |
* Contiene los nombres de las distintas proyecciones
|
317 |
* @return
|
318 |
*/
|
319 |
public JComboBox getCbProyeccion() { |
320 |
if (cbProyeccion==null){ |
321 |
ArrayList projections = obtainProjections();
|
322 |
String[] items = new String[projections.size()]; |
323 |
for (int i=0;i<projections.size();i++){ |
324 |
items[i] = projections.get(i).toString(); |
325 |
} |
326 |
cbProyeccion=new JComboBox(items); |
327 |
cbProyeccion.setEditable(false);
|
328 |
cbProyeccion.setToolTipText(PluginServices.getText(this,"SistCoor_cbToolTip")); |
329 |
cbProyeccion.addItemListener(this);
|
330 |
} |
331 |
return cbProyeccion;
|
332 |
} |
333 |
|
334 |
private ArrayList obtainProjections() { |
335 |
ArrayList items = new ArrayList(); |
336 |
|
337 |
String sentence = "SELECT coord_op_method_name " + |
338 |
"FROM epsg_coordoperationmethod " +
|
339 |
"WHERE coord_op_method_code > 9800";
|
340 |
EpsgConnection connect = new EpsgConnection();
|
341 |
connect.setConnectionEPSG(); |
342 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
343 |
try {
|
344 |
while (result.next()) {
|
345 |
items.add(result.getString("coord_op_method_name"));
|
346 |
} |
347 |
} catch (SQLException e) { |
348 |
// TODO Auto-generated catch block
|
349 |
e.printStackTrace(); |
350 |
} |
351 |
return items;
|
352 |
} |
353 |
/*
|
354 |
* Redimensiona el tama�o de las filas y columnas de la tabla
|
355 |
*
|
356 |
*/
|
357 |
public void ajustarTamanoTabla(){ |
358 |
TableColumn column = null; |
359 |
//Fijar el alto de las filas
|
360 |
getTableParametros().setRowHeight(20);
|
361 |
//Fijar el ancho de las columnas
|
362 |
column = getTableParametros().getColumnModel().getColumn(0);
|
363 |
column.setPreferredWidth(30);
|
364 |
column = getTableParametros().getColumnModel().getColumn(1);
|
365 |
column.setPreferredWidth(90);
|
366 |
column = getTableParametros().getColumnModel().getColumn(2);
|
367 |
column.setPreferredWidth(120);
|
368 |
|
369 |
} |
370 |
|
371 |
/**
|
372 |
* Fija los eventos de los RadioButtons y dem�s controles
|
373 |
*/
|
374 |
public void actionPerformed(ActionEvent e) { |
375 |
//MOSTRAR UN PANEL U OTRO
|
376 |
CardLayout cl = (CardLayout)(cardPanel.getLayout()); |
377 |
if (e.getSource().equals(getRbProyectado())){
|
378 |
/*Si est� seleccionada la opci�n de Proyectado
|
379 |
se muestra el panel de selecci�n de la proyecci�n con sus par�metros*/
|
380 |
cl.show(cardPanel, PROYECTADOPANEL); |
381 |
}else if(e.getSource().equals(getRbGeografico())){ |
382 |
/*Se muestra el panel de Sistema de Coordenadas Geografico*/
|
383 |
cl.show(cardPanel, GEOGRAFICOPANEL); |
384 |
} |
385 |
} |
386 |
|
387 |
/*
|
388 |
* Crear el panel que contiene los componentes de
|
389 |
* un sistema de coordenadas geografico
|
390 |
* */
|
391 |
public JPanel getGeograficoPanel() { |
392 |
if(geograficoPanel==null){ |
393 |
BorderLayout b=new BorderLayout(); |
394 |
b.setVgap(5);
|
395 |
b.setHgap(5);
|
396 |
geograficoPanel=new JPanel(b); |
397 |
geograficoPanel.add(new JButton("Crear panel Geogr�fico 2D")); |
398 |
} |
399 |
return geograficoPanel;
|
400 |
} |
401 |
|
402 |
public void fillData(ICrs crs) { |
403 |
if (!crs.getCrsWkt().getProjcs().equals("")) { |
404 |
for (int i = 0; i < getCbProyeccion().getItemCount(); i++) { |
405 |
if (getCbProyeccion().getItemAt(i).equals(crs.getCrsWkt().getProjection())) {
|
406 |
getCbProyeccion().setSelectedIndex(i); |
407 |
break;
|
408 |
} |
409 |
} |
410 |
int numRow = model.getRowCount();
|
411 |
while (numRow != 0) { |
412 |
numRow = numRow - 1;
|
413 |
model.removeRow(numRow); |
414 |
} |
415 |
Object[] data = new Object[3]; |
416 |
data[2] = "Metros"; |
417 |
for (int i = 0; i < crs.getCrsWkt().getParam_name().length; i++) { |
418 |
data[0] = crs.getCrsWkt().getParam_name()[i];
|
419 |
data[1] = crs.getCrsWkt().getParam_value()[i];
|
420 |
model.addRow(data); |
421 |
} |
422 |
} else {
|
423 |
getRbGeografico().setSelected(true);
|
424 |
CardLayout cl = (CardLayout)(cardPanel.getLayout()); |
425 |
cl.show(cardPanel, GEOGRAFICOPANEL); |
426 |
} |
427 |
} |
428 |
|
429 |
public void fillTable(String projection) { |
430 |
try {
|
431 |
Proj4 proj4 = new Proj4();
|
432 |
int index = proj4.findProjection(projection);
|
433 |
ArrayList params = proj4.getProj4ProjectionParameters(index);
|
434 |
String[] parameters = new String[params.size()]; |
435 |
String[] units = new String[params.size()]; |
436 |
for (int i = 0; i < params.size(); i++) { |
437 |
parameters[i] = params.get(i).toString(); |
438 |
int pos = proj4.findProjectionParameter(parameters[i]);
|
439 |
units[i] = proj4.getProjectionParameterUnitList(pos); |
440 |
|
441 |
} |
442 |
int numRow = model.getRowCount();
|
443 |
while (numRow != 0) { |
444 |
numRow = numRow - 1;
|
445 |
model.removeRow(numRow); |
446 |
} |
447 |
Object[] data = new Object[3]; |
448 |
data[1] = ""+0; |
449 |
data[2] = "Metros"; |
450 |
String[] items = null; |
451 |
for (int i = 0; i < parameters.length; i++) { |
452 |
data[0] = parameters[i];
|
453 |
if (units[i].equals("Angular")) { |
454 |
data[2] = "Angle"; |
455 |
//define los items del combo
|
456 |
ArrayList unit = obtenerItemsUnidadesAngular();
|
457 |
items = new String[unit.size()]; |
458 |
for (int j=0;j<unit.size();j++){ |
459 |
items[j] = unit.get(j).toString(); |
460 |
} |
461 |
} |
462 |
else if (units[i].equals("Unitless")) { |
463 |
data[2] = "Unitless"; |
464 |
//define los items del combo
|
465 |
ArrayList unit = obtenerItemsUnidadesScale();
|
466 |
items = new String[unit.size()]; |
467 |
for (int j=0;j<unit.size();j++){ |
468 |
items[j] = unit.get(j).toString(); |
469 |
} |
470 |
} |
471 |
else {
|
472 |
data[2] = "Meters"; |
473 |
//define los items del combo
|
474 |
ArrayList unit = obtenerItemsUnidades();
|
475 |
items = new String[unit.size()]; |
476 |
for (int j=0;j<unit.size();j++){ |
477 |
items[j] = unit.get(j).toString(); |
478 |
} |
479 |
} |
480 |
model.addRow(data); |
481 |
System.out.println(getTableParametros().getValueAt(i, 2)); |
482 |
TableColumn col = getTableParametros().getColumnModel().getColumn(2); |
483 |
ComboBoxEditor editor = new ComboBoxEditor(items); |
484 |
col.setCellEditor(editor); |
485 |
col.setCellRenderer(new ComboBoxRenderer(items));
|
486 |
getTableParametros().setCellEditor(editor); |
487 |
|
488 |
} |
489 |
|
490 |
} catch (CrsException e) {
|
491 |
// TODO Auto-generated catch block
|
492 |
e.printStackTrace(); |
493 |
} |
494 |
} |
495 |
public void itemStateChanged(ItemEvent e) { |
496 |
// TODO Auto-generated method stub
|
497 |
String op = (String)e.getItem(); |
498 |
fillTable(op); |
499 |
} |
500 |
|
501 |
} |
502 |
|