ProgressIndicator.st
author Claus Gittinger <cg@exept.de>
Sat, 18 May 1996 13:09:56 +0200
changeset 183 c63a4f284a6d
parent 86 4d7dbb5f1719
child 184 13a2f3677c68
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
62
claus
parents: 50
diff changeset
     1
"
claus
parents: 50
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
claus
parents: 50
diff changeset
     3
	      All Rights Reserved
claus
parents: 50
diff changeset
     4
claus
parents: 50
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents: 50
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents: 50
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents: 50
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents: 50
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents: 50
diff changeset
    10
 hereby transferred.
claus
parents: 50
diff changeset
    11
"
50
claus
parents:
diff changeset
    12
claus
parents:
diff changeset
    13
View subclass:#ProgressIndicator
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    14
	instanceVariableNames:'percentage showPercentage fgColor connectedTop connectedLabel'
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    15
	classVariableNames:''
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    16
	poolDictionaries:''
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    17
	category:'Views-Misc'
50
claus
parents:
diff changeset
    18
!
claus
parents:
diff changeset
    19
claus
parents:
diff changeset
    20
!ProgressIndicator class methodsFor:'documentation'!
claus
parents:
diff changeset
    21
62
claus
parents: 50
diff changeset
    22
copyright
claus
parents: 50
diff changeset
    23
"
claus
parents: 50
diff changeset
    24
 COPYRIGHT (c) 1995 by Claus Gittinger
claus
parents: 50
diff changeset
    25
	      All Rights Reserved
claus
parents: 50
diff changeset
    26
claus
parents: 50
diff changeset
    27
 This software is furnished under a license and may be used
claus
parents: 50
diff changeset
    28
 only in accordance with the terms of that license and with the
claus
parents: 50
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
claus
parents: 50
diff changeset
    30
 be provided or otherwise made available to, or used by, any
claus
parents: 50
diff changeset
    31
 other person.  No title to or ownership of the software is
claus
parents: 50
diff changeset
    32
 hereby transferred.
claus
parents: 50
diff changeset
    33
"
claus
parents: 50
diff changeset
    34
!
claus
parents: 50
diff changeset
    35
50
claus
parents:
diff changeset
    36
documentation
claus
parents:
diff changeset
    37
"
claus
parents:
diff changeset
    38
    a view showing a rectangle filled according the percentage value.
claus
parents:
diff changeset
    39
    Can be used as a progress indicator a la MSwindows.
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    40
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    41
    [author:]
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    42
        Claus Gittinger
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    43
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    44
    [see also:]
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    45
        ActionWaitBox AnimatedLabel
50
claus
parents:
diff changeset
    46
"
claus
parents:
diff changeset
    47
!
claus
parents:
diff changeset
    48
claus
parents:
diff changeset
    49
examples
claus
parents:
diff changeset
    50
"
62
claus
parents: 50
diff changeset
    51
    basic (internal) interface
claus
parents: 50
diff changeset
    52
    (if progress indicator is to be used in a complex box ...):
50
claus
parents:
diff changeset
    53
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    54
    Before you get frustrated - see the convenient-interface examples
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    55
    at the end ;-)
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    56
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    57
                                                                        [exBegin]
50
claus
parents:
diff changeset
    58
      |top p h|
claus
parents:
diff changeset
    59
62
claus
parents: 50
diff changeset
    60
      top := ModalBox new.
50
claus
parents:
diff changeset
    61
      top extent:300@100.
claus
parents:
diff changeset
    62
      top label:'Progress'.
claus
parents:
diff changeset
    63
      p := ProgressIndicator in:top.
claus
parents:
diff changeset
    64
      p origin:(0.0@0.5) corner:(1.0@0.5).
claus
parents:
diff changeset
    65
      p level:-1.
62
claus
parents: 50
diff changeset
    66
      h := p preferredExtent y.
