author | Claus Gittinger <cg@exept.de> |
Fri, 11 Jan 2013 16:13:27 +0100 | |
changeset 3053 | 2c1b6c1e317f |
parent 2616 | 98c4ab65ef38 |
child 3356 | 93f87a1eb6c0 |
permissions | -rw-r--r-- |
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 |
||
2531 | 100 |
value:value |
2532
6036e9c41f6d
Do not allow value: to set the realValue - avoid recursion errors when accessing a DrawValue
Stefan Vogel <sv@exept.de>
parents:
2531
diff
changeset
|
101 |
^ self new realValue:value |
2531 | 102 |
! |
103 |
||
2502 | 104 |
value:value drawValue:drawValue |
105 |
^ self new value:value drawValue:drawValue |
|
106 |
! |
|
107 |
||
108 |
value:anObject withResources:resourcePack |
|
109 |
"Create a DrawAdaptor for anObject, |
|
110 |
Resolved via the translations in resourcePack" |
|
111 |
||
112 |
^ self new value:anObject drawValue:(resourcePack string:anObject) |
|
113 |
||
114 |
" |
|
115 |
self value:#Hello withResources:Launcher classResources |
|
116 |
" |
|
117 |
! ! |
|
118 |
||
119 |
!DrawAdaptor methodsFor:'accessing'! |
|
120 |
||
121 |
asString |
|
122 |
^ drawValue |
|
123 |
! |
|
124 |
||
125 |
drawValue |
|
2531 | 126 |
^ drawValue ? value |
2502 | 127 |
! |
128 |
||
129 |
drawValue:something |
|
130 |
drawValue := something. |
|
131 |
! |
|
132 |
||
133 |
realValue |
|
134 |
^ value |
|
135 |
! |
|
136 |
||
2532
6036e9c41f6d
Do not allow value: to set the realValue - avoid recursion errors when accessing a DrawValue
Stefan Vogel <sv@exept.de>
parents:
2531
diff
changeset
|
137 |
realValue:something |
6036e9c41f6d
Do not allow value: to set the realValue - avoid recursion errors when accessing a DrawValue
Stefan Vogel <sv@exept.de>
parents:
2531
diff
changeset
|
138 |
value := something. |
6036e9c41f6d
Do not allow value: to set the realValue - avoid recursion errors when accessing a DrawValue
Stefan Vogel <sv@exept.de>
parents:
2531
diff
changeset
|
139 |
! |
6036e9c41f6d
Do not allow value: to set the realValue - avoid recursion errors when accessing a DrawValue
Stefan Vogel <sv@exept.de>
parents:
2531
diff
changeset
|
140 |
|
2502 | 141 |
string |
142 |
^ drawValue |
|
143 |
! |
|
144 |
||
145 |
value:valueArg drawValue:drawValueArg |
|
146 |
value := valueArg. |
|
147 |
drawValue := drawValueArg. |
|
148 |
! ! |
|
149 |
||
150 |
!DrawAdaptor methodsFor:'comparing'! |
|
151 |
||
152 |
= anObject |
|
153 |
"two TranslatedSymbols are equal, if they have the same symbol" |
|
154 |
||
155 |
self species == anObject species ifTrue:[ |
|
2524
166a10a040c1
changed #'=' fix error when comparing
Stefan Vogel <sv@exept.de>
parents:
2523
diff
changeset
|
156 |
^ value = anObject realValue. |
2502 | 157 |
]. |
158 |
^ value = anObject. |
|
159 |
||
160 |
" |
|
161 |
(self value:#hash drawValue:'x') = #hash |
|
162 |
(self value:#hash drawValue:'x') = 1 |
|
163 |
(self value:#hash drawValue:'x') = (self value:#hash drawValue:'y') |
|
164 |
" |
|
165 |
! |
|
166 |
||
167 |
hash |
|
168 |
"equal, if they have the same realObject" |
|
169 |
||
170 |
^ value hash |
|
171 |
! ! |
|
172 |
||
173 |
!DrawAdaptor methodsFor:'delegation drawing'! |
|
174 |
||
175 |
ascentOn:aGc |
|
2531 | 176 |
^ self drawValue ascentOn:aGc |
2502 | 177 |
! |
178 |
||
179 |
displayOn:aGCOrStream |
|
180 |
(aGCOrStream isStream or:[aGCOrStream == Transcript]) ifTrue:[ |
|
181 |
aGCOrStream |
|
182 |
nextPutAll:self className; |
|
183 |
nextPut:$(. |
|
2532
6036e9c41f6d
Do not allow value: to set the realValue - avoid recursion errors when accessing a DrawValue
Stefan Vogel <sv@exept.de>
parents:
2531
diff
changeset
|
184 |
self realValue printOn:aGCOrStream. |
2502 | 185 |
aGCOrStream nextPutAll:'->'. |
2531 | 186 |
self drawValue printOn:aGCOrStream. |
2502 | 187 |
aGCOrStream nextPut:$). |
188 |
] ifFalse:[ |
|
2531 | 189 |
self drawValue displayOn:aGCOrStream x:0 y:0. |
2502 | 190 |
]. |
191 |
! |
|
192 |
||
193 |
displayOn:aGc x:x y:y opaque:opaque |
|
194 |
"copied from object, but do the ascent handling here" |
|
195 |
||
2531 | 196 |
self drawValue displayOn:aGc x:x y:y opaque:opaque. |
2502 | 197 |
! |
198 |
||
199 |
heightOn:aGC |
|
200 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
201 |
||
2531 | 202 |
^ self drawValue heightOn:aGC |
2502 | 203 |
! |
204 |
||
2531 | 205 |
printOn:aStream |
2502 | 206 |
"this hast to be redefined to allow access from ComboLists via pressing the first character key" |
207 |
||
2531 | 208 |
^ self drawValue printOn:aStream |
2502 | 209 |
! |
210 |
||
211 |
widthFrom:startIndex to:endIndex on:aGC |
|
212 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
213 |
||
2531 | 214 |
^ self drawValue widthFrom:startIndex to:endIndex on:aGC |
2502 | 215 |
! |
216 |
||
217 |
widthOn:aGc |
|
2531 | 218 |
^ self drawValue widthOn:aGc |
2502 | 219 |
! ! |
220 |
||
2616 | 221 |
!DrawAdaptor methodsFor:'misc'! |
222 |
||
223 |
rebindWith:resources |
|
224 |
drawValue := resources string:value |
|
225 |
! ! |
|
226 |
||
2502 | 227 |
!DrawAdaptor class methodsFor:'documentation'! |
228 |
||
229 |
version |
|
2616 | 230 |
^ '$Header: /cvs/stx/stx/libview2/DrawAdaptor.st,v 1.6 2009-03-23 07:22:24 stefan Exp $' |
2502 | 231 |
! ! |