author | Claus Gittinger <cg@exept.de> |
Wed, 15 Nov 1995 17:20:37 +0100 | |
changeset 178 | 5c28593c2a3b |
parent 177 | c06d27f8525f |
child 198 | c0f39f9440a7 |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
59 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
105 | 13 |
'From Smalltalk/X, Version:2.10.5 on 14-mar-1995 at 11:06:48 am'! |
14 |
||
7 | 15 |
OrderedCollection subclass:#RadioButtonGroup |
155 | 16 |
instanceVariableNames:'valueChannel groupID' |
59 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Views-Support' |
|
0 | 20 |
! |
21 |
||
38 | 22 |
!RadioButtonGroup class methodsFor:'documentation '! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
59 | 27 |
All Rights Reserved |
0 | 28 |
|
38 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
version |
|
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
39 |
^ '$Header: /cvs/stx/stx/libwidg/RadioButtonGroup.st,v 1.18 1995-11-15 16:20:34 cg Exp $' |
38 | 40 |
! |
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
RadioButtonGroups control the interaction between RadioButtons |
|
45 |
turning off other button(s) when one of the group is pressed. |
|
63 | 46 |
To group some buttons (and have one-on behavior) use: |
47 |
||
48 |
|g| |
|
49 |
||
50 |
g := RadioButtonGroup new. |
|
51 |
... |
|
52 |
b1 := RadioButton label:.... |
|
53 |
g add:b1 |
|
54 |
... |
|
55 |
b2 := RadioButton label:.... |
|
56 |
g add:b2 |
|
57 |
... |
|
116 | 58 |
|
131 | 59 |
A radioButtonGroup installs itself as the model of its toggles or |
60 |
radioButtons. Therefore, you can no longer operate the individual |
|
61 |
elements on models. |
|
62 |
Instead, the group now provides a valueHolder which takes as value |
|
63 |
the index of the selected toggle. You can set/get this valueHolder |
|
64 |
via the valueChannel:/valueChannel messages. |
|
65 |
See the last example for how this is done. |
|
155 | 66 |
|
67 |
The groupID instance variable is not required for normal operation; |
|
68 |
the interface builder uses it to give a button-group some descriptive |
|
69 |
(unique) name. |
|
131 | 70 |
" |
71 |
! |
|
72 |
||
73 |
examples |
|
74 |
" |
|
116 | 75 |
example (using Toggles for 'at most one-on behavior'): |
76 |
||
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
77 |
|top panel toggle b group| |
116 | 78 |
|
79 |
top := StandardSystemView new. |
|
80 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
81 |
group := RadioButtonGroup new. |
116 | 82 |
b := Toggle label:'one' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
83 |
group add:b. |
116 | 84 |
b := Toggle label:'two' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
85 |
group add:b. |
116 | 86 |
b := Toggle label:'three' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
87 |
group add:b. |
130 | 88 |
top extent:(panel preferredExtent). |
116 | 89 |
top open. |
90 |
||
177 | 91 |
|
116 | 92 |
example (using RadioButtons for 'one-on behavior'): |
93 |
||
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
94 |
|top panel toggle b group| |
116 | 95 |
|
96 |
top := StandardSystemView new. |
|
97 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
98 |
group := RadioButtonGroup new. |
116 | 99 |
b := RadioButton label:'one' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
100 |
group add:b. |
116 | 101 |
b := RadioButton label:'two' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
102 |
group add:b. |
116 | 103 |
b := RadioButton label:'three' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
104 |
group add:b. |
130 | 105 |
top extent:(panel preferredExtent). |
116 | 106 |
top open. |
107 |
||
177 | 108 |
|
109 |
example (using Buttons for 'none-on behavior'; but the groups value remembers the last button): |
|
110 |
||
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
111 |
|top panel toggle b group| |
177 | 112 |
|
113 |
top := StandardSystemView new. |
|
114 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
115 |
group := RadioButtonGroup new. |
177 | 116 |
b := Button label:'one' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
117 |
group add:b. |
177 | 118 |
b := Button label:'two' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
119 |
group add:b. |
177 | 120 |
b := Button label:'three' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
121 |
group add:b. |
177 | 122 |
top extent:(panel preferredExtent). |
123 |
top open. |
|
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
124 |
group valueChannel inspect |
177 | 125 |
|
126 |
||
116 | 127 |
example (same, with button 'two' initially on): |
128 |
||
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
129 |
|top panel toggle b group| |
116 | 130 |
|
131 |
top := StandardSystemView new. |
|
132 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
133 |
group := RadioButtonGroup new. |
116 | 134 |
b := RadioButton label:'one' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
135 |
group add:b. |
116 | 136 |
b := RadioButton label:'two' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
137 |
group add:b. |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
138 |
group value:2. |
116 | 139 |
b := RadioButton label:'three' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
140 |
group add:b. |
130 | 141 |
top extent:(panel preferredExtent). |
116 | 142 |
top open. |
131 | 143 |
|
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
144 |
|
163 | 145 |
using checkBoxes (these have a label included): |
146 |
||
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
147 |
|top panel toggle b group| |
163 | 148 |
|
149 |
top := StandardSystemView new. |
|
150 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
177 | 151 |
panel horizontalLayout:#left. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
152 |
group := RadioButtonGroup new. |
163 | 153 |
b := CheckBox label:'one' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
154 |
group add:b. |
163 | 155 |
b := CheckBox label:'two' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
156 |
group add:b. |
163 | 157 |
b := CheckBox label:'three' in:panel. |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
158 |
group add:b. |
163 | 159 |
top extent:(panel preferredExtent). |
160 |
top open. |
|
161 |
||
162 |
||
131 | 163 |
example (operating on a model) |
164 |
||
165 |
|selected dialog group| |
|
166 |
||
167 |
selected := 2 asValue. |
|
168 |
dialog := Dialog new. |
|
169 |
group := RadioButtonGroup new. |
|
170 |
group add:(dialog addCheckBox:'one' on:nil) toggleView. |
|
171 |
group add:(dialog addCheckBox:'two' on:nil) toggleView. |
|
172 |
group add:(dialog addCheckBox:'three' on:nil) toggleView. |
|
173 |
group valueChannel:selected. |
|
174 |
dialog addAbortButton; addOkButton. |
|
175 |
dialog open. |
|
176 |
dialog accepted ifTrue:[ |
|
177 |
Transcript showCr:'you selected: ' , selected value printString |
|
163 | 178 |
] ifFalse:[ |
179 |
Transcript showCr:'aborted' |
|
131 | 180 |
] |
38 | 181 |
" |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
182 |
|
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
183 |
"Created: 15.11.1995 / 17:14:53 / cg" |
38 | 184 |
! ! |
0 | 185 |
|
155 | 186 |
!RadioButtonGroup methodsFor:'accessing'! |
187 |
||
188 |
groupID:aSymbol |
|
189 |
groupID := aSymbol |
|
190 |
||
191 |
"Modified: 5.9.1995 / 16:04:28 / claus" |
|
192 |
! |
|
193 |
||
194 |
groupID |
|
195 |
^ groupID |
|
196 |
||
197 |
"Modified: 5.9.1995 / 16:04:33 / claus" |
|
198 |
! ! |
|
199 |
||
131 | 200 |
!RadioButtonGroup methodsFor:'accessing-mvc'! |
201 |
||
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
202 |
value |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
203 |
^ valueChannel value |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
204 |
! |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
205 |
|
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
206 |
value:anIndex |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
207 |
valueChannel value:anIndex |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
208 |
! |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
209 |
|
131 | 210 |
valueChannel |
211 |
^ valueChannel |
|
212 |
! |
|
213 |
||
214 |
valueChannel:aValueHolder |
|
215 |
|oldValue newValue| |
|
216 |
||
217 |
valueChannel notNil ifTrue:[oldValue := valueChannel value]. |
|
218 |
valueChannel := aValueHolder. |
|
219 |
(newValue := valueChannel value) ~~ oldValue ifTrue:[ |
|
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
220 |
(self at:newValue) turnOnWithAction |
131 | 221 |
] |
222 |
! ! |
|
223 |
||
0 | 224 |
!RadioButtonGroup methodsFor:'adding / removing'! |
225 |
||
226 |
add:aRadioButton |
|
227 |
super add:aRadioButton. |
|
131 | 228 |
|
229 |
" |
|
230 |
this would work, if dependencies were not weak ... |
|
231 |
" |
|
105 | 232 |
"/ aRadioButton addDependent:self. |
131 | 233 |
|
234 |
||
235 |
" |
|
236 |
therefore, we have to install ourself as model of the buttons/toggles |
|
237 |
creating a valueChannel, if there is none yet. |
|
238 |
" |
|
239 |
valueChannel isNil ifTrue:[ |
|
240 |
valueChannel := 0 asValue |
|
241 |
]. |
|
242 |
aRadioButton isOn ifTrue:[valueChannel value:self size]. |
|
177 | 243 |
aRadioButton model:self; aspectMessage:#queryFrom:; changeMessage:#elementChanged:from:. |
131 | 244 |
|
0 | 245 |
! ! |
246 |
||
247 |
!RadioButtonGroup methodsFor:'update'! |
|
248 |
||
59 | 249 |
update:something with:someArgument from:changedButton |
131 | 250 |
" |
251 |
a RadioButton in this group has changed - notify the others |
|
252 |
" |
|
0 | 253 |
|
131 | 254 |
self elementChanged:(changedButton isOn) from:changedButton |
105 | 255 |
! |
256 |
||
177 | 257 |
queryFrom:aToggle |
258 |
"a query from a toggle, if its the selected one" |
|
259 |
||
260 |
self keysAndValuesDo:[:index :aComponent | |
|
261 |
((aToggle == aComponent) or:[aToggle isSubViewOf:aComponent]) ifTrue:[ |
|
262 |
^ valueChannel value == index |
|
263 |
] |
|
264 |
]. |
|
265 |
^ false |
|
266 |
||
267 |
"Modified: 14.11.1995 / 21:21:27 / cg" |
|
268 |
! |
|
269 |
||
105 | 270 |
elementChanged:aToggle |
131 | 271 |
"historic compatibility leftover - will vanish" |
272 |
||
273 |
^ self elementChanged:true from:aToggle |
|
274 |
! |
|
275 |
||
276 |
elementChanged:value from:aToggle |
|
277 |
"some element changed its value - find it, turn the others off |
|
278 |
and update my value" |
|
279 |
||
280 |
|newValue| |
|
281 |
||
177 | 282 |
self keysAndValuesDo:[:index :aComponent | |
283 |
((aToggle == aComponent) or:[aToggle isSubViewOf:aComponent]) ifTrue:[ |
|
131 | 284 |
value ifTrue:[newValue := index] |
177 | 285 |
] ifFalse:[ |
286 |
"/ aComponent isOn ifTrue:[ |
|
287 |
"/ aComponent turnOff |
|
288 |
"/ ] |
|
116 | 289 |
] |
131 | 290 |
]. |
177 | 291 |
"/ aToggle turnOn. |
292 |
valueChannel value:newValue. |
|
293 |
self changed:#queryFrom: |
|
0 | 294 |
|
164 | 295 |
"Modified: 21.9.1995 / 13:42:06 / claus" |
0 | 296 |
! ! |