Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / labelslidertext / LabelSliderTextContainer.java @ 12592

History | View | Annotate | Download (3.23 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.labelslidertext;
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

    
27
import javax.swing.JLabel;
28
import javax.swing.JPanel;
29

    
30
import org.gvsig.gui.beans.slidertext.SliderTextContainer;
31
/**
32
 * A?ade una etiqueta al componente Slider ajustando el tama?o del componente
33
 * a la longitud de la etiqueta. Al redimensionar el componente varia el tama?o
34
 * del slider
35
 * 
36
 * @author Nacho Brodin(nachobrodin@gmail.com) 
37
 */
38
public class LabelSliderTextContainer extends SliderTextContainer {
39
        private static final long serialVersionUID = -4617272063786945078L;
40
        public JLabel lName = null;
41
        private JPanel pLabel = null;
42

    
43
        /**
44
         * Constructor        
45
         * @param min Valor m?nimo del slider
46
         * @param max Valor m?ximo del slider
47
         * @param defaultPos Posici?n inicial
48
         * @param up Si es true el texto se coloca sobre el componente y si es false a la izquierda 
49
         * @param txt Texto de la etiqueta
50
         */
51
        public LabelSliderTextContainer(int min, int max, int defaultPos, boolean up, String txt){
52
                super(min, max, defaultPos);
53
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
54
                gridBagConstraints1.insets = new Insets(0,0,0,0);
55
                if(!up)
56
                        super.add(getPLabel(up), BorderLayout.WEST);
57
                else
58
                        super.add(getPLabel(up), BorderLayout.NORTH);
59
                getLName().setText(txt);
60
        }
61

    
62
        /**
63
         * This method initializes jPanel        
64
         *         
65
         * @return javax.swing.JPanel        
66
         */
67
        private JPanel getPLabel(boolean up) {
68
                if (pLabel == null) {
69
                        pLabel = new JPanel();
70
                        if(!up){
71
                                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
72
                                gridBagConstraints1.insets = new java.awt.Insets(0, 10, 8, 0);
73
                                pLabel.setLayout(new GridBagLayout());
74
                                pLabel.add(getLName(), gridBagConstraints1);
75
                        }else{
76
                                FlowLayout fl = new FlowLayout();
77
                                fl.setAlignment(FlowLayout.LEFT);
78
                                pLabel.setLayout(fl);
79
                                pLabel.add(getLName(), null);
80
                        }
81

    
82
                }
83
                return pLabel;
84
        }
85

    
86
        /**
87
         * This method initializes JLabel
88
         * @return
89
         */
90
        public JLabel getLName(){
91
                if(lName == null)
92
                        lName = new JLabel();
93
                return lName;
94
        }
95

    
96
        /**
97
         * Asigna el texto de la etiqueta
98
         * @param Texto de la etiqueta
99
         */
100
        public void setName(String name){
101
                lName.setText(name);
102
        }
103

    
104
        /**
105
         * Activa o desactiva el control
106
         */
107
        public void setControlEnabled(boolean active){
108
                this.lName.setEnabled(active);
109
                super.setControlEnabled(active);
110
        }
111
}