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