2502
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2008 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 |
"{ Package: 'stx:libview2' }"
|
|
13 |
|
|
14 |
Object subclass:#DrawAdaptor
|
|
15 |
instanceVariableNames:'value drawValue'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Support'
|
|
19 |
!
|
|
20 |
|
|
21 |
!DrawAdaptor class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2008 by eXept Software AG
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
|
37 |
documentation
|
|
38 |
"
|
|
39 |
DrawAdaptor constains to values:
|
|
40 |
- any Object
|
|
41 |
- a replacement Object to be used only for draw operations.
|
|
42 |
|
|
43 |
Use this class whenever you want to show something different for a given object -
|
|
44 |
e.g. to show some language specific text instead of a symbol or any object in ComboBoxes/PopUpLists.
|
|
45 |
|
|
46 |
[author:]
|
|
47 |
Stefan Vogel (stefan@zwerg)
|
|
48 |
|
|
49 |
[instance variables:]
|
|
50 |
value Object the original object
|
|
51 |
drawValue Object the replacement object used for draw operations
|
|
52 |
|
|
53 |
[class variables:]
|
|
54 |
|
|
55 |
[see also:]
|
|
56 |
|
|
57 |
"
|
|
58 |
!
|
|
59 |
|
|
60 |
examples
|
|
61 |
"
|
|
62 |
[exBegin]
|
|
63 |
|labelList top comboList|
|
|
64 |
|
|
65 |
labelList := DrawAdaptor collection:#(File Classes System Windows)
|
|
66 |
withResources:Launcher classResources.
|
|
67 |
|
|
68 |
top := StandardSystemView new.
|
|
69 |
top extent:(300 @ 200).
|
|
70 |
|
|
71 |
comboList := ComboListView in:top.
|
|
72 |
comboList origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
|
|
73 |
comboList bottomInset:(comboList preferredExtent y negated).
|
|
74 |
|
|
75 |
comboList list:labelList.
|
2523
|
76 |
comboList contents:labelList first.
|
|
77 |
comboList action:[:selected | Transcript showCR:selected realValue].
|
2502
|
78 |
top open.
|
|
79 |
[exEnd]
|
|
80 |
|
|
81 |
"
|
|
82 |
! !
|
|
83 |
|
|
84 |
!DrawAdaptor class methodsFor:'instance creation'!
|
|
85 |
|
|
86 |
collection:aCollectionOfObjects withResources:resourcePack
|
|
87 |
"create a collection of DrawAdaptors from aCollectionOfObjects (usually strings or symbols).
|
|
88 |
Use resourcePack to do the translation"
|
|
89 |
|
|
90 |
^ aCollectionOfObjects collect:[:each|
|
|
91 |
self value:each withResources:resourcePack
|
|
92 |
].
|
|
93 |
|
|
94 |
|
|
95 |
"
|
|
96 |
self collection:#(a File c) withResources:Launcher classResources
|
|
97 |
"
|
|
98 |
!
|
|
99 |
|
|
100 |
value:value drawValue:drawValue
|
|
101 |
^ self new value:value drawValue:drawValue
|
|
102 |
!
|
|
103 |
|
|
104 |
value:anObject withResources:resourcePack
|
|
105 |
"Create a DrawAdaptor for anObject,
|
|
106 |
Resolved via the translations in resourcePack"
|
|
107 |
|
|
108 |
^ self new value:anObject drawValue:(resourcePack string:anObject)
|
|
109 |
|
|
110 |
"
|
|
111 |
self value:#Hello withResources:Launcher classResources
|
|
112 |
"
|
|
113 |
! !
|
|
114 |
|
|
115 |
!DrawAdaptor methodsFor:'accessing'!
|
|
116 |
|
|
117 |
asString
|
|
118 |
^ drawValue
|
|
119 |
!
|
|
120 |
|
|
121 |
drawValue
|
|
122 |
^ drawValue
|
|
123 |
!
|
|
124 |
|
|
125 |
drawValue:something
|
|
126 |
drawValue := something.
|
|
127 |
!
|
|
128 |
|
|
129 |
realValue
|
|
130 |
^ value
|
|
131 |
!
|
|
132 |
|
|
133 |
string
|
|
134 |
^ drawValue
|
|
135 |
!
|
|
136 |
|
|
137 |
value:something
|
|
138 |
value := something.
|
|
139 |
!
|
|
140 |
|
|
141 |
value:valueArg drawValue:drawValueArg
|
|
142 |
value := valueArg.
|
|
143 |
drawValue := drawValueArg.
|
|
144 |
! !
|
|
145 |
|
|
146 |
!DrawAdaptor methodsFor:'comparing'!
|
|
147 |
|
|
148 |
= anObject
|
|
149 |
"two TranslatedSymbols are equal, if they have the same symbol"
|
|
150 |
|
|
151 |
self species == anObject species ifTrue:[
|
|
152 |
^ value = anObject value.
|
|
153 |
].
|
|
154 |
^ value = anObject.
|
|
155 |
|
|
156 |
"
|
|
157 |
(self value:#hash drawValue:'x') = #hash
|
|
158 |
(self value:#hash drawValue:'x') = 1
|
|
159 |
(self value:#hash drawValue:'x') = (self value:#hash drawValue:'y')
|
|
160 |
"
|
|
161 |
!
|
|
162 |
|
|
163 |
hash
|
|
164 |
"equal, if they have the same realObject"
|
|
165 |
|
|
166 |
^ value hash
|
|
167 |
! !
|
|
168 |
|
|
169 |
!DrawAdaptor methodsFor:'delegation drawing'!
|
|
170 |
|
|
171 |
ascentOn:aGc
|
|
172 |
^ drawValue ascentOn:aGc
|
|
173 |
!
|
|
174 |
|
|
175 |
displayOn:aGCOrStream
|
|
176 |
(aGCOrStream isStream or:[aGCOrStream == Transcript]) ifTrue:[
|
|
177 |
aGCOrStream
|
|
178 |
nextPutAll:self className;
|
|
179 |
nextPut:$(.
|
|
180 |
value printOn:aGCOrStream.
|
|
181 |
aGCOrStream nextPutAll:'->'.
|
|
182 |
drawValue printOn:aGCOrStream.
|
|
183 |
aGCOrStream nextPut:$).
|
|
184 |
] ifFalse:[
|
|
185 |
drawValue displayOn:aGCOrStream x:0 y:0.
|
|
186 |
].
|
|
187 |
!
|
|
188 |
|
|
189 |
displayOn:aGc x:x y:y opaque:opaque
|
|
190 |
"copied from object, but do the ascent handling here"
|
|
191 |
|
|
192 |
drawValue displayOn:aGc x:x y:y opaque:opaque.
|
|
193 |
!
|
|
194 |
|
|
195 |
heightOn:aGC
|
|
196 |
"return the height of the receiver, if it is to be displayed on aGC"
|
|
197 |
|
|
198 |
^ drawValue heightOn:aGC
|
|
199 |
!
|
|
200 |
|
|
201 |
printString
|
|
202 |
"this hast to be redefined to allow access from ComboLists via pressing the first character key"
|
|
203 |
|
|
204 |
^ drawValue printString
|
|
205 |
!
|
|
206 |
|
|
207 |
widthFrom:startIndex to:endIndex on:aGC
|
|
208 |
"return the width of the receiver, if it is to be displayed on aGC"
|
|
209 |
|
|
210 |
^ drawValue widthFrom:startIndex to:endIndex on:aGC
|
|
211 |
!
|
|
212 |
|
|
213 |
widthOn:aGc
|
|
214 |
^ drawValue widthOn:aGc
|
|
215 |
! !
|
|
216 |
|
|
217 |
!DrawAdaptor class methodsFor:'documentation'!
|
|
218 |
|
|
219 |
version
|
2523
|
220 |
^ '$Header: /cvs/stx/stx/libview2/DrawAdaptor.st,v 1.2 2008-07-22 18:49:37 stefan Exp $'
|
2502
|
221 |
! !
|