author | mawalch |
Mon, 22 May 2017 12:19:24 +0200 | |
changeset 3955 | 23fc9de7f301 |
parent 3927 | 8841d8751db1 |
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 |
||
3927 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
2502 | 16 |
Object subclass:#DrawAdaptor |
17 |
instanceVariableNames:'value drawValue' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Views-Support' |
|
21 |
! |
|
22 |
||
23 |
!DrawAdaptor class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 2008 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 |
documentation |
|
40 |
" |
|
41 |
DrawAdaptor constains to values: |
|
42 |
- any Object |
|
43 |
- a replacement Object to be used only for draw operations. |
|
44 |
||
45 |
Use this class whenever you want to show something different for a given object - |
|
46 |
e.g. to show some language specific text instead of a symbol or any object in ComboBoxes/PopUpLists. |
|
47 |
||
48 |
[author:] |
|
49 |
Stefan Vogel (stefan@zwerg) |
|
50 |
||
51 |
[instance variables:] |
|
52 |
value Object the original object |
|
53 |
drawValue Object the replacement object used for draw operations |
|
54 |
||
55 |
[class variables:] |
|
56 |
||
57 |
[see also:] |
|
58 |
||
59 |
" |
|
60 |
! |
|
61 |
||
62 |
examples |
|
63 |
" |
|
64 |
[exBegin] |
|
65 |
|labelList top comboList| |
|
66 |
||
67 |
labelList := DrawAdaptor collection:#(File Classes System Windows) |
|
68 |
withResources:Launcher classResources. |
|
69 |
||
70 |
top := StandardSystemView new. |
|
71 |
top extent:(300 @ 200). |
|
72 |
||
73 |
comboList := ComboListView in:top. |
|
74 |
comboList origin:(0.0 @ 0.0) corner:(1.0 @ 0.0). |
|
75 |
comboList bottomInset:(comboList preferredExtent y negated). |
|
76 |
||
77 |
comboList list:labelList. |
|
2523 | 78 |
comboList contents:labelList first. |
79 |
comboList action:[:selected | Transcript showCR:selected realValue]. |
|
2502 | 80 |
top open. |
81 |
[exEnd] |
|
82 |
||
83 |
" |
|
84 |
! ! |
|
85 |
||
86 |
!DrawAdaptor class methodsFor:'instance creation'! |
|
87 |
||
88 |
collection:aCollectionOfObjects withResources:resourcePack |
|
89 |
"create a collection of DrawAdaptors from aCollectionOfObjects (usually strings or symbols). |
|
90 |
Use resourcePack to do the translation" |
|
91 |
||
92 |
^ aCollectionOfObjects collect:[:each| |
|
93 |
self value:each withResources:resourcePack |
|
94 |
]. |
|
95 |
||
96 |
||
97 |
" |
|
98 |
self collection:#(a File c) withResources:Launcher classResources |
|
99 |
" |
|
100 |
! |
|
101 |
||
2531 | 102 |
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
|
103 |
^ self new realValue:value |
2531 | 104 |
! |
105 |
||
2502 | 106 |
value:value drawValue:drawValue |
107 |
^ self new value:value drawValue:drawValue |
|
108 |
! |
|
109 |
||
110 |
value:anObject withResources:resourcePack |
|
111 |
"Create a DrawAdaptor for anObject, |
|
112 |
Resolved via the translations in resourcePack" |
|
113 |
||
114 |
^ self new value:anObject drawValue:(resourcePack string:anObject) |
|
115 |
||
116 |
" |
|
117 |
self value:#Hello withResources:Launcher classResources |
|
118 |
" |
|
119 |
! ! |
|
120 |
||
121 |
!DrawAdaptor methodsFor:'accessing'! |
|
122 |
||
123 |
asString |
|
124 |
^ drawValue |
|
125 |
! |
|
126 |
||
127 |
drawValue |
|
2531 | 128 |
^ drawValue ? value |
2502 | 129 |
! |
130 |
||
131 |
drawValue:something |
|
132 |
drawValue := something. |
|
133 |
! |
|
134 |
||
135 |
realValue |
|
136 |
^ value |
|
137 |
! |
|
138 |
||
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
|
139 |
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
|
140 |
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
|
141 |
! |
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
|
142 |
|
2502 | 143 |
string |
144 |
^ drawValue |
|
145 |
! |
|
146 |
||
147 |
value:valueArg drawValue:drawValueArg |
|
148 |
value := valueArg. |
|
149 |
drawValue := drawValueArg. |
|
150 |
! ! |
|
151 |
||
152 |
!DrawAdaptor methodsFor:'comparing'! |
|
153 |
||
154 |
= anObject |
|
155 |
"two TranslatedSymbols are equal, if they have the same symbol" |
|
156 |
||
157 |
self species == anObject species ifTrue:[ |
|
2524
166a10a040c1
changed #'=' fix error when comparing
Stefan Vogel <sv@exept.de>
parents:
2523
diff
changeset
|
158 |
^ value = anObject realValue. |
2502 | 159 |
]. |
160 |
^ value = anObject. |
|
161 |
||
162 |
" |
|
163 |
(self value:#hash drawValue:'x') = #hash |
|
164 |
(self value:#hash drawValue:'x') = 1 |
|
165 |
(self value:#hash drawValue:'x') = (self value:#hash drawValue:'y') |
|
166 |
" |
|
167 |
! |
|
168 |
||
169 |
hash |
|
170 |
"equal, if they have the same realObject" |
|
171 |
||
172 |
^ value hash |
|
173 |
! ! |
|
174 |
||
175 |
!DrawAdaptor methodsFor:'delegation drawing'! |
|
176 |
||
177 |
ascentOn:aGc |
|
2531 | 178 |
^ self drawValue ascentOn:aGc |
2502 | 179 |
! |
180 |
||
181 |
displayOn:aGCOrStream |
|
3356 | 182 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
3927 | 183 |
"/ old ST80 means: draw-yourself on a GC. |
184 |
||
3356 | 185 |
(aGCOrStream isStream) ifFalse:[ |
186 |
self drawValue displayOn:aGCOrStream x:0 y:0. |
|
187 |
] ifTrue:[ |
|
2502 | 188 |
aGCOrStream |
189 |
nextPutAll:self className; |
|
190 |
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
|
191 |
self realValue printOn:aGCOrStream. |
2502 | 192 |
aGCOrStream nextPutAll:'->'. |
2531 | 193 |
self drawValue printOn:aGCOrStream. |
2502 | 194 |
aGCOrStream nextPut:$). |
195 |
]. |
|
3927 | 196 |
|
197 |
"Modified (comment): / 22-02-2017 / 16:46:28 / cg" |
|
2502 | 198 |
! |
199 |
||
200 |
displayOn:aGc x:x y:y opaque:opaque |
|
201 |
"copied from object, but do the ascent handling here" |
|
202 |
||
2531 | 203 |
self drawValue displayOn:aGc x:x y:y opaque:opaque. |
2502 | 204 |
! |
205 |
||
206 |
heightOn:aGC |
|
207 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
208 |
||
2531 | 209 |
^ self drawValue heightOn:aGC |
2502 | 210 |
! |
211 |
||
2531 | 212 |
printOn:aStream |
2502 | 213 |
"this hast to be redefined to allow access from ComboLists via pressing the first character key" |
214 |
||
2531 | 215 |
^ self drawValue printOn:aStream |
2502 | 216 |
! |
217 |
||
218 |
widthFrom:startIndex to:endIndex on:aGC |
|
219 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
220 |
||
2531 | 221 |
^ self drawValue widthFrom:startIndex to:endIndex on:aGC |
2502 | 222 |
! |
223 |
||
224 |
widthOn:aGc |
|
2531 | 225 |
^ self drawValue widthOn:aGc |
2502 | 226 |
! ! |
227 |
||
2616 | 228 |
!DrawAdaptor methodsFor:'misc'! |
229 |
||
230 |
rebindWith:resources |
|
231 |
drawValue := resources string:value |
|
232 |
! ! |
|
233 |
||
2502 | 234 |
!DrawAdaptor class methodsFor:'documentation'! |
235 |
||
236 |
version |
|
3927 | 237 |
^ '$Header$' |
2502 | 238 |
! ! |
3356 | 239 |