Statistics
| Revision:

svn-gvsig-desktop / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / wizard / DefSistCoordenadas.java @ 11570

History | View | Annotate | Download (9.94 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.ICrs;
27

    
28
import com.iver.andami.PluginServices;
29

    
30
import es.idr.teledeteccion.connection.EpsgConnection;
31
import es.idr.teledeteccion.connection.Query;
32

    
33

    
34

    
35
/**
36
 * Panel de Definici�n del Sistema de Coordenadas
37
 * 
38
 * @author Luisa Marina Fernandez Ruiz (luisam.fernandez@uclm.es)
39
 *
40
 */
41
public class DefSistCoordenadas extends JPanel implements ActionListener{
42
        
43
        private static final long serialVersionUID = 1L;
44
        private JPanel top;
45
        private JPanel proyectadoPanel;
46
        private JPanel geograficoPanel;
47
        private JPanel cardPanel;
48
        private JRadioButton rbGeografico;
49
        private JRadioButton rbProyectado;
50
        private ButtonGroup coordGroup;
51
        
52
        private JLabel lblProyeccion;
53
        private JComboBox cbProyeccion;
54
        private JTable tableParametros;
55
        private JScrollPane scrollTable;
56
        
57
        private DefaultTableModel model = null;
58
        
59
        private int theigth=140;
60
        private int twidth=300;
61
        
62
         final static String PROYECTADOPANEL = "Proyectado";
63
         final static String GEOGRAFICOPANEL = "Geogr�fico";
64
        
65
        
66
        public DefSistCoordenadas() {
67
                super();
68
                BorderLayout bl=new BorderLayout();
69
                bl.setVgap(5);
70
                bl.setHgap(5);
71
                this.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
72
                this.setLayout(bl);
73
                this.add(getTop(),BorderLayout.NORTH);
74
                cardPanel=new JPanel();
75
                cardPanel.setLayout(new CardLayout());
76
                //agregar los elementos correspondientes en el cardPanel
77
                cardPanel.add(PROYECTADOPANEL,getProyectadoPanel());
78
                cardPanel.add(GEOGRAFICOPANEL,getGeograficoPanel());
79
                //agregar cardPanel en el this
80
                this.add(cardPanel,BorderLayout.CENTER);
81
                
82
                
83
        }
84
        /**
85
         * Inicializa el radio button  Geogr�fico 2D
86
         * @return
87
         */
88
        public JRadioButton getRbGeografico() {
89
                if (rbGeografico==null){
90
                        rbGeografico=new JRadioButton(PluginServices.getText(this,"SistCoor_Geografico2D"));
91
                        rbGeografico.addActionListener(this);
92
                }
93
                return rbGeografico;
94
        }
95
        /**
96
         * Inicializa el radio button Proyectado
97
         * @return
98
         */
99
        public JRadioButton getRbProyectado() {
100
                if (rbProyectado==null){
101
                        rbProyectado=new JRadioButton(PluginServices.getText(this,"SistCoor_Proyactado"));
102
                        rbProyectado.addActionListener(this);
103
                }
104
                return rbProyectado;
105
        }
106
        /**
107
         * Inicializa el panel que contiene las opciones 
108
         * si el crs seleccionado es proyectado
109
         * 
110
         */
111
        public JPanel getProyectadoPanel() {
112
                if(proyectadoPanel==null){
113
                        BorderLayout b=new BorderLayout();
114
                        b.setVgap(5);
115
                        b.setHgap(5);
116
                        proyectadoPanel=new JPanel(b);
117
                        proyectadoPanel.setBorder(BorderFactory.createEmptyBorder(0,3,0,3));
118
                        JPanel p=new JPanel(new GridLayout(1,0,10,10));
119
                        JPanel in=new JPanel(new FlowLayout(FlowLayout.RIGHT,3,5));
120
                        in.add(getLblProyeccion());
121
                        p.add(in);
122
                        p.add(getCbProyeccion());
123
                        proyectadoPanel.add(p,BorderLayout.NORTH);
124
                        //JPanel center=new JPanel();
125
                        //center.add(parametrosJtable);
126
                        //center.add(new JButton("agregar la tabla con los parametros"));
127
                        proyectadoPanel.add(getScrollTable(),BorderLayout.CENTER);
128
                        //CREAR TODOS LOS ELEMENTOS 
129
                }
130
                return proyectadoPanel;
131
        }
132
        /**
133
         * Inicializa el panel superior donde se define el sistema 
134
         * de coordenadas
135
         * 
136
         */
137
        public JPanel getTop() {
138
                if(top==null){
139
                        top=new JPanel();
140
                        top.add(getRbGeografico());
141
                        top.add(getRbProyectado());
142
                        //Agrupar las opciones
143
                        agruparRadioButtons();
144
                        top.setBorder(new TitledBorder(PluginServices.getText(this,"SistCoor_titmarco")));
145
                }
146
                return top;
147
        }
148
        /**
149
         * Agrupa los radio button
150
         *
151
         */
152
        private void agruparRadioButtons() {
153
                if (coordGroup==null){
154
                                coordGroup=new ButtonGroup();
155
                                //Agrupar los botones de opcion
156
                                coordGroup.add(getRbProyectado());
157
                                coordGroup.add(getRbGeografico());
158
                                getRbProyectado().setSelected(true);
159
                        }        
160
        }
161
        /**
162
         * Inicializa el label Proyecci�n
163
         * @return
164
         */
165
        public JLabel getLblProyeccion() {
166
                if (lblProyeccion==null){
167
                        lblProyeccion=new JLabel();
168
                        lblProyeccion.setText(PluginServices.getText(this,"SistCoor_Proyeccion"));
169
                }
170
                return lblProyeccion;
171
        }
172
        /**
173
         * Crea la tabla donde se definen los par�metros de la
174
         * proyecci�n seleccionada en el combobox
175
         * @return
176
         */
177
        public JTable getTableParametros() {
178
                
179
                if(tableParametros==null){
180
                        tableParametros = new JTable();
181
                    model = (DefaultTableModel)tableParametros.getModel();
182
                    //Crea la tabla con 7 filas
183
                    Object[][] data = {
184
                                        {"", "", "Metros"},
185
                                        {"", "", "Metros"},
186
                                        {"", "", "Metros"},
187
                                        {"", "", "Metros"},
188
                                        {"", "", "Metros"},
189
                                        {"", "", "Metros"},
190
                                        {"", "", "Metros"}};
191
                    
192
                        String col1=PluginServices.getText(this,"SistCoor_Parametro");
193
                        String col2=PluginServices.getText(this,"SistCoor_Valor");
194
                        String col3=PluginServices.getText(this,"SistCoor_Unidades");
195
                         Object[] headers = {col1, col2, col3};
196
                    model.setDataVector(data,headers);
197
                     /*Agrega otra fila
198
                        model.addRow(new Object[]{"fila","","Metros"});*/
199
                    //TODO: Agregar los items "Unidades" al combo
200
                    //define los items del combo
201
                String[] items = new String[] { "Metros", "Grados", "Kilometros", "Decimetros", "Hect�metros" };
202
                TableColumn col = tableParametros.getColumnModel().getColumn(2);
203
                ComboBoxEditor editor = new ComboBoxEditor(items);
204
                col.setCellEditor(editor);
205
                col.setCellRenderer(new ComboBoxRenderer(items));
206
                //Define el tama�o de la tabla
207
                        tableParametros.setPreferredScrollableViewportSize(new Dimension(twidth,theigth));
208
                        //la posicion de las columnas es fija
209
                        tableParametros.getTableHeader().setReorderingAllowed( false );
210
                        //Ajustar ancho y alto de las filas y columnas
211
                        ajustarTamanoTabla();
212
                        }
213

    
214
                return tableParametros;
215
        }
216

    
217
        /**
218
         * Crear scrollPane y agregar la tabla en �l
219
         */
220
        public JScrollPane getScrollTable() {
221
                if(scrollTable==null){
222
                        scrollTable = new JScrollPane(getTableParametros());
223
                        scrollTable.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
224
                }
225
                return scrollTable;
226
        }
227
        /**
228
         * Contiene los nombres de las distintas proyecciones
229
         * @return
230
         */
231
        public JComboBox getCbProyeccion() {
232
                if (cbProyeccion==null){
233
                        ArrayList units = obtainProjections();
234
                        String[] items = new String[units.size()];
235
                        for (int i=0;i<units.size();i++){
236
                                items[i] = units.get(i).toString();
237
                        }
238
                        cbProyeccion=new JComboBox(items);
239
                        cbProyeccion.setEditable(false);
240
                        cbProyeccion.setToolTipText(PluginServices.getText(this,"SistCoor_cbToolTip"));
241
                                                
242
                }
243
                return cbProyeccion;
244
        }
245
        
246
        private ArrayList obtainProjections() {
247
                ArrayList items = new ArrayList();
248
                
249
                /*
250
                 * CREATE CACHED TABLE EPSG_COORDOPERATIONMETHOD(COORD_OP_METHOD_CODE INTEGER NOT NULL,
251
                 * COORD_OP_METHOD_NAME VARCHAR(50) NOT NULL,
252
                 * REVERSE_OP SMALLINT NOT NULL, 
253
                 */
254
                
255
                String sentence = "SELECT coord_op_method_name " +
256
                                                  "FROM epsg_coordoperationmethod " +                                      
257
                                                  "WHERE coord_op_method_code > 9800";
258
                EpsgConnection connect = new EpsgConnection();
259
                connect.setConnectionEPSG();
260
                ResultSet result = Query.select(sentence,connect.getConnection());
261
                try {
262
                        while (result.next()) {
263
                                items.add(result.getString("coord_op_method_name"));
264
                        }
265
                } catch (SQLException e) {
266
                        // TODO Auto-generated catch block
267
                        e.printStackTrace();
268
                }
269
                return items;
270
        }
271
        /*
272
         * Redimensiona el tama�o de las filas y columnas de la tabla
273
         *
274
         */
275
        public void ajustarTamanoTabla(){
276
            TableColumn column = null;
277
            //Fijar el alto de las filas
278
            getTableParametros().setRowHeight(20);
279
            //Fijar el ancho de las columnas
280
            column = getTableParametros().getColumnModel().getColumn(0);
281
            column.setPreferredWidth(30);
282
            column = getTableParametros().getColumnModel().getColumn(1);
283
            column.setPreferredWidth(90);
284
            column = getTableParametros().getColumnModel().getColumn(2);
285
            column.setPreferredWidth(120);
286

    
287
}
288
        
289
        /**
290
         * Fija los eventos de los RadioButtons y dem�s controles
291
         */
292
        public void actionPerformed(ActionEvent e) {
293
                //MOSTRAR UN PANEL U OTRO
294
        CardLayout cl = (CardLayout)(cardPanel.getLayout());      
295
        if (e.getSource().equals(getRbProyectado())){
296
                /*Si est� seleccionada la opci�n de Proyectado 
297
                se muestra el panel de selecci�n de la proyecci�n con sus par�metros*/
298
                 cl.show(cardPanel, PROYECTADOPANEL);
299
        }else if(e.getSource().equals(getRbGeografico())){
300
                /*Se muestra el panel de Sistema de Coordenadas Geografico*/
301
                 cl.show(cardPanel, GEOGRAFICOPANEL);
302
        }
303
                
304
        }
305

    
306
        /*
307
         * Crear el panel que contiene los componentes de 
308
         * un sistema de coordenadas geografico
309
         * */
310
        public JPanel getGeograficoPanel() {
311
                if(geograficoPanel==null){
312
                        BorderLayout b=new BorderLayout();
313
                        b.setVgap(5);
314
                        b.setHgap(5);
315
                        geograficoPanel=new JPanel(b);
316
                        geograficoPanel.add(new JButton("Crear panel Geogr�fico 2D"));
317
                }
318
                return geograficoPanel;
319
        }
320
        
321
        public void fillData(ICrs crs) {
322
                if (!crs.getCrsWkt().getProjcs().equals("")) {
323
                        for (int i = 0; i < getCbProyeccion().getItemCount(); i++) {
324
                                if (getCbProyeccion().getItemAt(i).equals(crs.getCrsWkt().getProjection())) {
325
                                        getCbProyeccion().setSelectedIndex(i);
326
                                        break;
327
                                }
328
                        }
329
                        int numRow = model.getRowCount();
330
                        while (numRow != 0) {
331
                                numRow = numRow - 1;
332
                                model.removeRow(numRow);
333
                        }
334
                        Object[] data = new Object[3];
335
                        data[2] = "Metros";
336
                        for (int i = 0; i < crs.getCrsWkt().getParam_name().length; i++) {
337
                                data[0] = crs.getCrsWkt().getParam_name()[i];
338
                                data[1] = crs.getCrsWkt().getParam_value()[i];
339
                                model.addRow(data);
340
                        }
341
                } else {
342
                        
343
                }
344
        }
345

    
346
}
347