author | Claus Gittinger <cg@exept.de> |
Mon, 15 Jul 1996 16:42:09 +0200 | |
changeset 791 | f76f4541742f |
parent 752 | a5781b7ff8cb |
child 1088 | 40de2fe27607 |
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 |
||
791
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
20 |
!RadioButtonGroup class methodsFor:'documentation '! |
38 | 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'): |
594 | 75 |
[exBegin] |
76 |
|top panel toggle b group| |
|
116 | 77 |
|
594 | 78 |
top := StandardSystemView new. |
79 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
80 |
group := RadioButtonGroup new. |
|
81 |
b := Toggle label:'one' in:panel. |
|
82 |
group add:b. |
|
83 |
b := Toggle label:'two' in:panel. |
|
84 |
group add:b. |
|
85 |
b := Toggle label:'three' in:panel. |
|
86 |
group add:b. |
|
87 |
top extent:(panel preferredExtent). |
|
88 |
top open. |
|
89 |
[exEnd] |
|
116 | 90 |
|
177 | 91 |
|
116 | 92 |
example (using RadioButtons for 'one-on behavior'): |
594 | 93 |
[exBegin] |
94 |
|top panel toggle b group| |
|
116 | 95 |
|
594 | 96 |
top := StandardSystemView new. |
97 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
98 |
group := RadioButtonGroup new. |
|
99 |
b := RadioButton label:'one' in:panel. |
|
100 |
group add:b. |
|
101 |
b := RadioButton label:'two' in:panel. |
|
102 |
group add:b. |
|
103 |
b := RadioButton label:'three' in:panel. |
|
104 |
group add:b. |
|
105 |
top extent:(panel preferredExtent). |
|
106 |
top open. |
|
107 |
[exEnd] |
|
116 | 108 |
|
177 | 109 |
|
110 |
example (using Buttons for 'none-on behavior'; but the groups value remembers the last button): |
|
594 | 111 |
[exBegin] |
112 |
|top panel toggle b group| |
|
177 | 113 |
|
594 | 114 |
top := StandardSystemView new. |
115 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
116 |
group := RadioButtonGroup new. |
|
117 |
b := Button label:'one' in:panel. |
|
118 |
group add:b. |
|
119 |
b := Button label:'two' in:panel. |
|
120 |
group add:b. |
|
121 |
b := Button label:'three' in:panel. |
|
122 |
group add:b. |
|
123 |
top extent:(panel preferredExtent). |
|
124 |
top open. |
|
125 |
group valueChannel inspect |
|
126 |
[exEnd] |
|
177 | 127 |
|
128 |
||
116 | 129 |
example (same, with button 'two' initially on): |
594 | 130 |
[exBegin] |
131 |
|top panel toggle b group| |
|
116 | 132 |
|
594 | 133 |
top := StandardSystemView new. |
134 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
135 |
group := RadioButtonGroup new. |
|
136 |
b := RadioButton label:'one' in:panel. |
|
137 |
group add:b. |
|
138 |
b := RadioButton label:'two' in:panel. |
|
139 |
group add:b. |
|
140 |
group value:2. |
|
141 |
b := RadioButton label:'three' in:panel. |
|
142 |
group add:b. |
|
143 |
top extent:(panel preferredExtent). |
|
144 |
top open. |
|
145 |
[exEnd] |
|
131 | 146 |
|
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
147 |
|
163 | 148 |
using checkBoxes (these have a label included): |
594 | 149 |
[exBegin] |
150 |
|top panel toggle b group| |
|
163 | 151 |
|
594 | 152 |
top := StandardSystemView new. |
153 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
154 |
panel horizontalLayout:#left. |
|
155 |
group := RadioButtonGroup new. |
|
156 |
b := CheckBox label:'one' in:panel. |
|
157 |
group add:b. |
|
158 |
b := CheckBox label:'two' in:panel. |
|
159 |
group add:b. |
|
160 |
b := CheckBox label:'three' in:panel. |
|
161 |
group add:b. |
|
162 |
top extent:(panel preferredExtent). |
|
163 |
top open. |
|
164 |
[exEnd] |
|
163 | 165 |
|
166 |
||
131 | 167 |
example (operating on a model) |
594 | 168 |
[exBegin] |
169 |
|selected dialog group| |
|
131 | 170 |
|
594 | 171 |
selected := 2 asValue. |
172 |
dialog := Dialog new. |
|
173 |
group := RadioButtonGroup new. |
|
174 |
group add:(dialog addCheckBox:'one' on:nil) toggleView. |
|
175 |
group add:(dialog addCheckBox:'two' on:nil) toggleView. |
|
176 |
group add:(dialog addCheckBox:'three' on:nil) toggleView. |
|
177 |
group valueChannel:selected. |
|
178 |
dialog addAbortButton; addOkButton. |
|
179 |
dialog open. |
|
180 |
dialog accepted ifTrue:[ |
|
655 | 181 |
Transcript showCR:'you selected: ' , selected value printString |
594 | 182 |
] ifFalse:[ |
655 | 183 |
Transcript showCR:'aborted' |
594 | 184 |
] |
185 |
[exEnd] |
|
38 | 186 |
" |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
187 |
|
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
188 |
"Created: 15.11.1995 / 17:14:53 / cg" |
594 | 189 |
"Modified: 27.4.1996 / 19:27:37 / cg" |
198 | 190 |
! |
191 |
||
192 |
version |
|
791
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
193 |
^ '$Header: /cvs/stx/stx/libwidg/RadioButtonGroup.st,v 1.24 1996-07-15 14:42:09 cg Exp $' |
38 | 194 |
! ! |
0 | 195 |
|
155 | 196 |
!RadioButtonGroup methodsFor:'accessing'! |
197 |
||
198 | 198 |
groupID |
199 |
^ groupID |
|
200 |
||
201 |
"Modified: 5.9.1995 / 16:04:33 / claus" |
|
202 |
! |
|
203 |
||
155 | 204 |
groupID:aSymbol |
205 |
groupID := aSymbol |
|
206 |
||
207 |
"Modified: 5.9.1995 / 16:04:28 / claus" |
|
208 |
! ! |
|
209 |
||
131 | 210 |
!RadioButtonGroup methodsFor:'accessing-mvc'! |
211 |
||
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
212 |
value |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
213 |
^ valueChannel value |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
214 |
! |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
215 |
|
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
216 |
value:anIndex |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
217 |
valueChannel value:anIndex |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
218 |
! |
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
219 |
|
131 | 220 |
valueChannel |
221 |
^ valueChannel |
|
222 |
! |
|
223 |
||
224 |
valueChannel:aValueHolder |
|
225 |
|oldValue newValue| |
|
226 |
||
227 |
valueChannel notNil ifTrue:[oldValue := valueChannel value]. |
|
228 |
valueChannel := aValueHolder. |
|
229 |
(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
|
230 |
(self at:newValue) turnOnWithAction |
131 | 231 |
] |
232 |
! ! |
|
233 |
||
0 | 234 |
!RadioButtonGroup methodsFor:'adding / removing'! |
235 |
||
236 |
add:aRadioButton |
|
791
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
237 |
|c| |
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
238 |
|
0 | 239 |
super add:aRadioButton. |
131 | 240 |
|
241 |
" |
|
242 |
this would work, if dependencies were not weak ... |
|
243 |
" |
|
105 | 244 |
"/ aRadioButton addDependent:self. |
131 | 245 |
|
246 |
||
247 |
" |
|
248 |
therefore, we have to install ourself as model of the buttons/toggles |
|
249 |
creating a valueChannel, if there is none yet. |
|
250 |
" |
|
251 |
valueChannel isNil ifTrue:[ |
|
791
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
252 |
valueChannel := 0 asValue |
131 | 253 |
]. |
254 |
aRadioButton isOn ifTrue:[valueChannel value:self size]. |
|
177 | 255 |
aRadioButton model:self; aspectMessage:#queryFrom:; changeMessage:#elementChanged:from:. |
131 | 256 |
|
791
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
257 |
(c := aRadioButton controller) notNil ifTrue:[ |
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
258 |
c beRadioButton |
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
259 |
] ifFalse:[ |
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
260 |
aRadioButton controller:(RadioButtonController new). |
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
261 |
] |
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
262 |
|
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
263 |
"Modified: 15.7.1996 / 14:07:19 / cg" |
0 | 264 |
! ! |
265 |
||
266 |
!RadioButtonGroup methodsFor:'update'! |
|
267 |
||
105 | 268 |
elementChanged:aToggle |
131 | 269 |
"historic compatibility leftover - will vanish" |
270 |
||
271 |
^ self elementChanged:true from:aToggle |
|
272 |
! |
|
273 |
||
274 |
elementChanged:value from:aToggle |
|
275 |
"some element changed its value - find it, turn the others off |
|
276 |
and update my value" |
|
277 |
||
278 |
|newValue| |
|
279 |
||
177 | 280 |
self keysAndValuesDo:[:index :aComponent | |
752
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
281 |
((aToggle == aComponent) or:[aToggle isComponentOf:aComponent]) ifTrue:[ |
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
282 |
value ifTrue:[newValue := index] |
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
283 |
] ifFalse:[ |
177 | 284 |
"/ aComponent isOn ifTrue:[ |
285 |
"/ aComponent turnOff |
|
286 |
"/ ] |
|
752
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
287 |
] |
131 | 288 |
]. |
177 | 289 |
"/ aToggle turnOn. |
290 |
valueChannel value:newValue. |
|
291 |
self changed:#queryFrom: |
|
0 | 292 |
|
164 | 293 |
"Modified: 21.9.1995 / 13:42:06 / claus" |
752
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
294 |
"Modified: 5.6.1996 / 14:25:51 / cg" |
198 | 295 |
! |
296 |
||
297 |
queryFrom:aToggle |
|
298 |
"a query from a toggle, if its the selected one" |
|
299 |
||
300 |
self keysAndValuesDo:[:index :aComponent | |
|
752
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
301 |
((aToggle == aComponent) or:[aToggle isComponentOf:aComponent]) ifTrue:[ |
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
302 |
^ valueChannel value == index |
198 | 303 |
] |
304 |
]. |
|
305 |
^ false |
|
306 |
||
752
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
307 |
"Modified: 5.6.1996 / 14:25:53 / cg" |
198 | 308 |
! |
309 |
||
310 |
update:something with:someArgument from:changedButton |
|
311 |
" |
|
312 |
a RadioButton in this group has changed - notify the others |
|
313 |
" |
|
314 |
||
315 |
self elementChanged:(changedButton isOn) from:changedButton |
|
0 | 316 |
! ! |
198 | 317 |