BlockValue.st
author Claus Gittinger <cg@exept.de>
Sat, 27 Apr 1996 19:59:26 +0200
changeset 231 2fec6188bd28
parent 223 b65dc250db8d
child 268 1998023f12dc
permissions -rw-r--r--
examples
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
     3
	      All Rights Reserved
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
ValueModel subclass:#BlockValue
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:'cachedValue arguments block'
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
    16
	classVariableNames:'NeverComputed'
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Interface-Support-Models'
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!BlockValue class methodsFor:'documentation'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
copyright
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
 COPYRIGHT (c) 1995 by Claus Gittinger
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    26
	      All Rights Reserved
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 This software is furnished under a license and may be used
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 only in accordance with the terms of that license and with the
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 be provided or otherwise made available to, or used by, any
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 other person.  No title to or ownership of the software is
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 hereby transferred.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
documentation
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
    BlockValues depend on multiple other objects (typically valueHolders)
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    and recompute a value whenever one of them changes.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    If the new value is different, it triggers itself a change to its dependents.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    Example use is to base an enableChannels value on multiple other boolean values.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    (See example for how this is done)
223
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 158
diff changeset
    46
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    47
    Notice: 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    48
        this class was implemented using protocol information
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    49
        from alpha testers - it may not be complete or compatible to
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    50
        the corresponding ST-80 class. 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    51
        If you encounter any incompatibilities, please forward a note 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    52
        describing the incompatibility verbal (i.e. no code) to the ST/X team.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    53
223
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 158
diff changeset
    54
    [author:]
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 158
diff changeset
    55
        Claus Gittinger
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
examples
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
"
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    62
    checkToggle 3 shows the value of toggle1 AND toggle2
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    63
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    64
        |val1 val2 both box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    65
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    66
        val1 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    67
        val2 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    68
        both := BlockValue 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    69
                    with:[:v1 :v2 | 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    70
                            Transcript showCr:'evaluating ...'.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    71
                            v1 value and:[v2 value]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    72
                         ] 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    73
                    arguments:(Array with:val1 with:val2).
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    74
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    75
        box := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    76
        box addCheckBox:'one' on:val1.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    77
        box addCheckBox:'two' on:val2.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    78
        box addHorizontalLine.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    79
        box addCheckBox:'both' on:both.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    80
        box open
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    81
                                                                        [exEnd]
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    82
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    83
    the same, using a convenient instance creation message:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    84
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    85
        |val1 val2 both box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    86
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    87
        val1 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    88
        val2 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    89
        both := BlockValue forLogical:val1 and:val2.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    91
        box := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    92
        box addCheckBox:'one' on:val1.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    93
        box addCheckBox:'two' on:val2.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    94
        box addHorizontalLine.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    95
        box addCheckBox:'both' on:both.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    96
        box open
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    97
                                                                        [exEnd]
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    98
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    99
    logical or:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   100
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   101
        |val1 val2 both box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   102
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   103
        val1 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   104
        val2 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   105
        both := BlockValue forLogical:val1 or:val2.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   107
        box := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   108
        box addCheckBox:'one' on:val1.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   109
        box addCheckBox:'two' on:val2.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   110
        box addHorizontalLine.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   111
        box addCheckBox:'both' on:both.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   112
        box open
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   113
                                                                        [exEnd]
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   114
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   115
    example use: enabling an element depending on two others:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   116
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   117
        |val1 val2 enabler val3 box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   118
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   119
        val1 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   120
        val2 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   121
        val3 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   122
        enabler := BlockValue forLogical:val1 and:val2.
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   123
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   124
        box := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   125
        box addCheckBox:'one' on:val1.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   126
        box addCheckBox:'two' on:val2.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   127
        box addHorizontalLine.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   128
        (box addCheckBox:'three' on:val3) enableChannel:enabler.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   129
        box open
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   130
                                                                        [exEnd]
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   134
!BlockValue class methodsFor:'initialization'!
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   135
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   136
initialize
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   137
    NeverComputed isNil ifTrue:[
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   138
	NeverComputed := Object new.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   139
    ]
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   140
! !
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   141
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
!BlockValue class methodsFor:'instance creation'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   144
forLogical:arg1 and:arg2
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   145
    "return a new BlockValue computing the logical AND of its args"
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   146
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   147
    ^ (super new) 
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   148
	setBlock:[:a :b | a value and:[b value]]
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   149
	arguments:(Array with:arg1 with:arg2) 
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   150
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   151
    "Created: 16.12.1995 / 19:20:14 / cg"
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   152
!
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   153
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   154
forLogical:arg1 or:arg2
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   155
    "return a new BlockValue computing the logical OR of its args"
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   156
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   157
    ^ (super new) 
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   158
	setBlock:[:a :b | a value or:[b value]]
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   159
	arguments:(Array with:arg1 with:arg2) 
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   160
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   161
    "Created: 16.12.1995 / 19:20:14 / cg"
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   162
!
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   163
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
with:aBlock
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
    "return a new BlockValue computing aBlock"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
    ^ (super new) setBlock:aBlock
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
    "Created: 16.12.1995 / 19:16:33 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   172
