author | Claus Gittinger <cg@exept.de> |
Sun, 04 Feb 1996 22:03:27 +0100 | |
changeset 161 | c47f1fd6cf5b |
parent 153 | 0a44627e1712 |
child 163 | 80f4fe3bcc71 |
permissions | -rw-r--r-- |
0 | 1 |
" |
6 | 2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
35 | 3 |
All Rights Reserved |
0 | 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 |
Object subclass:#Model |
|
125 | 14 |
instanceVariableNames:'dependents' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Interface-Support-Models' |
|
0 | 18 |
! |
19 |
||
21 | 20 |
!Model class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
35 | 25 |
All Rights Reserved |
0 | 26 |
|
21 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
0 | 35 |
|
21 | 36 |
documentation |
37 |
" |
|
38 |
Models are things that are presented in views. Instances keep track of |
|
35 | 39 |
which views are dependent of them and inform them of any changes. |
87 | 40 |
Actually the Model class is not really needed; since the dependency |
41 |
mechanism is inherited by Object, you can take any object as a model. |
|
42 |
However, instances of Model (and subclasses) keep the dependents locally |
|
35 | 43 |
in an instance variable; thus speeding up access a bit. |
44 |
||
21 | 45 |
Instance variables: |
87 | 46 |
dependents Collection those objects which depend on me. |
47 |
To save some storage, the dependent is |
|
48 |
kept directly here, IFF there os only one. |
|
49 |
Otherwise, a collection of dependents is |
|
50 |
held here. |
|
21 | 51 |
" |
125 | 52 |
! ! |
53 |
||
54 |
!Model methodsFor:'copying'! |
|
55 |
||
56 |
postCopy |
|
57 |
"release dependents after copying" |
|
58 |
||
59 |
self dependents:nil |
|
21 | 60 |
! ! |
0 | 61 |
|
83 | 62 |
!Model methodsFor:'dependents access'! |
0 | 63 |
|
83 | 64 |
addDependent:anObject |
65 |
"make the argument, anObject be a dependent of the receiver" |
|
66 |
||
67 |
|deps| |
|
68 |
||
69 |
deps := dependents. |
|
153
0a44627e1712
oops - did not like Id'Dicts as dependents ...
Claus Gittinger <cg@exept.de>
parents:
129
diff
changeset
|
70 |
(deps isNil and:[anObject isCollection not]) ifTrue:[ |
83 | 71 |
dependents := anObject |
72 |
] ifFalse:[ |
|
153
0a44627e1712
oops - did not like Id'Dicts as dependents ...
Claus Gittinger <cg@exept.de>
parents:
129
diff
changeset
|
73 |
deps isCollection ifTrue:[ |
83 | 74 |
deps add:anObject |
75 |
] ifFalse:[ |
|
76 |
dependents := IdentitySet with:dependents with:anObject |
|
77 |
] |
|
78 |
] |
|
79 |
! |
|
80 |
||
125 | 81 |
dependents |
82 |
"return a Collection of dependents - nil if there is none" |
|
83 |
||
84 |
^ dependents |
|
85 |
! |
|
86 |
||
87 |
dependents:aCollection |
|
88 |
"set the collection of dependents" |
|
89 |
||
90 |
dependents := aCollection |
|
91 |
! |
|
92 |
||
83 | 93 |
dependentsDo:aBlock |
94 |
"evaluate aBlock for all of my dependents" |
|
95 |
||
96 |
|deps| |
|
97 |
||
98 |
deps := dependents. |
|
99 |
deps notNil ifTrue:[ |
|
153
0a44627e1712
oops - did not like Id'Dicts as dependents ...
Claus Gittinger <cg@exept.de>
parents:
129
diff
changeset
|
100 |
deps isCollection ifTrue:[ |
83 | 101 |
deps do:aBlock |
102 |
] ifFalse:[ |
|
103 |
aBlock value:deps |
|
104 |
] |
|
105 |
] |
|
106 |
! |
|
107 |
||
125 | 108 |
release |
109 |
dependents := nil |
|
110 |
! |
|
111 |
||
83 | 112 |
removeDependent:anObject |
113 |
"make the argument, anObject be independent of the receiver" |
|
114 |
||
115 |
|deps sz| |
|
116 |
||
117 |
deps := dependents. |
|
118 |
deps notNil ifTrue:[ |
|
153
0a44627e1712
oops - did not like Id'Dicts as dependents ...
Claus Gittinger <cg@exept.de>
parents:
129
diff
changeset
|
119 |
deps isCollection ifTrue:[ |
83 | 120 |
deps remove:anObject ifAbsent:[]. |
153
0a44627e1712
oops - did not like Id'Dicts as dependents ...
Claus Gittinger <cg@exept.de>
parents:
129
diff
changeset
|
121 |
(sz := deps size) == 0 ifTrue:[ |
0a44627e1712
oops - did not like Id'Dicts as dependents ...
Claus Gittinger <cg@exept.de>
parents:
129
diff
changeset
|
122 |
dependents := nil |
83 | 123 |
] |
124 |
] ifFalse:[ |
|
125 |
dependents := nil |
|
126 |
] |
|
127 |
] |
|
0 | 128 |
! ! |
129 |
||
125 | 130 |
!Model methodsFor:'drawing'! |
28 | 131 |
|
125 | 132 |
displayOn:aGraphicsContext |
133 |
"display myself in aGraphicsContext" |
|
28 | 134 |
|
125 | 135 |
^ self subclassResponsibility |
136 |
! |
|
0 | 137 |
|
138 |
displayOn:aGraphicsContext clippingBox:aRectangle |
|
139 |
"display a part of me in aGraphicsContext" |
|
140 |
||
141 |
^ self subclassResponsibility |
|
125 | 142 |
! ! |
0 | 143 |
|
129 | 144 |
!Model class methodsFor:'documentation'! |
145 |
||
146 |
version |
|
153
0a44627e1712
oops - did not like Id'Dicts as dependents ...
Claus Gittinger <cg@exept.de>
parents:
129
diff
changeset
|
147 |
^ '$Header: /cvs/stx/stx/libview2/Model.st,v 1.18 1996-01-15 17:37:08 cg Exp $' |
129 | 148 |
! ! |