author | Claus Gittinger <cg@exept.de> |
Wed, 05 Jun 1996 17:07:37 +0200 | |
changeset 752 | a5781b7ff8cb |
parent 655 | acad3ef3a46c |
child 791 | f76f4541742f |
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'): |
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 |
|
752
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
193 |
^ '$Header: /cvs/stx/stx/libwidg/RadioButtonGroup.st,v 1.23 1996-06-05 15:07:37 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 |
|
237 |
super add:aRadioButton. |
|
131 | 238 |
|
239 |
" |
|
240 |
this would work, if dependencies were not weak ... |
|
241 |
" |
|
105 | 242 |
"/ aRadioButton addDependent:self. |
131 | 243 |
|
244 |
||
245 |
" |
|
246 |
therefore, we have to install ourself as model of the buttons/toggles |
|
247 |
creating a valueChannel, if there is none yet. |
|
248 |
" |
|
249 |
valueChannel isNil ifTrue:[ |
|
250 |
valueChannel := 0 asValue |
|
251 |
]. |
|
252 |
aRadioButton isOn ifTrue:[valueChannel value:self size]. |
|
177 | 253 |
aRadioButton model:self; aspectMessage:#queryFrom:; changeMessage:#elementChanged:from:. |
131 | 254 |
|
0 | 255 |
! ! |
256 |
||
257 |
!RadioButtonGroup methodsFor:'update'! |
|
258 |
||
105 | 259 |
elementChanged:aToggle |
131 | 260 |
"historic compatibility leftover - will vanish" |
261 |
||
262 |
^ self elementChanged:true from:aToggle |
|
263 |
! |
|
264 |
||
265 |
elementChanged:value from:aToggle |
|
266 |
"some element changed its value - find it, turn the others off |
|
267 |
and update my value" |
|
268 |
||
269 |
|newValue| |
|
270 |
||
177 | 271 |
self keysAndValuesDo:[:index :aComponent | |
752
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
272 |
((aToggle == aComponent) or:[aToggle isComponentOf:aComponent]) ifTrue:[ |
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
273 |
value ifTrue:[newValue := index] |
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
274 |
] ifFalse:[ |
177 | 275 |
"/ aComponent isOn ifTrue:[ |
276 |
"/ aComponent turnOff |
|
277 |
"/ ] |
|
752
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
278 |
] |
131 | 279 |
]. |
177 | 280 |
"/ aToggle turnOn. |
281 |
valueChannel value:newValue. |
|
282 |
self changed:#queryFrom: |
|
0 | 283 |
|
164 | 284 |
"Modified: 21.9.1995 / 13:42:06 / claus" |
752
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
285 |
"Modified: 5.6.1996 / 14:25:51 / cg" |
198 | 286 |
! |
287 |
||
288 |
queryFrom:aToggle |
|
289 |
"a query from a toggle, if its the selected one" |
|
290 |
||
291 |
self keysAndValuesDo:[:index :aComponent | |
|
752
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
292 |
((aToggle == aComponent) or:[aToggle isComponentOf:aComponent]) ifTrue:[ |
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
293 |
^ valueChannel value == index |
198 | 294 |
] |
295 |
]. |
|
296 |
^ false |
|
297 |
||
752
a5781b7ff8cb
isSubViewOf: -> isComponentOf:
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
298 |
"Modified: 5.6.1996 / 14:25:53 / cg" |
198 | 299 |
! |
300 |
||
301 |
update:something with:someArgument from:changedButton |
|
302 |
" |
|
303 |
a RadioButton in this group has changed - notify the others |
|
304 |
" |
|
305 |
||
306 |
self elementChanged:(changedButton isOn) from:changedButton |
|
0 | 307 |
! ! |
198 | 308 |