Statistics
| Revision:

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
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.sql.ResultSet;
10
import java.sql.SQLException;
11
import java.util.ArrayList;
12

    
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
import javax.swing.table.DefaultTableModel;
24
import javax.swing.table.TableColumn;
25

    
26
import org.gvsig.crs.CrsException;
27
import org.gvsig.crs.ICrs;
28
import org.gvsig.crs.Proj4;
29

    
30
import com.iver.andami.PluginServices;
31

    
32
import es.idr.teledeteccion.connection.EpsgConnection;
33
import es.idr.teledeteccion.connection.Query;
34

    
35

    
36

    
37
/**
38
 * Panel de Definici�n del Sistema de Coordenadas
39
 * 
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
        private JTable tableParametros;
57
        private JScrollPane scrollTable;
58
        
59
        private DefaultTableModel model = null;
60
        
61
        private int theigth=140;
62
        private int twidth=300;
63
        
64
         final static String PROYECTADOPANEL = "Proyectado";
65
         final static String GEOGRAFICOPANEL = "Geogr�fico";
66
        
67
        
68
        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
         * Inicializa el radio button  Geogr�fico 2D
88
         * @return
89
         */
90
        public JRadioButton getRbGeografico() {
91
                if (rbGeografico==null){
92
                        rbGeografico=new JRadioButton(PluginServices.getText(this,"SistCoor_Geografico2D"));
93
                        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
                        rbProyectado=new JRadioButton(PluginServices.getText(this,"SistCoor_Proyactado"));
104
                        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
                        JPanel p=new JPanel(new GridLayout(1,0,10,10));
121
                        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
                        top.setBorder(new TitledBorder(PluginServices.getText(this,"SistCoor_titmarco")));
147
                }
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
         * Inicializa el label Proyecci�n
165
         * @return
166
         */
167
        public JLabel getLblProyeccion() {
168
                if (lblProyeccion==null){
169
                        lblProyeccion=new JLabel();
170
                        lblProyeccion.setText(PluginServices.getText(this,"SistCoor_Proyeccion"));
171
                }
172
                return lblProyeccion;
173
        }
174
        /**
175
         * Crea la tabla donde se definen los par�metros de la
176
         * proyecci�n seleccionada en el combobox
177
         * @return
178
         */
179
        public JTable getTableParametros() {
180
                
181
                if(tableParametros==null){
182
                        tableParametros = new JTable();
183
                    model = (DefaultTableModel)tableParametros.getModel();
184
                    //Crea la tabla con 7 filas
185
                    Object[][] data = {
186
                                        {"", "", "Metros"},
187
                                        {"", "", "Metros"},
188
                                        {"", "", "Metros"},
189
                                        {"", "", "Metros"},
190
                                        {"", "", "Metros"},
191
                                        {"", "", "Metros"},
192
                                        {"", "", "Metros"}};
193
                    
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
                    model.setDataVector(data,headers);
199
                     /*Agrega otra fila
200
                        model.addRow(new Object[]{"fila","","Metros"});*/
201
                    //TODO: Agregar los items "Unidades" al combo
202
                    //define los items del combo
203
                    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
                TableColumn col = tableParametros.getColumnModel().getColumn(2);
210
                ComboBoxEditor editor = new ComboBoxEditor(items);
211
                col.setCellEditor(editor);
212
                col.setCellRenderer(new ComboBoxRenderer(items));
213
                //Define el tama�o de la tabla
214
                        tableParametros.setPreferredScrollableViewportSize(new Dimension(twidth,theigth));
215
                        //la posicion de las columnas es fija
216
                        tableParametros.getTableHeader().setReorderingAllowed( false );
217
                        //Ajustar ancho y alto de las filas y columnas
218
                        ajustarTamanoTabla();
219
                        }
220

    
221
                return tableParametros;
222
        }
223
        
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

    
250
        /**
251
         * Crear scrollPane y agregar la tabla en �l
252
         */
253
        public JScrollPane getScrollTable() {
254
                if(scrollTable==null){
255
                        scrollTable = new JScrollPane(getTableParametros());
256
                        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
                        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
                        cbProyeccion.setEditable(false);
273
                        cbProyeccion.setToolTipText(PluginServices.getText(this,"SistCoor_cbToolTip"));
274
                                                
275
                }
276
                return cbProyeccion;
277
        }
278
        
279
        private ArrayList obtainProjections() {
280
                ArrayList items = new ArrayList();
281
                                
282
                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
        /*
299
         * Redimensiona el tama�o de las filas y columnas de la tabla
300
         *
301
         */
302
        public void ajustarTamanoTabla(){
303
            TableColumn column = null;
304
            //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
}
315
        
316
        /**
317
         * Fija los eventos de los RadioButtons y dem�s controles
318
         */
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
                /*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
                 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

    
333
        /*
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
                        geograficoPanel.add(new JButton("Crear panel Geogr�fico 2D"));
344
                }
345
                return geograficoPanel;
346
        }
347
        
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
        
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

    
383
}
384