Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / gui / pointsTable / TableControlerPanel.java @ 5352

History | View | Annotate | Download (11 KB)

1
package org.gvsig.georeferencing.gui.pointsTable;
2

    
3
import java.awt.FlowLayout;
4

    
5
import javax.swing.ImageIcon;
6
import javax.swing.JButton;
7
import javax.swing.JComboBox;
8
import javax.swing.JLabel;
9
import javax.swing.JPanel;
10

    
11
import org.gvsig.georeferencing.GeoreferencingToolsModule;
12

    
13
import com.iver.andami.PluginServices;
14

    
15
/**
16
 * Control para el manejo de tablas. No contiene eventos, estos deben 
17
 * ser manejados desde la clase que lo llame.
18
 * 
19
 * @author Nacho Brodin (brodin_ign@gva.es)
20
 *
21
 */
22
public class TableControlerPanel extends JPanel{
23
                
24
        //**********************Vars**********************************
25
        private JButton                 bPrev = null;
26
        private JComboBox                 cPoint = null;
27
        private JButton                 bNext = null;
28
        private JButton                 bFirst = null;
29
        private JButton                 bLast = null;
30
        private JPanel                         pTableControl = null;
31
        private JLabel                         lPoints = null;
32
        private JLabel                         lNumberOfPoints = null;
33
        private JButton                 bNew = null;
34
        private JButton                 bDelPoint = null;
35
        private JButton                 bClear = null;
36
        private String                        pathToImages = "images/";//"/com/iver/cit/gvsig/gui/panels/images/";
37
        /**
38
         * Estado de los botones cuando se ejecuta disableAllControls
39
         */
40
        private boolean[]                                         buttonsState = new boolean[7];
41
        /**
42
         * DisableAllControls ha sido ejecutada si est? a true esta variabled
43
         */
44
        private boolean                                         disableAllControls = false;
45
        //**********************End Vars******************************
46
        
47
        //**********************Methods*******************************
48
        /**
49
         * This is the default constructor
50
         */
51
        public TableControlerPanel() {
52
                super();
53
                initialize();
54
        }
55

    
56
        /**
57
         * This method initializes this
58
         * 
59
         * @return void
60
         */
61
        private void initialize() {                
62
                this.setPreferredSize(new java.awt.Dimension(290,22));
63
                FlowLayout flowLayout5 = new FlowLayout();
64
                flowLayout5.setHgap(0);
65
                flowLayout5.setVgap(0);
66
        
67
                this.setLayout(flowLayout5);
68
                
69
                lPoints = new JLabel();
70
                lPoints.setText(PluginServices.getText(this, "puntos"));
71
                this.add(lPoints, null);
72
                
73
                this.add(getBFirst(), null);
74
                this.add(getBPrev(), null);
75
                this.add(getCPoint(), null);
76
                this.add(getBNext(), null);
77
                this.add(getBLast(), null);
78
                this.add(getBNew(), null);
79
                this.add(getLNumberOfPoints(), null);
80
                this.add(getBDelPoint(), null);
81
                this.add(getBClear(), null);
82
        }
83
        
84
        /**
85
         * Esta funci?n deshabilita todos los controles y guarda sus valores
86
         * de habilitado o deshabilitado para que cuando se ejecute restoreControlsValue
87
         * se vuelvan a quedar como estaba
88
         */
89
        public void disableAllControls(){
90
                if(!disableAllControls){
91
                        disableAllControls = true;
92
                        //Salvamos los estados
93
                        
94
                        buttonsState[0] = getBFirst().isEnabled();
95
                        buttonsState[1] = getBPrev().isEnabled();
96
                        buttonsState[2] = getCPoint().isEnabled();
97
                        buttonsState[3] = getBNext().isEnabled();
98
                        buttonsState[4] = getBLast().isEnabled();
99
                        buttonsState[5] = getBDelPoint().isEnabled();
100
                        buttonsState[6] = getBClear().isEnabled();
101
                                                
102
                        //Desactivamos controles
103
                        getBFirst().setEnabled(false);
104
                        getBPrev().setEnabled(false);
105
                        getCPoint().setEnabled(false);
106
                        getBNext().setEnabled(false);
107
                        getBLast().setEnabled(false);
108
                        getBDelPoint().setEnabled(false);
109
                        getBClear().setEnabled(false);
110
                }
111
        }
112
        
113
        /**
114
         * Esta funci?n deja los controles como estaban al ejecutar la funci?n 
115
         * disableAllControls
116
         */
117
        public void restoreControlsValue(){
118
                if(disableAllControls){
119
                        disableAllControls = false;
120
                        getBFirst().setEnabled(buttonsState[0]);
121
                        getBPrev().setEnabled(buttonsState[1]);
122
                        getCPoint().setEnabled(buttonsState[2]);
123
                        getBNext().setEnabled(buttonsState[3]);
124
                        getBLast().setEnabled(buttonsState[4]);
125
                        getBDelPoint().setEnabled(buttonsState[5]);
126
                        getBClear().setEnabled(buttonsState[6]);
127
                }
128
        }
129
        //**********************Methods*******************************
130
        /**
131
         * This method initializes jButton        
132
         *         
133
         * @return javax.swing.JButton        
134
         */    
135
        public JButton getBFirst() {
136
                if (bFirst == null) {
137
                        bFirst = new JButton();
138
                        bFirst.setPreferredSize(new java.awt.Dimension(22,22));
139
                        bFirst.setEnabled(false);
140
                        bFirst.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "first.png")));