with:aBlock argument:anArgument
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   173
    "return a new BlockValue computing aBlock"
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   174
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   175
    ^ (super new) setBlock:aBlock arguments:(Array with:anArgument)
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   176
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   177
    "Created: 16.12.1995 / 19:20:14 / cg"
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   178
!
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   179
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
with:aBlock arguments:aCollectionOfArguments
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
    "return a new BlockValue computing aBlock"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
    ^ (super new) setBlock:aBlock arguments:aCollectionOfArguments
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
    "Created: 16.12.1995 / 19:20:14 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
!BlockValue methodsFor:'accessing'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
dependOn:someObject
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    arguments isNil ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   192
	arguments := Array with:someObject
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
    ] ifFalse:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   194
	arguments := arguments copyWith:someObject
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
    someObject addDependent:self
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    "Modified: 16.12.1995 / 19:18:31 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
evaluate
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
    arguments isNil ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   203
	^ block value
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
    ^ block valueWithArguments:(arguments asArray)
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
    "Created: 16.12.1995 / 19:27:40 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
setBlock:aBlock
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
    block := aBlock.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    arguments notNil ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   213
	self release
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
    arguments := nil.
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   216
    cachedValue := NeverComputed.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
    "Created: 16.12.1995 / 19:16:59 / cg"
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   219
    "Modified: 16.12.1995 / 19:51:23 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
setBlock:aBlock arguments:aCollectionOfArguments
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    block := aBlock.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    arguments notNil ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   225
	self release
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
    arguments := aCollectionOfArguments.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    arguments do:[:arg |
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   229
	arg addDependent:self
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    ].
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   231
    cachedValue := NeverComputed.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
    "Created: 16.12.1995 / 19:21:41 / cg"
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   234
    "Modified: 16.12.1995 / 19:51:28 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   237
setValue:newValue 
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   238
    "physically set my value, without change notifications.
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   239
     This is a noop here, since my value is computed."
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   240
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   241
    ^ self
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   242
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   243
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   244
!
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   245
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
value
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   247
    cachedValue == NeverComputed ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   248
	cachedValue := self evaluate
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   249
    ].
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
    ^ cachedValue
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
    "Created: 16.12.1995 / 19:23:26 / cg"
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   253
    "Modified: 17.12.1995 / 15:59:16 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
!BlockValue methodsFor:'change and update'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
update:something with:aParameter from:someone
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
    |oldValue|
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    oldValue := cachedValue.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
    cachedValue := self evaluate.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    oldValue ~~ cachedValue ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   264
	self changed:#value
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
    "Created: 16.12.1995 / 19:22:54 / cg"
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   268
    "Modified: 17.12.1995 / 15:58:56 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
!BlockValue methodsFor:'release'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
release
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
    arguments notNil ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   275
	arguments do:[:arg | arg removeDependent:self].
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
    "Modified: 16.12.1995 / 19:21:11 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
!BlockValue class methodsFor:'documentation'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
version
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   284
    ^ '$Header: /cvs/stx/stx/libview2/BlockValue.st,v 1.6 1996-04-27 17:59:10 cg Exp $'
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
! !
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   286
BlockValue initialize!