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
|
|
14 |
instanceVariableNames:'dependents'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
71
|
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 |
version
|
|
37 |
"
|
99
|
38 |
$Header: /cvs/stx/stx/libview2/Model.st,v 1.14 1995-08-30 17:54:04 claus Exp $
|
21
|
39 |
"
|
|
40 |
!
|
0
|
41 |
|
21
|
42 |
documentation
|
|
43 |
"
|
|
44 |
Models are things that are presented in views. Instances keep track of
|
35
|
45 |
which views are dependent of them and inform them of any changes.
|
87
|
46 |
Actually the Model class is not really needed; since the dependency
|
|
47 |
mechanism is inherited by Object, you can take any object as a model.
|
|
48 |
However, instances of Model (and subclasses) keep the dependents locally
|
35
|
49 |
in an instance variable; thus speeding up access a bit.
|
|
50 |
|
21
|
51 |
Instance variables:
|
87
|
52 |
dependents Collection those objects which depend on me.
|
|
53 |
To save some storage, the dependent is
|
|
54 |
kept directly here, IFF there os only one.
|
|
55 |
Otherwise, a collection of dependents is
|
|
56 |
held here.
|
21
|
57 |
"
|
|
58 |
! !
|
0
|
59 |
|
83
|
60 |
!Model methodsFor:'dependents access'!
|
0
|
61 |
|
|
62 |
dependents
|
|
63 |
"return a Collection of dependents - nil if there is none"
|
|
64 |
|
|
65 |
^ dependents
|
|
66 |
!
|
|
67 |
|
10
|
68 |
dependents:aCollection
|
|
69 |
"set the collection of dependents"
|
0
|
70 |
|
10
|
71 |
dependents := aCollection
|
83
|
72 |
!
|
|
73 |
|
|
74 |
release
|
|
75 |
dependents := nil
|
|
76 |
!
|
|
77 |
|
|
78 |
addDependent:anObject
|
|
79 |
"make the argument, anObject be a dependent of the receiver"
|
|
80 |
|
|
81 |
|deps|
|
|
82 |
|
|
83 |
deps := dependents.
|
|
84 |
deps isNil ifTrue:[
|
|
85 |
dependents := anObject
|
|
86 |
] ifFalse:[
|
|
87 |
(deps isMemberOf:IdentitySet) ifTrue:[
|
|
88 |
deps add:anObject
|
|
89 |
] ifFalse:[
|
|
90 |
dependents := IdentitySet with:dependents with:anObject
|
|
91 |
]
|
|
92 |
]
|
|
93 |
!
|
|
94 |
|
|
95 |
dependentsDo:aBlock
|
|
96 |
"evaluate aBlock for all of my dependents"
|
|
97 |
|
|
98 |
|deps|
|
|
99 |
|
|
100 |
deps := dependents.
|
|
101 |
deps notNil ifTrue:[
|
|
102 |
(deps isMemberOf:IdentitySet) ifTrue:[
|
|
103 |
deps do:aBlock
|
|
104 |
] ifFalse:[
|
|
105 |
aBlock value:deps
|
|
106 |
]
|
|
107 |
]
|
|
108 |
!
|
|
109 |
|
|
110 |
removeDependent:anObject
|
|
111 |
"make the argument, anObject be independent of the receiver"
|
|
112 |
|
|
113 |
|deps sz|
|
|
114 |
|
|
115 |
deps := dependents.
|
|
116 |
deps notNil ifTrue:[
|
|
117 |
(deps isMemberOf:IdentitySet) ifTrue:[
|
|
118 |
deps remove:anObject ifAbsent:[].
|
|
119 |
(sz := deps size) == 1 ifTrue:[
|
|
120 |
dependents := deps first
|
|
121 |
] ifFalse:[
|
|
122 |
(sz == 0) ifTrue:[
|
|
123 |
dependents := nil
|
|
124 |
]
|
|
125 |
]
|
|
126 |
] ifFalse:[
|
|
127 |
dependents := nil
|
|
128 |
]
|
|
129 |
]
|
0
|
130 |
! !
|
|
131 |
|
28
|
132 |
!Model methodsFor:'copying'!
|
|
133 |
|
|
134 |
postCopy
|
|
135 |
"release dependents after copying"
|
|
136 |
|
|
137 |
self dependents:nil
|
|
138 |
! !
|
|
139 |
|
0
|
140 |
!Model methodsFor:'drawing'!
|
|
141 |
|
|
142 |
displayOn:aGraphicsContext clippingBox:aRectangle
|
|
143 |
"display a part of me in aGraphicsContext"
|
|
144 |
|
|
145 |
^ self subclassResponsibility
|
|
146 |
!
|
|
147 |
|
|
148 |
displayOn:aGraphicsContext
|
|
149 |
"display myself in aGraphicsContext"
|
|
150 |
|
|
151 |
^ self subclassResponsibility
|
|
152 |
! !
|