root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / fieldstree / TetraStateCheckBox.java @ 27077
History | View | Annotate | Download (5.88 KB)
1 |
package com.iver.cit.gvsig.gui.panels.fieldstree; |
---|---|
2 |
|
3 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
4 |
*
|
5 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
6 |
*
|
7 |
* This program is free software; you can redistribute it and/or
|
8 |
* modify it under the terms of the GNU General Public License
|
9 |
* as published by the Free Software Foundation; either version 2
|
10 |
* of the License, or (at your option) any later version.
|
11 |
*
|
12 |
* This program is distributed in the hope that it will be useful,
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
* GNU General Public License for more details.
|
16 |
*
|
17 |
* You should have received a copy of the GNU General Public License
|
18 |
* along with this program; if not, write to the Free Software
|
19 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
*
|
21 |
* For more information, contact:
|
22 |
*
|
23 |
* Generalitat Valenciana
|
24 |
* Conselleria d'Infraestructures i Transport
|
25 |
* Av. Blasco Ib??ez, 50
|
26 |
* 46010 VALENCIA
|
27 |
* SPAIN
|
28 |
*
|
29 |
* +34 963862235
|
30 |
* gvsig@gva.es
|
31 |
* www.gvsig.gva.es
|
32 |
*
|
33 |
* or
|
34 |
*
|
35 |
* IVER T.I. S.A
|
36 |
* Salamanca 50
|
37 |
* 46005 Valencia
|
38 |
* Spain
|
39 |
*
|
40 |
* +34 963163400
|
41 |
* dac@iver.es
|
42 |
*/
|
43 |
/* CVS MESSAGES:
|
44 |
*
|
45 |
* $Id$
|
46 |
* $Log$
|
47 |
* Revision 1.1 2006-12-26 09:12:48 ppiqueras
|
48 |
* Cambiado "atttibutes" en todas las aparaciones en atributos, m?todos, clases, paquetes o comentarios por "fields". (S?lo a aquellas que afectan a clases dentro del proyecto extWFS2). (En este caso se ha cambiado el nombre del paquete aparte de alguno otro nombre que puede haber cambiado).
|
49 |
*
|
50 |
* Revision 1.1 2006/10/27 11:33:19 jorpiell
|
51 |
* A?adida la treetable con los check box para seleccionar los atributos
|
52 |
*
|
53 |
*
|
54 |
*/
|
55 |
/**
|
56 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
57 |
*/
|
58 |
import java.awt.event.ActionListener; |
59 |
import java.awt.event.ItemListener; |
60 |
|
61 |
import javax.swing.ButtonGroup; |
62 |
import javax.swing.ButtonModel; |
63 |
import javax.swing.Icon; |
64 |
import javax.swing.JCheckBox; |
65 |
import javax.swing.event.ChangeListener; |
66 |
|
67 |
public class TetraStateCheckBox extends JCheckBox { |
68 |
public static final int WHITE = 0; |
69 |
public static final int GREY = 1; |
70 |
|
71 |
private final TetraStateDecorator model; |
72 |
|
73 |
public TetraStateCheckBox(String text, Icon icon, int color) { |
74 |
super(text, icon);
|
75 |
model = new TetraStateDecorator(getModel());
|
76 |
setModel(model); |
77 |
} |
78 |
|
79 |
public TetraStateCheckBox(String text){ |
80 |
this(text,null,WHITE); |
81 |
} |
82 |
|
83 |
public TetraStateCheckBox() {
|
84 |
this(null, null, WHITE); |
85 |
} |
86 |
|
87 |
/**
|
88 |
* Set the new state to either SELECTED, NOT_SELECTED or DONT_CARE. If state ==
|
89 |
* null, it is treated as DONT_CARE.
|
90 |
*/
|
91 |
public void setColor(int color) { |
92 |
model.setColor(color, isSelected()); |
93 |
} |
94 |
|
95 |
/**
|
96 |
* Return the current state, which is determined by the selection status of
|
97 |
* the model.
|
98 |
*/
|
99 |
public int getColor() { |
100 |
return model.getColor();
|
101 |
} |
102 |
|
103 |
/**
|
104 |
* Exactly which Design Pattern is this? Is it an Adapter, a Proxy or a
|
105 |
* Decorator? In this case, my vote lies with the Decorator, because we are
|
106 |
* extending functionality and "decorating" the original model with a more
|
107 |
* powerful model.
|
108 |
*/
|
109 |
private class TetraStateDecorator implements ButtonModel { |
110 |
private final ButtonModel other; |
111 |
|
112 |
private TetraStateDecorator(ButtonModel other) { |
113 |
this.other = other;
|
114 |
} |
115 |
|
116 |
private void setColor(int color, boolean isSelected) { |
117 |
if (color == WHITE) {
|
118 |
other.setArmed(false);
|
119 |
setPressed(false);
|
120 |
setSelected(isSelected); |
121 |
} else {
|
122 |
other.setArmed(true);
|
123 |
setPressed(true);
|
124 |
setSelected(isSelected); |
125 |
} |
126 |
} |
127 |
|
128 |
/**
|
129 |
* The current state is embedded in the selection / armed state of the
|
130 |
* model.
|
131 |
*
|
132 |
* We return the SELECTED state when the checkbox is selected but not
|
133 |
* armed, DONT_CARE state when the checkbox is selected and armed (grey)
|
134 |
* and NOT_SELECTED when the checkbox is deselected.
|
135 |
*/
|
136 |
private int getColor() { |
137 |
if (!isArmed()) {
|
138 |
return GREY;
|
139 |
} else {
|
140 |
return WHITE;
|
141 |
} |
142 |
} |
143 |
|
144 |
/** Filter: No one may change the armed status except us. */
|
145 |
public void setArmed(boolean b) { |
146 |
} |
147 |
|
148 |
/**
|
149 |
* We disable focusing on the component when it is not enabled.
|
150 |
*/
|
151 |
public void setEnabled(boolean b) { |
152 |
setFocusable(b); |
153 |
other.setEnabled(b); |
154 |
} |
155 |
|
156 |
public boolean isArmed() { |
157 |
return other.isArmed();
|
158 |
} |
159 |
|
160 |
public boolean isSelected() { |
161 |
return other.isSelected();
|
162 |
} |
163 |
|
164 |
public boolean isEnabled() { |
165 |
return other.isEnabled();
|
166 |
} |
167 |
|
168 |
public boolean isPressed() { |
169 |
return other.isPressed();
|
170 |
} |
171 |
|
172 |
public boolean isRollover() { |
173 |
return other.isRollover();
|
174 |
} |
175 |
|
176 |
public void setSelected(boolean b) { |
177 |
other.setSelected(b); |
178 |
} |
179 |
|
180 |
public void setPressed(boolean b) { |
181 |
other.setPressed(b); |
182 |
} |
183 |
|
184 |
public void setRollover(boolean b) { |
185 |
other.setRollover(b); |
186 |
} |
187 |
|
188 |
public void setMnemonic(int key) { |
189 |
other.setMnemonic(key); |
190 |
} |
191 |
|
192 |
public int getMnemonic() { |
193 |
return other.getMnemonic();
|
194 |
} |
195 |
|
196 |
public void setActionCommand(String s) { |
197 |
other.setActionCommand(s); |
198 |
} |
199 |
|
200 |
public String getActionCommand() { |
201 |
return other.getActionCommand();
|
202 |
} |
203 |
|
204 |
public void setGroup(ButtonGroup group) { |
205 |
other.setGroup(group); |
206 |
} |
207 |
|
208 |
public void addActionListener(ActionListener l) { |
209 |
other.addActionListener(l); |
210 |
} |
211 |
|
212 |
public void removeActionListener(ActionListener l) { |
213 |
other.removeActionListener(l); |
214 |
} |
215 |
|
216 |
public void addItemListener(ItemListener l) { |
217 |
other.addItemListener(l); |
218 |
} |
219 |
|
220 |
public void removeItemListener(ItemListener l) { |
221 |
other.removeItemListener(l); |
222 |
} |
223 |
|
224 |
public void addChangeListener(ChangeListener l) { |
225 |
other.addChangeListener(l); |
226 |
} |
227 |
|
228 |
public void removeChangeListener(ChangeListener l) { |
229 |
other.removeChangeListener(l); |
230 |
} |
231 |
|
232 |
public Object[] getSelectedObjects() { |
233 |
return other.getSelectedObjects();
|
234 |
} |
235 |
} |
236 |
} |