141
                        bFirst.setToolTipText(PluginServices.getText(this, "primero"));
142
                }
143
                return bFirst;
144
        }
145
        
146
        /**
147
         * This method initializes jButton        
148
         *         
149
         * @return javax.swing.JButton        
150
         */    
151
        public JButton getBLast() {
152
                if (bLast == null) {
153
                        bLast = new JButton();
154
                        bLast.setPreferredSize(new java.awt.Dimension(22,22));
155
                        bLast.setEnabled(false);
156
                        bLast.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "last.png")));
157
                        bLast.setToolTipText(PluginServices.getText(this, "ultimo"));
158
                }
159
                return bLast;
160
        }
161
        
162
        /**
163
         * This method initializes bBefore        
164
         *         
165
         * @return javax.swing.JButton        
166
         */
167
        public JButton getBPrev() {
168
                if (bPrev == null) {
169
                        bPrev = new JButton();
170
                        bPrev.setText("");
171
                        bPrev.setEnabled(false);
172
                        bPrev.setPreferredSize(new java.awt.Dimension(22,22));
173
                        bPrev.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "prev.png")));
174
                        bPrev.setActionCommand("");
175
                        bPrev.setToolTipText(PluginServices.getText(this, "anterior"));
176
                }
177
                return bPrev;
178
        }
179

    
180
        /**
181
         * This method initializes bNext        
182
         *         
183
         * @return javax.swing.JButton        
184
         */
185
        public JButton getBNext() {
186
                if (bNext == null) {
187
                        bNext = new JButton();
188
                        bNext.setText("");
189
                        bNext.setEnabled(false);
190
                        bNext.setPreferredSize(new java.awt.Dimension(22,22));
191
                        bNext.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "next.png")));
192
                        bNext.setActionCommand("");
193
                        bNext.setToolTipText(PluginServices.getText(this, "siguiente"));
194
                }
195
                return bNext;
196
        }
197
        
198
        /**
199
         * Este m?todo inicializa el combo que contiene el n?mero de puntos.        
200
         *         
201
         * @return javax.swing.JComboBox        
202
         */
203
        public JComboBox getCPoint() {
204
                if (cPoint == null) {
205
                        cPoint = new JComboBox();
206
                        cPoint.setPreferredSize(new java.awt.Dimension(50,22));
207
                        
208
                }
209
                return cPoint;
210
        }
211

    
212
        /**
213
         * @return Returns the lNumberOfPoints.
214
         */
215
        public JLabel getLNumberOfPoints() {
216
                if(lNumberOfPoints == null){
217
                        lNumberOfPoints = new JLabel();
218
                        lNumberOfPoints.setText(PluginServices.getText(this, "de")+" 0");
219
                        lNumberOfPoints.setPreferredSize(new java.awt.Dimension(40,15));
220
                }
221
                return lNumberOfPoints;
222
        }
223
        
224
        /**
225
         * This method initializes jButton        
226
         *         
227
         * @return javax.swing.JButton        
228
         */    
229
        public JButton getBNew() {
230
                if (bNew == null) {
231
                        bNew = new JButton();
232
                        bNew.setPreferredSize(new java.awt.Dimension(22,22));
233
                        bNew.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "newpoint.png")));
234
                        bNew.setToolTipText(PluginServices.getText(this, "nuevo"));
235
                }
236
                return bNew;
237
        }
238
        
239
        /**
240
         * Este m?todo inicializa el bot?n del eliminar punto que har? que se elimine
241
         * el punto seleccionado.        
242
         *         
243
         * @return javax.swing.JButton        
244
         */
245
        public JButton getBDelPoint() {
246
                if (bDelPoint == null) {
247
                        bDelPoint = new JButton();
248
                        bDelPoint.setText("");
249
                        bDelPoint.setEnabled(false);
250
                        bDelPoint.setPreferredSize(new java.awt.Dimension(22,22));
251
                        bDelPoint.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "delone.png")));
252
                        bDelPoint.setToolTipText(PluginServices.getText(this, "borrar_uno"));
253
                }
254
                return bDelPoint;
255
        }
256
        
257
        /**
258
         * Este m?todo inicializa el bot?n del clear que har? que se eliminen todos los
259
         * puntos seleccionados.        
260
         *         
261
         * @return javax.swing.JButton        
262
         */
263
        public JButton getBClear() {
264
                if (bClear == null) {
265
                        bClear = new JButton();
266
                        bClear.setText("");
267
                        bClear.setPreferredSize(new java.awt.Dimension(22,22));
268
                        bClear.setEnabled(false);
269
                        bClear.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "delall.png")));
