Statistics
| Revision:

root / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / NewCRSPanel.java @ 10788

History | View | Annotate | Download (10.8 KB)

1
package org.gvsig.crs.gui.panels;
2

    
3
import java.awt.BorderLayout;
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

    
12
import javax.swing.ButtonGroup;
13
import javax.swing.JButton;
14
import javax.swing.JLabel;
15
import javax.swing.JPanel;
16
import javax.swing.JRadioButton;
17
import javax.swing.JScrollPane;
18
import javax.swing.JTable;
19
import javax.swing.JTextField;
20
import javax.swing.ListSelectionModel;
21
import javax.swing.border.CompoundBorder;
22
import javax.swing.border.EmptyBorder;
23
import javax.swing.table.DefaultTableModel;
24
import javax.swing.table.TableColumn;
25

    
26
import org.gvsig.crs.gui.panels.wizard.MainPanel;
27

    
28
import com.iver.andami.PluginServices;
29
import com.iver.cit.gvsig.gui.TableSorter;
30

    
31
/**
32
 * Crea la interfaz de definici?n de un nuevo crs por el usuario
33
 * @author Luisa Marina Fernandez Ruiz (luisam.fernandez@uclm.es)
34
 *
35
 */
36
public class NewCRSPanel extends JPanel implements ActionListener,KeyListener{
37
        private static final long serialVersionUID = 1L;
38
        
39
        private JRadioButton codeRadioButton = null;
40
        private JRadioButton nameRadioButton = null;        
41
        private JRadioButton areaRadioButton = null;
42
        private JLabel lblCriterio=null;
43
        private JButton searchButton = null;
44
        private JTextField searchTextField = null;
45
        private JButton infoCrs;
46
        private JButton btnNuevo;
47
        private JButton btnEditar;
48
        private JButton btnEliminar;
49
        private JScrollPane jScrollPane=null;   
50
        private JTable jTable;
51
        public TableSorter sorter = null;
52
        public DefaultTableModel dtm = null;
53
        
54
        public NewCRSPanel() {
55
                super();
56
                initialize();
57
                //fijar los listener de todos los componentes
58
                setListener();
59
                habilitarJbuttons(false);
60
        }
61
        /**
62
         * Inicializa this
63
         *
64
         */
65
        private void initialize(){
66
                this.setLayout(new BorderLayout());
67
                this.setBorder(new EmptyBorder(1,1,1,1));
68
                //Este panel contiene los componentes de radio button
69
                JPanel radio=new JPanel();
70
                radio.setLayout(new GridLayout(1,4,10,0));
71
                radio.add(getLblCriterio());
72
                radio.add(getCodeRadioButton());
73
                radio.add(getNameRadioButton());
74
                radio.add(getAreaRadioButton());
75
                //Agrupar los radioButtons
76
                agruparRadioButtons();
77
                //Este panel contiene los componentes relacionados con la b?squeda
78
                JPanel busqueda=new JPanel();
79
                busqueda.setLayout(new FlowLayout(FlowLayout.LEFT,10,1));
80
                busqueda.add(getSearchButton());
81
                busqueda.add(getSearchTextField());
82
                //busqueda.setBackground(Color.red);
83
                JPanel pNorth=new JPanel();
84
                pNorth.setLayout(new GridLayout(2,1));
85
                pNorth.add(radio);
86
                pNorth.add(busqueda);
87
                this.add(pNorth,BorderLayout.NORTH);
88
                //agregar los botones de la tabla
89
                JPanel pInSouth=new JPanel();
90
                pInSouth.setLayout(new FlowLayout(FlowLayout.LEFT,10,0));
91
                pInSouth.add(getInfoCrs());
92
                pInSouth.add(getBtnNuevo());
93
                pInSouth.add(getBtnEditar());
94
                pInSouth.add(getBtnEliminar());
95
                JPanel pCenter=new JPanel();
96
                pCenter.setLayout(new BorderLayout());
97
                pCenter.add(getJScrollPane(),BorderLayout.CENTER);
98
                pCenter.add(pInSouth,BorderLayout.SOUTH);
99
                this.add(pCenter,BorderLayout.CENTER);
100
                
101
        
102
                
103
        }
104
        /**
105
         * Inicializa el bot?n que muestra la informaci?n de CRS seleccionado
106
         * @return
107
         */
108
        public JButton getInfoCrs() {
109
                if(infoCrs == null) {
110
                        infoCrs = new JButton();
111
                        infoCrs.setPreferredSize(new Dimension(85,23));
112
                        infoCrs.setText(PluginServices.getText(this,"infocrs"));                        
113
                        infoCrs.setMnemonic('I');
114
                        //TODO Poner el tooltipText con Plugin Services
115
                        infoCrs.setToolTipText("Mostrar la informacion del Crs selecionado");
116
                        
117
                }
118
                return infoCrs;
119
        }
120
        /**
121
         * Inicializa el panel que contiene la tabla de resultados
122
         * @return
123
         */
124
        private JScrollPane getJScrollPane() {
125
                if (jScrollPane == null) {
126
                        jScrollPane = new JScrollPane(getJTable(),JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
127
                        jScrollPane.setPreferredSize(new Dimension(500,150));
128
                        jScrollPane.setBorder(new CompoundBorder(new EmptyBorder(3,10,3,10),jScrollPane.getBorder()));
129
                        jScrollPane.setViewportView(getJTable());
130
                }
131
                return jScrollPane;
132
        }
133
        /**
134
         * Inicializa la tabla que se utiliza para mostrar 
135
         * los resultados de la b?squeda
136
         * @return
137
         */
138
        public JTable getJTable() {
139
                if (jTable == null) {
140
                        //TODO: Poner los titulos de las columnas correspondientes
141
                        String[] columnNames= {PluginServices.getText(this,"codigo"),
142
                                        PluginServices.getText(this,"nombre"),
143
                                        PluginServices.getText(this,"tipo"),
144
                                        PluginServices.getText(this,"area"),
145
                        PluginServices.getText(this,"descripcion")};
146
                        Object[][]data = {};                        
147
                        dtm = new DefaultTableModel(data, columnNames)
148
                         {
149
                                private static final long serialVersionUID = 1L;
150
                                public boolean isCellEditable(int row, int column) {
151
                                        return false;
152
                                }
153
                                /*
154
                                 * metodo necesario para cuando utilizamos tablas ordenadas
155
                                 * ya que sino al ordenar por algun campo no se queda con el orden
156
                                 * actual al seleccionar una fila (non-Javadoc)
157
                                 * @see javax.swing.table.TableModel#getColumnClass(int)
158
                                 */
159
                                public Class getColumnClass(int column)
160
                                {
161
                                        return getValueAt(0, column).getClass();
162
                                }
163
                                };
164
                        sorter = new TableSorter(dtm);                        
165

    
166
                        jTable = new JTable(sorter);
167
                        //jTable.setPreferredSize(new Dimension(800, 100));
168
                        sorter.setTableHeader(jTable.getTableHeader());
169
                        jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
170
                        jTable.setCellSelectionEnabled(false);
171
                        jTable.setRowSelectionAllowed(true);
172
                        jTable.setColumnSelectionAllowed(false);
173
                        jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
174
                        TableColumn column = null;
175
                        for (int i = 0; i < columnNames.length; i++) {
176
                            column = jTable.getColumnModel().getColumn(i);
177
                            if (i == 0) {
178
                                column.setPreferredWidth(50); //code column is shorter                                     
179
                            }                                    
180
                            else if (i == 2) {
181
                                    column.setPreferredWidth(80);
182
                            }        
183
                            else if (i==4){
184
                                    column.setPreferredWidth(300);
185
                            }
186
                            else {
187
                                column.setPreferredWidth(140);
188
                            }
189
                        }                        
190
                }
191
                
192
                return jTable;
193
                
194
        }
195
        /**
196
         * Inicializa el radioButton 'Codigo'
197
         * @return jRadioButton
198
         */
199
        public JRadioButton getCodeRadioButton() {
200
                if (codeRadioButton == null) {
201
                        codeRadioButton = new JRadioButton();
202
                        codeRadioButton.setText(PluginServices.getText(this,"por_codigo"));
203
                        codeRadioButton.setSelected(true);
204
                        codeRadioButton.addActionListener(this);
205
                }
206
                return codeRadioButton;
207
        }
208
        /**
209
         * Inicializa el radioButton 'Name'
210
         * @return jRadioButton
211
         */
212
        public JRadioButton getNameRadioButton() {
213
                if (nameRadioButton == null) {
214
                        nameRadioButton = new JRadioButton();
215
                        nameRadioButton.setText(PluginServices.getText(this,"por_nombre"));
216
                        nameRadioButton.addActionListener(this);
217
                }
218
                return nameRadioButton;
219
        }
220
        /**
221
         * Inicializa el radioButton 'Area'
222
         * @return jRadioButton
223
         */
224
        public JRadioButton getAreaRadioButton() {
225
                if (areaRadioButton == null) {
226
                        areaRadioButton = new JRadioButton();
227
                        areaRadioButton.setText(PluginServices.getText(this,"por_area"));
228
                        areaRadioButton.addActionListener(this);
229
                }
230
                return areaRadioButton;
231
        }
232
        /**
233
         * Agrupa los radioButtons
234
         */
235
        private void agruparRadioButtons(){
236
                ButtonGroup group= new ButtonGroup();
237
                group.add(getCodeRadioButton());
238
                group.add(getNameRadioButton());
239
                group.add(getAreaRadioButton());
240
        }
241
        /**
242
         * Inicializa el label 'Criterio de B?squeda'
243
         * @return jLabel
244
         */
245
        public JLabel getLblCriterio() {
246
                lblCriterio = new JLabel();
247
                lblCriterio.setText(PluginServices.getText(this, "criterio_busqueda")+":");
248
                return lblCriterio;
249
        }
250
        /**
251
         * Inicializa el bot?n 'Buscar'
252
         * @return jButton
253
         */
254
        public JButton getSearchButton() {
255
                if (searchButton == null) {
256
                        searchButton = new JButton();
257
                        searchButton.setPreferredSize(new Dimension(75,20));
258
                        searchButton.setText(PluginServices.getText(this,"buscar"));
259
                        searchButton.setMnemonic('S');
260
                        //searchButton.setToolTipText("Search of a CRS by selected criterion");
261
                                                
262
                }
263
                return searchButton;
264
        }
265
        /**
266
         * Inicializa el TextField 
267
         * en el que se incluye el texto a buscar
268
         * @return jTextField
269
         */
270
        public JTextField getSearchTextField() {
271
                if (searchTextField == null) {
272
                        searchTextField = new JTextField();
273
                        searchTextField.setPreferredSize(new Dimension(340,20));
274
                                
275
                }
276
                return searchTextField;
277
        }
278
        /**
279
         * Manejador de eventos
280
         */
281
        public void actionPerformed(ActionEvent e) {
282
                if (e.getSource().equals(getCodeRadioButton())){
283
                        getSearchTextField().setText("");
284
                }else if (e.getSource().equals(getNameRadioButton())){
285
                        getSearchTextField().setText("");
286
                }else if (e.getSource().equals(getAreaRadioButton())){
287
                        getSearchTextField().setText("");
288
                }else if (e.getSource().equals(getInfoCrs())){
289
                        //abrir el panel de informacion 
290
                        
291
                }else if (e.getSource().equals(getBtnEditar())){
292
                        //editar la fila seleccionada de la tabla (si hay)
293
                }else if (e.getSource().equals(getBtnEliminar())){
294
                        //eliminar la fila seleccionada de la tabla
295
                }else if (e.getSource().equals(getBtnNuevo())){
296
                        //mostrar el asistente de nuevo crs
297
                
298
                        MainPanel wizard = new MainPanel();
299
                        PluginServices.getMDIManager().addWindow(wizard);
300
                        
301
                }else if (e.getSource().equals(getSearchButton())){
302
                        //comprobar el texto y buscar
303
                }
304
        }
305
        public void keyPressed(KeyEvent e) {
306
                //Si se pulsa intro-->Buscar
307
                if (e.getSource() == this.getSearchTextField()) {
308
                        if (e.getKeyCode() == 10) {
309
                                getSearchTextField().setText("Buscar el texto");
310
                                //searchButton();
311
                        }                        
312
                }                
313
        }
314
        public void keyReleased(KeyEvent e) {
315
                
316
        }
317
        public void keyTyped(KeyEvent e) {
318
                
319
        }
320
        /**
321
         * Inicializa el bot?n 'Editar'  una fila de la tabla
322
         * @return jButton
323
         */
324
        public JButton getBtnEditar() {
325
                if (btnEditar==null){
326
                        btnEditar=new JButton();
327
                        btnEditar.setText(PluginServices.getText(this,"editar"));
328
                }
329
                return btnEditar;
330
        }
331
        /**
332
         * Inicializa el bot?n 'Eliminar' una fila de la tabla
333
         * @return
334
         */
335
        public JButton getBtnEliminar() {
336
                if (btnEliminar==null){
337
                        btnEliminar=new JButton();
338
                        btnEliminar.setText(PluginServices.getText(this,"eliminar"));
339
                }
340
                return btnEliminar;
341
        }
342
        /**
343
         * Inicializa el bot?n 'Nuevo' para la creaci?n de un nuevo Crs
344
         * @return
345
         */
346
        public JButton getBtnNuevo() {
347
                if (btnNuevo==null){
348
                        btnNuevo=new JButton();
349
                        btnNuevo.setText(PluginServices.getText(this,"nuevo"));
350
                }
351
                return btnNuevo;
352
        }
353
        /**
354
         * Establece los listener de todos los componentes
355
         */
356
        private void setListener(){
357
                getBtnEditar().addActionListener(this);
358
                getBtnEliminar().addActionListener(this);
359
                getBtnNuevo().addActionListener(this);
360
                getInfoCrs().addActionListener(this);
361
                getCodeRadioButton().addActionListener(this);
362
                getNameRadioButton().addActionListener(this);
363
                getAreaRadioButton().addActionListener(this);
364
                getSearchButton().addActionListener(this);
365
                getSearchTextField().addKeyListener(this);
366
                
367
        }
368
        private void habilitarJbuttons(boolean b){
369
                getInfoCrs().setEnabled(b);
370
                getBtnEditar().setEnabled(b);
371
                getBtnEliminar().setEnabled(b);
372
        }
373

    
374
}