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