author | Claus Gittinger <cg@exept.de> |
Sat, 01 Mar 1997 14:14:02 +0100 | |
changeset 1088 | 40de2fe27607 |
parent 791 | f76f4541742f |
child 1245 | 162b71744f37 |
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 |
||
1088 | 13 |
ValueHolder subclass:#RadioButtonGroup |
14 |
instanceVariableNames:'numberOfValues' |
|
586 | 15 |
classVariableNames:'' |
16 |
poolDictionaries:'' |
|
17 |
category:'Views-Support' |
|
0 | 18 |
! |
19 |
||
1088 | 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 |
|
1088 | 53 |
A radioButtonGroup is itself usable as a model, holding the index of |
54 |
the selected button. It can be used as a selectionIndexHolder of a |
|
55 |
SelectionInList instance. |
|
586 | 56 |
|
57 |
[author:] |
|
58 |
Claus Gittinger |
|
1088 | 59 |
|
60 |
[see also:] |
|
61 |
RadioButton Toggle CheckBox CheckToggle Button |
|
62 |
Model ValueHolder SelectionInList |
|
131 | 63 |
" |
586 | 64 |
|
1088 | 65 |
"Modified: 1.3.1997 / 14:11:57 / cg" |
131 | 66 |
! |
67 |
||
68 |
examples |
|
69 |
" |
|
1088 | 70 |
using Toggles for 'at most one-on behavior': |
594 | 71 |
[exBegin] |
1088 | 72 |
|top panel b group| |
116 | 73 |
|
1088 | 74 |
top := StandardSystemView label:'toggles'. |
594 | 75 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
76 |
group := RadioButtonGroup new. |
|
77 |
b := Toggle label:'one' in:panel. |
|
78 |
group add:b. |
|
79 |
b := Toggle label:'two' in:panel. |
|
80 |
group add:b. |
|
81 |
b := Toggle label:'three' in:panel. |
|
82 |
group add:b. |
|
83 |
top extent:(panel preferredExtent). |
|
84 |
top open. |
|
85 |
[exEnd] |
|
116 | 86 |
|
177 | 87 |
|
1088 | 88 |
using RadioButtons for 'one-on behavior': |
594 | 89 |
[exBegin] |
1088 | 90 |
|top panel b group| |
116 | 91 |
|
1088 | 92 |
top := StandardSystemView label:'radio'. |
594 | 93 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
94 |
group := RadioButtonGroup new. |
|
95 |
b := RadioButton label:'one' in:panel. |
|
96 |
group add:b. |
|
97 |
b := RadioButton label:'two' in:panel. |
|
98 |
group add:b. |
|
99 |
b := RadioButton label:'three' in:panel. |
|
100 |
group add:b. |
|
101 |
top extent:(panel preferredExtent). |
|
102 |
top open. |
|
103 |
[exEnd] |
|
116 | 104 |
|
177 | 105 |
|
1088 | 106 |
same, with initial selection: |
594 | 107 |
[exBegin] |
1088 | 108 |
|top panel b group| |
109 |
||
110 |
top := StandardSystemView label:'radio'. |
|
111 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
112 |
group := RadioButtonGroup new. |
|
113 |
b := RadioButton label:'one' in:panel. |
|
114 |
group add:b. |
|
115 |
b := RadioButton label:'two' in:panel. |
|
116 |
group add:b. |
|
117 |
b := RadioButton label:'three' in:panel. |
|
118 |
group add:b. |
|
119 |
top extent:(panel preferredExtent). |
|
120 |
||
121 |
group value:1. |
|
122 |
top open. |
|
123 |
[exEnd] |
|
124 |
||
125 |
||
126 |
using Buttons for 'none-on behavior'; |
|
127 |
buttons do not show the boolean state (they only fire); |
|
128 |
however, the groups value remembers the last pressed button: |
|
129 |
[exBegin] |
|
130 |
|top panel b group| |
|
177 | 131 |
|
594 | 132 |
top := StandardSystemView new. |
133 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
134 |
group := RadioButtonGroup new. |
|
135 |
b := Button label:'one' in:panel. |
|
136 |
group add:b. |
|
137 |
b := Button label:'two' in:panel. |
|
138 |
group add:b. |
|
139 |
b := Button label:'three' in:panel. |
|
140 |
group add:b. |
|
141 |
top extent:(panel preferredExtent). |
|
142 |
top open. |
|
1088 | 143 |
|
144 |
group inspect |
|
594 | 145 |
[exEnd] |
177 | 146 |
|
147 |
||
1088 | 148 |
using checkBoxes (these have a label included). |
149 |
notice, that we change their behavior to radioButton behavior: |
|
594 | 150 |
[exBegin] |
1088 | 151 |
|top panel b group| |
163 | 152 |
|
594 | 153 |
top := StandardSystemView new. |
154 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
155 |
panel horizontalLayout:#left. |
|
156 |
group := RadioButtonGroup new. |
|
157 |
b := CheckBox label:'one' in:panel. |
|
1088 | 158 |
b controller beRadioButton. |
594 | 159 |
group add:b. |
160 |
b := CheckBox label:'two' in:panel. |
|
1088 | 161 |
b controller beRadioButton. |
594 | 162 |
group add:b. |
163 |
b := CheckBox label:'three' in:panel. |
|
1088 | 164 |
b controller beRadioButton. |
594 | 165 |
group add:b. |
166 |
top extent:(panel preferredExtent). |
|
167 |
top open. |
|
168 |
[exEnd] |
|
163 | 169 |
|
170 |
||
1088 | 171 |
a small dialog |
594 | 172 |
[exBegin] |
1088 | 173 |
|dialog group b| |
131 | 174 |
|
594 | 175 |
dialog := Dialog new. |
1088 | 176 |
|
594 | 177 |
group := RadioButtonGroup new. |
1088 | 178 |
group add:(b := dialog addCheckBox:'one' on:nil). |
179 |
b controller beRadioButton. |
|
180 |
group add:(b := dialog addCheckBox:'two' on:nil). |
|
181 |
b controller beRadioButton. |
|
182 |
group add:(b := dialog addCheckBox:'three' on:nil). |
|
183 |
b controller beRadioButton. |
|
184 |
group value:2. |
|
594 | 185 |
dialog addAbortButton; addOkButton. |
186 |
dialog open. |
|
1088 | 187 |
|
594 | 188 |
dialog accepted ifTrue:[ |
1088 | 189 |
Transcript showCR:'you selected: ' , group value printString |
594 | 190 |
] ifFalse:[ |
655 | 191 |
Transcript showCR:'aborted' |
594 | 192 |
] |
193 |
[exEnd] |
|
1088 | 194 |
|
195 |
as a selectionIndexHolder of a selectionInList |
|
196 |
(i.e. a selectionInListView and a group displaying the same selection): |
|
197 |
[exBegin] |
|
198 |
|top top2 panel b sv group selectionInList| |
|
199 |
||
200 |
top := StandardSystemView extent:200@200. |
|
201 |
||
202 |
panel := HorizontalPanelView |
|
203 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
204 |
||
205 |
group := RadioButtonGroup new. |
|
206 |
selectionInList := SelectionInList new. |
|
207 |
selectionInList list:#('am' 'fm' 'off'). |
|
208 |
selectionInList selectionIndexHolder:group. |
|
209 |
||
210 |
b := RadioButton label:'am' in:panel. |
|
211 |
group add:b. |
|
212 |
||
213 |
b := RadioButton label:'fm' in:panel. |
|
214 |
group add:b. |
|
215 |
||
216 |
b := RadioButton label:'off' in:panel. |
|
217 |
group add:b. |
|
218 |
||
219 |
group value:1. |
|
220 |
top open. |
|
221 |
||
222 |
||
223 |
top2 := StandardSystemView extent:200@200. |
|
224 |
sv := SelectionInListView in:top2. |
|
225 |
sv model:selectionInList. |
|
226 |
sv origin:0.0@0.0 corner:1.0@1.0. |
|
227 |
top2 open. |
|
38 | 228 |
" |
178
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
229 |
|
5c28593c2a3b
turnOn/ turnOff changed back - now added turnOn/OffWithAction (sorry stefan)
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
230 |
"Created: 15.11.1995 / 17:14:53 / cg" |
1088 | 231 |
"Modified: 1.3.1997 / 14:13:36 / cg" |
198 | 232 |
! |
233 |
||
234 |
version |
|
1088 | 235 |
^ '$Header: /cvs/stx/stx/libwidg/RadioButtonGroup.st,v 1.25 1997-03-01 13:14:02 cg Exp $' |
131 | 236 |
! ! |
237 |
||
0 | 238 |
!RadioButtonGroup methodsFor:'adding / removing'! |
239 |
||
240 |
add:aRadioButton |
|
1088 | 241 |
"add a radioButton to the group - actually, this name is misleading; |
242 |
it simple creates an adaptor, which converts my value into a boolean, |
|
243 |
depending on the buttons index-number" |
|
791
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
244 |
|
1088 | 245 |
|c idx adaptor| |
131 | 246 |
|
1088 | 247 |
numberOfValues isNil ifTrue:[ |
248 |
numberOfValues := 0. |
|
249 |
]. |
|
250 |
numberOfValues := numberOfValues + 1. |
|
131 | 251 |
|
1088 | 252 |
idx := numberOfValues. |
131 | 253 |
|
1088 | 254 |
adaptor := PluggableAdaptor on:self. |
255 |
adaptor getBlock:[:m | m value == idx] |
|
256 |
putBlock:[:m :onOff | |
|
257 |
onOff ifTrue:[ |
|
258 |
m value:idx |
|
259 |
] ifFalse:[ |
|
260 |
idx == value ifTrue:[ |
|
261 |
m value:nil |
|
262 |
] |
|
263 |
] |
|
264 |
] |
|
265 |
updateBlock:[:m :a :v | true]. |
|
266 |
||
267 |
aRadioButton isOn ifTrue:[ |
|
268 |
self value:idx. |
|
131 | 269 |
]. |
1088 | 270 |
aRadioButton model:adaptor. |
131 | 271 |
|
1088 | 272 |
"/ (c := aRadioButton controller) notNil ifTrue:[ |
273 |
"/ c beRadioButton |
|
274 |
"/ ] ifFalse:[ |
|
275 |
"/ aRadioButton controller:(RadioButtonController new). |
|
276 |
"/ ] |
|
791
f76f4541742f
adding a button implies making it a radioButton
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
277 |
|
1088 | 278 |
"Modified: 1.3.1997 / 13:58:32 / cg" |
0 | 279 |
! ! |
280 |