svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / checkslidertext / CheckColorSliderTextContainer.java @ 40561
History | View | Annotate | Download (4.03 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.Dimension; |
28 |
import java.awt.GridBagConstraints; |
29 |
import java.awt.GridBagLayout; |
30 |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.ActionListener; |
32 |
|
33 |
import javax.swing.JCheckBox; |
34 |
import javax.swing.JLabel; |
35 |
import javax.swing.JPanel; |
36 |
|
37 |
import org.gvsig.gui.beans.slidertext.ColorSliderTextContainer; |
38 |
/**
|
39 |
* A?ade un check al componente Slider ajustando el tama?o del componente a la
|
40 |
* longitud del check. Al redimensionar el componente varia el tama?o del slider
|
41 |
*
|
42 |
* @version 08/06/2007
|
43 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
44 |
*/
|
45 |
public class CheckColorSliderTextContainer extends ColorSliderTextContainer implements ActionListener { |
46 |
private static final long serialVersionUID = 7047604405777061995L; |
47 |
public JCheckBox check = null; |
48 |
private JPanel pLabel = null; |
49 |
private String text = null; |
50 |
|
51 |
/**
|
52 |
* Constructor
|
53 |
* @param min Valor m?nimo del slider
|
54 |
* @param max Valor m?ximo del slider
|
55 |
* @param defaultPos Posici?n inicial
|
56 |
* @param txt Texto de la etiqueta del check
|
57 |
* @param active Valor por defecto del control.True activo y false desactivo
|
58 |
*/
|
59 |
public CheckColorSliderTextContainer(int min, int max, int defaultPos, String txt, boolean active) { |
60 |
super(min, max, defaultPos);
|
61 |
text = txt; |
62 |
add(getPCheck(), BorderLayout.WEST);
|
63 |
check.addActionListener(this);
|
64 |
check.setSelected(active); |
65 |
setControlEnabled(active); |
66 |
|
67 |
this.setMaximumSize(new Dimension(32767, 31)); |
68 |
this.setMinimumSize(new Dimension(250, 31)); |
69 |
} |
70 |
|
71 |
/**
|
72 |
* This method initializes jPanel
|
73 |
*
|
74 |
* @return javax.swing.JPanel
|
75 |
*/
|
76 |
private JPanel getPCheck() { |
77 |
if (pLabel == null) { |
78 |
pLabel = new JPanel(); |
79 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
80 |
gridBagConstraints1.insets = new java.awt.Insets(0, 0, 13, 0); |
81 |
pLabel.setLayout(new GridBagLayout()); |
82 |
pLabel.add(getCheck(), gridBagConstraints1); |
83 |
pLabel.add(new JLabel(text), gridBagConstraints1); |
84 |
} |
85 |
return pLabel;
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* This method initializes JLabel
|
90 |
* @return
|
91 |
*/
|
92 |
private JCheckBox getCheck() { |
93 |
if (check == null) |
94 |
check = new JCheckBox(); |
95 |
return check;
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* Activa o desactiva el control del panel
|
100 |
* @param active
|
101 |
*/
|
102 |
public void setChecked(boolean active) { |
103 |
getCheck().setSelected(active); |
104 |
super.setControlEnabled(active);
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* Hace visible el checkbox o no del componente
|
109 |
* @param value
|
110 |
*/
|
111 |
public void setCheckboxVisible(boolean value) { |
112 |
if (!value)
|
113 |
setChecked(true);
|
114 |
getCheck().setVisible(value); |
115 |
} |
116 |
|
117 |
/**
|
118 |
* Devuelve si el control esta activo
|
119 |
* @param active
|
120 |
*/
|
121 |
public boolean isChecked() { |
122 |
return getCheck().isSelected();
|
123 |
} |
124 |
|
125 |
public void actionPerformed(ActionEvent e) { |
126 |
if (e.getSource() == check) {
|
127 |
setControlEnabled(check.isSelected()); |
128 |
callChangeValue(); |
129 |
} |
130 |
} |
131 |
|
132 |
/* (non-Javadoc)
|
133 |
* @see javax.swing.JComponent#setEnabled(boolean)
|
134 |
*/
|
135 |
public void setEnabled(boolean enabled) { |
136 |
super.setEnabled(enabled);
|
137 |
getCheck().setEnabled(enabled); |
138 |
|
139 |
if (!getCheck().isSelected())
|
140 |
enabled = false;
|
141 |
|
142 |
getSlider().setEnabled(enabled); |
143 |
getJSpinner().setEnabled(enabled); |
144 |
} |
145 |
} |