Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / checkslidertext / CheckSliderTextContainer.java @ 12180

History | View | Annotate | Download (3.75 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.FlowLayout;
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.SliderTextContainer;
33
/**
34
 * A?ade un check al componente Slider ajustando el tama?o del componente
35
 * a la longitud del check. Al redimensionar el componente varia el tama?o
36
 * del slider
37
 * 
38
 * @author Nacho Brodin(nachobrodin@gmail.com) 
39
 */
40
public class CheckSliderTextContainer extends SliderTextContainer implements ActionListener{
41
        private static final long serialVersionUID = -542842897847364459L;
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 up Si es true el texto se coloca sobre el componente y si es false a la izquierda 
52
         * @param txt Texto de la etiqueta del check
53
         * @param active Valor por defecto del control.True activo y false desactivo
54
         */
55
        public CheckSliderTextContainer(int min, int max, int defaultPos, boolean up, String txt, boolean active){
56
                super(min, max, defaultPos);
57
                text = txt;
58
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
59
                gridBagConstraints1.insets = new Insets(0,0,0,0);
60
                if(!up)
61
                        super.add(getPCheck(up), BorderLayout.WEST);
62
                else
63
                        super.add(getPCheck(up), BorderLayout.NORTH);
64
                check.addActionListener(this);
65
                check.setSelected(active);
66
                setControlEnabled(active);
67
        }
68

    
69
        /**
70
         * This method initializes jPanel        
71
         *         
72
         * @return javax.swing.JPanel        
73
         */
74
        private JPanel getPCheck(boolean up) {
75
                if (pLabel == null) {
76
                        pLabel = new JPanel();
77
                        if (!up) {
78
                                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
79
                                gridBagConstraints1.insets = new java.awt.Insets(0, 10, 13, 0);
80
                                pLabel.setLayout(new GridBagLayout());
81
                                pLabel.add(getCheck(), gridBagConstraints1);
82
                        } else {
83
                                FlowLayout fl = new FlowLayout();
84
                                fl.setAlignment(FlowLayout.LEFT);
85
                                pLabel.setLayout(fl);
86
                                pLabel.add(getCheck(), null);
87
                        }
88
                }
89
                return pLabel;
90
        }
91

    
92
        /**
93
         * This method initializes JLabel
94
         * @return
95
         */
96
        public JCheckBox getCheck() {
97
                if(check == null)
98
                        check = new JCheckBox(text);
99
                return check;
100
        }
101

    
102
        /**
103
         * Activa o desactiva el control del panel
104
         * @param active
105
         */
106
        public void setControlEnabled(boolean active) {
107
                getCheck().setSelected(active);
108
                super.setControlEnabled(active);
109
        }
110

    
111
        /*
112
         * (non-Javadoc)
113
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
114
         */
115
        public void actionPerformed(ActionEvent e) {
116
                if (e.getSource() == check) {
117
                        setControlEnabled(check.isSelected());
118
                        callChangeValue();
119
                }
120
        }
121
}