Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / checkslidertext / CheckColorSliderTextContainer.java @ 19109

History | View | Annotate | Download (3.93 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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.checkslidertext;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.Dimension;
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27

    
28
import javax.swing.JCheckBox;
29
import javax.swing.JLabel;
30
import javax.swing.JPanel;
31

    
32
import org.gvsig.gui.beans.slidertext.ColorSliderTextContainer;
33
/**
34
 * A?ade un check al componente Slider ajustando el tama?o del componente a la
35
 * longitud del check. Al redimensionar el componente varia el tama?o del slider
36
 *
37
 * @version 08/06/2007
38
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
39
 */
40
public class CheckColorSliderTextContainer extends ColorSliderTextContainer implements ActionListener {
41
        private static final long        serialVersionUID        = 7047604405777061995L;
42
        public JCheckBox check = null;
43
        private JPanel pLabel = null;
44
        private String        text = null;
45

    
46
        /**
47
         * Constructor
48
         * @param min Valor m?nimo del slider
49
         * @param max Valor m?ximo del slider
50
         * @param defaultPos Posici?n inicial
51
         * @param txt Texto de la etiqueta del check
52
         * @param active Valor por defecto del control.True activo y false desactivo
53
         */
54
        public CheckColorSliderTextContainer(int min, int max, int defaultPos, String txt, boolean active) {
55
                super(min, max, defaultPos);
56
                text = txt;
57
                add(getPCheck(), BorderLayout.WEST);
58
                check.addActionListener(this);
59
                check.setSelected(active);
60
                setControlEnabled(active);
61

    
62
                this.setMaximumSize(new Dimension(32767, 31));
63
                this.setMinimumSize(new Dimension(250, 31));
64
        }
65

    
66
        /**
67
         * This method initializes jPanel
68
         *
69
         * @return javax.swing.JPanel
70
         */
71
        private JPanel getPCheck() {
72
                if (pLabel == null) {
73
                        pLabel = new JPanel();
74
                        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
75
                        gridBagConstraints1.insets = new java.awt.Insets(0, 0, 13, 0);
76
                        pLabel.setLayout(new GridBagLayout());
77
                        pLabel.add(getCheck(), gridBagConstraints1);
78
                        pLabel.add(new JLabel(text), gridBagConstraints1);
79
                }
80
                return pLabel;
81
        }
82

    
83
        /**
84
         * This method initializes JLabel
85
         * @return
86
         */
87
        private JCheckBox getCheck() {
88
                if (check == null)
89
                        check = new JCheckBox();
90
                return check;
91
        }
92

    
93
        /**
94
         * Activa o desactiva el control del panel
95
         * @param active
96
         */
97
        public void setChecked(boolean active) {
98
                getCheck().setSelected(active);
99
                super.setControlEnabled(active);
100
        }
101

    
102
        /**
103
         * Hace visible el checkbox o no del componente
104
         * @param value
105
         */
106
        public void setCheckboxVisible(boolean value) {
107
                if (!value)
108
                        setChecked(true);
109
                getCheck().setVisible(value);
110
        }
111

    
112
        /**
113
         * Devuelve si el control esta activo
114
         * @param active
115
         */
116
        public boolean isChecked() {
117
                return getCheck().isSelected();
118
        }
119

    
120
        public void actionPerformed(ActionEvent e) {
121
                if (e.getSource() == check) {
122
                        setControlEnabled(check.isSelected());
123
                        callChangeValue();
124
                }
125
        }
126

    
127
        /* (non-Javadoc)
128
         * @see javax.swing.JComponent#setEnabled(boolean)
129
         */
130
        public void setEnabled(boolean enabled) {
131
                super.setEnabled(enabled);
132
                getCheck().setEnabled(enabled);
133

    
134
                if (!getCheck().isSelected())
135
                        enabled = false;
136

    
137
                getSlider().setEnabled(enabled);
138
                getJSpinner().setEnabled(enabled);
139
        }
140
}