author | Claus Gittinger <cg@exept.de> |
Thu, 07 Dec 1995 23:25:03 +0100 | |
changeset 243 | 5c411425097d |
parent 197 | 00927189c882 |
child 355 | a55f62047156 |
permissions | -rw-r--r-- |
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 |
||
77 | 13 |
|
14 |
||
15 |
DialogBox subclass:#InfoBox |
|
16 |
instanceVariableNames:'formLabel textLabel' |
|
17 |
classVariableNames:'InfoBitmap' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Views-DialogBoxes' |
|
0 | 20 |
! |
21 |
||
77 | 22 |
!InfoBox class methodsFor:'documentation'! |
0 | 23 |
|
197 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
27 |
All Rights Reserved |
|
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 |
||
77 | 38 |
! |
8 | 39 |
|
40 |
documentation |
|
41 |
" |
|
38 | 42 |
this class implements a pop-up box to show an information message. |
43 |
It has a single ok-Button, which closes the box. |
|
44 |
Also entering return has (by default) the same effect as pressing |
|
45 |
the ok-button. |
|
59 | 46 |
InfoBox is a superclass of some other boxes - see WarningBox, YesNoBox etc. |
47 |
most of them simply redefine the icon shown in the upper left or |
|
48 |
add buttons. |
|
49 |
||
50 |
instance variables: |
|
51 |
||
52 |
formLabel <Label> shows a bitmap (warning, question-mark) |
|
53 |
||
54 |
textLabel <Label> shows the boxes text |
|
55 |
||
77 | 56 |
" |
59 | 57 |
|
77 | 58 |
! |
38 | 59 |
|
77 | 60 |
examples |
61 |
" |
|
59 | 62 |
InfoBoxes are created with: |
63 |
||
64 |
aBox := InfoBox title:'some title'. |
|
38 | 65 |
|
66 |
and shown with: |
|
67 |
||
59 | 68 |
aBox showAtPointer |
69 |
or |
|
70 |
aBox open |
|
38 | 71 |
|
72 |
The default box shows 'yes' in its button; this can be changed with: |
|
73 |
||
59 | 74 |
aBox okText:'some string'. |
38 | 75 |
|
76 |
the boxes bitmap-image can be changed with: |
|
77 |
||
184 | 78 |
aBox image:aForm |
77 | 79 |
|
80 |
||
81 |
Since this type of information is pretty common, a convenient information |
|
82 |
method has been added to Object. |
|
83 |
Thus, you can use: |
|
84 |
self information:'hello world' |
|
85 |
everwhere in your program. |
|
86 |
||
87 |
standard box: |
|
88 |
||
89 |
|box| |
|
90 |
||
91 |
box := InfoBox title:'hello world '. |
|
92 |
box open |
|
93 |
||
94 |
||
95 |
changing the buttons label: |
|
96 |
||
97 |
|box| |
|
98 |
||
99 |
box := InfoBox title:'hello world '. |
|
100 |
box okText:'wow'. |
|
101 |
box open |
|
102 |
||
103 |
||
104 |
changing the icon: |
|
105 |
||
106 |
|box| |
|
107 |
||
108 |
box := InfoBox title:'hello world '. |
|
184 | 109 |
box image:(Image fromFile:'bitmaps/SBrowser.xbm'). |
77 | 110 |
box okText:'wow'. |
111 |
box open |
|
112 |
||
113 |
or even: |
|
114 |
||
115 |
|box| |
|
116 |
||
117 |
box := InfoBox title:'hello garfield '. |
|
184 | 118 |
box image:((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:200@100). |
77 | 119 |
box okText:'wow'. |
120 |
box open |
|
121 |
||
122 |
||
123 |
If you plan to use boxes as in the last example, you may want to |
|
124 |
keep the box around for reuse (since the image magnification takes some time). |
|
125 |
||
126 |
|box| |
|
127 |
||
128 |
box := InfoBox title:'hello garfield '. |
|
184 | 129 |
box image:((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:200@100). |
77 | 130 |
box okText:'wow'. |
131 |
box open. |
|
132 |
||
133 |
box title:'hello again'. |
|
134 |
box open |
|
135 |
||
63 | 136 |
" |
77 | 137 |
! ! |
138 |
||
139 |
!InfoBox class methodsFor:'instance creation'! |
|
38 | 140 |
|
77 | 141 |
title:titleString |
142 |
"create a new infoBox with title, aTitleString" |
|
143 |
||
144 |
^ (self new) title:titleString |
|
38 | 145 |
|
77 | 146 |
" |
147 |
(InfoBox title:'hello') open |
|
148 |
" |
|
149 |
! ! |
|
60 | 150 |
|
77 | 151 |
!InfoBox class methodsFor:'defaults'! |
60 | 152 |
|
77 | 153 |
iconBitmap |
154 |
"return the bitmap shown as icon in my instances. |
|
155 |
The form is cached and reused, for faster opening." |
|
38 | 156 |
|
77 | 157 |
InfoBitmap isNil ifTrue:[ |
108 | 158 |
InfoBitmap := Image fromFile:'bitmaps/Information.xbm'. |
159 |
InfoBitmap notNil ifTrue:[ |
|
160 |
InfoBitmap := InfoBitmap on:Display |
|
161 |
] |
|
77 | 162 |
]. |
163 |
^ InfoBitmap |
|
59 | 164 |
! ! |
165 |
||
166 |
!InfoBox class methodsFor:'styles'! |
|
167 |
||
168 |
updateStyleCache |
|
169 |
|img| |
|
38 | 170 |
|
59 | 171 |
img := StyleSheet at:'informationBoxIcon'. |
72 | 172 |
img notNil ifTrue:[InfoBitmap := img on:Display]. |
59 | 173 |
! ! |
174 |
||
0 | 175 |
!InfoBox methodsFor:'accessing'! |
176 |
||
184 | 177 |
form:aFormOrImage |
178 |
"historical leftover - define a form to be displayed left of the title" |
|
179 |
||
180 |
self image:aFormOrImage |
|
181 |
! |
|
182 |
||
38 | 183 |
formLabel |
184 |
"return the formLabel = can be used to change its appearance" |
|
185 |
||
186 |
^ formLabel |
|
187 |
! |
|
188 |
||
197 | 189 |
image:aForm |
190 |
"define a form to be displayed left of the title |
|
191 |
- usually left as defaulted: |
|
192 |
an exclamation-mark here, warn-sign in warningBox, |
|
193 |
others in other subclasses." |
|
0 | 194 |
|
197 | 195 |
formLabel form:aForm. |
196 |
formLabel forceResize. |
|
197 |
shown ifTrue:[self resize] |
|
0 | 198 |
! |
199 |
||
77 | 200 |
textLabel |
201 |
"return the textLabel = can be used to change its appearance" |
|
202 |
||
203 |
^ textLabel |
|
204 |
! |
|
205 |
||
0 | 206 |
title |
8 | 207 |
"return the boxes title string" |
0 | 208 |
|
209 |
^ textLabel label |
|
197 | 210 |
! |
0 | 211 |
|
197 | 212 |
title:aString |
213 |
"set the boxes title string" |
|
60 | 214 |
|
197 | 215 |
aString ~= textLabel label ifTrue:[ |
216 |
textLabel label:aString. |
|
217 |
textLabel forceResize. |
|
218 |
shown ifTrue:[self resize] |
|
219 |
] |
|
0 | 220 |
! ! |
221 |
||
77 | 222 |
!InfoBox methodsFor:'initialization'! |
0 | 223 |
|
77 | 224 |
initFormBitmap |
225 |
"setup the bitmap shown in the upper left - |
|
226 |
extracted into a separate method for easier redefinition |
|
227 |
in subclasses" |
|
0 | 228 |
|
77 | 229 |
formLabel form:(self class iconBitmap) |
0 | 230 |
! |
231 |
||
180
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
232 |
initFormLabel |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
233 |
|mm| |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
234 |
|
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
235 |
mm := ViewSpacing. |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
236 |
|
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
237 |
formLabel := Label in:self. |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
238 |
formLabel borderWidth:0. |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
239 |
formLabel origin:(mm @ mm). |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
240 |
|
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
241 |
"Created: 16.11.1995 / 18:32:32 / cg" |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
242 |
! |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
243 |
|
77 | 244 |
initialize |
245 |
|mm| |
|
246 |
||
247 |
super initialize. |
|
248 |
self addOkButton. |
|
0 | 249 |
|
77 | 250 |
label := 'Info'. |
251 |
||
252 |
mm := ViewSpacing. |
|
253 |
||
180
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
254 |
self initFormLabel. |
77 | 255 |
self initFormBitmap. |
0 | 256 |
|
77 | 257 |
textLabel := Label label:'Information' in:self. |
258 |
textLabel borderWidth:0. |
|
259 |
textLabel origin:[(mm + formLabel widthIncludingBorder + mm) |
|
260 |
@ |
|
261 |
mm]. |
|
0 | 262 |
|
77 | 263 |
" |
264 |
|b| |
|
265 |
||
266 |
b := InfoBox new. |
|
267 |
b title:'hello'. |
|
268 |
b open |
|
269 |
" |
|
0 | 270 |
! ! |
197 | 271 |
|
272 |
!InfoBox methodsFor:'queries'! |
|
273 |
||
274 |
preferredExtent |
|
275 |
"return my preferred extent" |
|
276 |
||
277 |
|w h| |
|
278 |
||
279 |
"/ formLabel resize. |
|
280 |
"/ textLabel resize. |
|
281 |
||
282 |
w := margin + |
|
283 |
ViewSpacing + |
|
284 |
formLabel widthIncludingBorder + |
|
285 |
ViewSpacing + textLabel width + ViewSpacing + |
|
286 |
margin. |
|
287 |
w := w max:(okButton preferredExtent x + (ViewSpacing * 2)). |
|
288 |
h := ViewSpacing |
|
289 |
+ ((formLabel heightIncludingBorder) max:(textLabel height)) |
|
290 |
+ (ViewSpacing * 4) |
|
291 |
+ okButton heightIncludingBorder |
|
292 |
+ ViewSpacing. |
|
293 |
||
294 |
^ w @ h |
|
295 |
! ! |
|
296 |
||
243 | 297 |
!InfoBox class methodsFor:'documentation'! |
298 |
||
299 |
version |
|
300 |
^ '$Header: /cvs/stx/stx/libwidg/InfoBox.st,v 1.21 1995-12-07 22:23:19 cg Exp $' |
|
301 |
! ! |