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 |
|
55
|
14 |
'From Smalltalk/X, Version:2.10.5 on 8-may-1995 at 3:48:28 am'!
|
44
|
15 |
|
|
16 |
HorizontalPanelView subclass:#CheckBox
|
|
17 |
instanceVariableNames:'toggleView labelView'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Views-Interactors'
|
|
21 |
!
|
|
22 |
|
|
23 |
!CheckBox class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
version
|
|
26 |
"
|
55
|
27 |
$Header: /cvs/stx/stx/libwidg2/CheckBox.st,v 1.3 1995-05-09 01:57:57 claus Exp $
|
44
|
28 |
"
|
|
29 |
!
|
|
30 |
|
|
31 |
documentation
|
|
32 |
"
|
|
33 |
CheckBox has been added somwehat in a hurry
|
|
34 |
- obviously, much more protocol is needed.
|
|
35 |
|
|
36 |
For now, set actions etc. via sends to the components,
|
|
37 |
labelView and toggleView.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
|
41 |
examples
|
|
42 |
"
|
|
43 |
no-op checkBox:
|
|
44 |
|
|
45 |
|b|
|
|
46 |
|
|
47 |
b := CheckBox new.
|
|
48 |
b label:'foo'.
|
|
49 |
b open
|
|
50 |
|
|
51 |
|
|
52 |
changing colors (a demo only: it is no good style to fight the styleSheet):
|
|
53 |
|
|
54 |
|panel b|
|
|
55 |
|
|
56 |
panel := VerticalPanelView new.
|
|
57 |
|
|
58 |
b := CheckBox in:panel.
|
|
59 |
b label:'foo'.
|
|
60 |
|
|
61 |
b := CheckBox in:panel.
|
|
62 |
b label:'bar'.
|
|
63 |
b labelView foregroundColor:Color red.
|
|
64 |
|
|
65 |
b := CheckBox in:panel.
|
|
66 |
b label:'baz'.
|
|
67 |
b toggleView activeForegroundColor:Color blue.
|
|
68 |
|
|
69 |
panel open
|
|
70 |
|
|
71 |
|
|
72 |
using action-blocks:
|
|
73 |
|
49
|
74 |
|b|
|
44
|
75 |
|
|
76 |
b := CheckBox new.
|
|
77 |
b label:'check'.
|
49
|
78 |
b action:[:value | Transcript show:'set to: '; showCr:value].
|
44
|
79 |
b open.
|
|
80 |
|
|
81 |
|
49
|
82 |
with a model (default ST-80 behavior, sending #value: to the model):
|
|
83 |
(see changing value in the inspector)
|
|
84 |
|
|
85 |
|b model|
|
|
86 |
|
|
87 |
model := ValueHolder newBoolean.
|
|
88 |
|
|
89 |
b := CheckBox new.
|
|
90 |
b label:'check'.
|
|
91 |
b model:model.
|
|
92 |
b open.
|
|
93 |
model inspect.
|
|
94 |
|
|
95 |
with a model and different changeSelector
|
|
96 |
(using a plug here, for demonstration only):
|
44
|
97 |
|
|
98 |
|b model|
|
|
99 |
|
|
100 |
model := Plug new.
|
|
101 |
model respondTo:#changeCheck: with:[:arg | Transcript showCr:'change to ' , arg printString].
|
|
102 |
|
|
103 |
b := CheckBox new.
|
|
104 |
b label:'check'.
|
|
105 |
b model:model; change:#changeCheck:.
|
|
106 |
b open.
|
|
107 |
|
49
|
108 |
multiple checkBoxes on a single model (using different aspects)
|
|
109 |
|
|
110 |
|top panel b model value1 value2 ok|
|
|
111 |
|
|
112 |
value1 := true.
|
|
113 |
value2 := false.
|
|
114 |
model := Plug new.
|
|
115 |
model respondTo:#value1 with:[value1].
|
|
116 |
model respondTo:#value1: with:[:val | value1 := val].
|
|
117 |
model respondTo:#value2 with:[value2].
|
|
118 |
model respondTo:#value2: with:[:val | value2 := val].
|
|
119 |
|
|
120 |
top := DialogBox new.
|
|
121 |
top extent:200@300.
|
|
122 |
|
|
123 |
panel := VerticalPanelView new.
|
|
124 |
|
|
125 |
b := CheckBox in:panel.
|
|
126 |
b label:'check1'.
|
|
127 |
b model:model; aspect:#value1; change:#value1:.
|
|
128 |
|
|
129 |
b := CheckBox in:panel.
|
|
130 |
b label:'check2'.
|
|
131 |
b model:model; aspect:#value2; change:#value2:.
|
|
132 |
|
|
133 |
top addComponent:panel.
|
|
134 |
top addAbortButton; addOkButton.
|
|
135 |
top okAction:[ok := true].
|
|
136 |
ok := false.
|
|
137 |
top openModal.
|
|
138 |
|
|
139 |
ok ifTrue:[
|
|
140 |
Transcript show:'value1: '; showCr:model value1.
|
|
141 |
Transcript show:'value2: '; showCr:model value2.
|
|
142 |
]
|
44
|
143 |
"
|
|
144 |
!
|
|
145 |
|
|
146 |
copyright
|
|
147 |
"
|
|
148 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
49
|
149 |
All Rights Reserved
|
44
|
150 |
|
|
151 |
This software is furnished under a license and may be used
|
|
152 |
only in accordance with the terms of that license and with the
|
|
153 |
inclusion of the above copyright notice. This software may not
|
|
154 |
be provided or otherwise made available to, or used by, any
|
|
155 |
other person. No title to or ownership of the software is
|
|
156 |
hereby transferred.
|
|
157 |
"
|
|
158 |
|
|
159 |
! !
|
|
160 |
|
|
161 |
!CheckBox methodsFor:'accessing'!
|
|
162 |
|
55
|
163 |
label:aString
|
|
164 |
labelView label:aString.
|
|
165 |
labelView forceResize.
|
|
166 |
mustRearrange := true.
|
|
167 |
!
|
|
168 |
|
49
|
169 |
font:aFont
|
|
170 |
labelView font:aFont.
|
|
171 |
labelView forceResize.
|
|
172 |
mustRearrange := true.
|
|
173 |
!
|
|
174 |
|
|
175 |
font
|
|
176 |
^ labelView font
|
|
177 |
!
|
|
178 |
|
44
|
179 |
change:aChangeSelector
|
|
180 |
toggleView change:aChangeSelector
|
|
181 |
!
|
|
182 |
|
|
183 |
label
|
|
184 |
^ labelView label
|
|
185 |
!
|
|
186 |
|
55
|
187 |
model:aModel
|
|
188 |
labelView model:aModel.
|
|
189 |
toggleView model:aModel
|
|
190 |
!
|
|
191 |
|
44
|
192 |
labelView
|
49
|
193 |
"return the labelView; allows manipulation of the
|
|
194 |
labels attributes (colors etc.)"
|
|
195 |
|
44
|
196 |
^ labelView
|
|
197 |
!
|
|
198 |
|
|
199 |
toggleView
|
49
|
200 |
"return the toggleView; allows manipulation of the
|
|
201 |
toggles attributes (colors etc.)"
|
|
202 |
|
44
|
203 |
^ toggleView
|
|
204 |
!
|
|
205 |
|
|
206 |
aspect:aspectSymbol
|
|
207 |
labelView aspect:aspectSymbol.
|
|
208 |
toggleView aspect:aspectSymbol
|
49
|
209 |
!
|
44
|
210 |
|
55
|
211 |
turnOn
|
|
212 |
toggleView turnOn
|
|
213 |
!
|
|
214 |
|
49
|
215 |
action:aBlock
|
|
216 |
toggleView action:aBlock
|
|
217 |
!
|
|
218 |
|
|
219 |
enable
|
|
220 |
toggleView enable
|
|
221 |
!
|
|
222 |
|
55
|
223 |
turnOff
|
|
224 |
toggleView turnOff
|
|
225 |
!
|
|
226 |
|
|
227 |
sendChangeMessageWith:aValue
|
|
228 |
toggleView sendChangeMessageWith:aValue
|
|
229 |
!
|
|
230 |
|
49
|
231 |
disable
|
|
232 |
toggleView disable
|
44
|
233 |
! !
|
|
234 |
|
|
235 |
!CheckBox methodsFor:'initialization'!
|
|
236 |
|
|
237 |
initialize
|
|
238 |
|panel|
|
|
239 |
|
|
240 |
super initialize.
|
|
241 |
|
49
|
242 |
hLayout := #fixLeftSpace.
|
44
|
243 |
vLayout := #center.
|
|
244 |
|
|
245 |
toggleView := CheckToggle in:self.
|
|
246 |
|
|
247 |
labelView := Label in:self.
|
|
248 |
labelView label:'check'.
|
|
249 |
labelView forceResize.
|
|
250 |
labelView adjust:#left.
|
|
251 |
self height:labelView preferedExtent y + ViewSpacing.
|
55
|
252 |
"/ self delegate:(KeyboardForwarder toView:toggleView).
|
|
253 |
|
|
254 |
self controller:(toggleView controller view:toggleView).
|
44
|
255 |
|
|
256 |
"
|
|
257 |
|b|
|
|
258 |
|
|
259 |
b := CheckBox new.
|
|
260 |
b label:'foo'.
|
|
261 |
b open
|
|
262 |
"
|
|
263 |
! !
|
|
264 |
|