53 [#topCenter #topLeft #topRight #bottomLeft #bottomCenter #bottomRight] |
55 [#topCenter #topLeft #topRight #bottomLeft #bottomCenter #bottomRight] |
54 |
56 |
55 Its also possible, to not show the frame but only the label, by setting |
57 Its also possible, to not show the frame but only the label, by setting |
56 showFrame to false. |
58 showFrame to false. |
57 " |
59 " |
58 ! ! |
60 ! |
59 |
61 |
60 !FramedBox methodsFor:'private'! |
62 examples |
61 |
63 " |
62 redrawIfShown |
64 simple: |
63 shown ifTrue:[ |
65 |
64 self clear. |
66 |top frame1 frame2 frame3| |
65 self redraw |
67 |
66 ] |
68 top := StandardSystemView new. |
67 ! ! |
69 top extent:300@200. |
68 |
70 |
69 !FramedBox methodsFor:'accessing'! |
71 frame1 := FramedBox origin:0.0@0.0 corner:0.5@0.5 in:top. |
70 |
72 frame1 label:'frame1'. |
71 foregroundColor |
73 |
72 "return the frame labels foreground color" |
74 frame2 := FramedBox origin:0.5@0.0 corner:1.0@0.5 in:top. |
73 |
75 frame2 label:'frame2'. |
74 ^ fgColor |
76 |
75 ! |
77 frame3 := FramedBox origin:0.0@0.5 corner:1.0@1.0 in:top. |
76 |
78 frame3 label:'frame3'. |
77 foregroundColor:aColor |
79 |
78 "set the frame labels foreground color" |
80 top open |
79 |
81 |
80 aColor ~= fgColor ifTrue:[ |
82 |
81 fgColor := aColor. |
83 placing something inside: |
82 self redrawIfShown |
84 |
83 ] |
85 |top frame1 frame2 frame3 v1 v2 v3| |
84 ! |
86 |
85 |
87 top := StandardSystemView new. |
86 frameShown |
88 top extent:300@200. |
87 "return true, if frame is shown; |
89 |
88 if false, oly the label is shown" |
90 frame1 := FramedBox origin:0.0@0.0 corner:0.5@0.5 in:top. |
89 |
91 frame1 label:'frame1'. |
90 ^ showFrame |
92 v1 := View origin:0.0@0.0 corner:1.0@1.0 in:frame1. |
91 ! |
93 v1 viewBackground:(Color yellow); |
92 |
94 level:1. |
93 showFrame:aBoolean |
95 |
94 "turn on/off showing of the frame - |
96 frame2 := FramedBox origin:0.5@0.0 corner:1.0@0.5 in:top. |
95 without a frame, only the label is shown at its position" |
97 frame2 label:'frame2'. |
96 |
98 v2 := View origin:0.0@0.0 corner:1.0@1.0 in:frame2. |
97 aBoolean ~~ showFrame ifTrue:[ |
99 v2 viewBackground:(Color red); |
98 showFrame := aBoolean. |
100 level:1. |
99 self redrawIfShown |
101 |
100 ] |
102 frame3 := FramedBox origin:0.0@0.5 corner:1.0@1.0 in:top. |
101 ! |
103 frame3 label:'frame3'. |
102 |
104 v3 := View origin:0.0@0.0 corner:1.0@1.0 in:frame3. |
103 label |
105 v3 viewBackground:(Color green); |
104 "return the frames labelstring" |
106 level:1. |
105 |
107 |
106 ^ label |
108 top open |
107 ! |
109 |
108 |
110 |
109 label:aString |
111 placing something inside a frame in a dialog: |
110 "set the frames labelstring" |
112 |
111 |
113 |box panel frame1 frame2 frame3 v1 v1b v2 v3| |
112 (label ~= aString) ifTrue:[ |
114 |
113 label := aString. |
115 box := Dialog new. |
114 self redrawIfShown |
116 |
115 ] |
117 frame1 := FramedBox label:'frame1'. |
116 ! |
118 panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame1. |
117 |
119 v1 := View extent:100@100 in:panel. |
118 font:aFont |
120 v1 viewBackground:(Color red); |
119 "set the frame labelstrings font" |
121 level:1. |
120 |
122 v1b := View extent:100@100 in:panel. |
121 (font ~= aFont) ifTrue:[ |
123 v1b viewBackground:(Color yellow); |
122 super font:aFont. |
124 level:1. |
123 self redrawIfShown |
125 |
124 ] |
126 box addComponent:frame1. |
125 ! |
127 |
126 |
128 frame2 := FramedBox label:'frame2'. |
127 viewRectangle |
129 v2 := View origin:0.0@0.0 corner:1.0@1.0 in:frame2. |
128 "return the inside area - redefined to save frame from |
130 v2 viewBackground:(Color green); |
129 relative computations" |
131 level:1. |
130 |
132 box addComponent:frame2. |
131 |m2 sep| |
133 |
132 |
134 frame3 := FramedBox label:'frame3'. |
133 sep := font height. |
135 v3 := View origin:0.0@0.0 corner:1.0@1.0 in:frame3. |
134 m2 := sep + sep "+ sep". |
136 v3 viewBackground:(Color blue); |
135 |
137 level:1. |
136 showFrame ifFalse:[ |
138 box addComponent:frame3. |
137 ^ (0 @ sep) extent:(width @ height) |
139 |
138 ]. |
140 box addOkButton. |
139 ^ (sep @ sep) extent:((width - sep) @ (height - sep)) |
141 box open |
140 ! |
142 |
141 |
143 |
142 layout |
144 placing something inside a frame in a dialog: |
143 "return the current layout, which is a symbol describing |
145 |
144 the labels position." |
146 |box panel frame1 frame2 frame3 v1 v1b v2 v3| |
145 |
147 |
146 ^ layout |
148 box := Dialog new. |
147 ! |
149 |
148 |
150 frame1 := FramedBox label:'frame1'. |
149 layout:aSymbol |
151 panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame1. |
150 "define the position of the label; |
152 v1 := View extent:100@100 in:panel. |
151 aSymbol may be: #topLeft, #topCenter, #topRight; |
153 v1 viewBackground:(Color red); |
152 #bottomLeft, #bottomCenter or #bottomRight" |
154 level:1. |
153 |
155 v1b := View extent:100@100 in:panel. |
154 layout ~~ aSymbol ifTrue:[ |
156 v1b viewBackground:(Color yellow); |
155 layout := aSymbol. |
157 level:1. |
156 self redrawIfShown |
158 |
157 ] |
159 box addComponent:frame1. |
158 ! ! |
160 |
159 |
161 frame2 := FramedBox label:'frame2'. |
160 !FramedBox methodsFor:'event handling'! |
162 v2 := View origin:0.0@0.0 corner:1.0@1.0 in:frame2. |
161 |
163 v2 viewBackground:(Color green); |
162 sizeChanged:how |
164 level:1. |
163 self redrawIfShown. |
165 box addComponent:frame2. |
164 super sizeChanged:how |
166 |
|
167 frame3 := FramedBox label:'frame3'. |
|
168 v3 := View origin:0.0@0.0 corner:1.0@1.0 in:frame3. |
|
169 v3 viewBackground:(Color blue); |
|
170 level:1. |
|
171 box addComponent:frame3. |
|
172 |
|
173 box addOkButton. |
|
174 box open |
|
175 " |
165 ! ! |
176 ! ! |
166 |
177 |
167 !FramedBox methodsFor:'drawing'! |
178 !FramedBox methodsFor:'drawing'! |
168 |
179 |
169 drawFrame |
180 drawFrame |
244 self displayOpaqueString:l x:x y:y |
255 self displayOpaqueString:l x:x y:y |
245 ] |
256 ] |
246 ] |
257 ] |
247 ! ! |
258 ! ! |
248 |
259 |
|
260 !FramedBox methodsFor:'queries'! |
|
261 |
|
262 viewRectangle |
|
263 "return the inside area |
|
264 - redefined to save frame from relative computations." |
|
265 |
|
266 |m2 sep| |
|
267 |
|
268 sep := font height. |
|
269 m2 := sep + sep. |
|
270 |
|
271 showFrame ifFalse:[ |
|
272 ^ (0 @ sep) extent:(width @ (height - m2)) |
|
273 ]. |
|
274 ^ (sep @ sep) extent:((width - m2) @ (height - m2)) |
|
275 |
|
276 "/ |m2 sepH sepV| |
|
277 "/ |
|
278 "/ sepV := font height. |
|
279 "/ |
|
280 "/ showFrame ifFalse:[ |
|
281 "/ ^ (0 @ sepV) extent:(width @ (height - sepV - sepV)) |
|
282 "/ ]. |
|
283 "/ sepH := sepV // 2. |
|
284 "/ ^ (sepH @ sepH) extent:((width - sepH - sepH) @ (height - sepV - sepV)) |
|
285 ! |
|
286 |
|
287 preferedExtent |
|
288 "redefined to add space for the frame to the default extent" |
|
289 |
|
290 |m2 sep| |
|
291 |
|
292 sep := font height. |
|
293 m2 := sep + sep. |
|
294 |
|
295 showFrame ifFalse:[ |
|
296 ^ super preferedExtent + (0 @ m2) |
|
297 ]. |
|
298 ^ super preferedExtent+(m2 @ m2) |
|
299 ! ! |
|
300 |
|
301 !FramedBox methodsFor:'private'! |
|
302 |
|
303 redrawIfShown |
|
304 shown ifTrue:[ |
|
305 self clear. |
|
306 self redraw |
|
307 ] |
|
308 ! ! |
|
309 |
|
310 !FramedBox methodsFor:'accessing'! |
|
311 |
|
312 label:aString |
|
313 "set the frames labelstring" |
|
314 |
|
315 (label ~= aString) ifTrue:[ |
|
316 label := aString. |
|
317 self redrawIfShown |
|
318 ] |
|
319 ! |
|
320 |
|
321 foregroundColor |
|
322 "return the frame labels foreground color" |
|
323 |
|
324 ^ fgColor |
|
325 ! |
|
326 |
|
327 foregroundColor:aColor |
|
328 "set the frame labels foreground color" |
|
329 |
|
330 aColor ~= fgColor ifTrue:[ |
|
331 fgColor := aColor. |
|
332 self redrawIfShown |
|
333 ] |
|
334 ! |
|
335 |
|
336 frameShown |
|
337 "return true, if frame is shown; |
|
338 if false, oly the label is shown" |
|
339 |
|
340 ^ showFrame |
|
341 ! |
|
342 |
|
343 showFrame:aBoolean |
|
344 "turn on/off showing of the frame - |
|
345 without a frame, only the label is shown at its position" |
|
346 |
|
347 aBoolean ~~ showFrame ifTrue:[ |
|
348 showFrame := aBoolean. |
|
349 self redrawIfShown |
|
350 ] |
|
351 ! |
|
352 |
|
353 label |
|
354 "return the frames labelstring" |
|
355 |
|
356 ^ label |
|
357 ! |
|
358 |
|
359 font:aFont |
|
360 "set the frame labelstrings font" |
|
361 |
|
362 (font ~= aFont) ifTrue:[ |
|
363 super font:aFont. |
|
364 self redrawIfShown |
|
365 ] |
|
366 ! |
|
367 |
|
368 layout |
|
369 "return the current layout, which is a symbol describing |
|
370 the labels position." |
|
371 |
|
372 ^ layout |
|
373 ! |
|
374 |
|
375 layout:aSymbol |
|
376 "define the position of the label; |
|
377 aSymbol may be: #topLeft, #topCenter, #topRight; |
|
378 #bottomLeft, #bottomCenter or #bottomRight" |
|
379 |
|
380 layout ~~ aSymbol ifTrue:[ |
|
381 layout := aSymbol. |
|
382 self redrawIfShown |
|
383 ] |
|
384 ! ! |
|
385 |
249 !FramedBox methodsFor:'initialization'! |
386 !FramedBox methodsFor:'initialization'! |
250 |
387 |
251 initialize |
388 initialize |
252 super initialize. |
389 super initialize. |
253 showFrame := true |
390 showFrame := true |