svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / labelslidertext / LabelSliderTextContainer.java @ 40561
History | View | Annotate | Download (3.33 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.labelslidertext; |
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 |
|
32 |
import javax.swing.JLabel; |
33 |
import javax.swing.JPanel; |
34 |
|
35 |
import org.gvsig.gui.beans.slidertext.SliderTextContainer; |
36 |
/**
|
37 |
* A?ade una etiqueta al componente Slider ajustando el tama?o del componente
|
38 |
* a la longitud de la etiqueta. Al redimensionar el componente varia el tama?o
|
39 |
* del slider
|
40 |
*
|
41 |
* @author Nacho Brodin(nachobrodin@gmail.com)
|
42 |
*/
|
43 |
public class LabelSliderTextContainer extends SliderTextContainer { |
44 |
private static final long serialVersionUID = -4617272063786945078L; |
45 |
public JLabel lName = null; |
46 |
private JPanel pLabel = null; |
47 |
|
48 |
/**
|
49 |
* Constructor
|
50 |
* @param min Valor m?nimo del slider
|
51 |
* @param max Valor m?ximo del slider
|
52 |
* @param defaultPos Posici?n inicial
|
53 |
* @param up Si es true el texto se coloca sobre el componente y si es false a la izquierda
|
54 |
* @param txt Texto de la etiqueta
|
55 |
*/
|
56 |
public LabelSliderTextContainer(int min, int max, int defaultPos, boolean up, String txt){ |
57 |
super(min, max, defaultPos);
|
58 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
59 |
gridBagConstraints1.insets = new Insets(0,0,0,0); |
60 |
if(!up)
|
61 |
super.add(getPLabel(up), BorderLayout.WEST); |
62 |
else
|
63 |
super.add(getPLabel(up), BorderLayout.NORTH); |
64 |
getLName().setText(txt); |
65 |
} |
66 |
|
67 |
/**
|
68 |
* This method initializes jPanel
|
69 |
*
|
70 |
* @return javax.swing.JPanel
|
71 |
*/
|
72 |
private JPanel getPLabel(boolean up) { |
73 |
if (pLabel == null) { |
74 |
pLabel = new JPanel(); |
75 |
if(!up){
|
76 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
77 |
gridBagConstraints1.insets = new java.awt.Insets(0, 10, 8, 0); |
78 |
pLabel.setLayout(new GridBagLayout()); |
79 |
pLabel.add(getLName(), gridBagConstraints1); |
80 |
}else{
|
81 |
FlowLayout fl = new FlowLayout(); |
82 |
fl.setAlignment(FlowLayout.LEFT);
|
83 |
pLabel.setLayout(fl); |
84 |
pLabel.add(getLName(), null);
|
85 |
} |
86 |
|
87 |
} |
88 |
return pLabel;
|
89 |
} |
90 |
|
91 |
/**
|
92 |
* This method initializes JLabel
|
93 |
* @return
|
94 |
*/
|
95 |
public JLabel getLName(){ |
96 |
if(lName == null) |
97 |
lName = new JLabel(); |
98 |
return lName;
|
99 |
} |
100 |
|
101 |
/**
|
102 |
* Asigna el texto de la etiqueta
|
103 |
* @param Texto de la etiqueta
|
104 |
*/
|
105 |
public void setName(String name){ |
106 |
lName.setText(name); |
107 |
} |
108 |
|
109 |
/**
|
110 |
* Activa o desactiva el control
|
111 |
*/
|
112 |
public void setControlEnabled(boolean active){ |
113 |
this.lName.setEnabled(active);
|
114 |
super.setControlEnabled(active);
|
115 |
} |
116 |
} |