145
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
|
|
14 |
ValueModel subclass:#BlockValue
|
|
15 |
instanceVariableNames:'cachedValue arguments block'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Interface-Support-Models'
|
|
19 |
!
|
|
20 |
|
|
21 |
!BlockValue class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
|
|
36 |
!
|
|
37 |
|
|
38 |
documentation
|
|
39 |
"
|
|
40 |
BlockValues depend on multiple other objects (typically valueHolders)
|
|
41 |
and recompute a value whenever one of them changes.
|
|
42 |
If the new value is different, it triggers itself a change to its dependents.
|
|
43 |
|
|
44 |
Example use is to base an enableChannels value on multiple other boolean values.
|
|
45 |
(See example for how this is done)
|
|
46 |
"
|
|
47 |
|
|
48 |
!
|
|
49 |
|
|
50 |
examples
|
|
51 |
"
|
|
52 |
|val1 val2 both box|
|
|
53 |
|
|
54 |
val1 := false asValue.
|
|
55 |
val2 := false asValue.
|
|
56 |
both := BlockValue
|
|
57 |
with:[:v1 :v2 |
|
|
58 |
Transcript showCr:'evaluating ...'.
|
|
59 |
v1 value and:[v2 value]
|
|
60 |
]
|
|
61 |
arguments:(Array with:val1 with:val2).
|
|
62 |
|
|
63 |
box := Dialog new.
|
|
64 |
box addCheckBox:'one' on:val1.
|
|
65 |
box addCheckBox:'two' on:val2.
|
|
66 |
box addHorizontalLine.
|
|
67 |
box addCheckBox:'both' on:both.
|
|
68 |
box open
|
|
69 |
"
|
|
70 |
! !
|
|
71 |
|
|
72 |
!BlockValue class methodsFor:'instance creation'!
|
|
73 |
|
|
74 |
with:aBlock
|
|
75 |
"return a new BlockValue computing aBlock"
|
|
76 |
|
|
77 |
^ (super new) setBlock:aBlock
|
|
78 |
|
|
79 |
"Created: 16.12.1995 / 19:16:33 / cg"
|
|
80 |
!
|
|
81 |
|
|
82 |
with:aBlock arguments:aCollectionOfArguments
|
|
83 |
"return a new BlockValue computing aBlock"
|
|
84 |
|
|
85 |
^ (super new) setBlock:aBlock arguments:aCollectionOfArguments
|
|
86 |
|
|
87 |
"Created: 16.12.1995 / 19:20:14 / cg"
|
|
88 |
! !
|
|
89 |
|
|
90 |
!BlockValue methodsFor:'accessing'!
|
|
91 |
|
|
92 |
dependOn:someObject
|
|
93 |
arguments isNil ifTrue:[
|
|
94 |
arguments := Array with:someObject
|
|
95 |
] ifFalse:[
|
|
96 |
arguments := arguments copyWith:someObject
|
|
97 |
].
|
|
98 |
someObject addDependent:self
|
|
99 |
|
|
100 |
"Modified: 16.12.1995 / 19:18:31 / cg"
|
|
101 |
!
|
|
102 |
|
|
103 |
evaluate
|
|
104 |
arguments isNil ifTrue:[
|
|
105 |
^ block value
|
|
106 |
].
|
|
107 |
^ block valueWithArguments:(arguments asArray)
|
|
108 |
|
|
109 |
"Created: 16.12.1995 / 19:27:40 / cg"
|
|
110 |
!
|
|
111 |
|
|
112 |
setBlock:aBlock
|
|
113 |
block := aBlock.
|
|
114 |
arguments notNil ifTrue:[
|
|
115 |
self release
|
|
116 |
].
|
|
117 |
arguments := nil.
|
|
118 |
|
|
119 |
"Created: 16.12.1995 / 19:16:59 / cg"
|
|
120 |
"Modified: 16.12.1995 / 19:21:22 / cg"
|
|
121 |
!
|
|
122 |
|
|
123 |
setBlock:aBlock arguments:aCollectionOfArguments
|
|
124 |
block := aBlock.
|
|
125 |
arguments notNil ifTrue:[
|
|
126 |
self release
|
|
127 |
].
|
|
128 |
arguments := aCollectionOfArguments.
|
|
129 |
arguments do:[:arg |
|
|
130 |
arg addDependent:self
|
|
131 |
].
|
|
132 |
|
|
133 |
"Created: 16.12.1995 / 19:21:41 / cg"
|
|
134 |
"Modified: 16.12.1995 / 19:29:42 / cg"
|
|
135 |
!
|
|
136 |
|
|
137 |
value
|
|
138 |
^ cachedValue
|
|
139 |
|
|
140 |
"Created: 16.12.1995 / 19:23:26 / cg"
|
|
141 |
"Modified: 16.12.1995 / 19:27:50 / cg"
|
|
142 |
! !
|
|
143 |
|
|
144 |
!BlockValue methodsFor:'change and update'!
|
|
145 |
|
|
146 |
update:something with:aParameter from:someone
|
|
147 |
|oldValue|
|
|
148 |
|
|
149 |
oldValue := cachedValue.
|
|
150 |
cachedValue := self evaluate.
|
|
151 |
oldValue ~~ cachedValue ifTrue:[
|
|
152 |
self changed:something with:aParameter
|
|
153 |
].
|
|
154 |
|
|
155 |
"Created: 16.12.1995 / 19:22:54 / cg"
|
|
156 |
"Modified: 16.12.1995 / 19:28:00 / cg"
|
|
157 |
! !
|
|
158 |
|
|
159 |
!BlockValue methodsFor:'release'!
|
|
160 |
|
|
161 |
release
|
|
162 |
arguments notNil ifTrue:[
|
|
163 |
arguments do:[:arg | arg removeDependent:self].
|
|
164 |
].
|
|
165 |
|
|
166 |
"Modified: 16.12.1995 / 19:21:11 / cg"
|
|
167 |
! !
|
|
168 |
|
|
169 |
!BlockValue class methodsFor:'documentation'!
|
|
170 |
|
|
171 |
version
|
|
172 |
^ '$Header: /cvs/stx/stx/libview2/BlockValue.st,v 1.1 1995-12-16 18:36:39 cg Exp $'
|
|
173 |
! !
|