Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / checkslidertext / CheckSliderTextContainer.java @ 40561

History | View | Annotate | Download (5.42 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.checkslidertext;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.FlowLayout;
28
import java.awt.GridBagConstraints;
29
import java.awt.GridBagLayout;
30
import java.awt.Insets;
31
import java.awt.event.ActionEvent;
32
import java.awt.event.ActionListener;
33

    
34
import javax.swing.JCheckBox;
35
import javax.swing.JLabel;
36
import javax.swing.JPanel;
37

    
38
import org.gvsig.gui.beans.slidertext.SliderTextContainer;
39
/**
40
 * A?ade un check al componente Slider ajustando el tama?o del componente
41
 * a la longitud del check. Al redimensionar el componente varia el tama?o
42
 * del slider
43
 * 
44
 * @author Nacho Brodin(nachobrodin@gmail.com) 
45
 */
46
public class CheckSliderTextContainer extends SliderTextContainer implements ActionListener{
47
        private static final long serialVersionUID  = -542842897847364459L;
48
        public JCheckBox          check             = null;
49
        private JPanel            pLabel            = null;
50
        private String            text              = null;
51
        private boolean           showCheck         = true;
52
        private JLabel            labelWithoutCheck = null;
53

    
54
        /**
55
         * Constructor        
56
         * @param min Valor m?nimo del slider
57
         * @param max Valor m?ximo del slider
58
         * @param defaultPos Posici?n inicial
59
         * @param up Si es true el texto se coloca sobre el componente y si es false a la izquierda 
60
         * @param txt Texto de la etiqueta del check
61
         * @param active Valor por defecto del control.True activo y false desactivo
62
         * @deprecated Es recomendable el uso del constructor con el par?metro border. Tiene la misma funcionalidad 
63
         * si se pone ese par?metro a true. Se mantiene este constructor por compatibilidad con versiones 
64
         * anteriores.
65
         */
66
        public CheckSliderTextContainer(int min, int max, int defaultPos, boolean up, String txt, boolean active){
67
                this(min, max, defaultPos, up, txt, active, false, true);
68
        }
69
        
70
        /**
71
         * Constructor        
72
         * @param min Valor m?nimo del slider
73
         * @param max Valor m?ximo del slider
74
         * @param defaultPos Posici?n inicial
75
         * @param up Si es true el texto se coloca sobre el componente y si es false a la izquierda 
76
         * @param txt Texto de la etiqueta del check
77
         * @param active Valor por defecto del control.True activo y false desactivo
78
         * @param border True para mostrar el borde al control y false para ocultarlo
79
         * @param showCheck True para mostrar el checkbox de activaci?n y desactivaci?n. False para ocultarlo
80
         */
81
        public CheckSliderTextContainer(int min, int max, int defaultPos, boolean up, String txt, boolean active, boolean border, boolean showCheck) {
82
                super(min, max, defaultPos, border);
83
                this.showCheck = showCheck;
84
                text = txt;
85
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
86
                gridBagConstraints1.insets = new Insets(0,0,0,0);
87
                if(!up)
88
                        super.add(getPCheck(up), BorderLayout.WEST);
89
                else
90
                        super.add(getPCheck(up), BorderLayout.NORTH);
91
                if(showCheck) {
92
                        check.addActionListener(this);
93
                        check.setSelected(active);
94
                }
95
                setControlEnabled(active);
96
        }
97

    
98
        /**
99
         * This method initializes jPanel        
100
         *         
101
         * @return javax.swing.JPanel        
102
         */
103
        private JPanel getPCheck(boolean up) {
104
                if (pLabel == null) {
105
                        pLabel = new JPanel();
106
                        if (!up) {
107
                                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
108
                                pLabel.setLayout(new GridBagLayout());
109
                                if(showCheck) {
110
                                        gridBagConstraints1.insets = new java.awt.Insets(0, 10, 13, 0);
111
                                        pLabel.add(getCheck(), gridBagConstraints1);
112
                                } else {
113
                                        gridBagConstraints1.insets = new java.awt.Insets(0, 0, 13, 0);
114
                                        labelWithoutCheck = new JLabel(text); 
115
                                        pLabel.add(labelWithoutCheck, gridBagConstraints1);
116
                                }
117
                        } else {
118
                                FlowLayout fl = new FlowLayout();
119
                                fl.setAlignment(FlowLayout.LEFT);
120
                                pLabel.setLayout(fl);
121
                                if(showCheck)
122
                                        pLabel.add(getCheck(), null);
123
                                else {
124
                                        labelWithoutCheck = new JLabel(text); 
125
                                        pLabel.add(labelWithoutCheck, null);
126
                                }
127
                        }
128
                }
129
                return pLabel;
130
        }
131

    
132
        /**
133
         * This method initializes JLabel
134
         * @return
135
         */
136
        public JCheckBox getCheck() {
137
                if(check == null)
138
                        check = new JCheckBox(text);
139
                return check;
140
        }
141

    
142
        /**
143
         * Activa o desactiva el control del panel
144
         * @param active
145
         */
146
        public void setControlEnabled(boolean active) {
147
                if(showCheck)
148
                        getCheck().setSelected(active);
149
                if(labelWithoutCheck != null)
150
                        labelWithoutCheck.setEnabled(active);
151
                super.setControlEnabled(active);
152
        }
153

    
154
        /*
155
         * (non-Javadoc)
156
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
157
         */
158
        public void actionPerformed(ActionEvent e) {
159
                if (e.getSource() == check) {
160
                        setControlEnabled(check.isSelected());
161
                        callChangeValue(true);
162
                }
163
        }
164
}