author | HG Automerge |
Thu, 19 Jan 2017 12:00:14 +0000 | |
branch | jv |
changeset 3854 | 4afd107bc911 |
parent 3356 | 93f87a1eb6c0 |
child 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 |
||
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 |
|
3356 | 180 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
181 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
|
182 |
(aGCOrStream isStream) ifFalse:[ |
|
183 |
self drawValue displayOn:aGCOrStream x:0 y:0. |
|
184 |
] ifTrue:[ |
|
2502 | 185 |
aGCOrStream |
186 |
nextPutAll:self className; |
|
187 |
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
|
188 |
self realValue printOn:aGCOrStream. |
2502 | 189 |
aGCOrStream nextPutAll:'->'. |
2531 | 190 |
self drawValue printOn:aGCOrStream. |
2502 | 191 |
aGCOrStream nextPut:$). |
192 |
]. |
|
193 |
! |
|
194 |
||
195 |
displayOn:aGc x:x y:y opaque:opaque |
|
196 |
"copied from object, but do the ascent handling here" |
|
197 |
||
2531 | 198 |
self drawValue displayOn:aGc x:x y:y opaque:opaque. |
2502 | 199 |
! |
200 |
||
201 |
heightOn:aGC |
|
202 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
203 |
||
2531 | 204 |
^ self drawValue heightOn:aGC |
2502 | 205 |
! |
206 |
||
2531 | 207 |
printOn:aStream |
2502 | 208 |
"this hast to be redefined to allow access from ComboLists via pressing the first character key" |
209 |
||
2531 | 210 |
^ self drawValue printOn:aStream |
2502 | 211 |
! |
212 |
||
213 |
widthFrom:startIndex to:endIndex on:aGC |
|
214 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
215 |
||
2531 | 216 |
^ self drawValue widthFrom:startIndex to:endIndex on:aGC |
2502 | 217 |
! |
218 |
||
219 |
widthOn:aGc |
|
2531 | 220 |
^ self drawValue widthOn:aGc |
2502 | 221 |
! ! |
222 |
||
2616 | 223 |
!DrawAdaptor methodsFor:'misc'! |
224 |
||
225 |
rebindWith:resources |
|
226 |
drawValue := resources string:value |
|
227 |
! ! |
|
228 |
||
2502 | 229 |
!DrawAdaptor class methodsFor:'documentation'! |
230 |
||
231 |
version |
|
3356 | 232 |
^ '$Header: /cvs/stx/stx/libview2/DrawAdaptor.st,v 1.7 2014-07-10 12:23:21 cg Exp $' |
2502 | 233 |
! ! |
3356 | 234 |