Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / checkslidertext / CheckColorSliderTextContainer.java @ 12091

History | View | Annotate | Download (3.87 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.Insets;
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28

    
29
import javax.swing.JCheckBox;
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 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
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
58
                gridBagConstraints1.insets = new Insets(0,0,0,0);
59
                super.add(getPCheck(), BorderLayout.WEST);
60
                check.addActionListener(this);
61
                check.setSelected(active);
62
                setControlEnabled(active);
63

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

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

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

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

    
103
        /**
104
         * Devuelve si el control esta activo
105
         * @param active
106
         */
107
        public boolean isChecked() {
108
                return getCheck().isSelected();
109
        }
110

    
111
        public void actionPerformed(ActionEvent e) {
112
                if (e.getSource() == check) {
113
                        setControlEnabled(check.isSelected());
114
                        callChangeValue();
115
                }
116
        }
117

    
118
        /* (non-Javadoc)
119
         * @see javax.swing.JComponent#setEnabled(boolean)
120
         */
121
        public void setEnabled(boolean enabled) {
122
                getCheck().setEnabled(enabled);
123
                if (enabled) {
124
                        if (!getCheck().isSelected()) {
125
                                getSlider().setEnabled(false);
126
                                getJSpinner().setEnabled(false);
127
                        } else {
128
                                super.setEnabled(enabled);
129
                        }
130
                } else {
131
                        super.setEnabled(enabled);
132
                }
133
        }
134
}