44
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
49
|
3 |
All Rights Reserved
|
44
|
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 |
|
|
13 |
|
|
14 |
HorizontalPanelView subclass:#CheckBox
|
|
15 |
instanceVariableNames:'toggleView labelView'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Interactors'
|
|
19 |
!
|
|
20 |
|
|
21 |
!CheckBox class methodsFor:'documentation'!
|
|
22 |
|
100
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
|
44
|
36 |
!
|
|
37 |
|
|
38 |
documentation
|
|
39 |
"
|
|
40 |
CheckBox has been added somwehat in a hurry
|
|
41 |
- obviously, much more protocol is needed.
|
|
42 |
|
|
43 |
For now, set actions etc. via sends to the components,
|
|
44 |
labelView and toggleView.
|
|
45 |
"
|
|
46 |
!
|
|
47 |
|
|
48 |
examples
|
|
49 |
"
|
|
50 |
no-op checkBox:
|
|
51 |
|
|
52 |
|b|
|
|
53 |
|
|
54 |
b := CheckBox new.
|
|
55 |
b label:'foo'.
|
|
56 |
b open
|
|
57 |
|
|
58 |
|
56
|
59 |
no-op checkBox, disabled:
|
|
60 |
|
|
61 |
|b|
|
|
62 |
|
|
63 |
b := CheckBox new.
|
|
64 |
b label:'foo'.
|
|
65 |
b disable.
|
|
66 |
b open
|
|
67 |
|
|
68 |
|
|
69 |
changing colors
|
|
70 |
(a demo only: it is no good style to fight the styleSheet):
|
44
|
71 |
|
|
72 |
|panel b|
|
|
73 |
|
|
74 |
panel := VerticalPanelView new.
|
|
75 |
|
|
76 |
b := CheckBox in:panel.
|
|
77 |
b label:'foo'.
|
|
78 |
|
|
79 |
b := CheckBox in:panel.
|
|
80 |
b label:'bar'.
|
|
81 |
b labelView foregroundColor:Color red.
|
|
82 |
|
|
83 |
b := CheckBox in:panel.
|
|
84 |
b label:'baz'.
|
|
85 |
b toggleView activeForegroundColor:Color blue.
|
|
86 |
|
|
87 |
panel open
|
|
88 |
|
|
89 |
|
|
90 |
using action-blocks:
|
|
91 |
|
49
|
92 |
|b|
|
44
|
93 |
|
|
94 |
b := CheckBox new.
|
|
95 |
b label:'check'.
|
49
|
96 |
b action:[:value | Transcript show:'set to: '; showCr:value].
|
44
|
97 |
b open.
|
|
98 |
|
|
99 |
|
49
|
100 |
with a model (default ST-80 behavior, sending #value: to the model):
|
|
101 |
(see changing value in the inspector)
|
|
102 |
|
|
103 |
|b model|
|
|
104 |
|
|
105 |
model := ValueHolder newBoolean.
|
|
106 |
|
|
107 |
b := CheckBox new.
|
|
108 |
b label:'check'.
|
|
109 |
b model:model.
|
|
110 |
b open.
|
|
111 |
model inspect.
|
|
112 |
|
56
|
113 |
|
49
|
114 |
with a model and different changeSelector
|
|
115 |
(using a plug here, for demonstration only):
|
44
|
116 |
|
|
117 |
|b model|
|
|
118 |
|
|
119 |
model := Plug new.
|
|
120 |
model respondTo:#changeCheck: with:[:arg | Transcript showCr:'change to ' , arg printString].
|
|
121 |
|
|
122 |
b := CheckBox new.
|
|
123 |
b label:'check'.
|
59
|
124 |
b model:model; changeMessage:#changeCheck:.
|
44
|
125 |
b open.
|
|
126 |
|
56
|
127 |
|
|
128 |
with models, one checkBox disabling the others:
|
|
129 |
|
|
130 |
|dialog translator enableChannel val1 val2 val3 eBox box1 box2 box3|
|
|
131 |
|
|
132 |
translator := Plug new.
|
|
133 |
translator respondTo:#enableDisable
|
79
|
134 |
with:[
|
|
135 |
enableChannel value
|
|
136 |
ifTrue:[
|
|
137 |
box1 enable.
|
|
138 |
box2 enable.
|
|
139 |
box3 enable.
|
|
140 |
]
|
|
141 |
ifFalse:[
|
|
142 |
box1 disable.
|
|
143 |
box2 disable.
|
|
144 |
box3 disable.
|
|
145 |
]
|
|
146 |
].
|
56
|
147 |
|
|
148 |
enableChannel := true asValue.
|
|
149 |
enableChannel onChangeSend:#enableDisable to:translator.
|
|
150 |
val1 := true asValue.
|
|
151 |
val2 := false asValue.
|
|
152 |
val3 := true asValue.
|
|
153 |
|
|
154 |
dialog := Dialog new.
|
|
155 |
dialog addCheckBox:'enable' on:enableChannel.
|
|
156 |
dialog addVerticalSpace.
|
|
157 |
dialog leftIndent:30.
|
|
158 |
box1 := dialog addCheckBox:'value1' on:val1.
|
|
159 |
dialog addVerticalSpace.
|
|
160 |
box2 := dialog addCheckBox:'value2' on:val2.
|
|
161 |
dialog addVerticalSpace.
|
|
162 |
box3 := dialog addCheckBox:'value3' on:val3.
|
|
163 |
dialog addVerticalSpace.
|
|
164 |
dialog addOkButton.
|
|
165 |
|
|
166 |
dialog open.
|
|
167 |
|
|
168 |
|
49
|
169 |
multiple checkBoxes on a single model (using different aspects)
|
|
170 |
|
79
|
171 |
|top panel b model value1 value2|
|
49
|
172 |
|
|
173 |
value1 := true.
|
|
174 |
value2 := false.
|
|
175 |
model := Plug new.
|
|
176 |
model respondTo:#value1 with:[value1].
|
|
177 |
model respondTo:#value1: with:[:val | value1 := val].
|
|
178 |
model respondTo:#value2 with:[value2].
|
|
179 |
model respondTo:#value2: with:[:val | value2 := val].
|
|
180 |
|
|
181 |
top := DialogBox new.
|
|
182 |
top extent:200@300.
|
|
183 |
|
|
184 |
panel := VerticalPanelView new.
|
|
185 |
|
|
186 |
b := CheckBox in:panel.
|
|
187 |
b label:'check1'.
|
59
|
188 |
b model:model; aspect:#value1; changeMessage:#value1:.
|
49
|
189 |
|
|
190 |
b := CheckBox in:panel.
|
|
191 |
b label:'check2'.
|
59
|
192 |
b model:model; aspect:#value2; changeMessage:#value2:.
|
49
|
193 |
|
|
194 |
top addComponent:panel.
|
|
195 |
top addAbortButton; addOkButton.
|
|
196 |
top openModal.
|
|
197 |
|
79
|
198 |
top accepted ifTrue:[
|
49
|
199 |
Transcript show:'value1: '; showCr:model value1.
|
|
200 |
Transcript show:'value2: '; showCr:model value2.
|
|
201 |
]
|
44
|
202 |
"
|
|
203 |
! !
|
|
204 |
|
62
|
205 |
!CheckBox class methodsFor:'instance creation'!
|
|
206 |
|
76
|
207 |
label:aStringOrImage model:aModel
|
|
208 |
"create & return a new checkBox, on aModel (typically a ValueHolder),
|
|
209 |
with aStringOrImage as label."
|
|
210 |
|
|
211 |
^ (self new model:aModel) label:aStringOrImage
|
|
212 |
|
|
213 |
"Created: 17.9.1995 / 14:20:58 / claus"
|
44
|
214 |
!
|
|
215 |
|
55
|
216 |
model:aModel
|
100
|
217 |
"create & return a new checkBox, on aModel (typically a ValueHolder)"
|
79
|
218 |
|
100
|
219 |
^ self new model:aModel
|
56
|
220 |
! !
|
|
221 |
|
|
222 |
!CheckBox methodsFor:'accessing'!
|
|
223 |
|
44
|
224 |
labelView
|
49
|
225 |
"return the labelView; allows manipulation of the
|
|
226 |
labels attributes (colors etc.)"
|
|
227 |
|
44
|
228 |
^ labelView
|
|
229 |
!
|
|
230 |
|
|
231 |
toggleView
|
49
|
232 |
"return the toggleView; allows manipulation of the
|
|
233 |
toggles attributes (colors etc.)"
|
|
234 |
|
44
|
235 |
^ toggleView
|
56
|
236 |
! !
|
|
237 |
|
100
|
238 |
!CheckBox methodsFor:'accessing-behavior'!
|
|
239 |
|
|
240 |
action:aBlock
|
|
241 |
"forward to toggle"
|
|
242 |
|
|
243 |
toggleView action:aBlock
|
|
244 |
!
|
|
245 |
|
|
246 |
disable
|
|
247 |
"forward to toggle & change labels color"
|
|
248 |
|
|
249 |
toggleView disable.
|
|
250 |
labelView foregroundColor:(toggleView disabledForegroundColor).
|
|
251 |
!
|
|
252 |
|
|
253 |
enable
|
|
254 |
"forward to toggle & change labels color"
|
|
255 |
|
|
256 |
toggleView enable.
|
|
257 |
labelView foregroundColor:(toggleView foregroundColor).
|
|
258 |
!
|
78
|
259 |
|
100
|
260 |
pressAction:aBlock
|
|
261 |
toggleView pressAction:aBlock.
|
|
262 |
|
|
263 |
"Created: 22.9.1995 / 15:54:04 / claus"
|
|
264 |
!
|
|
265 |
|
|
266 |
releaseAction:aBlock
|
|
267 |
toggleView releaseAction:aBlock.
|
|
268 |
|
|
269 |
"Created: 22.9.1995 / 15:54:11 / claus"
|
|
270 |
!
|
|
271 |
|
|
272 |
turnOff
|
|
273 |
"forward to toggle"
|
|
274 |
|
|
275 |
toggleView turnOff
|
|
276 |
!
|
|
277 |
|
|
278 |
turnOn
|
|
279 |
"forward to toggle"
|
|
280 |
|
|
281 |
toggleView turnOn
|
78
|
282 |
! !
|
|
283 |
|
56
|
284 |
!CheckBox methodsFor:'accessing-look'!
|
44
|
285 |
|
100
|
286 |
activeLogo:anImageOrString
|
|
287 |
toggleView activeLogo:anImageOrString
|
56
|
288 |
|
100
|
289 |
"Created: 22.9.1995 / 15:44:08 / claus"
|
|
290 |
!
|
|
291 |
|
|
292 |
font
|
|
293 |
"forward from label"
|
|
294 |
|
|
295 |
^ labelView font
|
49
|
296 |
!
|
44
|
297 |
|
56
|
298 |
font:aFont
|
|
299 |
"forward to label & resize"
|
55
|
300 |
|
56
|
301 |
labelView font:aFont.
|
|
302 |
labelView forceResize.
|
79
|
303 |
self layoutChanged.
|
|
304 |
self resize.
|
49
|
305 |
!
|
|
306 |
|
56
|
307 |
label
|
|
308 |
"forward from label"
|
|
309 |
|
|
310 |
^ labelView label
|
79
|
311 |
!
|
|
312 |
|
100
|
313 |
label:aString
|
|
314 |
"forward to label & resize"
|
79
|
315 |
|
100
|
316 |
labelView label:aString.
|
|
317 |
labelView forceResize.
|
|
318 |
self layoutChanged.
|
|
319 |
self resize.
|
79
|
320 |
!
|
|
321 |
|
|
322 |
passiveLogo:anImageOrString
|
|
323 |
toggleView passiveLogo:anImageOrString
|
|
324 |
|
|
325 |
"Created: 22.9.1995 / 15:44:14 / claus"
|
56
|
326 |
! !
|
|
327 |
|
100
|
328 |
!CheckBox methodsFor:'accessing-mvc'!
|
63
|
329 |
|
100
|
330 |
aspectMessage:aspectSymbol
|
|
331 |
"forward to label & toggle"
|
|
332 |
|
|
333 |
labelView aspectMessage:aspectSymbol.
|
|
334 |
toggleView aspectMessage:aspectSymbol
|
|
335 |
!
|
63
|
336 |
|
100
|
337 |
changeMessage:aChangeSelector
|
|
338 |
"forward to toggle"
|
|
339 |
|
|
340 |
toggleView changeMessage:aChangeSelector
|
|
341 |
!
|
|
342 |
|
|
343 |
model:aModel
|
|
344 |
"forward to label & toggle"
|
|
345 |
|
|
346 |
labelView model:aModel.
|
|
347 |
toggleView model:aModel
|
63
|
348 |
! !
|
|
349 |
|
100
|
350 |
!CheckBox methodsFor:'accessing-state'!
|
55
|
351 |
|
100
|
352 |
isOn
|
|
353 |
^ toggleView isOn
|
44
|
354 |
! !
|
|
355 |
|
|
356 |
!CheckBox methodsFor:'initialization'!
|
|
357 |
|
|
358 |
initialize
|
56
|
359 |
super initialize.
|
44
|
360 |
|
56
|
361 |
borderWidth := 0.
|
44
|
362 |
|
49
|
363 |
hLayout := #fixLeftSpace.
|
44
|
364 |
vLayout := #center.
|
|
365 |
|
|
366 |
toggleView := CheckToggle in:self.
|
|
367 |
|
|
368 |
labelView := Label in:self.
|
58
|
369 |
labelView label:'check'; borderWidth:0.
|
44
|
370 |
labelView forceResize.
|
|
371 |
labelView adjust:#left.
|
62
|
372 |
self height:labelView preferredExtent y + ViewSpacing.
|
55
|
373 |
|
56
|
374 |
"
|
|
375 |
all of my input goes to the toggle
|
|
376 |
"
|
|
377 |
self delegate:(KeyboardForwarder toView:toggleView).
|
44
|
378 |
|
|
379 |
"
|
|
380 |
|b|
|
|
381 |
|
|
382 |
b := CheckBox new.
|
|
383 |
b label:'foo'.
|
|
384 |
b open
|
|
385 |
"
|
|
386 |
! !
|
100
|
387 |
|
|
388 |
!CheckBox methodsFor:'private'!
|
|
389 |
|
|
390 |
sendChangeMessageWith:aValue
|
|
391 |
"redefined to have mimic changes being sent from the toggle
|
|
392 |
instead of myself"
|
|
393 |
|
|
394 |
toggleView sendChangeMessageWith:aValue
|
|
395 |
! !
|
|
396 |
|
|
397 |
!CheckBox methodsFor:'queries'!
|
|
398 |
|
|
399 |
preferredExtent
|
|
400 |
|prefCheck prefLabel bw2|
|
|
401 |
|
|
402 |
^ super preferredExtent + (10@0).
|
|
403 |
"/ prefCheck := toggleView preferredExtent.
|
|
404 |
"/ prefLabel := labelView preferredExtent.
|
|
405 |
"/ bw2 := borderWidth * 2.
|
|
406 |
"/ ^ (prefCheck x + prefLabel x + (3 * ViewSpacing)) @ ((prefCheck y max:prefLabel y) + bw2 + 2)
|
|
407 |
! !
|
|
408 |
|
|
409 |
!CheckBox class methodsFor:'documentation'!
|
|
410 |
|
|
411 |
version
|
|
412 |
^ '$Header: /cvs/stx/stx/libwidg2/CheckBox.st,v 1.14 1995-11-23 18:17:40 cg Exp $'
|
|
413 |
! !
|