author | Claus Gittinger <cg@exept.de> |
Sun, 23 Nov 2014 15:33:00 +0100 | |
changeset 5173 | d7db63d56ccd |
parent 2661 | 98a32f29fa08 |
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 |
||
2449 | 13 |
"{ Package: 'stx:libwidg' }" |
14 |
||
1088 | 15 |
ValueHolder subclass:#RadioButtonGroup |
16 |
instanceVariableNames:'numberOfValues' |
|
586 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Views-Support' |
|
0 | 20 |
! |
21 |
||
2449 | 22 |
!RadioButtonGroup class methodsFor:'documentation'! |
38 | 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 |
documentation |
|
39 |
" |
|
40 |
RadioButtonGroups control the interaction between RadioButtons |
|
41 |
turning off other button(s) when one of the group is pressed. |
|
63 | 42 |
To group some buttons (and have one-on behavior) use: |
43 |
||
586 | 44 |
|g| |
63 | 45 |
|
586 | 46 |
g := RadioButtonGroup new. |
47 |
... |
|
48 |
b1 := RadioButton label:.... |
|
49 |
g add:b1 |
|
50 |
... |
|
51 |
b2 := RadioButton label:.... |
|
52 |
g add:b2 |
|
53 |
... |
|
116 | 54 |
|
1088 | 55 |
A radioButtonGroup is itself usable as a model, holding the index of |
56 |
the selected button. It can be used as a selectionIndexHolder of a |
|
57 |
SelectionInList instance. |
|
586 | 58 |
|
59 |
[author:] |
|
60 |
Claus Gittinger |
|
1088 | 61 |
|
62 |
[see also:] |
|
63 |
RadioButton Toggle CheckBox CheckToggle Button |
|
64 |
Model ValueHolder SelectionInList |
|
131 | 65 |
" |
586 | 66 |
|
1088 | 67 |
"Modified: 1.3.1997 / 14:11:57 / cg" |
131 | 68 |
! |
69 |
||
70 |
examples |
|
71 |
" |
|
1088 | 72 |
using Toggles for 'at most one-on behavior': |
594 | 73 |
[exBegin] |
1088 | 74 |
|top panel b group| |
116 | 75 |
|
1088 | 76 |
top := StandardSystemView label:'toggles'. |
594 | 77 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
78 |
group := RadioButtonGroup new. |
|
79 |
b := Toggle label:'one' in:panel. |
|
80 |
group add:b. |
|
81 |
b := Toggle label:'two' in:panel. |
|
82 |
group add:b. |
|
83 |
b := Toggle label:'three' in:panel. |
|
84 |
group add:b. |
|
85 |
top extent:(panel preferredExtent). |
|
86 |
top open. |
|
87 |
[exEnd] |
|
116 | 88 |
|
177 | 89 |
|
1088 | 90 |
using RadioButtons for 'one-on behavior': |
594 | 91 |
[exBegin] |
1088 | 92 |
|top panel b group| |
116 | 93 |
|
1088 | 94 |
top := StandardSystemView label:'radio'. |
594 | 95 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
96 |
group := RadioButtonGroup new. |
|
97 |
b := RadioButton label:'one' in:panel. |
|
98 |
group add:b. |
|
99 |
b := RadioButton label:'two' in:panel. |
|
100 |
group add:b. |
|
101 |
b := RadioButton label:'three' in:panel. |
|
102 |
group add:b. |
|
103 |
top extent:(panel preferredExtent). |
|
104 |
top open. |
|
105 |
[exEnd] |
|
116 | 106 |
|
177 | 107 |
|
1088 | 108 |
same, with initial selection: |
594 | 109 |
[exBegin] |
1088 | 110 |
|top panel b group| |
111 |
||
112 |
top := StandardSystemView label:'radio'. |
|
113 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
114 |
group := RadioButtonGroup new. |
|
115 |
b := RadioButton label:'one' in:panel. |
|
116 |
group add:b. |
|
117 |
b := RadioButton label:'two' in:panel. |
|
118 |
group add:b. |
|
119 |
b := RadioButton label:'three' in:panel. |
|
120 |
group add:b. |
|
121 |
top extent:(panel preferredExtent). |
|
122 |
||
123 |
group value:1. |
|
124 |
top open. |
|
125 |
[exEnd] |
|
126 |
||
127 |
||
128 |
using Buttons for 'none-on behavior'; |
|
129 |
buttons do not show the boolean state (they only fire); |
|
130 |
however, the groups value remembers the last pressed button: |
|
131 |
[exBegin] |
|
132 |
|top panel b group| |
|
177 | 133 |
|
594 | 134 |
top := StandardSystemView new. |
135 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
136 |
group := RadioButtonGroup new. |
|
137 |
b := Button label:'one' in:panel. |
|
138 |
group add:b. |
|
139 |
b := Button label:'two' in:panel. |
|
140 |
group add:b. |
|
141 |
b := Button label:'three' in:panel. |
|
142 |
group add:b. |
|
143 |
top extent:(panel preferredExtent). |
|
144 |
top open. |
|
1088 | 145 |
|
146 |
group inspect |
|
594 | 147 |
[exEnd] |
177 | 148 |
|
149 |
||
1088 | 150 |
using checkBoxes (these have a label included). |
151 |
notice, that we change their behavior to radioButton behavior: |
|
594 | 152 |
[exBegin] |
1088 | 153 |
|top panel b group| |
163 | 154 |
|
594 | 155 |
top := StandardSystemView new. |
156 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
157 |
panel horizontalLayout:#left. |
|
158 |
group := RadioButtonGroup new. |
|
159 |
b := CheckBox label:'one' in:panel. |
|
1088 | 160 |
b controller beRadioButton. |
594 | 161 |
group add:b. |
162 |
b := CheckBox label:'two' in:panel. |
|
1088 | 163 |
b controller beRadioButton. |
594 | 164 |
group add:b. |
165 |
b := CheckBox label:'three' in:panel. |
|
1088 | 166 |
b controller beRadioButton. |
594 | 167 |
group add:b. |
168 |
top extent:(panel preferredExtent). |
|
169 |
top open. |
|
170 |
[exEnd] |
|
163 | 171 |
|
172 |
||
1088 | 173 |
a small dialog |
594 | 174 |
[exBegin] |
1088 | 175 |
|dialog group b| |
131 | 176 |
|
594 | 177 |
dialog := Dialog new. |
1088 | 178 |
|
594 | 179 |
group := RadioButtonGroup new. |
1088 | 180 |
group add:(b := dialog addCheckBox:'one' on:nil). |
181 |
b controller beRadioButton. |
|
182 |
group add:(b := dialog addCheckBox:'two' on:nil). |
|
183 |
b controller beRadioButton. |
|
184 |
group add:(b := dialog addCheckBox:'three' on:nil). |
|
185 |
b controller beRadioButton. |
|
186 |
group value:2. |
|
594 | 187 |
dialog addAbortButton; addOkButton. |
188 |
dialog open. |
|
1088 | 189 |
|
594 | 190 |
dialog accepted ifTrue:[ |
1088 | 191 |
Transcript showCR:'you selected: ' , group value printString |
594 | 192 |
] ifFalse:[ |
655 | 193 |
Transcript showCR:'aborted' |
594 | 194 |
] |
195 |
[exEnd] |
|
1088 | 196 |
|
197 |
as a selectionIndexHolder of a selectionInList |
|
198 |
(i.e. a selectionInListView and a group displaying the same selection): |
|
199 |
[exBegin] |
|
200 |
|top top2 panel b sv group selectionInList| |
|
201 |
||
202 |
top := StandardSystemView extent:200@200. |
|
203 |
||
204 |
panel := HorizontalPanelView |
|
205 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
206 |
||
207 |
group := RadioButtonGroup new. |
|
208 |
selectionInList := SelectionInList new. |
|
209 |
selectionInList list:#('am' 'fm' 'off'). |
|
210 |
selectionInList selectionIndexHolder:group. |
|
211 |
||
212 |
b := RadioButton label:'am' in:panel. |
|
213 |
group add:b. |
|
214 |
||
215 |
b := RadioButton label:'fm' in:panel. |
|
216 |
group add:b. |
|
217 |
||
218 |
b := RadioButton label:'off' in:panel. |
|
219 |
group add:b. |
|
220 |
||
221 |
group value:1. |
|
222 |
top open. |
|
223 |
||
224 |
||
225 |
top2 := StandardSystemView extent:200@200. |
|
226 |
sv := SelectionInListView in:top2. |
|
227 |
sv model:selectionInList. |
|
228 |
sv origin:0.0@0.0 corner:1.0@1.0. |
|
229 |
top2 open. |
|
1377 | 230 |
[exEnd] |
38 | 231 |
" |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
232 |
|
1377 | 233 |
"Created: / 15.11.1995 / 17:14:53 / cg" |
234 |
"Modified: / 30.10.1997 / 20:18:25 / cg" |
|
235 |
! ! |
|
236 |
||
237 |
!RadioButtonGroup class methodsFor:'helpers'! |
|
238 |
||
239 |
adaptorFor:someValueHolder value:buttonValue |
|
240 |
"create and return an adaptor for a radioButton" |
|
241 |
||
242 |
|adaptor| |
|
243 |
||
244 |
adaptor := PluggableAdaptor on:someValueHolder. |
|
245 |
||
246 |
"/ the adapter plays boolean-value holder towards |
|
247 |
"/ the radioButton, returning true iff the groups |
|
248 |
"/ value is the same as the buttons index-value; false otherwise. |
|
249 |
"/ Likewise, a true-store from the button sets the group value |
|
250 |
"/ to the buttons index. |
|
251 |
||
1815
e3a6c8e93fd1
react on equal value (used to be identical)
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
252 |
adaptor getBlock:[:m | (m value = buttonValue) ] |
1377 | 253 |
putBlock:[:m :onOff | |
254 |
onOff ifTrue:[ |
|
255 |
m value:buttonValue |
|
256 |
] ifFalse:[ |
|
257 |
"/ support for toggles |
|
1815
e3a6c8e93fd1
react on equal value (used to be identical)
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
258 |
buttonValue = m value ifTrue:[ |
1377 | 259 |
m value:nil |
260 |
] |
|
261 |
] |
|
262 |
] |
|
263 |
updateBlock:[:m :a :v | true]. |
|
264 |
||
265 |
^ adaptor |
|
266 |
||
267 |
"Created: / 30.10.1997 / 19:45:34 / cg" |
|
268 |
"Modified: / 30.10.1997 / 20:14:25 / cg" |
|
131 | 269 |
! ! |
270 |
||
2144 | 271 |
!RadioButtonGroup methodsFor:'adding & removing'! |
0 | 272 |
|
273 |
add:aRadioButton |
|
1088 | 274 |
"add a radioButton to the group - actually, this name is misleading; |
275 |
it simple creates an adaptor, which converts my value into a boolean, |
|
1245 | 276 |
depending on the buttons index-number |
277 |
" |
|
278 |
self add:aRadioButton value:nil |
|
279 |
! |
|
131 | 280 |
|
1810 | 281 |
add:aRadioButton value:aValueOrNil |
1245 | 282 |
"add a radioButton to the group - actually, this name is misleading; |
1810 | 283 |
it simply creates an adaptor, which converts my value into a boolean, |
284 |
depending on the buttons index-number or aValueOrNil" |
|
131 | 285 |
|
1810 | 286 |
|adaptor selectValue| |
131 | 287 |
|
1367 | 288 |
numberOfValues := (numberOfValues ? 0) + 1. |
1810 | 289 |
selectValue := aValueOrNil ? numberOfValues. |
1245 | 290 |
|
1367 | 291 |
"/ the adapter plays boolean-value holder towards |
292 |
"/ the radioButton, returning true iff the groups |
|
293 |
"/ value is the same as the buttons index-value; false otherwise. |
|
294 |
"/ Likewise, a true-store from the button sets the group value |
|
295 |
"/ to the buttons index. |
|
296 |
||
1810 | 297 |
adaptor := self class adaptorFor:self value:selectValue. |
1088 | 298 |
aRadioButton isOn ifTrue:[ |
1810 | 299 |
self value:selectValue. |
131 | 300 |
]. |
1088 | 301 |
aRadioButton model:adaptor. |
1367 | 302 |
|
1377 | 303 |
"Modified: / 30.10.1997 / 20:14:54 / cg" |
0 | 304 |
! ! |
305 |
||
2661 | 306 |
!RadioButtonGroup methodsFor:'queries'! |
307 |
||
308 |
numberOfValues |
|
309 |
^ numberOfValues |
|
310 |
! ! |
|
311 |
||
2449 | 312 |
!RadioButtonGroup class methodsFor:'documentation'! |
313 |
||
314 |
version |
|
2661 | 315 |
^ '$Header: /cvs/stx/stx/libwidg/RadioButtonGroup.st,v 1.33 2002-11-11 09:49:19 cg Exp $' |
2449 | 316 |
! ! |