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