1058
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1997 by 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 |
"
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
Object subclass:#ResourceRetriever
|
|
17 |
instanceVariableNames:'className resourceOwner selector labelText'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Interface-Support-UI'
|
|
21 |
!
|
|
22 |
|
|
23 |
ResourceRetriever class instanceVariableNames:'LabelResources'
|
|
24 |
|
|
25 |
"
|
|
26 |
The following class instance variables are inherited by this class:
|
|
27 |
|
|
28 |
Object -
|
|
29 |
"
|
|
30 |
!
|
|
31 |
|
|
32 |
!ResourceRetriever class methodsFor:'documentation'!
|
|
33 |
|
|
34 |
copyright
|
|
35 |
"
|
|
36 |
COPYRIGHT (c) 1997 by eXept Software AG
|
|
37 |
All Rights Reserved
|
|
38 |
|
|
39 |
This software is furnished under a license and may be used
|
|
40 |
only in accordance with the terms of that license and with the
|
|
41 |
inclusion of the above copyright notice. This software may not
|
|
42 |
be provided or otherwise made available to, or used by, any
|
|
43 |
other person. No title to or ownership of the software is
|
|
44 |
hereby transferred.
|
|
45 |
"
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
!
|
|
50 |
|
|
51 |
documentation
|
|
52 |
"
|
|
53 |
ST80 compatibility class.
|
|
54 |
|
|
55 |
The class is not completed yet and certainly not bug free.
|
|
56 |
Also, it is not guaranteed that all winSpecs are understood.
|
|
57 |
|
|
58 |
Notice:
|
|
59 |
this class was implemented using protocol information
|
|
60 |
from alpha testers, literature and by reading public domain code
|
|
61 |
- it may not be complete or compatible to
|
|
62 |
the corresponding ST-80 class.
|
|
63 |
If you encounter any incompatibilities, please forward a note
|
|
64 |
describing the incompatibility verbal (i.e. no code) to the ST/X team.
|
|
65 |
|
|
66 |
[author:]
|
|
67 |
Claus Atzkern
|
|
68 |
|
|
69 |
[see also:]
|
|
70 |
Application
|
|
71 |
Menu
|
|
72 |
MenuItem
|
|
73 |
"
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
! !
|
|
78 |
|
|
79 |
!ResourceRetriever class methodsFor:'accessing resource'!
|
|
80 |
|
|
81 |
findResourceLabel: label in: aResourceOwner
|
|
82 |
"look for a string
|
|
83 |
in aResourceOwner,
|
|
84 |
in class of aResourceOwner,
|
|
85 |
in resources of class of aResourceOwner,
|
|
86 |
and finally in my label resources
|
|
87 |
"
|
|
88 |
|
|
89 |
aResourceOwner isNil ifTrue: [^label].
|
|
90 |
|
|
91 |
label isSymbol
|
|
92 |
ifTrue:
|
|
93 |
[
|
|
94 |
(aResourceOwner respondsTo: label)
|
|
95 |
ifTrue:
|
|
96 |
[
|
|
97 |
^aResourceOwner perform: label
|
|
98 |
].
|
|
99 |
|
|
100 |
(aResourceOwner isClass not and: [aResourceOwner class respondsTo: label])
|
|
101 |
ifTrue:
|
|
102 |
[
|
|
103 |
^aResourceOwner perform: label
|
|
104 |
].
|
|
105 |
].
|
|
106 |
|
|
107 |
((aResourceOwner isKindOf: ApplicationModel) or:
|
|
108 |
[aResourceOwner isKindOf: SimpleView])
|
|
109 |
ifTrue:
|
|
110 |
[
|
|
111 |
^aResourceOwner resources string: label
|
|
112 |
].
|
|
113 |
|
|
114 |
((aResourceOwner isSubclassOf: ApplicationModel) or:
|
|
115 |
[aResourceOwner isSubclassOf: SimpleView])
|
|
116 |
ifTrue:
|
|
117 |
[
|
|
118 |
^aResourceOwner resources string: label
|
|
119 |
].
|
|
120 |
|
|
121 |
^self labelResources string:label
|
|
122 |
|
|
123 |
!
|
|
124 |
|
|
125 |
labelResources
|
|
126 |
"if not already loaded, get the common label resourcePack
|
|
127 |
and return it"
|
|
128 |
|
|
129 |
LabelResources isNil ifTrue:[
|
|
130 |
LabelResources := ResourcePack for:self.
|
|
131 |
].
|
|
132 |
^ LabelResources
|
|
133 |
! !
|
|
134 |
|
|
135 |
!ResourceRetriever methodsFor:'accessing'!
|
|
136 |
|
|
137 |
className
|
|
138 |
"return the value of the instance variable 'className' (automatically generated)"
|
|
139 |
|
|
140 |
^ className!
|
|
141 |
|
|
142 |
className:something
|
|
143 |
"set the class which provides the resources
|
|
144 |
"
|
|
145 |
className := something.
|
|
146 |
resourceOwner := nil.
|
|
147 |
!
|
|
148 |
|
|
149 |
labelText
|
|
150 |
^ labelText
|
|
151 |
!
|
|
152 |
|
|
153 |
labelText:aText
|
|
154 |
labelText := aText
|
|
155 |
!
|
|
156 |
|
|
157 |
selector
|
|
158 |
"return the value of the instance variable 'selector' (automatically generated)"
|
|
159 |
|
|
160 |
^ selector!
|
|
161 |
|
|
162 |
selector:something
|
|
163 |
"set the value of the instance variable 'selector' (automatically generated)"
|
|
164 |
|
|
165 |
selector := something.
|
|
166 |
!
|
|
167 |
|
|
168 |
value
|
|
169 |
"returns the value assigned to resource or nil
|
|
170 |
"
|
|
171 |
|resource|
|
|
172 |
|
|
173 |
(resource := self resource) isNil ifTrue:[
|
|
174 |
^ labelText
|
|
175 |
].
|
|
176 |
|
|
177 |
(labelText notNil and:[resource isImage]) ifTrue:[
|
|
178 |
^ LabelAndIcon icon:resource string:labelText
|
|
179 |
].
|
|
180 |
^ resource
|
|
181 |
|
|
182 |
"Modified: / 31.10.1997 / 12:10:05 / cg"
|
|
183 |
! !
|
|
184 |
|
|
185 |
!ResourceRetriever methodsFor:'accessing resource'!
|
|
186 |
|
|
187 |
findGuiResourcesIn:aResourceContainer
|
|
188 |
"setup a resource owner
|
|
189 |
"
|
|
190 |
className isNil ifTrue:[
|
|
191 |
resourceOwner := aResourceContainer
|
|
192 |
].
|
|
193 |
!
|
|
194 |
|
|
195 |
resource
|
|
196 |
"returns a form assigned to resource or nil
|
|
197 |
"
|
|
198 |
|img cls|
|
|
199 |
|
|
200 |
selector isNil ifTrue:[
|
|
201 |
^nil
|
|
202 |
].
|
|
203 |
|
|
204 |
resourceOwner isNil ifTrue:[
|
|
205 |
(resourceOwner := Smalltalk resolveName:className inClass:self class) isNil ifTrue:[
|
|
206 |
^ nil
|
|
207 |
]
|
|
208 |
].
|
|
209 |
|
|
210 |
(resourceOwner respondsTo:#visualFor:) ifTrue:[
|
|
211 |
(img := resourceOwner visualFor:selector) notNil ifTrue:[
|
|
212 |
^ img
|
|
213 |
]
|
|
214 |
].
|
|
215 |
|
|
216 |
(resourceOwner respondsTo:selector) ifTrue:[
|
|
217 |
^ resourceOwner perform:selector
|
|
218 |
].
|
|
219 |
|
|
220 |
resourceOwner isClass ifFalse:[
|
|
221 |
cls := resourceOwner class.
|
|
222 |
|
|
223 |
(cls respondsTo:selector) ifTrue:[
|
|
224 |
^ cls perform:selector
|
|
225 |
]
|
|
226 |
].
|
|
227 |
^ nil
|
|
228 |
|
|
229 |
"Modified: / 31.10.1997 / 12:09:52 / cg"
|
|
230 |
! !
|
|
231 |
|
|
232 |
!ResourceRetriever methodsFor:'converting'!
|
|
233 |
|
|
234 |
fromLiteralArrayEncoding:anArray
|
|
235 |
"read my values from an encoding.
|
|
236 |
"
|
|
237 |
className := anArray at: 2.
|
|
238 |
selector := anArray at: 3.
|
|
239 |
|
|
240 |
anArray size == 4 ifTrue:[
|
|
241 |
labelText := anArray at:4
|
|
242 |
].
|
|
243 |
resourceOwner := nil.
|
|
244 |
|
|
245 |
!
|
|
246 |
|
|
247 |
literalArrayEncoding
|
|
248 |
"encode myself as an array, from which a copy of the receiver can be
|
|
249 |
reconstructed with #decodeAsLiteralArray.
|
|
250 |
|
|
251 |
The encoding is:
|
|
252 |
(#ResourceRetriever className selector)
|
|
253 |
|
|
254 |
or if labelText not nil:
|
|
255 |
(#ResourceRetriever className selector labelText)
|
|
256 |
"
|
|
257 |
|myClassName|
|
|
258 |
|
|
259 |
myClassName := self class name.
|
|
260 |
labelText isNil ifTrue:[
|
|
261 |
^ Array with:myClassName with:className with:selector
|
|
262 |
] ifFalse:[
|
|
263 |
^ Array with:myClassName with:className with:selector with:labelText
|
|
264 |
].
|
|
265 |
|
|
266 |
"Modified: / 26.1.1998 / 13:52:43 / cg"
|
|
267 |
! !
|
|
268 |
|
|
269 |
!ResourceRetriever methodsFor:'testing'!
|
|
270 |
|
|
271 |
isDefined
|
|
272 |
"returns true if resource exists
|
|
273 |
"
|
|
274 |
selector notNil ifTrue:[
|
|
275 |
^ (resourceOwner notNil or:[className notNil])
|
|
276 |
].
|
|
277 |
^ false
|
|
278 |
!
|
|
279 |
|
|
280 |
notDefined
|
|
281 |
"returns false if resource is not defined
|
|
282 |
"
|
|
283 |
self isDefined ifTrue:[^ false ]
|
|
284 |
ifFalse:[^ true ]
|
|
285 |
! !
|
|
286 |
|
|
287 |
!ResourceRetriever class methodsFor:'documentation'!
|
|
288 |
|
|
289 |
version
|
|
290 |
^ '$Header: /cvs/stx/stx/libview2/ResourceRetriever.st,v 1.1 1998-08-30 12:13:51 cg Exp $'
|
|
291 |
! !
|