author | tz |
Mon, 30 Mar 1998 14:27:33 +0200 | |
changeset 826 | d8470e26754d |
parent 634 | cee0d1f706e1 |
child 843 | 34de7f6bea2d |
permissions | -rw-r--r-- |
62 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
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 |
" |
|
50 | 12 |
|
13 |
View subclass:#ProgressIndicator |
|
826 | 14 |
instanceVariableNames:'percentage showPercentage fgColor bgColor connectedTop |
15 |
connectedLabel collector finishAction closeTopWhenDone' |
|
183 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Views-Misc' |
|
50 | 19 |
! |
20 |
||
334 | 21 |
!ProgressIndicator class methodsFor:'documentation'! |
50 | 22 |
|
62 | 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 |
! |
|
36 |
||
50 | 37 |
documentation |
38 |
" |
|
39 |
a view showing a rectangle filled according the percentage value. |
|
40 |
Can be used as a progress indicator a la MSwindows. |
|
574 | 41 |
Can be used as a widget within an application, or |
42 |
via the convenient #inBox: instance creation messages, |
|
43 |
which shows a progressDisplay in a modalBox, while some |
|
44 |
action is performed. |
|
45 |
See examples. |
|
183 | 46 |
|
47 |
[author:] |
|
634 | 48 |
Claus Gittinger |
183 | 49 |
|
50 |
[see also:] |
|
634 | 51 |
ActionWaitBox AnimatedLabel |
50 | 52 |
" |
53 |
! |
|
54 |
||
55 |
examples |
|
56 |
" |
|
62 | 57 |
basic (internal) interface |
58 |
(if progress indicator is to be used in a complex box ...): |
|
50 | 59 |
|
183 | 60 |
Before you get frustrated - see the convenient-interface examples |
61 |
at the end ;-) |
|
62 |
||
634 | 63 |
[exBegin] |
50 | 64 |
|top p h| |
65 |
||
62 | 66 |
top := ModalBox new. |
50 | 67 |
top extent:300@100. |
68 |
top label:'Progress'. |
|
69 |
p := ProgressIndicator in:top. |
|
70 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
71 |
p level:-1. |
|
62 | 72 |
h := p preferredExtent y. |
50 | 73 |
p topInset:(h // 2) negated; |
634 | 74 |
bottomInset:(h // 2) negated; |
75 |
leftInset:5; |
|
76 |
rightInset:5. |
|
50 | 77 |
|
78 |
[ |
|
634 | 79 |
1 to:100 do:[:val | |
80 |
(Delay forSeconds:0.05) wait. |
|
81 |
p percentage:val |
|
82 |
]. |
|
83 |
top hide. |
|
62 | 84 |
] fork. |
85 |
top open. |
|
634 | 86 |
[exEnd] |
50 | 87 |
|
88 |
changing colors, turning percentage display off: |
|
634 | 89 |
[exBegin] |
50 | 90 |
|top p h| |
91 |
||
92 |
top := StandardSystemView new. |
|
93 |
top extent:300@100. |
|
94 |
top label:'Progress'. |
|
95 |
p := ProgressIndicator in:top. |
|
96 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
97 |
p level:-1. |
|
98 |
p showPercentage:false. |
|
99 |
p foregroundColor:(Color red). |
|
100 |
h := 10. |
|
101 |
p topInset:(h // 2) negated; |
|
634 | 102 |
bottomInset:(h // 2) negated; |
103 |
leftInset:5; |
|
104 |
rightInset:5. |
|
50 | 105 |
top open. |
106 |
[ |
|
634 | 107 |
1 to:100 do:[:val | |
108 |
(Delay forSeconds:0.05) wait. |
|
109 |
p percentage:val |
|
110 |
] |
|
50 | 111 |
] fork |
634 | 112 |
[exEnd] |
50 | 113 |
|
114 |
with border (2D look): |
|
634 | 115 |
[exBegin] |
50 | 116 |
|top p h| |
117 |
||
118 |
top := StandardSystemView new. |
|
119 |
top extent:300@100. |
|
120 |
top label:'Progress'. |
|
121 |
p := ProgressIndicator in:top. |
|
122 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
123 |
p borderWidth:1. |
|
62 | 124 |
h := p preferredExtent y. |
50 | 125 |
p topInset:(h // 2) negated; |
634 | 126 |
bottomInset:(h // 2) negated; |
127 |
leftInset:5; |
|
128 |
rightInset:5. |
|
50 | 129 |
top open. |
130 |
[ |
|
634 | 131 |
1 to:100 do:[:val | |
132 |
(Delay forSeconds:0.05) wait. |
|
133 |
p percentage:val |
|
134 |
] |
|
50 | 135 |
] fork |
634 | 136 |
[exEnd] |
50 | 137 |
|
138 |
||
139 |
getting progress from a model: |
|
634 | 140 |
[exBegin] |
50 | 141 |
|model top p h| |
142 |
||
143 |
model := 0 asValue. |
|
144 |
||
145 |
top := StandardSystemView new. |
|
146 |
top extent:300@100. |
|
147 |
top label:'Progress'. |
|
148 |
p := ProgressIndicator in:top. |
|
149 |
p model:model. |
|
150 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
151 |
p level:-1. |
|
62 | 152 |
h := p preferredExtent y. |
50 | 153 |
p topInset:(h // 2) negated; |
634 | 154 |
bottomInset:(h // 2) negated; |
155 |
leftInset:5; |
|
156 |
rightInset:5. |
|
50 | 157 |
top open. |
158 |
||
159 |
[ |
|
634 | 160 |
1 to:100 do:[:val | |
161 |
(Delay forSeconds:0.05) wait. |
|
162 |
model value:val |
|
163 |
] |
|
50 | 164 |
] fork |
634 | 165 |
[exEnd] |
50 | 166 |
|
62 | 167 |
|
50 | 168 |
concrete example: |
169 |
search all files in the source directory for a string |
|
170 |
using grep. Show progress while doing so. |
|
634 | 171 |
[exBegin] |
50 | 172 |
|top p h names done| |
173 |
||
174 |
top := StandardSystemView new. |
|
175 |
top extent:300@100. |
|
176 |
top label:'Searching ...'. |
|
177 |
p := ProgressIndicator in:top. |
|
178 |
p origin:(0.0@0.5) corner:(1.0@0.5). |
|
179 |
p level:-1. |
|
62 | 180 |
h := p preferredExtent y. |
50 | 181 |
p topInset:(h // 2) negated; |
634 | 182 |
bottomInset:(h // 2) negated; |
183 |
leftInset:5; |
|
184 |
rightInset:5. |
|
50 | 185 |
top openWithPriority:(Processor activePriority + 1). |
186 |
||
187 |
names := 'source' asFilename directoryContents. |
|
188 |
done := 0. |
|
189 |
names do:[:aName | |
|
634 | 190 |
|fn stream line| |
50 | 191 |
|
634 | 192 |
p percentage:(done / names size * 100). |
193 |
fn := ('source/' , aName) asFilename. |
|
194 |
fn isDirectory ifFalse:[ |
|
195 |
stream := fn readStream. |
|
196 |
[stream atEnd] whileFalse:[ |
|
197 |
line := stream nextLine. |
|
198 |
(line findString:'subclass:') ~~ 0 ifTrue:[ |
|
199 |
Transcript showCR:line |
|
200 |
]. |
|
201 |
]. |
|
202 |
stream close. |
|
203 |
]. |
|
204 |
done := done + 1 |
|
50 | 205 |
]. |
206 |
||
207 |
top destroy |
|
634 | 208 |
[exEnd] |
62 | 209 |
|
210 |
||
211 |
using the convenient inBox-interface |
|
212 |
||
213 |
(this creates a box and an activity label and evaluates a block |
|
214 |
to indicate ...) |
|
215 |
||
216 |
basic interface demonstration: |
|
634 | 217 |
[exBegin] |
62 | 218 |
|p| |
219 |
||
220 |
p := ProgressIndicator |
|
634 | 221 |
inBoxWithLabel:'doing something ...' |
222 |
abortable:true. |
|
62 | 223 |
p showProgressOf: |
634 | 224 |
[:progressValue :currentAction | |
62 | 225 |
|
634 | 226 |
1 to:100 do:[:val | |
227 |
(Delay forSeconds:0.05) wait. |
|
228 |
val == 25 ifTrue:[ |
|
229 |
currentAction value:'still going ...' |
|
230 |
]. |
|
231 |
val == 50 ifTrue:[ |
|
232 |
currentAction value:'halfway through ...' |
|
233 |
]. |
|
234 |
val == 75 ifTrue:[ |
|
235 |
currentAction value:'almost finished ...' |
|
236 |
]. |
|
237 |
progressValue value:val |
|
238 |
] |
|
239 |
] |
|
240 |
[exEnd] |
|
62 | 241 |
|
242 |
||
243 |
above search example using this convenient interface: |
|
634 | 244 |
[exBegin] |
62 | 245 |
|p| |
246 |
||
183 | 247 |
p := ProgressIndicator |
634 | 248 |
inBoxWithLabel:'searching files ...' |
249 |
abortable:false. |
|
62 | 250 |
p showProgressOf: |
634 | 251 |
[:progressValue :currentAction | |
252 |
|names nDone| |
|
62 | 253 |
|
634 | 254 |
names := 'source' asFilename directoryContents. |
255 |
nDone := 0. |
|
256 |
names do:[:aName | |
|
257 |
|fn stream line| |
|
183 | 258 |
|
634 | 259 |
progressValue value:(nDone / names size * 100). |
260 |
currentAction value:'searching ' , 'source/' , aName , ' ...'. |
|
62 | 261 |
|
634 | 262 |
fn := ('source/' , aName) asFilename. |
263 |
fn isDirectory ifFalse:[ |
|
264 |
stream := fn readStream. |
|
265 |
[stream atEnd] whileFalse:[ |
|
266 |
line := stream nextLine. |
|
267 |
(line findString:'subclass:') ~~ 0 ifTrue:[ |
|
268 |
Transcript showCR:line |
|
269 |
]. |
|
270 |
]. |
|
271 |
stream close. |
|
272 |
]. |
|
273 |
nDone := nDone + 1 |
|
274 |
]. |
|
275 |
]. |
|
276 |
[exEnd] |
|
62 | 277 |
|
278 |
||
279 |
a nice example: copying files a la windows ... |
|
183 | 280 |
the following copies all files to /dev/null. |
634 | 281 |
[exBegin] |
62 | 282 |
|p| |
283 |
||
284 |
(ProgressIndicator |
|
634 | 285 |
inBoxWithLabel:'copy files to /dev/null ...' |
286 |
abortable:true) |
|
287 |
showProgressOf: |
|
288 |
[:progressValue :currentAction | |
|
289 |
|files nFiles nDone| |
|
62 | 290 |
|
634 | 291 |
files := '.' asFilename directoryContents. |
292 |
nFiles := files size. |
|
293 |
nDone := 0. |
|
294 |
files do:[:aFileName | |
|
295 |
|percent| |
|
50 | 296 |
|
634 | 297 |
nDone := nDone + 1. |
298 |
percent := nDone / nFiles * 100. |
|
299 |
progressValue value:percent. |
|
300 |
aFileName asFilename isDirectory ifTrue:[ |
|
301 |
Transcript showCR:('skipping ' , aFileName , ' ...'). |
|
302 |
currentAction value:('skipping ' , aFileName , ' ...'). |
|
303 |
] ifFalse:[ |
|
304 |
Transcript showCR:('copying ' , aFileName , ' ...'). |
|
305 |
currentAction value:('copying ' , aFileName , ' ...'). |
|
306 |
Object errorSignal handle:[:ex | |
|
307 |
self warn:'an error occurred while copying ' , aFileName. |
|
308 |
ex return |
|
309 |
] do:[ |
|
310 |
aFileName asFilename copyTo:'/dev/null'. |
|
311 |
] |
|
312 |
]. |
|
313 |
]. |
|
314 |
]. |
|
315 |
[exEnd] |
|
183 | 316 |
" |
50 | 317 |
! ! |
318 |
||
334 | 319 |
!ProgressIndicator class methodsFor:'instance creation'! |
62 | 320 |
|
321 |
inBox |
|
574 | 322 |
"create a topView containing an instance of myself, |
323 |
for later use with #showProgressOf:" |
|
324 |
||
325 |
^ self inBoxWithLabel:'executing ...' abortable:false |
|
326 |
||
327 |
"Modified: 22.10.1997 / 21:08:37 / cg" |
|
62 | 328 |
! |
329 |
||
330 |
inBoxWithLabel:aLabel |
|
331 |
"create a topView containing an instance of myself, |
|
332 |
for later use with #showProgressOf:" |
|
333 |
||
334 |
^ self inBoxWithLabel:aLabel abortable:false |
|
335 |
! |
|
336 |
||
337 |
inBoxWithLabel:aLabel abortable:abortable |
|
338 |
"create a topView containing an instance of myself, |
|
339 |
for later use with #showProgressOf:" |
|
340 |
||
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
341 |
^ self |
634 | 342 |
inBoxWithLabel:aLabel |
343 |
text:'' |
|
344 |
abortable:abortable |
|
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
345 |
|
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
346 |
"Modified: 17.7.1996 / 15:14:58 / cg" |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
347 |
! |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
348 |
|
237 | 349 |
inBoxWithLabel:aLabel icon:anIcon text:text abortable:abortable view:additionalView closeWhenDone:closeWhenDoneBoolean |
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
350 |
"create a topView containing an instance of myself, |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
351 |
for later use with #showProgressOf:" |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
352 |
|
237 | 353 |
|top p l h y y2| |
62 | 354 |
|
355 |
top := Dialog new. |
|
356 |
top label:aLabel. |
|
357 |
top cursor:(Cursor wait). |
|
826 | 358 |
y2 := 0. |
237 | 359 |
anIcon notNil ifTrue:[ |
826 | 360 |
y := top yPosition. |
361 |
l := top addTextLabel:anIcon. |
|
362 |
l borderWidth:0. |
|
363 |
l adjust:#left. |
|
364 |
l cursor:(Cursor wait). |
|
365 |
y2 := top yPosition. |
|
366 |
top yPosition:y. |
|
237 | 367 |
]. |
368 |
||
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
369 |
l := top addTextLabel:text. |
62 | 370 |
l borderWidth:0. |
74 | 371 |
l adjust:#left. |
62 | 372 |
l cursor:(Cursor wait). |
826 | 373 |
anIcon notNil ifTrue: [l leftInset:(anIcon width + 10)]. |
237 | 374 |
|
375 |
top yPosition:(top yPosition max:y2). |
|
62 | 376 |
|
377 |
top addVerticalSpace. |
|
378 |
||
379 |
p := ProgressIndicator new. |
|
380 |
p extent:(1.0 @ p preferredExtent y). |
|
381 |
p level:-1. |
|
382 |
p leftInset:5; |
|
383 |
rightInset:5. |
|
384 |
p cursor:(Cursor wait). |
|
237 | 385 |
p closeTopWhenDone:closeWhenDoneBoolean. |
62 | 386 |
p connectToTop:top label:l. |
387 |
||
388 |
top addComponent:p. |
|
389 |
||
237 | 390 |
additionalView notNil ifTrue:[ |
826 | 391 |
top addComponent:additionalView. |
392 |
additionalView extent:(1.0 @ additionalView preferredExtent y). |
|
237 | 393 |
]. |
394 |
||
62 | 395 |
abortable ifTrue:[ |
826 | 396 |
top addVerticalSpace. |
397 |
top addAbortButton |
|
62 | 398 |
]. |
399 |
||
400 |
^ p |
|
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
401 |
|
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
402 |
"Created: 17.7.1996 / 15:14:33 / cg" |
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
403 |
"Modified: 17.7.1996 / 15:16:58 / cg" |
237 | 404 |
! |
405 |
||
406 |
inBoxWithLabel:aLabel text:text abortable:abortable |
|
407 |
"create a topView containing an instance of myself, |
|
408 |
for later use with #showProgressOf:" |
|
409 |
||
410 |
^ self |
|
634 | 411 |
inBoxWithLabel:aLabel |
412 |
text:text |
|
413 |
abortable:abortable |
|
414 |
view:nil |
|
237 | 415 |
|
416 |
! |
|
417 |
||
418 |
inBoxWithLabel:aLabel text:text abortable:abortable view:additionalView |
|
419 |
"create a topView containing an instance of myself, |
|
420 |
for later use with #showProgressOf:" |
|
421 |
||
422 |
^ self |
|
634 | 423 |
inBoxWithLabel:aLabel |
424 |
text:text |
|
425 |
abortable:abortable |
|
426 |
view:additionalView |
|
427 |
closeWhenDone:true |
|
237 | 428 |
|
429 |
! |
|
430 |
||
431 |
inBoxWithLabel:aLabel text:text abortable:abortable view:additionalView closeWhenDone:closeWhenDoneBoolean |
|
432 |
"create a topView containing an instance of myself, |
|
433 |
for later use with #showProgressOf:" |
|
434 |
||
435 |
^ self |
|
634 | 436 |
inBoxWithLabel:aLabel |
437 |
icon:nil |
|
438 |
text:text |
|
439 |
abortable:abortable |
|
440 |
view:additionalView |
|
441 |
closeWhenDone:closeWhenDoneBoolean |
|
237 | 442 |
|
62 | 443 |
! ! |
444 |
||
183 | 445 |
!ProgressIndicator methodsFor:'accessing'! |
446 |
||
334 | 447 |
percentage:aNumber |
448 |
"set the percentage" |
|
237 | 449 |
|
183 | 450 |
|newPercentage| |
451 |
||
452 |
newPercentage := ((aNumber max:0) min:100) rounded. |
|
453 |
newPercentage ~~ percentage ifTrue:[ |
|
634 | 454 |
percentage := newPercentage. |
455 |
shown ifTrue:[self invalidate]. |
|
183 | 456 |
] |
334 | 457 |
|
458 |
"Modified: 29.3.1997 / 16:08:00 / cg" |
|
459 |
! ! |
|
460 |
||
461 |
!ProgressIndicator methodsFor:'accessing - behavior'! |
|
462 |
||
463 |
closeTopWhenDone:aBoolean |
|
464 |
"set/clear the close-topView-when-done flag" |
|
465 |
||
466 |
closeTopWhenDone := aBoolean |
|
467 |
||
468 |
"Created: 3.9.1996 / 14:22:03 / cg" |
|
469 |
"Modified: 29.3.1997 / 16:08:19 / cg" |
|
470 |
! |
|
471 |
||
472 |
finishAction:aBlock |
|
473 |
"define an action to be performed when finished" |
|
474 |
||
475 |
finishAction := aBlock |
|
476 |
||
477 |
"Created: 3.9.1996 / 14:15:15 / cg" |
|
478 |
"Modified: 29.3.1997 / 16:08:35 / cg" |
|
479 |
! ! |
|
480 |
||
481 |
!ProgressIndicator methodsFor:'accessing - look'! |
|
482 |
||
826 | 483 |
backgroundColor |
484 |
"return the percentage displays background color" |
|
485 |
||
486 |
^ bgColor |
|
487 |
||
488 |
! |
|
489 |
||
490 |
backgroundColor:aColor |
|
491 |
"set the percentage displays background color" |
|
492 |
||
493 |
aColor ~~ bgColor ifTrue:[ |
|
494 |
bgColor := aColor. |
|
495 |
||
496 |
shown ifTrue:[ |
|
497 |
self invalidate |
|
498 |
] |
|
499 |
]. |
|
500 |
||
501 |
! |
|
502 |
||
335
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
503 |
foregroundColor |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
504 |
"return the percentage displays foreground color" |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
505 |
|
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
506 |
^ fgColor |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
507 |
|
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
508 |
"Created: 29.3.1997 / 16:12:28 / cg" |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
509 |
! |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
510 |
|
334 | 511 |
foregroundColor:aColor |
512 |
"set the percentage displays foreground color" |
|
513 |
||
634 | 514 |
aColor ~~ fgColor ifTrue:[ |
515 |
fgColor := aColor. |
|
516 |
||
517 |
shown ifTrue:[ |
|
518 |
self invalidate |
|
519 |
] |
|
336 | 520 |
]. |
334 | 521 |
|
347 | 522 |
"Modified: 3.4.1997 / 21:14:32 / cg" |
183 | 523 |
! |
524 |
||
335
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
525 |
showPercentage |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
526 |
"return the flag controlling if the percentage is to be shown numerically" |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
527 |
|
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
528 |
^ showPercentage |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
529 |
|
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
530 |
"Created: 29.3.1997 / 16:12:39 / cg" |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
531 |
! |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
532 |
|
183 | 533 |
showPercentage:aBoolean |
334 | 534 |
"set/clear the flag controlling if the percentage is to be shown numerically" |
535 |
||
336 | 536 |
showPercentage := aBoolean. |
537 |
shown ifTrue:[ |
|
634 | 538 |
self invalidate |
336 | 539 |
]. |
334 | 540 |
|
336 | 541 |
"Modified: 29.3.1997 / 16:27:37 / cg" |
183 | 542 |
! ! |
543 |
||
544 |
!ProgressIndicator methodsFor:'change & update'! |
|
545 |
||
546 |
update:aspect with:aParameter from:changedObject |
|
574 | 547 |
"react upon value changes of my model" |
548 |
||
183 | 549 |
(aspect == aspectMsg |
550 |
and:[changedObject == model]) ifTrue:[ |
|
634 | 551 |
self percentage:(model perform:aspectMsg). |
552 |
^ self |
|
183 | 553 |
]. |
554 |
^ super update:aspect with:aParameter from:changedObject |
|
574 | 555 |
|
556 |
"Modified: 22.10.1997 / 21:05:11 / cg" |
|
183 | 557 |
! ! |
558 |
||
559 |
!ProgressIndicator methodsFor:'drawing'! |
|
560 |
||
561 |
redraw |
|
574 | 562 |
"redraw the percentage bar and optional percentage string" |
563 |
||
183 | 564 |
|s rx sx sy sw m w h| |
565 |
||
566 |
m := margin + 1. |
|
567 |
w := width - (m*2). |
|
568 |
h := height - (m*2). |
|
569 |
||
570 |
rx := (w * percentage / 100) rounded. |
|
571 |
||
826 | 572 |
self paint:bgColor. |
183 | 573 |
self fillRectangleX:m y:m width:w height:h. |
574 |
||
575 |
showPercentage ifTrue:[ |
|
826 | 576 |
s := percentage printString , ' %'. |
577 |
sw := font widthOf:s. |
|
578 |
sx := (width - sw) // 2. |
|
579 |
sy := height // 2 + font descent + 2. |
|
347 | 580 |
|
826 | 581 |
rx <= (sx+sw) ifTrue:[ |
582 |
self paint:Color black. |
|
583 |
self displayString:s x:sx y:sy. |
|
584 |
] |
|
183 | 585 |
]. |
586 |
||
587 |
self paint:fgColor. |
|
588 |
self fillRectangleX:m y:m width:rx height:h. |
|
589 |
||
590 |
showPercentage ifTrue:[ |
|
826 | 591 |
rx >= sx ifTrue:[ |
592 |
self clippingRectangle:(m@m corner:rx+1 @ h). |
|
593 |
self paint:Color white. |
|
594 |
self displayString:s x:sx y:sy. |
|
595 |
self clippingRectangle:nil |
|
596 |
] |
|
183 | 597 |
] |
347 | 598 |
|
574 | 599 |
"Modified: 22.10.1997 / 21:05:31 / cg" |
183 | 600 |
! ! |
601 |
||
602 |
!ProgressIndicator methodsFor:'initialization'! |
|
603 |
||
574 | 604 |
initStyle |
605 |
"initialize styleSheet values" |
|
335
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
606 |
|
575 | 607 |
<resource: #style (#'progressIndicator.viewBackground' |
826 | 608 |
#'progressIndicator.foregroundColor')> |
574 | 609 |
|
610 |
super initStyle. |
|
335
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
611 |
|
347 | 612 |
self is3D ifTrue:[ |
826 | 613 |
self level:-1 |
347 | 614 |
]. |
615 |
||
826 | 616 |
bgColor := styleSheet colorAt:'progressIndicator.viewBackground' default:Color white. |
574 | 617 |
fgColor := styleSheet colorAt:'progressIndicator.foregroundColor' default:Color blue. |
335
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
618 |
fgColor := fgColor onDevice:device. |
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
619 |
|
183 | 620 |
showPercentage := true. |
335
6f007bdeae94
resource-tag & access methods.
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
621 |
|
574 | 622 |
! |
623 |
||
624 |
initialize |
|
826 | 625 |
|
574 | 626 |
super initialize. |
826 | 627 |
|
574 | 628 |
percentage := 0. |
629 |
! ! |
|
630 |
||
631 |
!ProgressIndicator methodsFor:'private'! |
|
632 |
||
633 |
connectToTop:top label:label |
|
634 |
connectedTop := top. |
|
635 |
connectedLabel := label |
|
183 | 636 |
! ! |
637 |
||
638 |
!ProgressIndicator methodsFor:'queries'! |
|
639 |
||
640 |
preferredExtent |
|
574 | 641 |
"return my preferred extent" |
642 |
||
334 | 643 |
preferredExtent notNil ifTrue:[ |
634 | 644 |
^ preferredExtent |
334 | 645 |
]. |
183 | 646 |
^ 100 @ (font height + font descent + ((margin + 1) * 2)) |
334 | 647 |
|
574 | 648 |
"Modified: 22.10.1997 / 21:07:17 / cg" |
183 | 649 |
! ! |
650 |
||
62 | 651 |
!ProgressIndicator methodsFor:'showing progress'! |
652 |
||
653 |
showProgressOf:aBlock |
|
654 |
"show progress, while evaluating aBlock. |
|
655 |
If the receiver has been created with inBox, show the |
|
656 |
box centered on the screen. If not, the view is assumed to |
|
657 |
be contained in another view, and no special startup actions |
|
658 |
are performed. |
|
659 |
||
660 |
The block is passed two arguments, the progressValue, |
|
661 |
which should be set to the percentage from time-to-time |
|
662 |
within the block and an action value, which should be set to |
|
663 |
the currently performed action (a string) from time to time. |
|
664 |
The second valueHolder can be left unchanged. |
|
665 |
||
666 |
Caveat: cannot (currently) suppress close of the box ..." |
|
667 |
||
221 | 668 |
|progressValue labelValue p| |
62 | 669 |
|
670 |
progressValue := 0 asValue. |
|
671 |
labelValue := '' asValue. |
|
672 |
||
673 |
connectedLabel notNil ifTrue:[ |
|
634 | 674 |
connectedLabel |
675 |
model:labelValue; |
|
676 |
aspect:#value; |
|
677 |
labelMessage:#value. |
|
62 | 678 |
]. |
679 |
||
680 |
self model:progressValue. |
|
681 |
||
221 | 682 |
"/ the worker process |
683 |
||
62 | 684 |
p := [ |
634 | 685 |
[ |
686 |
WindowGroup windowGroupQuerySignal handle:[:ex | |
|
687 |
ex proceedWith:self topView windowGroup |
|
688 |
] do:[ |
|
689 |
aBlock value:progressValue value:labelValue |
|
690 |
] |
|
691 |
] valueNowOrOnUnwindDo:[ |
|
692 |
p := nil. |
|
693 |
closeTopWhenDone ifTrue:[ |
|
694 |
connectedTop hide |
|
695 |
]. |
|
696 |
finishAction notNil ifTrue:[ |
|
697 |
finishAction value |
|
698 |
] |
|
699 |
] |
|
62 | 700 |
] fork. |
701 |
||
237 | 702 |
Processor activeProcess |
634 | 703 |
withPriority:(Processor activePriority + 1) |
704 |
do:[ |
|
705 |
self topView show. |
|
706 |
]. |
|
237 | 707 |
p notNil ifTrue:[p terminate]. |
62 | 708 |
|
709 |
" |
|
710 |
|p| |
|
711 |
||
712 |
p := ProgressIndicator inBox. |
|
713 |
p showProgressOf: |
|
634 | 714 |
[:progressValue :currentAction | |
715 |
1 to:100 do:[:percent | |
|
716 |
(Delay forSeconds:0.05) wait. |
|
717 |
progressValue value:percent |
|
718 |
]. |
|
719 |
]. |
|
62 | 720 |
|
721 |
'it can be reused ...'. |
|
722 |
p showProgressOf: |
|
634 | 723 |
[:progressValue :currentAction | |
724 |
1 to:100 by:5 do:[:percent | |
|
725 |
(Delay forSeconds:0.05) wait. |
|
726 |
progressValue value:percent |
|
727 |
]. |
|
728 |
]. |
|
62 | 729 |
|
730 |
" |
|
219
44246b9b4288
use new windowGroupQuery for background process
Claus Gittinger <cg@exept.de>
parents:
201
diff
changeset
|
731 |
|
237 | 732 |
"Modified: 3.9.1996 / 14:22:43 / cg" |
62 | 733 |
! ! |
734 |
||
334 | 735 |
!ProgressIndicator class methodsFor:'documentation'! |
50 | 736 |
|
183 | 737 |
version |
826 | 738 |
^ '$Header: /cvs/stx/stx/libwidg2/ProgressIndicator.st,v 1.19 1998-03-30 12:27:33 tz Exp $' |
50 | 739 |
! ! |