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 |
|
|
22 |
RadioButtonGroup comment:'
|
5
|
23 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
59
|
24 |
All Rights Reserved
|
0
|
25 |
|
155
|
26 |
$Header: /cvs/stx/stx/libwidg/RadioButtonGroup.st,v 1.13 1995-09-07 12:45:50 claus Exp $
|
38
|
27 |
'!
|
|
28 |
|
|
29 |
!RadioButtonGroup class methodsFor:'documentation '!
|
|
30 |
|
|
31 |
copyright
|
|
32 |
"
|
|
33 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
59
|
34 |
All Rights Reserved
|
0
|
35 |
|
38
|
36 |
This software is furnished under a license and may be used
|
|
37 |
only in accordance with the terms of that license and with the
|
|
38 |
inclusion of the above copyright notice. This software may not
|
|
39 |
be provided or otherwise made available to, or used by, any
|
|
40 |
other person. No title to or ownership of the software is
|
|
41 |
hereby transferred.
|
|
42 |
"
|
|
43 |
!
|
|
44 |
|
|
45 |
version
|
|
46 |
"
|
155
|
47 |
$Header: /cvs/stx/stx/libwidg/RadioButtonGroup.st,v 1.13 1995-09-07 12:45:50 claus Exp $
|
38
|
48 |
"
|
|
49 |
!
|
|
50 |
|
|
51 |
documentation
|
|
52 |
"
|
|
53 |
RadioButtonGroups control the interaction between RadioButtons
|
|
54 |
turning off other button(s) when one of the group is pressed.
|
63
|
55 |
To group some buttons (and have one-on behavior) use:
|
|
56 |
|
|
57 |
|g|
|
|
58 |
|
|
59 |
g := RadioButtonGroup new.
|
|
60 |
...
|
|
61 |
b1 := RadioButton label:....
|
|
62 |
g add:b1
|
|
63 |
...
|
|
64 |
b2 := RadioButton label:....
|
|
65 |
g add:b2
|
|
66 |
...
|
116
|
67 |
|
131
|
68 |
A radioButtonGroup installs itself as the model of its toggles or
|
|
69 |
radioButtons. Therefore, you can no longer operate the individual
|
|
70 |
elements on models.
|
|
71 |
Instead, the group now provides a valueHolder which takes as value
|
|
72 |
the index of the selected toggle. You can set/get this valueHolder
|
|
73 |
via the valueChannel:/valueChannel messages.
|
|
74 |
See the last example for how this is done.
|
155
|
75 |
|
|
76 |
The groupID instance variable is not required for normal operation;
|
|
77 |
the interface builder uses it to give a button-group some descriptive
|
|
78 |
(unique) name.
|
131
|
79 |
"
|
|
80 |
!
|
|
81 |
|
|
82 |
examples
|
|
83 |
"
|
116
|
84 |
example (using Toggles for 'at most one-on behavior'):
|
|
85 |
|
|
86 |
|top panel toggle b g|
|
|
87 |
|
|
88 |
top := StandardSystemView new.
|
|
89 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
90 |
g := RadioButtonGroup new.
|
|
91 |
b := Toggle label:'one' in:panel.
|
|
92 |
g add:b.
|
|
93 |
b := Toggle label:'two' in:panel.
|
|
94 |
g add:b.
|
|
95 |
b := Toggle label:'three' in:panel.
|
|
96 |
g add:b.
|
130
|
97 |
top extent:(panel preferredExtent).
|
116
|
98 |
top open.
|
|
99 |
|
|
100 |
example (using RadioButtons for 'one-on behavior'):
|
|
101 |
|
|
102 |
|top panel toggle b g|
|
|
103 |
|
|
104 |
top := StandardSystemView new.
|
|
105 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
106 |
g := RadioButtonGroup new.
|
|
107 |
b := RadioButton label:'one' in:panel.
|
|
108 |
g add:b.
|
|
109 |
b := RadioButton label:'two' in:panel.
|
|
110 |
g add:b.
|
|
111 |
b := RadioButton label:'three' in:panel.
|
|
112 |
g add:b.
|
130
|
113 |
top extent:(panel preferredExtent).
|
116
|
114 |
top open.
|
|
115 |
|
|
116 |
example (same, with button 'two' initially on):
|
|
117 |
|
|
118 |
|top panel toggle b g|
|
|
119 |
|
|
120 |
top := StandardSystemView new.
|
|
121 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
122 |
g := RadioButtonGroup new.
|
|
123 |
b := RadioButton label:'one' in:panel.
|
|
124 |
g add:b.
|
|
125 |
b := RadioButton label:'two' in:panel.
|
|
126 |
g add:b.
|
|
127 |
b turnOn.
|
|
128 |
b := RadioButton label:'three' in:panel.
|
|
129 |
g add:b.
|
130
|
130 |
top extent:(panel preferredExtent).
|
116
|
131 |
top open.
|
131
|
132 |
|
|
133 |
example (operating on a model)
|
|
134 |
|
|
135 |
|selected dialog group|
|
|
136 |
|
|
137 |
selected := 2 asValue.
|
|
138 |
dialog := Dialog new.
|
|
139 |
group := RadioButtonGroup new.
|
|
140 |
group add:(dialog addCheckBox:'one' on:nil) toggleView.
|
|
141 |
group add:(dialog addCheckBox:'two' on:nil) toggleView.
|
|
142 |
group add:(dialog addCheckBox:'three' on:nil) toggleView.
|
|
143 |
group valueChannel:selected.
|
|
144 |
dialog addAbortButton; addOkButton.
|
|
145 |
dialog open.
|
|
146 |
dialog accepted ifTrue:[
|
|
147 |
Transcript showCr:'you selected: ' , selected value printString
|
|
148 |
]
|
|
149 |
|
38
|
150 |
"
|
|
151 |
! !
|
0
|
152 |
|
155
|
153 |
!RadioButtonGroup methodsFor:'accessing'!
|
|
154 |
|
|
155 |
groupID:aSymbol
|
|
156 |
groupID := aSymbol
|
|
157 |
|
|
158 |
"Modified: 5.9.1995 / 16:04:28 / claus"
|
|
159 |
!
|
|
160 |
|
|
161 |
groupID
|
|
162 |
^ groupID
|
|
163 |
|
|
164 |
"Modified: 5.9.1995 / 16:04:33 / claus"
|
|
165 |
! !
|
|
166 |
|
131
|
167 |
!RadioButtonGroup methodsFor:'accessing-mvc'!
|
|
168 |
|
|
169 |
valueChannel
|
|
170 |
^ valueChannel
|
|
171 |
!
|
|
172 |
|
|
173 |
valueChannel:aValueHolder
|
|
174 |
|oldValue newValue|
|
|
175 |
|
|
176 |
valueChannel notNil ifTrue:[oldValue := valueChannel value].
|
|
177 |
valueChannel := aValueHolder.
|
|
178 |
(newValue := valueChannel value) ~~ oldValue ifTrue:[
|
|
179 |
(self at:newValue) turnOn
|
|
180 |
]
|
|
181 |
! !
|
|
182 |
|
0
|
183 |
!RadioButtonGroup methodsFor:'adding / removing'!
|
|
184 |
|
|
185 |
add:aRadioButton
|
|
186 |
super add:aRadioButton.
|
131
|
187 |
|
|
188 |
"
|
|
189 |
this would work, if dependencies were not weak ...
|
|
190 |
"
|
105
|
191 |
"/ aRadioButton addDependent:self.
|
131
|
192 |
|
|
193 |
|
|
194 |
"
|
|
195 |
therefore, we have to install ourself as model of the buttons/toggles
|
|
196 |
creating a valueChannel, if there is none yet.
|
|
197 |
"
|
|
198 |
valueChannel isNil ifTrue:[
|
|
199 |
valueChannel := 0 asValue
|
|
200 |
].
|
|
201 |
aRadioButton isOn ifTrue:[valueChannel value:self size].
|
|
202 |
aRadioButton model:self; aspectMessage:nil; changeMessage:#elementChanged:from:.
|
|
203 |
|
0
|
204 |
! !
|
|
205 |
|
|
206 |
!RadioButtonGroup methodsFor:'update'!
|
|
207 |
|
59
|
208 |
update:something with:someArgument from:changedButton
|
|
209 |
(self includes:changedButton) ifFalse:[^ self].
|
|
210 |
|
131
|
211 |
"
|
|
212 |
a RadioButton in this group has changed - notify the others
|
|
213 |
"
|
0
|
214 |
|
105
|
215 |
"/ "in case we have a toggle in the group,
|
|
216 |
"/ and it has been turned off - turn it on again
|
|
217 |
"/ "
|
|
218 |
"/ changedButton isOn ifFalse:[
|
|
219 |
"/ changedButton toggleNoAction.
|
|
220 |
"/ ^ self
|
|
221 |
"/ ].
|
131
|
222 |
self elementChanged:(changedButton isOn) from:changedButton
|
105
|
223 |
!
|
|
224 |
|
|
225 |
elementChanged:aToggle
|
131
|
226 |
"historic compatibility leftover - will vanish"
|
|
227 |
|
|
228 |
^ self elementChanged:true from:aToggle
|
|
229 |
!
|
|
230 |
|
|
231 |
elementChanged:value from:aToggle
|
|
232 |
"some element changed its value - find it, turn the others off
|
|
233 |
and update my value"
|
|
234 |
|
|
235 |
|newValue|
|
|
236 |
|
|
237 |
self keysAndValuesDo:[:index :aButton |
|
116
|
238 |
(aButton == aToggle) ifFalse:[
|
|
239 |
aButton isOn ifTrue:[
|
|
240 |
aButton turnOff
|
|
241 |
]
|
131
|
242 |
] ifTrue:[
|
|
243 |
value ifTrue:[newValue := index]
|
116
|
244 |
]
|
131
|
245 |
].
|
|
246 |
valueChannel value:newValue
|
0
|
247 |
|
|
248 |
! !
|