Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2060 / libraries / libUIComponent / src / org / gvsig / gui / beans / table / MoveRowsPanel.java @ 39371

History | View | Annotate | Download (4.15 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.gui.beans.table;
20

    
21
import java.awt.Dimension;
22
import java.net.URL;
23

    
24
import javax.swing.ImageIcon;
25
import javax.swing.JButton;
26
import javax.swing.JPanel;
27

    
28
import org.gvsig.gui.beans.Messages;
29
import org.gvsig.gui.beans.table.listeners.TableListener;
30
import org.gvsig.gui.util.StatusComponent;
31

    
32
public class MoveRowsPanel extends JPanel {
33
  private static final long serialVersionUID = -4496318143555472677L;
34

    
35
        private int             HEIGHT_BUTTONS  = 19;       // 16 estaria bien
36
        private JButton         bUp             = null;
37
        private JButton         bDown           = null;
38
        private int             selected        = -1;
39
        private int             cont            = 0;
40
        private String          pathToImages    = "images/"; // "/com/iver/cit/gvsig/gui/panels/images/";
41

    
42
        /**
43
         * Objeto para controlar el estado de los componentes visuales 
44
         */
45
        private StatusComponent statusComponent = null;
46
        
47
        /**
48
         * This is the default constructor
49
         */
50
        public MoveRowsPanel(TableListener tableListener) {
51
                initialize(tableListener);
52
        }
53
        
54
        private void initialize(TableListener tableListener) {
55
                statusComponent = new StatusComponent(this);
56

    
57
                setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 1, 0));
58
                add(getBUp());
59
                add(getBDown());
60

    
61
                getBUp().addActionListener(tableListener);
62
                getBDown().addActionListener(tableListener);
63
        }
64

    
65
        public void setSelectedIndex(int i, int cont) {
66
                selected = i;
67
                this.cont = cont;
68
                checkArrows();
69
        }
70
        
71
        /**
72
         * Comprueba la posici?n del combo para ver si tiene que
73
         * habilitar o deshabilitar las flechas de delante y detr?s.
74
         */
75
        private void checkArrows(){
76
                if (!statusComponent.isEnabled())
77
                        return;
78

    
79
                if (selected == -1) {
80
                        getBUp().setEnabled(false);
81
                        getBDown().setEnabled(false);
82
                        return;
83
                }
84

    
85
                if (selected == 0) {
86
                        getBUp().setEnabled(false);
87
                } else {
88
                        getBUp().setEnabled(true);
89
                }
90

    
91
                if (selected == (cont - 1)) {
92
                        getBDown().setEnabled(false);
93
                } else {
94
                        getBDown().setEnabled(true);
95
                }
96
        }        
97

    
98
        /**
99
         * This method initializes bUp
100
         * @return javax.swing.JButton
101
         */
102
        public JButton getBUp() {
103
                if (bUp == null) {
104
                        bUp = new JButton("");
105
                        bUp.setEnabled(true);
106
                        bUp.setPreferredSize(new Dimension(22, HEIGHT_BUTTONS));
107
                        URL url = getClass().getResource(pathToImages + "up-16x16.png");
108
                        if(url != null)
109
                                bUp.setIcon(new ImageIcon(url));
110
                        bUp.setActionCommand("");
111
                        bUp.setToolTipText(Messages.getText("subir"));
112
                }
113
                return bUp;
114
        }
115
        
116

    
117
        /**
118
         * This method initializes bDown
119
         * @return javax.swing.JButton
120
         */
121
        public JButton getBDown() {
122
                if (bDown == null) {
123
                        bDown = new JButton("");
124
                        bDown.setEnabled(true);
125
                        bDown.setPreferredSize(new Dimension(22, HEIGHT_BUTTONS));
126
                        URL url = getClass().getResource(pathToImages + "down-16x16.png");
127
                        if(url != null)
128
                                bDown.setIcon(new ImageIcon(url));
129
                        bDown.setActionCommand("");
130
                        bDown.setToolTipText(Messages.getText("bajar"));
131
                }
132
                return bDown;
133
        }
134
        
135
        /**
136
         * Esta funci?n deshabilita todos los controles y guarda sus valores
137
         * de habilitado o deshabilitado para que cuando se ejecute restoreControlsValue
138
         * se vuelvan a quedar como estaba
139
         */
140
        public void disableAllControls(){
141
                statusComponent.setEnabled(false);
142
        }
143

    
144
        /**
145
         * Esta funci?n deja los controles como estaban al ejecutar la funci?n
146
         * disableAllControls
147
         */
148
        public void restoreControlsValue(){
149
                statusComponent.setEnabled(true);
150
        }        
151
}