author | Jan Vrany <jan.vrany@labware.com> |
Wed, 22 Mar 2023 13:57:18 +0000 | |
branch | jv |
changeset 25445 | 1623217d2268 |
parent 18011 | deb0c3355881 |
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 |
||
1074 | 14 |
Object subclass:#InterestConverter |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
15 |
instanceVariableNames:'destination selector aspect' |
1074 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-Support-Models' |
|
19 |
! |
|
20 |
||
21 |
!InterestConverter class methodsFor:'documentation'! |
|
22 |
||
5272 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1996 by Claus Gittinger / eXept Software AG |
|
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 |
||
1074 | 38 |
documentation |
39 |
" |
|
40 |
instances convert update messages into messages as setup via |
|
8436 | 41 |
#onChangeSend:to:. |
1074 | 42 |
This is a temporary kludge and will be replaced by a more intelligent |
43 |
DependencyCollection class in the future. |
|
1291 | 44 |
|
45 |
[author:] |
|
46 |
Claus Gittinger |
|
1074 | 47 |
" |
48 |
! |
|
49 |
||
50 |
examples |
|
51 |
" |
|
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
52 |
#onChangeSend:to / #retractInterestsIn: |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
53 |
interested in any change: |
1315 | 54 |
[exBegin] |
1074 | 55 |
|p b| |
56 |
||
1422 | 57 |
b := [Transcript showCR:'--> notification: point has changed']. |
1074 | 58 |
|
59 |
p := Point new. |
|
60 |
p onChangeSend:#value to:b. |
|
61 |
Delay waitForSeconds:1. |
|
1422 | 62 |
Transcript showCR:'sending change ...'. |
1074 | 63 |
p changed. |
2716 | 64 |
Transcript showCR:'retracting ...'. |
1074 | 65 |
p retractInterestsFor:b. |
66 |
Delay waitForSeconds:1. |
|
1422 | 67 |
Transcript showCR:'sending change ...'. |
1074 | 68 |
p changed. |
1315 | 69 |
[exEnd] |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
70 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
71 |
|
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 |
#expressInterestIn:for:sendBack / #retractInterestIn:for: |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
74 |
interested in a specific change: |
1315 | 75 |
[exBegin] |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
76 |
|p b| |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
77 |
|
1422 | 78 |
b := [Transcript showCR:'the point changed']. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
79 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
80 |
p := Point new. |
1422 | 81 |
Transcript showCR:'interest in #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
82 |
p expressInterestIn:#foo for:b sendBack:#value. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
83 |
p x:1. |
1422 | 84 |
Transcript showCR:'now changing #bar'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
85 |
p changed:#bar. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
86 |
Transcript cr. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
87 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
88 |
Delay waitForSeconds:1. |
1422 | 89 |
Transcript showCR:'now changing #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
90 |
p changed:#foo. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
91 |
Transcript cr. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
92 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
93 |
Delay waitForSeconds:1. |
1422 | 94 |
Transcript showCR:'no more interest in #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
95 |
p retractInterestIn:#foo for:b. |
1422 | 96 |
Transcript showCR:'now changing #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
97 |
p changed:#foo. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
98 |
Transcript cr. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
99 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
100 |
Delay waitForSeconds:1. |
1422 | 101 |
Transcript showCR:'interest in #bar now'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
102 |
p expressInterestIn:#bar for:b sendBack:#value. |
1422 | 103 |
Transcript showCR:'now changing #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
104 |
p changed:#foo. |
1422 | 105 |
Transcript showCR:'now changing #bar'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
106 |
p changed:#bar. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
107 |
Transcript cr. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
108 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
109 |
Delay waitForSeconds:1. |
1422 | 110 |
Transcript showCR:'interest in #foo now'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
111 |
p expressInterestIn:#foo for:b sendBack:#value. |
1422 | 112 |
Transcript showCR:'now changing #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
113 |
p changed:#foo. |
1422 | 114 |
Transcript showCR:'now changing #bar'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
115 |
p changed:#bar. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
116 |
Transcript cr. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
117 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
118 |
Delay waitForSeconds:1. |
1422 | 119 |
Transcript showCR:'no more interests'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
120 |
p retractInterestsFor:b. |
1422 | 121 |
Transcript showCR:'now changing #foo'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
122 |
p changed:#foo. |
1422 | 123 |
Transcript showCR:'now changing #bar'. |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
124 |
p changed:#bar. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
125 |
Transcript cr. |
1315 | 126 |
[exEnd] |
1074 | 127 |
" |
128 |
! ! |
|
129 |
||
130 |
!InterestConverter class methodsFor:'instance creation'! |
|
131 |
||
132 |
destination:anObject selector:aSelector |
|
2717 | 133 |
"create & return an interestConverter, which sends aSelector |
134 |
to anObject when a change notification arrives" |
|
135 |
||
1074 | 136 |
^ self basicNew destination:anObject selector:aSelector |
2717 | 137 |
|
138 |
"Modified: 21.5.1997 / 11:59:08 / cg" |
|
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
139 |
! |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
140 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
141 |
destination:anObject selector:aSelector aspect:aspect |
2717 | 142 |
"create & return an interestConverter, which sends aSelector |
143 |
to anObject when a change notification for aspect arrives" |
|
144 |
||
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
145 |
^ self basicNew destination:anObject selector:aSelector aspect:aspect |
2717 | 146 |
|
147 |
"Modified: 21.5.1997 / 11:59:26 / cg" |
|
1074 | 148 |
! ! |
149 |
||
150 |
!InterestConverter methodsFor:'accessing'! |
|
151 |
||
2717 | 152 |
aspect |
153 |
"return my aspect (if any)" |
|
154 |
||
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
155 |
^ aspect |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
156 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
157 |
"Created: 8.3.1996 / 23:00:37 / cg" |
2717 | 158 |
"Modified: 21.5.1997 / 11:59:43 / cg" |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
159 |
! |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
160 |
|
1074 | 161 |
destination |
162 |
^ destination |
|
163 |
||
164 |
"Created: 7.3.1996 / 10:57:01 / cg" |
|
165 |
! |
|
166 |
||
167 |
destination:dest selector:sel |
|
168 |
destination := dest. |
|
169 |
selector := sel |
|
170 |
||
171 |
"Created: 7.3.1996 / 10:49:13 / cg" |
|
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
172 |
! |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
173 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
174 |
destination:dest selector:sel aspect:a |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
175 |
destination := dest. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
176 |
selector := sel. |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
177 |
aspect := a |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
178 |
|
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
179 |
"Created: 8.3.1996 / 22:42:03 / cg" |
7347 | 180 |
! |
181 |
||
182 |
selector |
|
183 |
^ selector |
|
184 |
||
185 |
"Created: 7.3.1996 / 10:57:01 / cg" |
|
1074 | 186 |
! ! |
187 |
||
188 |
!InterestConverter methodsFor:'change & update'! |
|
189 |
||
190 |
update:something with:aParameter from:someObject |
|
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
191 |
(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
|
192 |
(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
|
193 |
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
|
194 |
] ifFalse:[ |
11737
cbf8d519c784
update:with:from: - up to 3 arguments into block
Claus Gittinger <cg@exept.de>
parents:
11715
diff
changeset
|
195 |
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
|
196 |
] |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
197 |
] |
1074 | 198 |
|
199 |
"Created: 7.3.1996 / 10:14:30 / cg" |
|
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1074
diff
changeset
|
200 |
"Modified: 8.3.1996 / 22:41:53 / cg" |
1074 | 201 |
! ! |
202 |
||
6056 | 203 |
!InterestConverter methodsFor:'printing'! |
204 |
||
14286
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
205 |
displayOn:aGCOrStream |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
206 |
"Compatibility |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
207 |
append a printed desription on some stream (Dolphin, Squeak) |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
208 |
OR: |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
209 |
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
|
210 |
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
|
211 |
(although the fallBack is to display its printString ...)" |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
212 |
|
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
213 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
214 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
215 |
aGCOrStream isStream ifFalse:[ |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
216 |
^ super displayOn:aGCOrStream. |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
217 |
]. |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
218 |
|
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
219 |
aGCOrStream |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
220 |
nextPutAll:self class name; |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
221 |
nextPutAll:'(sending '. |
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 |
selector storeOn:aGCOrStream. |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
224 |
aGCOrStream nextPutAll:' to '. |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
225 |
destination printOn:aGCOrStream. |
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
226 |
aGCOrStream nextPut:$). |
6056 | 227 |
! ! |
228 |
||
9281 | 229 |
!InterestConverter methodsFor:'testing'! |
230 |
||
231 |
isInterestConverter |
|
232 |
^ true |
|
233 |
! ! |
|
234 |
||
1074 | 235 |
!InterestConverter class methodsFor:'documentation'! |
236 |
||
237 |
version |
|
14286
2998078bc2aa
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
11737
diff
changeset
|
238 |
^ '$Header: /cvs/stx/stx/libbasic/InterestConverter.st,v 1.16 2012-08-03 15:52:54 stefan Exp $' |
1074 | 239 |
! ! |