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