0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 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 |
|
|
13 |
View subclass:#Label
|
105
|
14 |
instanceVariableNames:'logo labelWidth labelHeight labelOriginX labelOriginY adjust
|
202
|
15 |
hSpace vSpace bgColor fgColor fixSize labelMsg converter
|
|
16 |
labelChannel foregroundChannel backgroundChannel'
|
105
|
17 |
classVariableNames:'DefaultFont DefaultForegroundColor DefaultBackgroundColor'
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Views-Layout'
|
0
|
20 |
!
|
|
21 |
|
3
|
22 |
!Label class methodsFor:'documentation'!
|
|
23 |
|
38
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
27 |
All Rights Reserved
|
38
|
28 |
|
|
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 |
|
3
|
38 |
documentation
|
|
39 |
"
|
38
|
40 |
This class implements labels, which are views to display a string or image.
|
|
41 |
The Label will try to do its best to make its contents fit into the
|
|
42 |
view. The contents can be a String, a collection of Strings (i.e.
|
118
|
43 |
a StringCollection) or a Form/Image.
|
63
|
44 |
|
|
45 |
The contents is drawn in fgColor/bgColor, which can be changed using:
|
|
46 |
|
59
|
47 |
aLabel foregroundColor:aColor
|
|
48 |
aLabel backgroundColor:aColor
|
3
|
49 |
|
38
|
50 |
When a label is assigned a contents, it will resize itself to fit
|
|
51 |
the required size. This resizing can be suppressed by setting the
|
|
52 |
fixsize attribute to true using:
|
63
|
53 |
|
59
|
54 |
aLabel sizeFixed:true
|
3
|
55 |
|
38
|
56 |
This can be used, if resizing of the label is not wanted.
|
63
|
57 |
However, in this case you have to make certain that the size is big enough
|
118
|
58 |
to hold any changed logos later. (usually, you create the label first with
|
|
59 |
the longest string first to have it compute its size, then set the fixSize
|
|
60 |
attribute to avoid resizing later).
|
125
|
61 |
Be careful when placing self-resizing labels into panels - by default,
|
|
62 |
panels do not react on the size change - leading to ugly looking geometry.
|
|
63 |
(but you can tell the panel to watch for changes with #elementsCHangeSize:)
|
38
|
64 |
|
|
65 |
The placement of the contents within the label is controlled by
|
63
|
66 |
the adjust attribute, it can be set with:
|
|
67 |
|
59
|
68 |
aLabel adjust:how
|
3
|
69 |
|
63
|
70 |
where how is one of the symbols left, #right, #center, #centerLeft or
|
|
71 |
#centerRight (see the comment in Label>>adjust:). The default is #center.
|
3
|
72 |
|
145
|
73 |
model-less operation (ok for static labels):
|
118
|
74 |
if no model is set, the labels contents is set with:
|
|
75 |
|
|
76 |
aLabel label:aStringOrImage
|
|
77 |
|
|
78 |
and stays constant unless changed by new calls to #label:.
|
|
79 |
|
|
80 |
|
145
|
81 |
model operation (ST-80 style):
|
118
|
82 |
labels with a model, aspectMsg and labelMsg react to
|
|
83 |
changes of the aspect, and send a labelMsg-message
|
|
84 |
to the model in order to aquire a new labelString or image.
|
|
85 |
The model should send 'self changed:aspectMsg' if it thinks the label
|
|
86 |
should change and return a string or image from the labelMsg-message.
|
|
87 |
|
|
88 |
label model:aModel.
|
|
89 |
label aspect:aspectSymbol.
|
|
90 |
label labelMessage:labelSymbol.
|
|
91 |
|
|
92 |
model sends #changed:aspectSymbol
|
|
93 |
---> label will redraw its label from value of model perform:labelSymbol
|
|
94 |
|
|
95 |
Having a labelSymbol different from the aspectSymbol allows for two labels
|
|
96 |
to react on the same aspect-change, but use different messages when asking
|
|
97 |
the model for a new label contents. By default, the labelMsg is nil,
|
|
98 |
so the label does NOT update its shown contents.
|
|
99 |
The aspectMsg defaults to #value.
|
|
100 |
|
125
|
101 |
|
145
|
102 |
|
|
103 |
channel operation (new ST/X style):
|
|
104 |
|
|
105 |
the label will react on changes of the token found in the
|
|
106 |
channels: foregroundChannel, backgroundChannel and labelChannel.
|
|
107 |
These are valueHolders and can be shared between labels.
|
|
108 |
|
|
109 |
|
|
110 |
|
38
|
111 |
Instance variables:
|
3
|
112 |
|
59
|
113 |
logo <Object> the logo, can be a Form, String or Text
|
|
114 |
labelWidth <Integer> the width of the logo in device units
|
|
115 |
labelHeight <Integer> the height of the logo in device units
|
|
116 |
labelOriginX <Integer> the x-position of the logo withing the Label
|
|
117 |
labelOriginY <Integer> the y-position of the logo withing the Label
|
|
118 |
adjust <Symbol> controls how the logo is positioned within the
|
|
119 |
label. Can be one of:#left,#right,#center,
|
|
120 |
#centerLeft or #centerRight (see comment in adjust:)
|
|
121 |
hSpace <Integer> number of horizontal pixels around logo
|
|
122 |
vSpace <Integer> number of vertical pixels around logo
|
3
|
123 |
|
59
|
124 |
bgColor <Color> background color
|
|
125 |
fgColor <Color> foreground color
|
38
|
126 |
|
59
|
127 |
fixSize <Boolean> if true, a change of the logo change will not
|
|
128 |
resize the label; otherwise, its size is adjusted.
|
|
129 |
default:false.
|
50
|
130 |
|
118
|
131 |
labelMsg <Symbol> if non-nil, this is sent to the model to
|
|
132 |
aquire the labelString or labelImage.
|
|
133 |
If nil, the label stays as is
|
113
|
134 |
|
118
|
135 |
styleSheet parameters:
|
50
|
136 |
|
118
|
137 |
labelForegroundColor <Color> color to draw foreground pixels (i.e. the string)
|
|
138 |
labelBackgroundColor <Color> color to draw background pixels
|
|
139 |
labelFont <Font> font to use for textual labels
|
3
|
140 |
"
|
63
|
141 |
!
|
|
142 |
|
|
143 |
examples
|
|
144 |
"
|
|
145 |
Notice, that Buttons and others inherit from Label;
|
|
146 |
therefore, the following geometry examples apply to all subclasses too.
|
|
147 |
|
|
148 |
|
113
|
149 |
simple (default position is 0@0):
|
63
|
150 |
|top l|
|
|
151 |
|
|
152 |
top := StandardSystemView new.
|
|
153 |
top extent:(200 @ 200).
|
|
154 |
|
|
155 |
l := Label in:top.
|
|
156 |
l label:'hello world'.
|
|
157 |
|
|
158 |
top open
|
|
159 |
|
113
|
160 |
|
|
161 |
there is also a creation message which sets the label:
|
|
162 |
|top l|
|
|
163 |
|
|
164 |
top := StandardSystemView new.
|
|
165 |
top extent:(200 @ 200).
|
|
166 |
|
|
167 |
l := Label label:'hello world' in:top.
|
|
168 |
|
|
169 |
top open
|
|
170 |
|
|
171 |
|
63
|
172 |
placement:
|
|
173 |
|top l|
|
|
174 |
|
|
175 |
top := StandardSystemView new.
|
|
176 |
top extent:(200 @ 200).
|
|
177 |
|
|
178 |
l := Label in:top.
|
|
179 |
l label:'hello world'.
|
|
180 |
l origin:50@100.
|
|
181 |
|
|
182 |
top open
|
|
183 |
|
113
|
184 |
|
63
|
185 |
level:
|
|
186 |
|top l|
|
|
187 |
|
|
188 |
top := StandardSystemView new.
|
|
189 |
top extent:(200 @ 200).
|
|
190 |
|
|
191 |
l := Label in:top.
|
|
192 |
l level:5.
|
|
193 |
l label:'hello world'.
|
|
194 |
l origin:50@100.
|
|
195 |
|
|
196 |
top open
|
|
197 |
|
113
|
198 |
|
63
|
199 |
another level:
|
|
200 |
|top l|
|
|
201 |
|
|
202 |
top := StandardSystemView new.
|
|
203 |
top extent:(200 @ 200).
|
|
204 |
|
|
205 |
l := Label in:top.
|
|
206 |
l level:-1.
|
|
207 |
l label:'hello world'.
|
|
208 |
l origin:50@100.
|
|
209 |
|
|
210 |
top open
|
|
211 |
|
113
|
212 |
|
118
|
213 |
colors & font:
|
|
214 |
|top l|
|
|
215 |
|
|
216 |
top := StandardSystemView new.
|
|
217 |
top extent:(200 @ 200).
|
|
218 |
|
|
219 |
l := Label in:top.
|
|
220 |
l level:-1.
|
|
221 |
l font:(Font family:'Times' size:18).
|
|
222 |
l foregroundColor:Color yellow.
|
|
223 |
l backgroundColor:Color red.
|
|
224 |
l label:'hello world'.
|
|
225 |
l origin:50@100.
|
|
226 |
|
|
227 |
top open
|
|
228 |
|
|
229 |
|
63
|
230 |
border & colors:
|
|
231 |
|top l|
|
|
232 |
|
|
233 |
top := StandardSystemView new.
|
|
234 |
top extent:(200 @ 200).
|
|
235 |
|
|
236 |
l := Label in:top.
|
|
237 |
l level:0.
|
|
238 |
l borderWidth:1.
|
|
239 |
l borderColor:Color red.
|
|
240 |
l foregroundColor:Color green darkened.
|
|
241 |
l backgroundColor:Color green lightened.
|
|
242 |
l label:'hello world'.
|
|
243 |
l origin:50@100.
|
|
244 |
|
|
245 |
top open
|
|
246 |
|
113
|
247 |
|
63
|
248 |
adjust (resize to see):
|
|
249 |
|top l|
|
|
250 |
|
|
251 |
top := StandardSystemView new.
|
|
252 |
top extent:(200 @ 200).
|
|
253 |
|
|
254 |
l := Label in:top.
|
|
255 |
l borderWidth:1.
|
|
256 |
l label:'default - centered'.
|
118
|
257 |
l origin:0.0@40.
|
63
|
258 |
l width:1.0.
|
|
259 |
|
|
260 |
l := Label in:top.
|
|
261 |
l borderWidth:1.
|
|
262 |
l adjust:#left.
|
|
263 |
l label:'left adjust'.
|
118
|
264 |
l origin:0.0@70.
|
|
265 |
l width:1.0.
|
|
266 |
|
|
267 |
l := Label in:top.
|
|
268 |
l borderWidth:1.
|
|
269 |
l adjust:#centerLeft.
|
|
270 |
l label:'centerLeft adjust and a bit too long'.
|
63
|
271 |
l origin:0.0@100.
|
|
272 |
l width:1.0.
|
|
273 |
|
|
274 |
l := Label in:top.
|
|
275 |
l borderWidth:1.
|
|
276 |
l adjust:#right.
|
|
277 |
l label:'right adjust'.
|
|
278 |
l origin:0.0@130.
|
|
279 |
l width:1.0.
|
|
280 |
|
118
|
281 |
l := Label in:top.
|
|
282 |
l borderWidth:1.
|
|
283 |
l adjust:#centerRight.
|
|
284 |
l label:'centerRight adjust and a bit too long'.
|
|
285 |
l origin:0.0@160.
|
|
286 |
l width:1.0.
|
|
287 |
|
63
|
288 |
top open
|
|
289 |
|
113
|
290 |
|
131
|
291 |
fitting-adjust (resize to see):
|
|
292 |
Warning: #fit is experimental and should not be used.
|
|
293 |
|
|
294 |
|top l|
|
|
295 |
|
|
296 |
top := StandardSystemView new.
|
|
297 |
top extent:(200 @ 200).
|
|
298 |
|
|
299 |
l := Label origin:0.25 @ 0.25 corner:0.75@0.75 in:top.
|
|
300 |
l label:'stretch'.
|
|
301 |
l level:-1.
|
|
302 |
l adjust:#fit.
|
|
303 |
|
|
304 |
top open
|
|
305 |
|
|
306 |
or:
|
|
307 |
Warning: #fit is experimental and should not be used.
|
|
308 |
|
|
309 |
|top l|
|
|
310 |
|
|
311 |
top := StandardSystemView new.
|
|
312 |
top extent:(200 @ 200).
|
|
313 |
|
|
314 |
l := Label origin:0.25 @ 0.25 corner:0.75@0.75 in:top.
|
|
315 |
l label:(Image fromFile:'bitmaps/SBrowser.xbm').
|
|
316 |
l level:-1.
|
|
317 |
l adjust:#fit.
|
|
318 |
|
|
319 |
top open
|
|
320 |
|
|
321 |
|
63
|
322 |
just a reminder, that instead of doing placement manually
|
113
|
323 |
as in ...:
|
118
|
324 |
|
63
|
325 |
|top l|
|
|
326 |
|
|
327 |
top := StandardSystemView new.
|
|
328 |
top extent:(200 @ 200).
|
|
329 |
|
|
330 |
l := Label in:top.
|
|
331 |
l borderWidth:1.
|
|
332 |
l label:'default - centered'.
|
|
333 |
l origin:0.1@70.
|
|
334 |
l width:0.8.
|
|
335 |
|
|
336 |
l := Label in:top.
|
|
337 |
l borderWidth:1.
|
|
338 |
l adjust:#left.
|
|
339 |
l label:'left adjust'.
|
|
340 |
l origin:0.1@100.
|
|
341 |
l width:0.8.
|
|
342 |
|
|
343 |
l := Label in:top.
|
|
344 |
l borderWidth:1.
|
|
345 |
l adjust:#right.
|
|
346 |
l label:'right adjust'.
|
|
347 |
l origin:0.1@130.
|
|
348 |
l width:0.8.
|
|
349 |
|
|
350 |
top open
|
|
351 |
|
113
|
352 |
|
|
353 |
... it is much easier, to use a geometry handler, such as
|
63
|
354 |
a VerticalPanel. Try:
|
113
|
355 |
|
63
|
356 |
|top panel l|
|
|
357 |
|
|
358 |
top := StandardSystemView new.
|
|
359 |
top extent:(200 @ 200).
|
|
360 |
|
|
361 |
panel := VerticalPanelView
|
|
362 |
origin:0.0 @ 0.0
|
|
363 |
corner:1.0 @ 1.0
|
|
364 |
in:top.
|
|
365 |
|
|
366 |
panel horizontalLayout:#fit.
|
|
367 |
panel verticalLayout:#center.
|
|
368 |
|
|
369 |
l := Label in:panel.
|
|
370 |
l borderWidth:1.
|
|
371 |
l label:'default - centered'.
|
|
372 |
|
|
373 |
l := Label in:panel.
|
|
374 |
l borderWidth:1.
|
|
375 |
l adjust:#left.
|
|
376 |
l label:'left adjust'.
|
|
377 |
|
|
378 |
l := Label in:panel.
|
|
379 |
l borderWidth:1.
|
|
380 |
l adjust:#right.
|
|
381 |
l label:'right adjust'.
|
|
382 |
|
|
383 |
top open
|
|
384 |
|
113
|
385 |
|
63
|
386 |
labels with bitmaps or images:
|
|
387 |
|
|
388 |
|top l|
|
|
389 |
|
|
390 |
top := StandardSystemView new.
|
|
391 |
top extent:(200 @ 200).
|
|
392 |
|
|
393 |
l := Label in:top.
|
|
394 |
l level:-1.
|
118
|
395 |
l label:((Image fromFile:'bitmaps/garfield.gif') magnifyBy:0.2 @ 0.2).
|
63
|
396 |
l origin:50@100.
|
|
397 |
|
|
398 |
top open
|
113
|
399 |
|
|
400 |
|
145
|
401 |
Channel operation
|
|
402 |
-----------------
|
|
403 |
|
|
404 |
|top panel logoChannel fgChannel bgChannel l b|
|
|
405 |
|
|
406 |
top := StandardSystemView new.
|
|
407 |
top extent:(450 @ 200).
|
|
408 |
|
|
409 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
410 |
|
|
411 |
l := Label in:panel.
|
|
412 |
l level:-1.
|
|
413 |
l label:'change my colors'.
|
|
414 |
l origin:50@100.
|
|
415 |
l sizeFixed:true.
|
|
416 |
|
|
417 |
fgChannel := Color blue asValue.
|
146
|
418 |
bgChannel := Color grey asValue.
|
145
|
419 |
logoChannel := 'change me' asValue.
|
|
420 |
|
|
421 |
b := Toggle label:'change fg' in:panel. b showLamp:false; onLevel:-2.
|
|
422 |
b pressAction:[fgChannel value:Color red].
|
|
423 |
b releaseAction:[fgChannel value:Color blue].
|
|
424 |
|
|
425 |
b := Toggle label:'change bg' in:panel.
|
|
426 |
b pressAction:[bgChannel value:Color yellow].
|
|
427 |
b releaseAction:[bgChannel value:Color grey].
|
|
428 |
|
|
429 |
b := Toggle label:'change text' in:panel.
|
|
430 |
b pressAction:[logoChannel value:'wow'].
|
|
431 |
b releaseAction:[logoChannel value:'not bad' ].
|
|
432 |
|
|
433 |
l labelChannel:logoChannel.
|
|
434 |
l foregroundChannel:fgChannel.
|
|
435 |
l backgroundChannel:bgChannel.
|
|
436 |
|
|
437 |
top open
|
|
438 |
|
|
439 |
|
146
|
440 |
multiple labels on one channel:
|
|
441 |
|
|
442 |
|l1 l2 b conv|
|
|
443 |
|
|
444 |
l1 := Label label:'label1'.
|
|
445 |
|
|
446 |
l2 := Label label:'label2'.
|
|
447 |
|
|
448 |
b := Button label:'change'.
|
|
449 |
conv := (ConvertedValue new
|
|
450 |
conversion:[:input |
|
|
451 |
input ifTrue:[
|
|
452 |
Color red
|
|
453 |
] ifFalse:[
|
|
454 |
Color blue
|
|
455 |
]]).
|
|
456 |
conv value:false.
|
|
457 |
|
|
458 |
b controller pressChannel:conv.
|
|
459 |
l1 foregroundChannel:conv.
|
|
460 |
l2 foregroundColor:Color white; backgroundChannel:conv.
|
|
461 |
|
|
462 |
b open.
|
|
463 |
l1 open.
|
|
464 |
l2 open.
|
|
465 |
|
|
466 |
|
125
|
467 |
MVC operation
|
145
|
468 |
-------------
|
|
469 |
|
125
|
470 |
model provides the label):
|
|
471 |
(have to use a plug to simulate a model which responds to
|
|
472 |
the #someAspect message):
|
113
|
473 |
|
|
474 |
|top l model|
|
|
475 |
|
|
476 |
model := Plug new.
|
|
477 |
model respondTo:#someAspect with:['models labelString'].
|
|
478 |
|
|
479 |
top := StandardSystemView new.
|
|
480 |
top extent:(200 @ 200).
|
|
481 |
|
|
482 |
l := Label in:top.
|
118
|
483 |
l model:model; labelMessage:#someAspect.
|
113
|
484 |
|
|
485 |
top open
|
118
|
486 |
...
|
|
487 |
|
|
488 |
model changed:#someAspect
|
|
489 |
...
|
113
|
490 |
|
|
491 |
|
118
|
492 |
concrete example (track a counters value):
|
125
|
493 |
(here, the default aspect #value is used both to notify the label about
|
|
494 |
changes and to aquire a new value from the model).
|
113
|
495 |
|
|
496 |
|top l model|
|
|
497 |
|
118
|
498 |
model := ValueHolder new.
|
|
499 |
model value:0.
|
|
500 |
[
|
|
501 |
1 to:20 do:[:i |
|
|
502 |
(Delay forSeconds:1) wait.
|
|
503 |
model value:i
|
|
504 |
].
|
|
505 |
top destroy
|
|
506 |
] fork.
|
113
|
507 |
|
|
508 |
top := StandardSystemView new.
|
|
509 |
top extent:(200 @ 200).
|
|
510 |
|
|
511 |
l := Label in:top.
|
125
|
512 |
l level:-1.
|
118
|
513 |
l model:model; labelMessage:#value.
|
|
514 |
|
|
515 |
top open
|
|
516 |
|
|
517 |
|
133
|
518 |
with a printConverter:
|
|
519 |
|
|
520 |
|top l model|
|
|
521 |
|
|
522 |
model := Date today asValue.
|
|
523 |
[
|
|
524 |
1 to:50 do:[:i |
|
|
525 |
(Delay forSeconds:1) wait.
|
|
526 |
model value:(model value addDays:1)
|
|
527 |
].
|
|
528 |
top destroy
|
|
529 |
] fork.
|
|
530 |
|
|
531 |
top := StandardSystemView new.
|
|
532 |
top extent:(200 @ 200).
|
|
533 |
|
|
534 |
l := Label in:top.
|
|
535 |
l level:-1.
|
|
536 |
l converter:(PrintConverter new initForDate).
|
|
537 |
l model:model; labelMessage:#value.
|
|
538 |
|
|
539 |
top open
|
|
540 |
|
|
541 |
|
125
|
542 |
model changes aspect after a while; two labels on the same model:
|
118
|
543 |
|
|
544 |
|top l model|
|
|
545 |
|
|
546 |
model := Plug new.
|
|
547 |
model respondTo:#labelValue1 with:['models labelString1'].
|
|
548 |
model respondTo:#labelValue2 with:['models labelString2'].
|
|
549 |
|
|
550 |
top := StandardSystemView new.
|
|
551 |
top extent:(200 @ 200).
|
|
552 |
|
|
553 |
l := Label origin:0.0@0.0 corner:1.0@0.5 in:top.
|
|
554 |
l model:model; aspect:#someAspect; labelMessage:#labelValue1.
|
|
555 |
l := Label origin:0.0@0.5 corner:1.0@1.0 in:top.
|
|
556 |
l model:model; aspect:#someAspect; labelMessage:#labelValue2.
|
113
|
557 |
|
|
558 |
top open.
|
118
|
559 |
|
113
|
560 |
(Delay forSeconds:5) wait.
|
118
|
561 |
model respondTo:#labelValue1 with:['new string1'].
|
|
562 |
model respondTo:#labelValue2 with:['new string2'].
|
|
563 |
|
113
|
564 |
model changed:#someAspect
|
118
|
565 |
|
|
566 |
|
125
|
567 |
plugged MVC operation (getBlock returns the label):
|
118
|
568 |
|
|
569 |
|top l model|
|
|
570 |
|
|
571 |
model := PluggableAdaptor new
|
|
572 |
getBlock:[:m | 'hello']
|
|
573 |
putBlock:nil
|
|
574 |
updateBlock:nil.
|
|
575 |
|
|
576 |
top := StandardSystemView new.
|
|
577 |
top extent:(200 @ 200).
|
|
578 |
|
|
579 |
l := Label origin:0.0@0.0 corner:1.0@0.5 in:top.
|
|
580 |
l model:model; labelMessage:#value.
|
|
581 |
|
|
582 |
top open.
|
125
|
583 |
|
|
584 |
|
|
585 |
use different label-selectors to access fields of a complex model:
|
|
586 |
|
|
587 |
|top panel model|
|
|
588 |
|
|
589 |
model := Plug new.
|
|
590 |
model respondTo:#field1 with:['value1'].
|
|
591 |
model respondTo:#field2 with:['value2'].
|
|
592 |
model respondTo:#field3 with:['value3'].
|
|
593 |
model respondTo:#field4 with:['value4'].
|
|
594 |
|
|
595 |
top := StandardSystemView new.
|
|
596 |
|
|
597 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
598 |
panel elementsChangeSize:true.
|
|
599 |
|
|
600 |
panel addSubView:((Label on:model) labelMessage:#field1).
|
|
601 |
panel addSubView:((Label on:model) labelMessage:#field2).
|
|
602 |
panel addSubView:((Label on:model) labelMessage:#field3).
|
|
603 |
panel addSubView:((Label on:model) labelMessage:#field4).
|
|
604 |
|
|
605 |
top extent:(200 @ 200).
|
|
606 |
top open.
|
|
607 |
|
|
608 |
(Delay forSeconds:5) wait.
|
|
609 |
|
|
610 |
model respondTo:#field2 with:['new value2'].
|
|
611 |
model changed:#value
|
|
612 |
|
|
613 |
|
|
614 |
same as above, using default aspects in the label, and an adaptor
|
|
615 |
to translate aspects:
|
|
616 |
|
|
617 |
|top panel model v1|
|
|
618 |
|
|
619 |
model := Plug new.
|
|
620 |
model respondTo:#field1 with:[v1].
|
|
621 |
model respondTo:#field1: with:[:arg | v1 := arg. model changed:#field1].
|
|
622 |
model respondTo:#field2 with:['value2'].
|
|
623 |
model respondTo:#field2: with:[:arg |].
|
|
624 |
model respondTo:#field3 with:['value3'].
|
|
625 |
model respondTo:#field3: with:[:arg |].
|
|
626 |
model respondTo:#field4 with:['value4'].
|
|
627 |
model respondTo:#field4: with:[:arg |].
|
|
628 |
|
|
629 |
top := StandardSystemView new.
|
|
630 |
|
|
631 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
632 |
panel elementsChangeSize:true.
|
|
633 |
|
|
634 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field1)) labelMessage:#value).
|
|
635 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field2)) labelMessage:#value).
|
|
636 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field3)) labelMessage:#value).
|
|
637 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field4)) labelMessage:#value).
|
|
638 |
|
|
639 |
top extent:(200 @ 200).
|
|
640 |
top open.
|
|
641 |
|
|
642 |
(Delay forSeconds:5) wait.
|
|
643 |
|
|
644 |
model field1:'new value1'.
|
|
645 |
|
|
646 |
|
|
647 |
use an adapter to access fields of a complex model:
|
|
648 |
|
|
649 |
|top l panel model|
|
|
650 |
|
|
651 |
model := #('one' 'two' 'three') asValue.
|
|
652 |
|
|
653 |
top := StandardSystemView new.
|
|
654 |
|
|
655 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
656 |
panel elementsChangeSize:true.
|
|
657 |
|
|
658 |
panel addSubView:((Label on:(ProtocolAdaptor
|
|
659 |
subjectChannel:model
|
|
660 |
accessPath:#(1))) labelMessage:#value).
|
|
661 |
panel addSubView:((Label on:(ProtocolAdaptor
|
|
662 |
subjectChannel:model
|
|
663 |
accessPath:#(2))) labelMessage:#value).
|
|
664 |
panel addSubView:((Label on:(ProtocolAdaptor
|
|
665 |
subjectChannel:model
|
|
666 |
accessPath:#(3))) labelMessage:#value).
|
|
667 |
|
|
668 |
top extent:(200 @ 200).
|
|
669 |
top open.
|
|
670 |
|
|
671 |
(Delay forSeconds:5) wait.
|
|
672 |
|
|
673 |
model value:#('oneone' 'twotwo' 'threethree').
|
63
|
674 |
"
|
202
|
675 |
!
|
|
676 |
|
|
677 |
version
|
|
678 |
^ '$Header: /cvs/stx/stx/libwidg/Label.st,v 1.35 1995-11-23 14:36:21 cg Exp $'
|
3
|
679 |
! !
|
|
680 |
|
105
|
681 |
!Label class methodsFor:'instance creation'!
|
|
682 |
|
|
683 |
form:aForm
|
118
|
684 |
"return a new Label showing a form.
|
|
685 |
OBSOLETE: you should now use #label: for both text and bitmap labels."
|
105
|
686 |
|
131
|
687 |
^ (self on:Screen current) form:aForm
|
105
|
688 |
!
|
|
689 |
|
|
690 |
form:aForm in:aView
|
118
|
691 |
"return a new Label showing a form.
|
|
692 |
OBSOLETE: you should now use #label:in: for both text and bitmap labels."
|
105
|
693 |
|
|
694 |
^ (self in:aView) form:aForm
|
|
695 |
! !
|
|
696 |
|
0
|
697 |
!Label class methodsFor:'defaults'!
|
|
698 |
|
|
699 |
defaultExtent
|
3
|
700 |
"return default extent"
|
0
|
701 |
|
|
702 |
^ 16 @ 16
|
59
|
703 |
!
|
|
704 |
|
118
|
705 |
defaultFont
|
|
706 |
^ DefaultFont notNil ifTrue:[DefaultFont] ifFalse:[super defaultFont]
|
|
707 |
!
|
|
708 |
|
59
|
709 |
updateStyleCache
|
77
|
710 |
DefaultForegroundColor := StyleSheet colorAt:'labelForegroundColor'.
|
|
711 |
DefaultForegroundColor isNil ifTrue:[
|
|
712 |
DefaultForegroundColor := StyleSheet colorAt:'foregroundColor' default:Black.
|
|
713 |
].
|
60
|
714 |
DefaultBackgroundColor := StyleSheet colorAt:'labelBackgroundColor'.
|
77
|
715 |
DefaultBackgroundColor isNil ifTrue:[
|
|
716 |
DefaultForegroundColor := StyleSheet colorAt:'backgroundColor'.
|
|
717 |
].
|
60
|
718 |
DefaultFont := StyleSheet fontAt:'labelFont'.
|
|
719 |
|
|
720 |
"
|
|
721 |
self updateStyleCache
|
|
722 |
"
|
0
|
723 |
! !
|
|
724 |
|
202
|
725 |
!Label methodsFor:'accessing-channels'!
|
105
|
726 |
|
202
|
727 |
backgroundChannel:aValueHolder
|
|
728 |
|prev|
|
105
|
729 |
|
202
|
730 |
prev := backgroundChannel.
|
|
731 |
backgroundChannel := aValueHolder.
|
|
732 |
self setupChannel:aValueHolder for:#backgroundChannelChanged withOld:prev
|
|
733 |
!
|
145
|
734 |
|
|
735 |
foregroundChannel:aValueHolder
|
146
|
736 |
|prev|
|
|
737 |
|
|
738 |
prev := foregroundChannel.
|
145
|
739 |
foregroundChannel := aValueHolder.
|
146
|
740 |
self setupChannel:aValueHolder for:#foregroundChannelChanged withOld:prev
|
145
|
741 |
!
|
|
742 |
|
|
743 |
labelChannel:aValueHolder
|
146
|
744 |
|prev|
|
|
745 |
|
|
746 |
prev := labelChannel.
|
145
|
747 |
labelChannel := aValueHolder.
|
146
|
748 |
self setupChannel:aValueHolder for:#labelChannelChanged withOld:prev
|
145
|
749 |
! !
|
|
750 |
|
202
|
751 |
!Label methodsFor:'accessing-colors'!
|
125
|
752 |
|
202
|
753 |
backgroundColor
|
|
754 |
"return the background color"
|
125
|
755 |
|
202
|
756 |
^ bgColor
|
125
|
757 |
!
|
|
758 |
|
202
|
759 |
backgroundColor:aColor
|
|
760 |
"set the background color"
|
125
|
761 |
|
202
|
762 |
bgColor := aColor on:device.
|
131
|
763 |
shown ifTrue:[self redraw]
|
105
|
764 |
!
|
|
765 |
|
|
766 |
foregroundColor
|
|
767 |
"return the foreground color"
|
|
768 |
|
|
769 |
^ fgColor
|
|
770 |
!
|
|
771 |
|
202
|
772 |
foregroundColor:aColor
|
|
773 |
"set the foreground color"
|
105
|
774 |
|
202
|
775 |
fgColor := aColor on:device.
|
131
|
776 |
shown ifTrue:[self redraw]
|
105
|
777 |
!
|
|
778 |
|
|
779 |
foregroundColor:fg backgroundColor:bg
|
|
780 |
"set the colors to be used for drawing"
|
|
781 |
|
|
782 |
fgColor := fg on:device.
|
|
783 |
bgColor := bg on:device.
|
131
|
784 |
shown ifTrue:[self redraw]
|
133
|
785 |
! !
|
|
786 |
|
|
787 |
!Label methodsFor:'accessing-contents'!
|
0
|
788 |
|
202
|
789 |
form:aForm
|
|
790 |
"set the labels form; adjust extent if not already realized.
|
|
791 |
OBSOLETE: you should now use #label: for both strings and images"
|
118
|
792 |
|
202
|
793 |
self label:aForm
|
|
794 |
!
|
|
795 |
|
|
796 |
label
|
|
797 |
"return the labels string or image"
|
|
798 |
|
|
799 |
^ logo
|
118
|
800 |
!
|
105
|
801 |
|
118
|
802 |
label:aStringOrFormOrImage
|
|
803 |
"set the labelString or image; adjust extent if not already realized and
|
|
804 |
not fixedSize"
|
|
805 |
|
|
806 |
(aStringOrFormOrImage ~~ logo) ifTrue:[
|
|
807 |
"/
|
|
808 |
"/ avoid recompute of size, if its an image with
|
|
809 |
"/ the same size
|
|
810 |
"/
|
|
811 |
aStringOrFormOrImage isImageOrForm ifTrue:[
|
|
812 |
logo notNil ifTrue:[
|
|
813 |
logo isImageOrForm ifTrue:[
|
|
814 |
logo extent = aStringOrFormOrImage extent ifTrue:[
|
|
815 |
logo := aStringOrFormOrImage.
|
|
816 |
^ self
|
|
817 |
]
|
105
|
818 |
]
|
|
819 |
]
|
118
|
820 |
] ifFalse:[
|
|
821 |
(logo = aStringOrFormOrImage) ifTrue:[
|
|
822 |
^ self
|
|
823 |
]
|
105
|
824 |
].
|
118
|
825 |
logo := aStringOrFormOrImage.
|
105
|
826 |
self newLayout
|
|
827 |
]
|
|
828 |
!
|
0
|
829 |
|
202
|
830 |
labelString:aString
|
|
831 |
"for ST-80 compatibility: same as #label:
|
|
832 |
set the label-string; adjust extent if not already realized and not fixedSize"
|
118
|
833 |
|
202
|
834 |
self label:aString
|
|
835 |
!
|
|
836 |
|
|
837 |
labelWidth
|
|
838 |
"return the logos width in pixels"
|
|
839 |
|
|
840 |
^ labelWidth
|
118
|
841 |
!
|
|
842 |
|
|
843 |
logo:something
|
|
844 |
"set the labels form or string.
|
|
845 |
OBSOLETE: the old version used #form: for images and #label: for strings.
|
|
846 |
you should now use #label: for any."
|
|
847 |
|
|
848 |
self label:something
|
133
|
849 |
! !
|
|
850 |
|
|
851 |
!Label methodsFor:'accessing-layout'!
|
|
852 |
|
202
|
853 |
adjust
|
|
854 |
"return the adjust symbol"
|
0
|
855 |
|
202
|
856 |
^ adjust
|
125
|
857 |
!
|
|
858 |
|
105
|
859 |
adjust:how
|
|
860 |
"set the adjust, how which must be one of
|
0
|
861 |
|
105
|
862 |
#left -> left adjust logo
|
|
863 |
#right -> right adjust logo
|
|
864 |
#center -> center logo
|
118
|
865 |
#centerRight -> center logo; if no fit, right adjust
|
|
866 |
(use with filenames, where the interresting part is
|
|
867 |
at the right if the label is too small)
|
105
|
868 |
#centerLeft -> center logo; if it does not fit, left adjust it
|
118
|
869 |
(use with strings where the interresting part is at the
|
|
870 |
left if the label is too small)
|
105
|
871 |
"
|
118
|
872 |
|
105
|
873 |
(adjust ~~ how) ifTrue:[
|
|
874 |
adjust := how.
|
|
875 |
self newLayout
|
|
876 |
]
|
|
877 |
!
|
|
878 |
|
202
|
879 |
font:aFont
|
|
880 |
"set the font - if I'm not realized and not fixedSize, adjust my size"
|
125
|
881 |
|
202
|
882 |
(aFont ~~ font) ifTrue:[
|
|
883 |
super font:(aFont on:device).
|
|
884 |
self newLayout
|
|
885 |
]
|
133
|
886 |
!
|
|
887 |
|
|
888 |
horizontalSpace:aNumber
|
|
889 |
"set the number of pixels by which the logo
|
|
890 |
is horizontally inset from the border"
|
|
891 |
|
162
|
892 |
hSpace := aNumber.
|
|
893 |
self newLayout
|
133
|
894 |
!
|
|
895 |
|
202
|
896 |
layout
|
|
897 |
"for protocol compatibility: alias for #adjust.
|
|
898 |
Please use #adjust, since #layout conflicts with a method
|
|
899 |
in VW (which has a completely different meaning).
|
|
900 |
In future versions of ST/X, #layout will behave the VW way."
|
|
901 |
|
|
902 |
self obsoleteMethodWarning:'use #adjust'.
|
|
903 |
^ self adjust
|
|
904 |
!
|
|
905 |
|
|
906 |
layout:something
|
|
907 |
"OBSOLETE compatibility interface. Will vanish.
|
|
908 |
for protocol compatibility: alias for #adjust:.
|
|
909 |
Please use #adjust:, since #layout: conflicts with a method
|
|
910 |
in VW (which has a completely different meaning).
|
|
911 |
In future versions of ST/X, #layout: will behave the VW way.
|
|
912 |
In the meantime, try to figure out what is meant ... a kludge"
|
|
913 |
|
|
914 |
something isLayout ifTrue:[^ super layout:something].
|
|
915 |
|
|
916 |
self obsoleteMethodWarning:'use #adjust:'.
|
|
917 |
self adjust:something
|
|
918 |
|
|
919 |
"Modified: 31.8.1995 / 23:08:13 / claus"
|
|
920 |
!
|
|
921 |
|
|
922 |
sizeFixed
|
|
923 |
"return the fix-size attribute"
|
|
924 |
|
|
925 |
^ fixSize
|
|
926 |
!
|
|
927 |
|
|
928 |
sizeFixed:aBoolean
|
|
929 |
"set/clear the fix-size attribute.
|
|
930 |
If true, the receiver will not change its size when the labelString/logo
|
|
931 |
changes. If false (the default), it will resize itself to make the logo
|
|
932 |
fit."
|
|
933 |
|
|
934 |
fixSize := aBoolean
|
|
935 |
!
|
|
936 |
|
|
937 |
verticalSpace:aNumber
|
|
938 |
"set the number of pixels by which the logo
|
|
939 |
is vertically inset from the border"
|
|
940 |
|
|
941 |
vSpace := aNumber.
|
|
942 |
self newLayout
|
|
943 |
! !
|
|
944 |
|
|
945 |
!Label methodsFor:'accessing-mvc'!
|
|
946 |
|
|
947 |
addModelInterfaceTo:aDictionary
|
|
948 |
"see comment in View>>modelInterface"
|
|
949 |
|
|
950 |
super addModelInterfaceTo:aDictionary.
|
|
951 |
aDictionary at:#labelMessage put:labelMsg
|
|
952 |
!
|
|
953 |
|
|
954 |
converter:aConverter
|
|
955 |
"set the printConverter;
|
|
956 |
that one is asked to convert the models value to a printed
|
|
957 |
representation (if non-nil). If nil, the model is supposed to
|
|
958 |
return a string or bitmap image."
|
|
959 |
|
|
960 |
converter := aConverter
|
|
961 |
!
|
105
|
962 |
|
202
|
963 |
labelMessage
|
|
964 |
"return the symbol used to aquire the labelString/image from the model
|
|
965 |
when the aspect changes.
|
|
966 |
The default is nil, which means: leave the label unchanged."
|
|
967 |
|
|
968 |
^ labelMsg
|
|
969 |
!
|
|
970 |
|
|
971 |
labelMessage:aSymbol
|
|
972 |
"set the symbol used to aquire the labelString/image from the model.
|
|
973 |
The default is nil, which means: leave the label unchanged."
|
|
974 |
|
|
975 |
labelMsg ~~ aSymbol ifTrue:[
|
|
976 |
labelMsg := aSymbol.
|
|
977 |
self getLabelFromModel
|
|
978 |
]
|
|
979 |
!
|
|
980 |
|
|
981 |
model:aModel
|
|
982 |
super model:aModel.
|
|
983 |
self getLabelFromModel.
|
|
984 |
! !
|
|
985 |
|
|
986 |
!Label methodsFor:'change & update'!
|
|
987 |
|
|
988 |
backgroundChannelChanged
|
|
989 |
self backgroundColor:(backgroundChannel value)
|
|
990 |
!
|
|
991 |
|
|
992 |
foregroundChannelChanged
|
|
993 |
self foregroundColor:(foregroundChannel value)
|
|
994 |
!
|
|
995 |
|
|
996 |
labelChannelChanged
|
|
997 |
self label:(labelChannel value)
|
|
998 |
!
|
|
999 |
|
|
1000 |
update:something with:aParameter from:changedObject
|
|
1001 |
"the MVC way of changing the label ..."
|
|
1002 |
|
|
1003 |
changedObject == model ifTrue:[
|
|
1004 |
something == aspectMsg ifTrue:[
|
|
1005 |
self getLabelFromModel.
|
|
1006 |
^ self.
|
|
1007 |
]
|
|
1008 |
].
|
|
1009 |
^ super update:something with:aParameter from:changedObject
|
|
1010 |
! !
|
|
1011 |
|
|
1012 |
!Label methodsFor:'event handling'!
|
|
1013 |
|
|
1014 |
sizeChanged:how
|
|
1015 |
"sent whenever size is changed by someone else - recompute the
|
|
1016 |
logos position within the View."
|
|
1017 |
|
|
1018 |
|prevPosition|
|
|
1019 |
|
|
1020 |
super sizeChanged:how.
|
|
1021 |
prevPosition := labelOriginX.
|
|
1022 |
self computeLabelOrigin
|
|
1023 |
shown ifTrue:[
|
|
1024 |
(adjust == #fit
|
|
1025 |
or:[labelOriginX ~~ prevPosition
|
|
1026 |
or:[how ~~ #smaller]]) ifTrue:[
|
|
1027 |
"/ self clear.
|
|
1028 |
self redraw.
|
|
1029 |
self redrawEdges
|
|
1030 |
]
|
105
|
1031 |
]
|
0
|
1032 |
! !
|
|
1033 |
|
|
1034 |
!Label methodsFor:'initialization'!
|
|
1035 |
|
|
1036 |
initStyle
|
|
1037 |
super initStyle.
|
|
1038 |
|
59
|
1039 |
DefaultFont notNil ifTrue:[font := DefaultFont on:device].
|
|
1040 |
DefaultBackgroundColor notNil ifTrue:[
|
|
1041 |
bgColor := DefaultBackgroundColor on:device
|
38
|
1042 |
] ifFalse:[
|
59
|
1043 |
bgColor := viewBackground on:device.
|
|
1044 |
].
|
|
1045 |
DefaultForegroundColor notNil ifTrue:[
|
|
1046 |
fgColor := DefaultForegroundColor on:device
|
|
1047 |
] ifFalse:[
|
|
1048 |
fgColor := Black on:device.
|
38
|
1049 |
]
|
0
|
1050 |
!
|
|
1051 |
|
105
|
1052 |
initialize
|
|
1053 |
super initialize.
|
|
1054 |
|
|
1055 |
font := font on:device.
|
|
1056 |
self height:(font height + font descent).
|
|
1057 |
adjust := #center.
|
118
|
1058 |
labelOriginX := labelOriginY := 0.
|
|
1059 |
labelWidth := labelHeight := 0.
|
105
|
1060 |
logo := nil.
|
|
1061 |
fixSize := false.
|
|
1062 |
hSpace := (self horizontalPixelPerMillimeter:0.5) rounded.
|
131
|
1063 |
vSpace := (self verticalPixelPerMillimeter:0.25) rounded
|
105
|
1064 |
!
|
|
1065 |
|
0
|
1066 |
recreate
|
|
1067 |
"after snapin, labels dimensions may have changed due to
|
|
1068 |
different font parameters"
|
|
1069 |
|
|
1070 |
super recreate.
|
3
|
1071 |
font := font on:device.
|
0
|
1072 |
self computeLabelSize.
|
|
1073 |
self computeLabelOrigin
|
|
1074 |
! !
|
|
1075 |
|
202
|
1076 |
!Label methodsFor:'private'!
|
|
1077 |
|
|
1078 |
computeLabelOrigin
|
|
1079 |
"(re)compute the origin of the label whenever label or font changes"
|
|
1080 |
|
|
1081 |
|x y|
|
|
1082 |
|
|
1083 |
labelHeight isNil ifTrue:[^ self].
|
|
1084 |
|
|
1085 |
adjust == #fit ifTrue:[
|
|
1086 |
labelOriginX := labelOriginY := margin.
|
|
1087 |
^ self
|
|
1088 |
].
|
|
1089 |
|
|
1090 |
"if it does not fit, should we make the origin visible,
|
|
1091 |
or the center (for text, the center seems better. For images,
|
|
1092 |
I dont really know ehich is better ...
|
|
1093 |
The commented code below makes the origin visible
|
|
1094 |
"
|
|
1095 |
"/ (labelHeight < height) ifTrue:[
|
|
1096 |
"/ y := (height - labelHeight) // 2
|
|
1097 |
"/ ] ifFalse:[
|
|
1098 |
"/ y := 0
|
|
1099 |
"/ ].
|
|
1100 |
|
|
1101 |
"always center vertically"
|
|
1102 |
y := (height - labelHeight) // 2.
|
|
1103 |
|
|
1104 |
labelOriginY := y.
|
|
1105 |
|
|
1106 |
(((adjust == #center)
|
|
1107 |
or:[adjust == #centerRight])
|
|
1108 |
or:[adjust == #centerLeft]) ifTrue:[
|
|
1109 |
" center text/form in button "
|
|
1110 |
x := (width - labelWidth) // 2.
|
|
1111 |
(width < labelWidth) ifTrue:[
|
|
1112 |
"no fit"
|
|
1113 |
(adjust == #centerLeft) ifTrue:[
|
|
1114 |
x := margin
|
|
1115 |
] ifFalse:[
|
|
1116 |
(adjust == #centerRight) ifTrue:[
|
|
1117 |
x := width - labelWidth - margin
|
|
1118 |
]
|
|
1119 |
]
|
|
1120 |
]
|
|
1121 |
] ifFalse:[
|
|
1122 |
(adjust == #left) ifTrue:[
|
|
1123 |
x := margin
|
|
1124 |
] ifFalse:[
|
|
1125 |
x := width - labelWidth - margin
|
|
1126 |
]
|
|
1127 |
].
|
|
1128 |
labelOriginX := x
|
|
1129 |
!
|
|
1130 |
|
|
1131 |
computeLabelSize
|
|
1132 |
"compute the extent needed to hold the label; aForm or aString"
|
|
1133 |
|
|
1134 |
|numberOfLines textHeight textWidth|
|
|
1135 |
|
|
1136 |
logo isNil ifTrue:[^ self].
|
|
1137 |
|
|
1138 |
logo isImageOrForm ifTrue:[
|
|
1139 |
labelWidth := logo width.
|
|
1140 |
labelHeight := logo height.
|
|
1141 |
^ self
|
|
1142 |
].
|
|
1143 |
|
|
1144 |
"must be a String or collection of strings"
|
|
1145 |
logo isString ifTrue:[
|
|
1146 |
numberOfLines := 1 + (logo occurrencesOf:(Character cr)).
|
|
1147 |
(numberOfLines ~~ 1) ifTrue:[
|
|
1148 |
logo := logo asStringCollection
|
|
1149 |
]
|
|
1150 |
] ifFalse:[
|
|
1151 |
numberOfLines := logo size.
|
|
1152 |
(numberOfLines <= 1) ifTrue:[
|
|
1153 |
logo := logo asString
|
|
1154 |
]
|
|
1155 |
].
|
|
1156 |
|
|
1157 |
"/ textHeight := font height * numberOfLines + font descent.
|
|
1158 |
textHeight := font height * numberOfLines.
|
|
1159 |
textWidth := font widthOf:logo.
|
|
1160 |
labelWidth := textWidth + (hSpace * 2) .
|
|
1161 |
labelHeight := textHeight + (vSpace * 2)
|
|
1162 |
!
|
|
1163 |
|
|
1164 |
getLabelFromModel
|
|
1165 |
"ask my model for the label to show.
|
|
1166 |
Here, we use labelMsg (instead of aspectMsg).
|
|
1167 |
This allows multiple labels to react on the same aspect,
|
|
1168 |
but show different labels when changed
|
|
1169 |
(also, since labelMsg defaults to nil, constant labels
|
|
1170 |
which have a nil labelMsg will not try to aquire a labelString)."
|
|
1171 |
|
|
1172 |
|val|
|
|
1173 |
|
|
1174 |
(model notNil
|
|
1175 |
and:[labelMsg notNil]) ifTrue:[
|
|
1176 |
val := model perform:labelMsg.
|
|
1177 |
converter notNil ifTrue:[
|
|
1178 |
val := converter printStringFor:val
|
|
1179 |
].
|
|
1180 |
self label:val.
|
|
1181 |
].
|
|
1182 |
!
|
|
1183 |
|
|
1184 |
newLayout
|
|
1185 |
"recompute position/size after a change
|
|
1186 |
- helper for form:/font: etc."
|
|
1187 |
|
|
1188 |
self computeLabelSize.
|
|
1189 |
fixSize ifFalse:[
|
|
1190 |
self resize
|
|
1191 |
] ifTrue:[
|
|
1192 |
self computeLabelOrigin
|
|
1193 |
].
|
|
1194 |
shown ifTrue:[
|
|
1195 |
self redraw
|
|
1196 |
]
|
|
1197 |
! !
|
|
1198 |
|
|
1199 |
!Label methodsFor:'queries'!
|
|
1200 |
|
|
1201 |
preferredExtent
|
|
1202 |
"return my preferred extent - this is the minimum size I would like to have"
|
|
1203 |
|
|
1204 |
|extra|
|
|
1205 |
|
|
1206 |
logo notNil ifTrue:[
|
|
1207 |
extra := margin * 2.
|
|
1208 |
^ (labelWidth + extra + hSpace) @ (labelHeight + extra + vSpace)
|
|
1209 |
].
|
|
1210 |
|
|
1211 |
^ super preferredExtent
|
|
1212 |
! !
|
|
1213 |
|
0
|
1214 |
!Label methodsFor:'redrawing'!
|
|
1215 |
|
77
|
1216 |
clearInsideWith:bg
|
|
1217 |
|cutOff mustClear|
|
0
|
1218 |
|
|
1219 |
cutOff := margin * 2.
|
|
1220 |
|
3
|
1221 |
mustClear := true.
|
|
1222 |
|
87
|
1223 |
(logo notNil and:[logo isImageOrForm]) ifTrue:[
|
59
|
1224 |
(labelOriginX == 0 and:[labelOriginY == 0]) ifTrue:[
|
|
1225 |
logo width >= (width - cutOff) ifTrue:[
|
|
1226 |
logo height >= (height - cutOff) ifTrue:[
|
|
1227 |
"no need to clear before - avoid flicker"
|
|
1228 |
mustClear := false
|
|
1229 |
]
|
|
1230 |
]
|
|
1231 |
].
|
3
|
1232 |
].
|
|
1233 |
|
|
1234 |
mustClear ifTrue:[
|
59
|
1235 |
self paint:bg.
|
|
1236 |
self fillRectangleX:margin y:margin
|
|
1237 |
width:(width - cutOff)
|
|
1238 |
height:(height - cutOff).
|
3
|
1239 |
].
|
77
|
1240 |
!
|
|
1241 |
|
|
1242 |
drawWith:fg and:bg
|
|
1243 |
"redraw my label with fg/bg - this generic method is also used by subclasses
|
|
1244 |
(especially Button) to redraw the logo in different colors."
|
|
1245 |
|
132
|
1246 |
|x y scaleH scaleV nW nH hSep vSep m2|
|
77
|
1247 |
|
|
1248 |
self clearInsideWith:bg.
|
0
|
1249 |
|
|
1250 |
logo notNil ifTrue:[
|
59
|
1251 |
self paint:fg on:bg.
|
131
|
1252 |
|
133
|
1253 |
m2 := margin * 2.
|
|
1254 |
hSep := (hSpace*2).
|
|
1255 |
vSep := (vSpace*2).
|
|
1256 |
|
87
|
1257 |
logo isImageOrForm ifTrue:[
|
131
|
1258 |
x := labelOriginX.
|
|
1259 |
y := labelOriginY.
|
|
1260 |
|
|
1261 |
adjust == #fit ifTrue:[
|
|
1262 |
scaleH := ((width - hSep) / (logo width)) asFloat.
|
|
1263 |
scaleV := ((height - vSep) / (logo height)) asFloat.
|
|
1264 |
self scale:(scaleH @ scaleV).
|
|
1265 |
x := transformation applyInverseScaleX:x.
|
|
1266 |
y := transformation applyInverseScaleY:y.
|
|
1267 |
].
|
|
1268 |
|
87
|
1269 |
logo := logo on:device.
|
59
|
1270 |
"/ self background:bg.
|
131
|
1271 |
self displayOpaqueForm:logo x:x y:y
|
59
|
1272 |
] ifFalse:[
|
|
1273 |
x := labelOriginX + hSpace.
|
|
1274 |
y := labelOriginY + (font ascent) + vSpace.
|
0
|
1275 |
|
131
|
1276 |
adjust == #fit ifTrue:[
|
|
1277 |
scaleH := ((width - m2 - hSep) / (labelWidth - hSpace)) asFloat.
|
|
1278 |
scaleV := ((height - m2 - vSep) / (labelHeight - vSpace)) asFloat.
|
|
1279 |
self scale:(scaleH min: scaleV).
|
|
1280 |
x := transformation applyInverseScaleX:x.
|
|
1281 |
y := y - font ascent + (transformation applyScaleY:font ascent).
|
|
1282 |
y := transformation applyInverseScaleY:y.
|
|
1283 |
scaleH < scaleV ifTrue:[
|
|
1284 |
nH := labelHeight * scaleH.
|
|
1285 |
"/ now, center vertically
|
|
1286 |
y := y + ((height - nH - m2 - vSep) / scaleH / 2).
|
|
1287 |
].
|
|
1288 |
scaleV < scaleH ifTrue:[
|
|
1289 |
"/ now, center horizontally
|
|
1290 |
nW := labelWidth * scaleV.
|
|
1291 |
x := x + ((width - nW - m2 - hSep) / scaleV / 2)
|
|
1292 |
].
|
|
1293 |
].
|
|
1294 |
|
87
|
1295 |
logo isString ifTrue:[
|
59
|
1296 |
self displayString:logo x:x y:y
|
|
1297 |
] ifFalse:[
|
|
1298 |
logo do:[ :line |
|
|
1299 |
self displayString:(line printString) x:x y:y.
|
|
1300 |
y := y + (font height)
|
|
1301 |
]
|
131
|
1302 |
].
|
|
1303 |
|
|
1304 |
].
|
|
1305 |
|
|
1306 |
adjust == #fit ifTrue:[
|
|
1307 |
self scale:1
|
|
1308 |
].
|
|
1309 |
|
0
|
1310 |
]
|
|
1311 |
!
|
|
1312 |
|
|
1313 |
redraw
|
|
1314 |
"redraw my label"
|
|
1315 |
|
|
1316 |
shown ifTrue:[
|
59
|
1317 |
self drawWith:fgColor and:bgColor
|
0
|
1318 |
]
|
|
1319 |
! !
|
105
|
1320 |
|
110
|
1321 |
!Label methodsFor:'resizing'!
|
|
1322 |
|
|
1323 |
forceResize
|
118
|
1324 |
"resize myself to make text fit into myself. Here, this is done even if
|
|
1325 |
fixSize is set."
|
110
|
1326 |
|
|
1327 |
logo notNil ifTrue:[
|
130
|
1328 |
self extent:self preferredExtent.
|
110
|
1329 |
self computeLabelOrigin
|
|
1330 |
]
|
105
|
1331 |
!
|
|
1332 |
|
|
1333 |
resize
|
|
1334 |
"resize myself to make text fit into myself.
|
118
|
1335 |
but only do so, if I am not fixedSize and I have NOT been
|
|
1336 |
given a relative extent or an extend computation block."
|
105
|
1337 |
|
110
|
1338 |
(logo notNil
|
|
1339 |
and:[fixSize not
|
|
1340 |
and:[relativeExtent isNil
|
|
1341 |
and:[extentRule isNil
|
|
1342 |
and:[relativeCorner isNil
|
|
1343 |
and:[cornerRule isNil]]]]]) ifTrue:[
|
|
1344 |
self forceResize
|
|
1345 |
] ifFalse:[
|
105
|
1346 |
self computeLabelOrigin
|
|
1347 |
]
|
|
1348 |
! !
|
|
1349 |
|