svn-gvsig-desktop / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / checkslidertext / CheckSliderTextContainer.java @ 10741
History | View | Annotate | Download (3.54 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 |
|
20 |
package org.gvsig.gui.beans.checkslidertext; |
21 |
|
22 |
import java.awt.BorderLayout; |
23 |
import java.awt.FlowLayout; |
24 |
import java.awt.GridBagConstraints; |
25 |
import java.awt.GridBagLayout; |
26 |
import java.awt.Insets; |
27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
|
30 |
import javax.swing.JCheckBox; |
31 |
import javax.swing.JPanel; |
32 |
|
33 |
import org.gvsig.gui.beans.slidertext.SliderTextContainer; |
34 |
|
35 |
/**
|
36 |
* A?ade un check al componente Slider ajustando el tama?o del componente
|
37 |
* a la longitud del check. Al redimensionar el componente varia el tama?o
|
38 |
* del slider
|
39 |
* @author Nacho Brodin(nachobrodin@gmail.com)
|
40 |
*
|
41 |
*/
|
42 |
public class CheckSliderTextContainer extends SliderTextContainer implements ActionListener{ |
43 |
final private static long serialVersionUID = 0; |
44 |
public JCheckBox check = null; |
45 |
private JPanel pLabel = null; |
46 |
private String text = 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 del check
|
55 |
* @param active Valor por defecto del control.True activo y false desactivo
|
56 |
*/
|
57 |
public CheckSliderTextContainer(int min, int max, int defaultPos, boolean up, String txt, boolean active){ |
58 |
super(min, max, defaultPos);
|
59 |
text = txt; |
60 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
61 |
gridBagConstraints1.insets = new Insets(0,0,0,0); |
62 |
if(!up)
|
63 |
super.add(getPCheck(up), BorderLayout.WEST); |
64 |
else
|
65 |
super.add(getPCheck(up), BorderLayout.NORTH); |
66 |
check.addActionListener(this);
|
67 |
check.setSelected(active); |
68 |
setControlEnabled(active); |
69 |
} |
70 |
|
71 |
/**
|
72 |
* This method initializes jPanel
|
73 |
*
|
74 |
* @return javax.swing.JPanel
|
75 |
*/
|
76 |
private JPanel getPCheck(boolean up) { |
77 |
if (pLabel == null) { |
78 |
pLabel = new JPanel(); |
79 |
if(!up){
|
80 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
81 |
gridBagConstraints1.insets = new java.awt.Insets(0, 10, 13, 0); |
82 |
pLabel.setLayout(new GridBagLayout()); |
83 |
pLabel.add(getCheck(), gridBagConstraints1); |
84 |
}else{
|
85 |
FlowLayout fl = new FlowLayout(); |
86 |
fl.setAlignment(FlowLayout.LEFT);
|
87 |
pLabel.setLayout(fl); |
88 |
pLabel.add(getCheck(), null);
|
89 |
} |
90 |
} |
91 |
return pLabel;
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* This method initializes JLabel
|
96 |
* @return
|
97 |
*/
|
98 |
public JCheckBox getCheck(){ |
99 |
if(check == null) |
100 |
check = new JCheckBox(text); |
101 |
return check;
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* Activa o desactiva el control del panel
|
106 |
* @param active
|
107 |
*/
|
108 |
public void setControlEnabled(boolean active){ |
109 |
getCheck().setSelected(active); |
110 |
super.setControlEnabled(active);
|
111 |
} |
112 |
|
113 |
public void actionPerformed(ActionEvent e) { |
114 |
if(e.getSource() == check)
|
115 |
setControlEnabled(check.isSelected()); |
116 |
} |
117 |
} |