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 |
|
|
20 |
Model comment:'
|
21
|
21 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
35
|
22 |
All Rights Reserved
|
23
|
23 |
|
83
|
24 |
$Header: /cvs/stx/stx/libview2/Model.st,v 1.11 1995-07-02 16:16:44 claus Exp $
|
21
|
25 |
'!
|
0
|
26 |
|
21
|
27 |
!Model class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
35
|
32 |
All Rights Reserved
|
0
|
33 |
|
21
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
0
|
42 |
|
21
|
43 |
version
|
|
44 |
"
|
83
|
45 |
$Header: /cvs/stx/stx/libview2/Model.st,v 1.11 1995-07-02 16:16:44 claus Exp $
|
21
|
46 |
"
|
|
47 |
!
|
0
|
48 |
|
21
|
49 |
documentation
|
|
50 |
"
|
|
51 |
Models are things that are presented in views. Instances keep track of
|
35
|
52 |
which views are dependent of them and inform them of any changes.
|
|
53 |
Actually the Model class is not really needed - you can take any object
|
|
54 |
as a model - however instances of Model (and subclasses) keep the dependents
|
|
55 |
in an instance variable; thus speeding up access a bit.
|
|
56 |
|
21
|
57 |
They should know how to display myself in a GraphicsContext.
|
|
58 |
This was written to be more ST-80 conform.
|
|
59 |
|
|
60 |
Instance variables:
|
35
|
61 |
dependents WeakCollection the views depending on me
|
21
|
62 |
"
|
|
63 |
! !
|
0
|
64 |
|
83
|
65 |
!Model methodsFor:'dependents access'!
|
0
|
66 |
|
|
67 |
dependents
|
|
68 |
"return a Collection of dependents - nil if there is none"
|
|
69 |
|
|
70 |
^ dependents
|
|
71 |
!
|
|
72 |
|
10
|
73 |
dependents:aCollection
|
|
74 |
"set the collection of dependents"
|
0
|
75 |
|
10
|
76 |
dependents := aCollection
|
83
|
77 |
!
|
|
78 |
|
|
79 |
release
|
|
80 |
dependents := nil
|
|
81 |
!
|
|
82 |
|
|
83 |
addDependent:anObject
|
|
84 |
"make the argument, anObject be a dependent of the receiver"
|
|
85 |
|
|
86 |
|deps|
|
|
87 |
|
|
88 |
deps := dependents.
|
|
89 |
deps isNil ifTrue:[
|
|
90 |
dependents := anObject
|
|
91 |
] ifFalse:[
|
|
92 |
(deps isMemberOf:IdentitySet) ifTrue:[
|
|
93 |
deps add:anObject
|
|
94 |
] ifFalse:[
|
|
95 |
dependents := IdentitySet with:dependents with:anObject
|
|
96 |
]
|
|
97 |
]
|
|
98 |
!
|
|
99 |
|
|
100 |
dependentsDo:aBlock
|
|
101 |
"evaluate aBlock for all of my dependents"
|
|
102 |
|
|
103 |
|deps|
|
|
104 |
|
|
105 |
deps := dependents.
|
|
106 |
deps notNil ifTrue:[
|
|
107 |
(deps isMemberOf:IdentitySet) ifTrue:[
|
|
108 |
deps do:aBlock
|
|
109 |
] ifFalse:[
|
|
110 |
aBlock value:deps
|
|
111 |
]
|
|
112 |
]
|
|
113 |
!
|
|
114 |
|
|
115 |
removeDependent:anObject
|
|
116 |
"make the argument, anObject be independent of the receiver"
|
|
117 |
|
|
118 |
|deps sz|
|
|
119 |
|
|
120 |
deps := dependents.
|
|
121 |
deps notNil ifTrue:[
|
|
122 |
(deps isMemberOf:IdentitySet) ifTrue:[
|
|
123 |
deps remove:anObject ifAbsent:[].
|
|
124 |
(sz := deps size) == 1 ifTrue:[
|
|
125 |
dependents := deps first
|
|
126 |
] ifFalse:[
|
|
127 |
(sz == 0) ifTrue:[
|
|
128 |
dependents := nil
|
|
129 |
]
|
|
130 |
]
|
|
131 |
] ifFalse:[
|
|
132 |
dependents := nil
|
|
133 |
]
|
|
134 |
]
|
0
|
135 |
! !
|
|
136 |
|
28
|
137 |
!Model methodsFor:'copying'!
|
|
138 |
|
|
139 |
postCopy
|
|
140 |
"release dependents after copying"
|
|
141 |
|
|
142 |
self dependents:nil
|
|
143 |
! !
|
|
144 |
|
0
|
145 |
!Model methodsFor:'drawing'!
|
|
146 |
|
|
147 |
displayOn:aGraphicsContext clippingBox:aRectangle
|
|
148 |
"display a part of me in aGraphicsContext"
|
|
149 |
|
|
150 |
^ self subclassResponsibility
|
|
151 |
!
|
|
152 |
|
|
153 |
displayOn:aGraphicsContext
|
|
154 |
"display myself in aGraphicsContext"
|
|
155 |
|
|
156 |
^ self subclassResponsibility
|
|
157 |
! !
|