50
claus
parents:
diff changeset
    67
      p topInset:(h // 2) negated; 
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    68
        bottomInset:(h // 2) negated;
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    69
        leftInset:5;
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    70
        rightInset:5.
50
claus
parents:
diff changeset
    71
claus
parents:
diff changeset
    72
      [
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    73
          1 to:100 do:[:val |
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    74
              (Delay forSeconds:0.05) wait.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    75
              p percentage:val 
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    76
          ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    77
          top hide.
62
claus
parents: 50
diff changeset
    78
      ] fork.
claus
parents: 50
diff changeset
    79
      top open.
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    80
                                                                        [exEnd]
50
claus
parents:
diff changeset
    81
claus
parents:
diff changeset
    82
    changing colors, turning percentage display off:
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    83
                                                                        [exBegin]
50
claus
parents:
diff changeset
    84
      |top p h|
claus
parents:
diff changeset
    85
claus
parents:
diff changeset
    86
      top := StandardSystemView new.
claus
parents:
diff changeset
    87
      top extent:300@100.
claus
parents:
diff changeset
    88
      top label:'Progress'.
claus
parents:
diff changeset
    89
      p := ProgressIndicator in:top.
claus
parents:
diff changeset
    90
      p origin:(0.0@0.5) corner:(1.0@0.5).
claus
parents:
diff changeset
    91
      p level:-1.
claus
parents:
diff changeset
    92
      p showPercentage:false.
claus
parents:
diff changeset
    93
      p foregroundColor:(Color red).
claus
parents:
diff changeset
    94
      h := 10.
claus
parents:
diff changeset
    95
      p topInset:(h // 2) negated; 
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    96
        bottomInset:(h // 2) negated;
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    97
        leftInset:5;
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    98
        rightInset:5.
50
claus
parents:
diff changeset
    99
      top open.
claus
parents:
diff changeset
   100
      [
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   101
          1 to:100 do:[:val |
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   102
              (Delay forSeconds:0.05) wait.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   103
              p percentage:val 
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   104
          ]
50
claus
parents:
diff changeset
   105
      ] fork
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   106
                                                                        [exEnd]
50
claus
parents:
diff changeset
   107
claus
parents:
diff changeset
   108
    with border (2D look):
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   109
                                                                        [exBegin]
50
claus
parents:
diff changeset
   110
      |top p h|
claus
parents:
diff changeset
   111
claus
parents:
diff changeset
   112
      top := StandardSystemView new.
claus
parents:
diff changeset
   113
      top extent:300@100.
claus
parents:
diff changeset
   114
      top label:'Progress'.
claus
parents:
diff changeset
   115
      p := ProgressIndicator in:top.
claus
parents:
diff changeset
   116
      p origin:(0.0@0.5) corner:(1.0@0.5).
claus
parents:
diff changeset
   117
      p borderWidth:1.
62
claus
parents: 50
diff changeset
   118
      h := p preferredExtent y.
50
claus
parents:
diff changeset
   119
      p topInset:(h // 2) negated; 
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   120
        bottomInset:(h // 2) negated;
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   121
        leftInset:5;
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   122
        rightInset:5.
50
claus
parents:
diff changeset
   123
      top open.
claus
parents:
diff changeset
   124
      [
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   125
          1 to:100 do:[:val |
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   126
              (Delay forSeconds:0.05) wait.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   127
              p percentage:val 
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   128
          ]
50
claus
parents:
diff changeset
   129
      ] fork
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   130
                                                                        [exEnd]
50
claus
parents:
diff changeset
   131
claus
parents:
diff changeset
   132
claus
parents:
diff changeset
   133
    getting progress from a model:
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   134
                                                                        [exBegin]
50
claus
parents:
diff changeset
   135
      |model top p h|
claus
parents:
diff changeset
   136
claus
parents:
diff changeset
   137
      model := 0 asValue.
claus
parents:
diff changeset
   138
claus
parents:
diff changeset
   139
      top := StandardSystemView new.
claus
parents:
diff changeset
   140
      top extent:300@100.
claus
parents:
diff changeset
   141
      top label:'Progress'.
claus
parents:
diff changeset
   142
      p := ProgressIndicator in:top.
claus
parents:
diff changeset
   143
      p model:model.
claus
parents:
diff changeset
   144
      p origin:(0.0@0.5) corner:(1.0@0.5).
claus
parents:
diff changeset
   145
      p level:-1.
62
claus
parents: 50
diff changeset
   146
      h := p preferredExtent y.
50
claus
parents:
diff changeset
   147
      p topInset:(h // 2) negated; 
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   148
        bottomInset:(h // 2) negated;
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   149
        leftInset:5;
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   150
        rightInset:5.
50
claus
parents:
diff changeset
   151
      top open.
claus
parents:
diff changeset
   152
claus
parents:
diff changeset
   153
      [
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   154
          1 to:100 do:[:val |
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   155
              (Delay forSeconds:0.05) wait.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   156
              model value:val 
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   157
          ]
50
claus
parents:
diff changeset
   158
      ] fork
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   159
                                                                        [exEnd]
50
claus
parents:
diff changeset
   160
62
claus
parents: 50
diff changeset
   161
50
claus
parents:
diff changeset
   162
    concrete example:
claus
parents:
diff changeset
   163
      search all files in the source directory for a string
claus
parents:
diff changeset
   164
      using grep. Show progress while doing so.
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   165
                                                                        [exBegin]
50
claus
parents:
diff changeset
   166
      |top p h names done|
claus
parents:
diff changeset
   167
claus
parents:
diff changeset
   168
      top := StandardSystemView new.
claus
parents:
diff changeset
   169
      top extent:300@100.
claus
parents:
diff changeset
   170
      top label:'Searching ...'.
claus
parents:
diff changeset
   171
      p := ProgressIndicator in:top.
claus
parents:
diff changeset
   172
      p origin:(0.0@0.5) corner:(1.0@0.5).
claus
parents:
diff changeset
   173
      p level:-1.
62
claus
parents: 50
diff changeset
   174
      h := p preferredExtent y.
50
claus
parents:
diff changeset
   175
      p topInset:(h // 2) negated; 
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   176
        bottomInset:(h // 2) negated;
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   177
        leftInset:5;
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   178
        rightInset:5.
50
claus
parents:
diff changeset
   179
      top openWithPriority:(Processor activePriority + 1).
claus
parents:
diff changeset
   180
claus
parents:
diff changeset
   181
      names := 'source' asFilename directoryContents.
claus
parents:
diff changeset
   182
      done := 0.
claus
parents:
diff changeset
   183
      names do:[:aName |
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   184
        |fn stream line|
50
claus
parents:
diff changeset
   185
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   186
        p percentage:(done / names size * 100).
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   187
        fn := ('source/' , aName) asFilename.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   188
        fn isDirectory ifFalse:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   189
            stream := fn readStream.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   190
            [stream atEnd] whileFalse:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   191
                line := stream nextLine.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   192
                (line findString:'subclass:') ~~ 0 ifTrue:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   193
                    Transcript showCr:line
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   194
                ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   195
            ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   196
            stream close.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   197
        ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   198
        done := done + 1
50
claus
parents:
diff changeset
   199
      ].
claus
parents:
diff changeset
   200
claus
parents:
diff changeset
   201
      top destroy
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   202
                                                                        [exEnd]
62
claus
parents: 50
diff changeset
   203
claus
parents: 50
diff changeset
   204
claus
parents: 50
diff changeset
   205
   using the convenient inBox-interface
claus
parents: 50
diff changeset
   206
claus
parents: 50
diff changeset
   207
   (this creates a box and an activity label and evaluates a block
claus
parents: 50
diff changeset
   208
    to indicate ...)
claus
parents: 50
diff changeset
   209
claus
parents: 50
diff changeset
   210
    basic interface demonstration:
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   211
                                                                        [exBegin]
62
claus
parents: 50
diff changeset
   212
      |p|
claus
parents: 50
diff changeset
   213
claus
parents: 50
diff changeset
   214
      p := ProgressIndicator 
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   215
                inBoxWithLabel:'doing something  ...'
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   216
                abortable:true.
62
claus
parents: 50
diff changeset
   217
      p showProgressOf:
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   218
            [:progressValue :currentAction |
62
claus
parents: 50
diff changeset
   219
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   220
              1 to:100 do:[:val |
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   221
                  (Delay forSeconds:0.05) wait.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   222
                  val == 25 ifTrue:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   223
                      currentAction value:'still going ...'
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   224
                  ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   225
                  val == 50 ifTrue:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   226
                      currentAction value:'halfway through ...'
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   227
                  ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   228
                  val == 75 ifTrue:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   229
                      currentAction value:'almost finished ...'
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   230
                  ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   231
                  progressValue value:val 
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   232
              ]
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   233
            ]
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   234
                                                                        [exEnd]
62
claus
parents: 50
diff changeset
   235
claus
parents: 50
diff changeset
   236
claus
parents: 50
diff changeset
   237
    above search example using this convenient interface:
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   238
                                                                        [exBegin]
62
claus
parents: 50
diff changeset
   239
      |p|
claus
parents: 50
diff changeset
   240
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   241
      p := ProgressIndicator 
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   242
                inBoxWithLabel:'searching files ...'
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   243
                abortable:false.
62
claus
parents: 50
diff changeset
   244
      p showProgressOf:
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   245
            [:progressValue :currentAction |
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   246
                |names nDone|
62
claus
parents: 50
diff changeset
   247
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   248
                names := 'source' asFilename directoryContents.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   249
                nDone := 0.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   250
                names do:[:aName |
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   251
                  |fn stream line|
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   252
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   253
                  progressValue value:(nDone / names size * 100).
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   254
                  currentAction value:'searching ' , 'source/' , aName , ' ...'.
62
claus
parents: 50
diff changeset
   255
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   256
                  fn := ('source/' , aName) asFilename.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   257
                  fn isDirectory ifFalse:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   258
                      stream := fn readStream.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   259
                      [stream atEnd] whileFalse:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   260
                          line := stream nextLine.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   261
                          (line findString:'subclass:') ~~ 0 ifTrue:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   262
                              Transcript showCr:line
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   263
                          ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   264
                      ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   265
                      stream close.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   266
                  ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   267
                  nDone := nDone + 1
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   268
                ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   269
            ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   270
                                                                        [exEnd]
62
claus
parents: 50
diff changeset
   271
claus
parents: 50
diff changeset
   272
claus
parents: 50
diff changeset
   273
    a nice example: copying files a la windows ...
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   274
    the following copies all files to /dev/null.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   275
                                                                        [exBegin]
62
claus
parents: 50
diff changeset
   276
      |p|
claus
parents: 50
diff changeset
   277
claus
parents: 50
diff changeset
   278
      (ProgressIndicator 
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   279
                inBoxWithLabel:'copy files to /dev/null ...'
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   280
                abortable:true)
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   281
         showProgressOf:
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   282
            [:progressValue :currentAction |
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   283
                |files nFiles nDone|
62
claus
parents: 50
diff changeset
   284
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   285
                files := '.' asFilename directoryContents.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   286
                nFiles := files size.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   287
                nDone := 0.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   288
                files do:[:aFileName |
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   289
                    |percent|
50
claus
parents:
diff changeset
   290
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   291
                    nDone := nDone + 1.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   292
                    percent := nDone / nFiles * 100.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   293
                    progressValue value:percent. 
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   294
                    aFileName asFilename isDirectory ifTrue:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   295
                        Transcript showCr:('skipping ' , aFileName , ' ...'). 
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   296
                        currentAction value:('skipping ' , aFileName , ' ...'). 
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   297
                    ] ifFalse:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   298
                        Transcript showCr:('copying ' , aFileName , ' ...').
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   299
                        currentAction value:('copying ' , aFileName , ' ...').
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   300
                        Object errorSignal handle:[:ex |
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   301
                            self warn:'an error occurred while copying ' , aFileName.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   302
                            ex return
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   303
                        ] do:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   304
                            aFileName asFilename copyTo:'/dev/null'.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   305
                        ]
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   306
                    ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   307
                ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   308
            ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   309
                                                                        [exEnd]
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   310
"
50
claus
parents:
diff changeset
   311
! !
claus
parents:
diff changeset
   312
62
claus
parents: 50
diff changeset
   313
!ProgressIndicator class methodsFor:'instance creation'!
claus
parents: 50
diff changeset
   314
claus
parents: 50
diff changeset
   315
inBox
claus
parents: 50
diff changeset
   316
    ^ self inBoxWithLabel:'executing ...' abortable:false 
claus
parents: 50
diff changeset
   317
!
claus
parents: 50
diff changeset
   318
claus
parents: 50
diff changeset
   319
inBoxWithLabel:aLabel
claus
parents: 50
diff changeset
   320
    "create a topView containing an instance of myself,
claus
parents: 50
diff changeset
   321
     for later use with #showProgressOf:"
claus
parents: 50
diff changeset
   322
claus
parents: 50
diff changeset
   323
    ^ self inBoxWithLabel:aLabel abortable:false 
claus
parents: 50
diff changeset
   324
!
claus
parents: 50
diff changeset
   325
claus
parents: 50
diff changeset
   326
inBoxWithLabel:aLabel abortable:abortable
claus
parents: 50
diff changeset
   327
    "create a topView containing an instance of myself,
claus
parents: 50
diff changeset
   328
     for later use with #showProgressOf:"
claus
parents: 50
diff changeset
   329
claus
parents: 50
diff changeset
   330
    |top p l h|
claus
parents: 50
diff changeset
   331
claus
parents: 50
diff changeset
   332
    top := Dialog new.
claus
parents: 50
diff changeset
   333
    top extent:300@100; sizeFixed:true.
claus
parents: 50
diff changeset
   334
    top label:aLabel.
claus
parents: 50
diff changeset
   335
    top cursor:(Cursor wait).
claus
parents: 50
diff changeset
   336
claus
parents: 50
diff changeset
   337
    l := top addTextLabel:''.
claus
parents: 50
diff changeset
   338
    l borderWidth:0.
74
claus
parents: 62
diff changeset
   339
    l adjust:#left.
62
claus
parents: 50
diff changeset
   340
    l cursor:(Cursor wait).
claus
parents: 50
diff changeset
   341
claus
parents: 50
diff changeset
   342
    top addVerticalSpace.
claus
parents: 50
diff changeset
   343
claus
parents: 50
diff changeset
   344
    p := ProgressIndicator new.
claus
parents: 50
diff changeset
   345
    p extent:(1.0 @ p preferredExtent y).
claus
parents: 50
diff changeset
   346
    p level:-1.
claus
parents: 50
diff changeset
   347
    p leftInset:5;
claus
parents: 50
diff changeset
   348
      rightInset:5.
claus
parents: 50
diff changeset
   349
    p cursor:(Cursor wait).
claus
parents: 50
diff changeset
   350
    p connectToTop:top label:l.
claus
parents: 50
diff changeset
   351
claus
parents: 50
diff changeset
   352
    top addComponent:p.
claus
parents: 50
diff changeset
   353
claus
parents: 50
diff changeset
   354
    abortable ifTrue:[
claus
parents: 50
diff changeset
   355
	top addVerticalSpace.
claus
parents: 50
diff changeset
   356
	top addAbortButton
claus
parents: 50
diff changeset
   357
    ].
claus
parents: 50
diff changeset
   358
claus
parents: 50
diff changeset
   359
    ^ p
claus
parents: 50
diff changeset
   360
! !
claus
parents: 50
diff changeset
   361
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   362
!ProgressIndicator methodsFor:'accessing'!
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   363
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   364
foregroundColor:aColor 
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   365
    fgColor := aColor
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   366
!
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   367
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   368
percentage:aNumber
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   369
    |newPercentage|
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   370
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   371
    newPercentage := ((aNumber max:0) min:100) rounded.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   372
    newPercentage ~~ percentage ifTrue:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   373
	percentage := newPercentage.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   374
	shown ifTrue:[self redraw].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   375
    ]
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   376
!
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   377
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   378
showPercentage:aBoolean
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   379
    showPercentage := aBoolean
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   380
! !
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   381
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   382
!ProgressIndicator methodsFor:'change & update'!
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   383
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   384
update:aspect with:aParameter from:changedObject
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   385
    (aspect == aspectMsg
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   386
    and:[changedObject == model]) ifTrue:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   387
	self percentage:(model perform:aspectMsg).
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   388
	^ self
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   389
    ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   390
    ^ super update:aspect with:aParameter from:changedObject
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   391
! !
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   392
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   393
!ProgressIndicator methodsFor:'drawing'!
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   394
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   395
redraw
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   396
    |s rx sx sy sw m w h|
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   397
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   398
    m := margin + 1.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   399
    w := width - (m*2).
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   400
    h := height - (m*2).
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   401
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   402
    s := percentage printString , ' %'.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   403
    sw := font widthOf:s.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   404
    sx := (width - sw) // 2.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   405
    sy := height // 2 + font descent + 2.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   406
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   407
    rx := (w * percentage / 100) rounded.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   408
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   409
    self paint:Color white.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   410
    self fillRectangleX:m y:m width:w height:h.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   411
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   412
    showPercentage ifTrue:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   413
	rx <= (sx+sw) ifTrue:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   414
	    self paint:Color black.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   415
	    self displayString:s x:sx y:sy.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   416
	]
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   417
    ].
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   418
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   419
    self paint:fgColor.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   420
    self fillRectangleX:m y:m width:rx height:h.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   421
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   422
    showPercentage ifTrue:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   423
	rx >= sx ifTrue:[
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   424
	    self clipRect:(m@m corner:rx+1 @ h).
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   425
	    self paint:Color white.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   426
	    self displayString:s x:sx y:sy.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   427
	    self clipRect:nil
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   428
	]
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   429
    ]
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   430
! !
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   431
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   432
!ProgressIndicator methodsFor:'initialization'!
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   433
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   434
initialize
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   435
    super initialize.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   436
    viewBackground := styleSheet colorAt:'progressIndicatorViewBackground' default:Color white.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   437
    fgColor := styleSheet colorAt:'progressIndicatorForegroundColor' default:Color blue.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   438
    percentage := 0.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   439
    showPercentage := true.
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   440
! !
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   441
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   442
!ProgressIndicator methodsFor:'queries'!
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   443
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   444
preferredExtent
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   445
    ^ 100 @ (font height + font descent + ((margin + 1) * 2))
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   446
! !
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   447
62
claus
parents: 50
diff changeset
   448
!ProgressIndicator methodsFor:'showing progress'!
claus
parents: 50
diff changeset
   449
claus
parents: 50
diff changeset
   450
connectToTop:top label:label
claus
parents: 50
diff changeset
   451
    connectedTop := top.
claus
parents: 50
diff changeset
   452
    connectedLabel := label
claus
parents: 50
diff changeset
   453
!
claus
parents: 50
diff changeset
   454
claus
parents: 50
diff changeset
   455
showProgressOf:aBlock
claus
parents: 50
diff changeset
   456
    "show progress, while evaluating aBlock.
claus
parents: 50
diff changeset
   457
     If the receiver has been created with inBox, show the
claus
parents: 50
diff changeset
   458
     box centered on the screen. If not, the view is assumed to
claus
parents: 50
diff changeset
   459
     be contained in another view, and no special startup actions
claus
parents: 50
diff changeset
   460
     are performed.
claus
parents: 50
diff changeset
   461
claus
parents: 50
diff changeset
   462
     The block is passed two arguments, the progressValue,
claus
parents: 50
diff changeset
   463
     which should be set to the percentage from time-to-time
claus
parents: 50
diff changeset
   464
     within the block and an action value, which should be set to
claus
parents: 50
diff changeset
   465
     the currently performed action (a string) from time to time.
claus
parents: 50
diff changeset
   466
     The second valueHolder can be left unchanged.
claus
parents: 50
diff changeset
   467
claus
parents: 50
diff changeset
   468
     Caveat: cannot (currently) suppress close of the box ..."
claus
parents: 50
diff changeset
   469
claus
parents: 50
diff changeset
   470
    |progressValue labelValue p|
claus
parents: 50
diff changeset
   471
claus
parents: 50
diff changeset
   472
    progressValue := 0 asValue.
claus
parents: 50
diff changeset
   473
    labelValue := '' asValue.
claus
parents: 50
diff changeset
   474
claus
parents: 50
diff changeset
   475
    connectedLabel notNil ifTrue:[
claus
parents: 50
diff changeset
   476
	connectedLabel 
claus
parents: 50
diff changeset
   477
	    model:labelValue;
claus
parents: 50
diff changeset
   478
	    aspect:#value;
claus
parents: 50
diff changeset
   479
	    labelMessage:#value.
claus
parents: 50
diff changeset
   480
    ].
claus
parents: 50
diff changeset
   481
claus
parents: 50
diff changeset
   482
    self model:progressValue.
claus
parents: 50
diff changeset
   483
claus
parents: 50
diff changeset
   484
    p := [
claus
parents: 50
diff changeset
   485
	[
claus
parents: 50
diff changeset
   486
	    aBlock value:progressValue value:labelValue
claus
parents: 50
diff changeset
   487
	] valueNowOrOnUnwindDo:[
claus
parents: 50
diff changeset
   488
	    p := nil.
claus
parents: 50
diff changeset
   489
	    connectedTop notNil ifTrue:[
claus
parents: 50
diff changeset
   490
		connectedTop hide
claus
parents: 50
diff changeset
   491
	    ]
claus
parents: 50
diff changeset
   492
	]
claus
parents: 50
diff changeset
   493
    ] fork.
claus
parents: 50
diff changeset
   494
claus
parents: 50
diff changeset
   495
    connectedTop notNil ifTrue:[
claus
parents: 50
diff changeset
   496
	Processor activeProcess 
claus
parents: 50
diff changeset
   497
	    withPriority:(Processor activePriority + 1)
claus
parents: 50
diff changeset
   498
	    do:[
claus
parents: 50
diff changeset
   499
		self topView show.
claus
parents: 50
diff changeset
   500
	    ].
claus
parents: 50
diff changeset
   501
	p notNil ifTrue:[p terminate].
claus
parents: 50
diff changeset
   502
    ] ifFalse:[
claus
parents: 50
diff changeset
   503
	self halt:'not yet implemented'.
claus
parents: 50
diff changeset
   504
    ]
claus
parents: 50
diff changeset
   505
claus
parents: 50
diff changeset
   506
claus
parents: 50
diff changeset
   507
    "
claus
parents: 50
diff changeset
   508
      |p|
claus
parents: 50
diff changeset
   509
claus
parents: 50
diff changeset
   510
      p := ProgressIndicator inBox.
claus
parents: 50
diff changeset
   511
      p showProgressOf:
claus
parents: 50
diff changeset
   512
	    [:progressValue :currentAction |
claus
parents: 50
diff changeset
   513
		1 to:100 do:[:percent |
claus
parents: 50
diff changeset
   514
		    (Delay forSeconds:0.05) wait.
claus
parents: 50
diff changeset
   515
		    progressValue value:percent 
claus
parents: 50
diff changeset
   516
		].
claus
parents: 50
diff changeset
   517
	    ].
claus
parents: 50
diff changeset
   518
claus
parents: 50
diff changeset
   519
      'it can be reused ...'.  
claus
parents: 50
diff changeset
   520
      p showProgressOf:
claus
parents: 50
diff changeset
   521
	    [:progressValue :currentAction |
claus
parents: 50
diff changeset
   522
		1 to:100 by:5 do:[:percent |
claus
parents: 50
diff changeset
   523
		    (Delay forSeconds:0.05) wait.
claus
parents: 50
diff changeset
   524
		    progressValue value:percent 
claus
parents: 50
diff changeset
   525
		].
claus
parents: 50
diff changeset
   526
	    ].
claus
parents: 50
diff changeset
   527
claus
parents: 50
diff changeset
   528
    "
claus
parents: 50
diff changeset
   529
! !
claus
parents: 50
diff changeset
   530
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   531
!ProgressIndicator class methodsFor:'documentation'!
50
claus
parents:
diff changeset
   532
183
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   533
version
c63a4f284a6d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   534
    ^ '$Header: /cvs/stx/stx/libwidg2/ProgressIndicator.st,v 1.5 1996-05-18 11:09:56 cg Exp $'
50
claus
parents:
diff changeset
   535
! !