|
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-UIPainter' |
|
21 ! |
|
22 |
|
23 !ResourceRetriever class methodsFor:'documentation'! |
|
24 |
|
25 copyright |
|
26 " |
|
27 COPYRIGHT (c) 1997 by eXept Software AG |
|
28 All Rights Reserved |
|
29 |
|
30 This software is furnished under a license and may be used |
|
31 only in accordance with the terms of that license and with the |
|
32 inclusion of the above copyright notice. This software may not |
|
33 be provided or otherwise made available to, or used by, any |
|
34 other person. No title to or ownership of the software is |
|
35 hereby transferred. |
|
36 " |
|
37 |
|
38 |
|
39 |
|
40 ! |
|
41 |
|
42 documentation |
|
43 " |
|
44 This class is used to retrieve resources for a painted interface of |
|
45 some sort. If the className is specified, then the owner of the resource |
|
46 is fixed at painting time. If not, then the ApplicationModel which invokes |
|
47 the painted interface is assumed to be the owner of the resource. |
|
48 |
|
49 When the retriever is sent the message #value, it sends the message #valueFor: |
|
50 to the resource owner, to retrive the resource |
|
51 |
|
52 [author:] |
|
53 Claus Atzkern |
|
54 |
|
55 [see also:] |
|
56 Application |
|
57 Menu |
|
58 MenuItem |
|
59 " |
|
60 |
|
61 |
|
62 |
|
63 ! ! |
|
64 |
|
65 !ResourceRetriever methodsFor:'accessing'! |
|
66 |
|
67 className |
|
68 "return the value of the instance variable 'className' (automatically generated)" |
|
69 |
|
70 ^ className! |
|
71 |
|
72 className:something |
|
73 "set the class which provides the resources |
|
74 " |
|
75 className := something. |
|
76 resourceOwner := nil. |
|
77 ! |
|
78 |
|
79 selector |
|
80 "return the value of the instance variable 'selector' (automatically generated)" |
|
81 |
|
82 ^ selector! |
|
83 |
|
84 selector:something |
|
85 "set the value of the instance variable 'selector' (automatically generated)" |
|
86 |
|
87 selector := something. |
|
88 ! |
|
89 |
|
90 value |
|
91 "returns value assigned to resource or nil |
|
92 " |
|
93 |resource| |
|
94 |
|
95 (resource := self resource) isNil ifTrue:[ |
|
96 ^ labelText |
|
97 ]. |
|
98 |
|
99 (labelText notNil and:[resource isImage]) ifTrue:[ |
|
100 ^ LabelAndIcon icon:resource string:(Text string:labelText emphasis:#bold) |
|
101 ]. |
|
102 ^ resource |
|
103 ! ! |
|
104 |
|
105 !ResourceRetriever methodsFor:'accessing resource'! |
|
106 |
|
107 findGuiResourcesIn:aResourceContainer |
|
108 "setup a resource owner |
|
109 " |
|
110 className isNil ifTrue:[ |
|
111 resourceOwner := aResourceContainer |
|
112 ]. |
|
113 ! |
|
114 |
|
115 resource |
|
116 "returns form assigned to resource or nil |
|
117 " |
|
118 selector isNil ifTrue:[ |
|
119 ^nil |
|
120 ]. |
|
121 |
|
122 resourceOwner isNil ifTrue:[ |
|
123 ( className isNil |
|
124 or:[(resourceOwner := Smalltalk at:className ifAbsent:nil) isNil] |
|
125 ) ifTrue:[ |
|
126 ^ nil |
|
127 ] |
|
128 ]. |
|
129 ^ resourceOwner visualFor:selector. |
|
130 ! ! |
|
131 |
|
132 !ResourceRetriever methodsFor:'converting'! |
|
133 |
|
134 fromLiteralArrayEncoding:anArray |
|
135 "read my values from an encoding. |
|
136 " |
|
137 className := anArray at: 2. |
|
138 selector := anArray at: 3. |
|
139 |
|
140 anArray size == 4 ifTrue:[ |
|
141 labelText := anArray at:4 |
|
142 ]. |
|
143 resourceOwner := nil. |
|
144 |
|
145 ! |
|
146 |
|
147 literalArrayEncoding |
|
148 "encode myself as an array, from which a copy of the receiver can be |
|
149 reconstructed with #decodeAsLiteralArray. |
|
150 |
|
151 The encoding is: |
|
152 (#ResourceRetriever className selector) |
|
153 |
|
154 or if labelText not nil: |
|
155 (#ResourceRetriever className selector labelText) |
|
156 " |
|
157 labelText isNil ifTrue:[ |
|
158 ^ Array with:(self class name) with:className with:selector |
|
159 ] ifFalse:[ |
|
160 ^ Array with:(self class name) with:className with:selector with:labelText |
|
161 ]. |
|
162 |
|
163 ! ! |
|
164 |
|
165 !ResourceRetriever methodsFor:'testing'! |
|
166 |
|
167 isDefined |
|
168 "returns true if resource exists |
|
169 " |
|
170 selector notNil ifTrue:[ |
|
171 ^ (resourceOwner notNil or:[className notNil]) |
|
172 ]. |
|
173 ^ false |
|
174 ! |
|
175 |
|
176 notDefined |
|
177 "returns false if resource is not defined |
|
178 " |
|
179 self isDefined ifTrue:[^ false ] |
|
180 ifFalse:[^ true ] |
|
181 ! ! |
|
182 |
|
183 !ResourceRetriever class methodsFor:'documentation'! |
|
184 |
|
185 version |
|
186 ^ '$Header$' |
|
187 ! ! |