270
                        bClear.setActionCommand("");
271
                        bClear.setToolTipText(PluginServices.getText(this, "borrar_todos"));
272
                }
273
                return bClear;
274
        }
275
        
276
        /**
277
         * Resetea el control al estado inicial. Limpia el combo, pone
278
         * el n?mero de elementos a 0 y desactiva las flechas.
279
         *
280
         */
281
        public void resetControls(){
282
                getCPoint().removeAllItems();
283
                getLNumberOfPoints().setText(PluginServices.getText(this, "de 0"));
284
                checkArrows();
285
        }
286
        
287
        /**
288
         * Elimina del control un elemento de una posici?n.
289
         * <UL>
290
         * <LI>Actualiza el combo</LI>
291
         * <LI>Actualiza el texto que dice el n?mero de elementos</LI>
292
         * <LI>Actualiza las flechas</LI>
293
         * </UL>
294
         * @param pos Posici?n del elemento a eliminar.
295
         */
296
        public void setNItems(int n){
297
                if(n < 1)
298
                        return;
299
                getCPoint().removeAllItems();
300
                for(int i=1;i<=n;i++){
301
                        try{
302
                                getCPoint().addItem(String.valueOf(i));
303
                        }catch(ArrayIndexOutOfBoundsException ex){
304
                                //No a?adimos nada
305
                        }
306
                }
307
                getLNumberOfPoints().setText(PluginServices.getText(this, "de ") + " " + n);
308
                checkArrows();
309
        }
310
        
311
        /**
312
         * Selecciona un elemento del control
313
         * @param index
314
         */
315
        public void setSelectedIndex(int index){
316
                getCPoint().setSelectedIndex(index);
317
                checkArrows();
318
        }
319
        
320
        /**
321
         * Devuelve el punto seleccionado
322
         * @return Punto seleccionado.
323
         */
324
        public int getSelectedIndex(){
325
                return getCPoint().getSelectedIndex();
326
        }
327
        
328
        /**
329
         * Obtiene el n?mero de elementos en la lista.
330
         * @return N?mero de elementos
331
         */
332
        public int getItemCount(){
333
                return getCPoint().getItemCount();
334
        }
335
        
336
        /**
337
         * Obtiene el Objeto seleccionado como cadena de texto.
338
         * @return N?mero seleccionado
339
         */
340
        public String getSelectedItem(){
341
                return getCPoint().getSelectedItem().toString();
342
        }
343
        
344
        /**
345
         * Comprueba la posici?n del combo para ver si tiene que
346
         * habilitar o deshabilitar las flechas de delante y detr?s.
347
         */
348
        public void checkArrows(){
349
                if(getCPoint().getItemCount() <= 0){
350
                        getBClear().setEnabled(false);
351
                        getBDelPoint().setEnabled(false);
352
                }else{
353
                        getBClear().setEnabled(true);
354
                        getBDelPoint().setEnabled(true);
355
                }
356
                
357
                if(getCPoint().getSelectedIndex() == -1){
358
                        getBPrev().setEnabled(false);
359
                        getBNext().setEnabled(false);
360
                        getBLast().setEnabled(false);
361
                        getBFirst().setEnabled(false);
362
                        
363
                        return;
364
                }
365
                if(getCPoint().getSelectedIndex() == 0){
366
                        getBPrev().setEnabled(false);
367
                        getBFirst().setEnabled(false);
368
                }else{
369
                        getBPrev().setEnabled(true);
370
                        getBFirst().setEnabled(true);
371
                }
372
                
373
                if(getCPoint().getSelectedIndex() == (getCPoint().getItemCount() - 1) ){
374
                        getBNext().setEnabled(false);
375
                        getBLast().setEnabled(false);
376
                }else{
377
                        getBNext().setEnabled(true);
378
                        getBLast().setEnabled(true);
379
                }
380
        }
381
        
382
        /**
383
         * A?ade un punto al combo y checkea los controles colocandolos en los valores correctos.
384
         * @param countPoints N?mero de punto a a?adir al final del combo
385
         */
386
        public void addPointToTable(int countPoints){
387
                getCPoint().addItem("" + countPoints);
388
                getLNumberOfPoints().setText(PluginServices.getText(this, "de ") + " " + countPoints);
389
                setSelectedIndex(getItemCount() - 1);
390
                checkArrows();
391
        }
392
        
393
        /**
394
         * Asigna la ruta donde est?n las imagenes
395
         * @param pathToImages
396
         */
397
        public void setPathToImages(String pathToImages) {
398
                this.pathToImages = pathToImages;
399
        }
400
        
401
        /**
402
     * Activa o desactiva este panel y todos los que lo componen
403
     * @param enabled variable booleana para la activaci?n y/o desactivaci?n
404
     */
405
    public void setEnabled(boolean enabled){
406
            this.getBDelPoint().setEnabled(enabled);
407
            this.getBClear().setEnabled(enabled);
408
    }
409
 }