author | Claus Gittinger <cg@exept.de> |
Thu, 27 Jun 2019 15:21:18 +0200 | |
changeset 24377 | 2fbcb2fa6c43 |
parent 21546 | a0d2c61004a7 |
child 24387 | 93437c789d8a |
permissions | -rw-r--r-- |
5272 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by Claus Gittinger / eXept Software AG |
|
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 |
" |
|
6056 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
21546 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1074 | 16 |
Object subclass:#InterestConverter |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
17 |
instanceVariableNames:'destination selector aspect' |
1074 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
20 |
category:'Interface-Support-Models' |
|
21 |
! |
|
22 |
||
23 |
!InterestConverter class methodsFor:'documentation'! |
|
24 |
||
5272 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1996 by Claus Gittinger / eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
||
38 |
! |
|
39 |
||
1074 | 40 |
documentation |
41 |
" |
|
42 |
instances convert update messages into messages as setup via |
|
8436 | 43 |
#onChangeSend:to:. |
1074 | 44 |
This is a temporary kludge and will be replaced by a more intelligent |
45 |
DependencyCollection class in the future. |
|
1291 | 46 |
|
47 |
[author:] |
|
48 |
Claus Gittinger |
|
1074 | 49 |
" |
50 |
! |
|
51 |
||
52 |
examples |
|
53 |
" |
|
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
54 |
#onChangeSend:to / #retractInterestsIn: |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
55 |
interested in any change: |
1315 | 56 |
[exBegin] |
1074 | 57 |
|p b| |
58 |
||
1422 | 59 |
b := [Transcript showCR:'--> notification: point has changed']. |
1074 | 60 |
|
61 |
p := Point new. |
|
62 |
p onChangeSend:#value to:b. |
|
63 |
Delay waitForSeconds:1. |
|
1422 | 64 |
Transcript showCR:'sending change ...'. |
1074 | 65 |
p changed. |
2716 | 66 |
Transcript showCR:'retracting ...'. |
1074 | 67 |
p retractInterestsFor:b. |
68 |
Delay waitForSeconds:1. |
|
1422 | 69 |
Transcript showCR:'sending change ...'. |
1074 | 70 |
p changed. |
1315 | 71 |
[exEnd] |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
72 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
73 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
74 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
75 |
#expressInterestIn:for:sendBack / #retractInterestIn:for: |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
76 |
interested in a specific change: |
1315 | 77 |
[exBegin] |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
78 |
|p b| |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
79 |
|
1422 | 80 |
b := [Transcript showCR:'the point changed']. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
81 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
82 |
p := Point new. |
1422 | 83 |
Transcript showCR:'interest in #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
84 |
p expressInterestIn:#foo for:b sendBack:#value. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
85 |
p x:1. |
1422 | 86 |
Transcript showCR:'now changing #bar'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
87 |
p changed:#bar. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
88 |
Transcript cr. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
89 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
90 |
Delay waitForSeconds:1. |
1422 | 91 |
Transcript showCR:'now changing #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
92 |
p changed:#foo. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
93 |
Transcript cr. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
94 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
95 |
Delay waitForSeconds:1. |
1422 | 96 |
Transcript showCR:'no more interest in #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
97 |
p retractInterestIn:#foo for:b. |
1422 | 98 |
Transcript showCR:'now changing #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
99 |
p changed:#foo. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
100 |
Transcript cr. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
101 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
102 |
Delay waitForSeconds:1. |
1422 | 103 |
Transcript showCR:'interest in #bar now'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
104 |
p expressInterestIn:#bar for:b sendBack:#value. |
1422 | 105 |
Transcript showCR:'now changing #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
106 |
p changed:#foo. |
1422 | 107 |
Transcript showCR:'now changing #bar'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
108 |
p changed:#bar. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
109 |
Transcript cr. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
110 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
111 |
Delay waitForSeconds:1. |
1422 | 112 |
Transcript showCR:'interest in #foo now'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
113 |
p expressInterestIn:#foo for:b sendBack:#value. |
1422 | 114 |
Transcript showCR:'now changing #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
115 |
p changed:#foo. |
1422 | 116 |
Transcript showCR:'now changing #bar'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
117 |
p changed:#bar. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
118 |
Transcript cr. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
119 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
120 |
Delay waitForSeconds:1. |
1422 | 121 |
Transcript showCR:'no more interests'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
122 |
p retractInterestsFor:b. |
1422 | 123 |
Transcript showCR:'now changing #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
124 |
p changed:#foo. |
1422 | 125 |
Transcript showCR:'now changing #bar'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
126 |
p changed:#bar. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
127 |
Transcript cr. |
1315 | 128 |
[exEnd] |
1074 | 129 |
" |
130 |
! ! |
|
131 |
||
132 |
!InterestConverter class methodsFor:'instance creation'! |
|
133 |
||
134 |
destination:anObject selector:aSelector |
|
2717 | 135 |
"create & return an interestConverter, which sends aSelector |
136 |
to anObject when a change notification arrives" |
|
137 |
||
1074 | 138 |
^ self basicNew destination:anObject selector:aSelector |
2717 | 139 |
|
140 |
"Modified: 21.5.1997 / 11:59:08 / cg" |
|
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
141 |
! |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
142 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
143 |
destination:anObject selector:aSelector aspect:aspect |
2717 | 144 |
"create & return an interestConverter, which sends aSelector |
145 |
to anObject when a change notification for aspect arrives" |
|
146 |
||
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
147 |
^ self basicNew destination:anObject selector:aSelector aspect:aspect |
2717 | 148 |
|
149 |
"Modified: 21.5.1997 / 11:59:26 / cg" |
|
1074 | 150 |
! ! |
151 |
||
152 |
!InterestConverter methodsFor:'accessing'! |
|
153 |
||
2717 | 154 |
aspect |
155 |
"return my aspect (if any)" |
|
156 |
||
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
157 |
^ aspect |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
158 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
159 |
"Created: 8.3.1996 / 23:00:37 / cg" |
2717 | 160 |
"Modified: 21.5.1997 / 11:59:43 / cg" |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
161 |
! |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
162 |
|
1074 | 163 |
destination |
164 |
^ destination |
|
165 |
||
166 |
"Created: 7.3.1996 / 10:57:01 / cg" |
|
167 |
! |
|
168 |
||
169 |
destination:dest selector:sel |
|
170 |
destination := dest. |
|
171 |
selector := sel |
|
172 |
||
173 |
"Created: 7.3.1996 / 10:49:13 / cg" |
|
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
174 |
! |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
175 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
176 |
destination:dest selector:sel aspect:a |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
177 |
destination := dest. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
178 |
selector := sel. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
179 |
aspect := a |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
180 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
181 |
"Created: 8.3.1996 / 22:42:03 / cg" |
7347 | 182 |
! |
183 |
||
184 |
selector |
|
185 |
^ selector |
|
186 |
||
187 |
"Created: 7.3.1996 / 10:57:01 / cg" |
|
1074 | 188 |
! ! |
189 |
||
190 |
!InterestConverter methodsFor:'change & update'! |
|
191 |
||
192 |
update:something with:aParameter from:someObject |
|
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
193 |
(aspect isNil or:[aspect == something]) ifTrue:[ |
11715
03f0d5aee2fd
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
9281
diff
changeset
|
194 |
(selector numArgs) == 0 ifTrue:[ |
03f0d5aee2fd
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
9281
diff
changeset
|
195 |
destination perform:selector |
03f0d5aee2fd
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
9281
diff
changeset
|
196 |
] ifFalse:[ |
11737
cbf8d519c784
update:with:from: - up to 3 arguments into block
Claus Gittinger <cg@exept.de>
parents:
11715
diff
changeset
|
197 |
destination perform:selector withOptionalArgument:something and:aParameter and:someObject |
11715
03f0d5aee2fd
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
9281
diff
changeset
|
198 |
] |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
199 |
] |
1074 | 200 |
|
201 |
"Created: 7.3.1996 / 10:14:30 / cg" |
|
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
202 |
"Modified: 8.3.1996 / 22:41:53 / cg" |
1074 | 203 |
! ! |
204 |
||
21546 | 205 |
!InterestConverter methodsFor:'printing & storing'! |
6056 | 206 |
|
14286
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
207 |
displayOn:aGCOrStream |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
208 |
"Compatibility |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
209 |
append a printed desription on some stream (Dolphin, Squeak) |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
210 |
OR: |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
211 |
display the receiver in a graphicsContext at 0@0 (ST80). |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
212 |
This method allows for any object to be displayed in some view |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
213 |
(although the fallBack is to display its printString ...)" |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
214 |
|
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
215 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
21546 | 216 |
"/ old ST80 means: draw-yourself on a GC. |
14286
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
217 |
aGCOrStream isStream ifFalse:[ |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
218 |
^ super displayOn:aGCOrStream. |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
219 |
]. |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
220 |
|
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
221 |
aGCOrStream |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
222 |
nextPutAll:self class name; |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
223 |
nextPutAll:'(sending '. |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
224 |
|
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
225 |
selector storeOn:aGCOrStream. |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
226 |
aGCOrStream nextPutAll:' to '. |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
227 |
destination printOn:aGCOrStream. |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
228 |
aGCOrStream nextPut:$). |
21546 | 229 |
|
230 |
"Modified (comment): / 22-02-2017 / 16:48:30 / cg" |
|
6056 | 231 |
! ! |
232 |
||
9281 | 233 |
!InterestConverter methodsFor:'testing'! |
234 |
||
235 |
isInterestConverter |
|
236 |
^ true |
|
237 |
! ! |
|
238 |
||
1074 | 239 |
!InterestConverter class methodsFor:'documentation'! |
240 |
||
241 |
version |
|
21546 | 242 |
^ '$Header$' |
1074 | 243 |
! ! |
21546 | 244 |