author | Jan Vrany <jan.vrany@labware.com> |
Thu, 09 Feb 2023 14:03:49 +0000 | |
branch | jv |
changeset 6265 | 09ae5bbed69e |
parent 5291 | 31dd692da914 |
child 5553 | d8caa65e2d54 |
permissions | -rw-r--r-- |
1431 | 1 |
" |
2 |
COPYRIGHT (c) 1999 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 |
" |
|
1794 | 12 |
"{ Package: 'stx:libwidg2' }" |
13 |
||
4697 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
4734 | 16 |
AbstractHierarchicalItem subclass:#HierarchicalItem |
17 |
instanceVariableNames:'isExpanded height width' |
|
1390 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
1430 | 20 |
category:'Views-Support' |
1390 | 21 |
! |
22 |
||
23 |
HierarchicalItem subclass:#Example |
|
24 |
instanceVariableNames:'label icon' |
|
25 |
classVariableNames:'PenguinIcon' |
|
26 |
poolDictionaries:'' |
|
27 |
privateIn:HierarchicalItem |
|
28 |
! |
|
29 |
||
30 |
!HierarchicalItem class methodsFor:'documentation'! |
|
31 |
||
1431 | 32 |
copyright |
33 |
" |
|
34 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
35 |
All Rights Reserved |
|
36 |
||
37 |
This software is furnished under a license and may be used |
|
38 |
only in accordance with the terms of that license and with the |
|
39 |
inclusion of the above copyright notice. This software may not |
|
40 |
be provided or otherwise made available to, or used by, any |
|
41 |
other person. No title to or ownership of the software is |
|
42 |
hereby transferred. |
|
43 |
" |
|
44 |
||
45 |
! |
|
46 |
||
1390 | 47 |
documentation |
48 |
" |
|
49 |
Hierarchical Items are mostly like Models, but the list of |
|
50 |
dependencies are kept by its HierarchicalList. |
|
5291 | 51 |
Instances of (subclasses of) me are used to build up hierarchical trees. |
52 |
This class is usually subclassed, to add label, icon or value (reference to some info) |
|
53 |
to the tree item. |
|
54 |
||
1390 | 55 |
[Instance variables:] |
56 |
parent <Item, List or nil> parent or my HierarchicalList. |
|
57 |
children <Collection or nil> list of children |
|
58 |
isExpanded <Boolean> indicates whether the item is |
|
59 |
expanded or collapsed |
|
4734 | 60 |
width <Integer> cached width of displayed label |
61 |
height <Integer> cached height of displayed label |
|
1390 | 62 |
|
63 |
[author:] |
|
64 |
Claus Atzkern |
|
65 |
||
66 |
[see also:] |
|
67 |
HierarchicalList |
|
68 |
HierarchicalListView |
|
69 |
" |
|
70 |
! ! |
|
71 |
||
4747 | 72 |
!HierarchicalItem methodsFor:'accessing'! |
73 |
||
74 |
height |
|
4748 | 75 |
"return the cached height" |
76 |
||
4747 | 77 |
^ height |
78 |
! |
|
79 |
||
80 |
height:something |
|
4748 | 81 |
"set the cached height" |
82 |
||
4747 | 83 |
height := something. |
84 |
! |
|
85 |
||
86 |
width |
|
4748 | 87 |
"return the cached width" |
88 |
||
4747 | 89 |
^ width |
90 |
! |
|
91 |
||
92 |
width:something |
|
4748 | 93 |
"set the cached width" |
94 |
||
4747 | 95 |
width := something. |
96 |
! ! |
|
97 |
||
1390 | 98 |
!HierarchicalItem methodsFor:'private'! |
99 |
||
4754 | 100 |
fetchChildren |
101 |
"should compute the list of children via the model. |
|
102 |
Be aware, that the somewhat stupid 'optimization' of how the model is fetched may lead to |
|
103 |
a O(n*log n) or even O(n^2) behavior here. |
|
4765 | 104 |
*** to optimize: redefine #model by subClass" |
4754 | 105 |
|
106 |
|model childrenFromModel| |
|
107 |
||
108 |
(model := self model) notNil ifTrue:[ |
|
109 |
childrenFromModel := model childrenFor:self |
|
110 |
]. |
|
111 |
^ childrenFromModel |
|
112 |
! |
|
113 |
||
4734 | 114 |
makeWidthAndHeightUnknown |
115 |
width := height := nil |
|
1390 | 116 |
! |
117 |
||
118 |
setExpanded:aBoolean |
|
2547 | 119 |
"set expanded flag without any computation or notification" |
120 |
||
1390 | 121 |
isExpanded := aBoolean |
122 |
! ! |
|
123 |
||
2851 | 124 |
!HierarchicalItem methodsFor:'protocol-displaying'! |
1390 | 125 |
|
126 |
heightOn:aGC |
|
4734 | 127 |
"return the height of the receiver, if it is to be displayed on aGC" |
3912 | 128 |
|
1606 | 129 |
height isNil ifTrue:[ |
130 |
height := self heightOf:(self label) on:aGC |
|
131 |
]. |
|
132 |
^ height |
|
1390 | 133 |
! |
134 |
||
135 |
widthOn:aGC |
|
3911 | 136 |
"return the width of the receiver, if it is to be displayed on aGC" |
137 |
||
1606 | 138 |
width isNil ifTrue:[ |
139 |
width := self widthOf:(self label) on:aGC |
|
140 |
]. |
|
141 |
^ width |
|
1390 | 142 |
! ! |
143 |
||
144 |
!HierarchicalItem methodsFor:'queries'! |
|
145 |
||
146 |
isExpanded |
|
2547 | 147 |
"returns true if the item is expanded" |
148 |
||
149 |
^ isExpanded |
|
2252 | 150 |
! ! |
151 |
||
1390 | 152 |
!HierarchicalItem::Example class methodsFor:'instance creation'! |
153 |
||
154 |
labeled:aLabel |
|
155 |
^ self new setLabel:aLabel |
|
156 |
||
157 |
||
158 |
! |
|
159 |
||
160 |
labeled:aLabel icon:anIcon |
|
161 |
^ self new setLabel:aLabel icon:anIcon |
|
162 |
||
163 |
||
164 |
! ! |
|
165 |
||
166 |
!HierarchicalItem::Example class methodsFor:'resources'! |
|
167 |
||
168 |
iconForLevel:aLevel |
|
169 |
"returns an icon |
|
170 |
" |
|
171 |
aLevel == 2 ifTrue:[ ^ ResourceSelectionBrowser iconPrivateClass ]. |
|
172 |
aLevel == 3 ifTrue:[ ^ ResourceSelectionBrowser iconClass ]. |
|
173 |
aLevel == 4 ifTrue:[ ^ ResourceSelectionBrowser iconCategory ]. |
|
174 |
||
175 |
^ nil |
|
176 |
! |
|
177 |
||
178 |
penguinIcon |
|
179 |
PenguinIcon isNil ifTrue:[ |
|
1794 | 180 |
PenguinIcon := Smalltalk imageFromFileNamed:'xpmBitmaps/misc_logos/linux_penguin.xpm' |
181 |
inPackage:'stx:goodies' |
|
1390 | 182 |
]. |
183 |
^ PenguinIcon |
|
184 |
! ! |
|
185 |
||
186 |
!HierarchicalItem::Example methodsFor:'accessing'! |
|
187 |
||
188 |
children |
|
2781 | 189 |
|lvl lbl txt image img icon| |
1390 | 190 |
|
191 |
children notNil ifTrue:[ |
|
192 |
^ children |
|
193 |
]. |
|
194 |
||
195 |
(lvl := self level) == 5 ifTrue:[ |
|
196 |
children := #(). |
|
197 |
^ children |
|
198 |
]. |
|
199 |
icon := self class iconForLevel:(lvl + 1). |
|
200 |
children := OrderedCollection new. |
|
201 |
||
202 |
lvl < 4 ifTrue:[ |
|
203 |
txt := (lvl + 1) printString, ' ['. |
|
2781 | 204 |
img := Icon saveIcon. |
1390 | 205 |
|
206 |
1 to:5 do:[:i| |
|
207 |
(i == 2 or:[i == 3]) ifTrue:[ |
|
208 |
lbl := img |
|
209 |
] ifFalse:[ |
|
210 |
i == 4 ifTrue:[ |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
211 |
lbl := Array with:(self class penguinIcon) |
4666 | 212 |
with:('penguin#and#text' copyReplaceAll:$# with:(Character cr)). |
1390 | 213 |
] ifFalse:[ |
214 |
lbl := txt, (i printString), ']' |
|
215 |
] |
|
216 |
]. |
|
217 |
children add:(self class labeled:lbl icon:icon) |
|
218 |
]. |
|
219 |
] ifFalse:[ |
|
220 |
image := ResourceSelectionBrowser iconPrivateClass. |
|
221 |
txt := LabelAndIcon icon:image string:'Text'. |
|
222 |
img := Icon copyIcon. |
|
223 |
||
224 |
1 to:5 do:[:i| |
|
225 |
lbl := i odd ifTrue:[txt] ifFalse:[img]. |
|
1398 | 226 |
lbl := Array with:lbl with:'test' with:img. |
1390 | 227 |
children add:(self class labeled:lbl icon:icon). |
3333 | 228 |
]. |
229 |
children add:(self class labeled:'Edit Text'). |
|
1390 | 230 |
]. |
231 |
||
232 |
children do:[:aChild| aChild parent:self ]. |
|
233 |
^ children |
|
234 |
! |
|
235 |
||
236 |
icon |
|
237 |
"returns the icon |
|
238 |
" |
|
239 |
^ icon |
|
240 |
! |
|
241 |
||
242 |
icon:anIcon |
|
243 |
"set the icon; if icon changed, a notification |
|
244 |
is raised. |
|
245 |
" |
|
246 |
icon ~= anIcon ifTrue:[ |
|
247 |
icon := anIcon. |
|
248 |
self iconChanged |
|
249 |
] |
|
250 |
! |
|
251 |
||
252 |
label |
|
253 |
"returns the label |
|
254 |
" |
|
255 |
^ label |
|
256 |
||
257 |
! |
|
258 |
||
259 |
label:aLabel |
|
260 |
"set the label; if label changed, a notification |
|
261 |
is raised. |
|
262 |
" |
|
263 |
label ~= aLabel ifTrue:[ |
|
264 |
label := aLabel. |
|
265 |
self changed. |
|
266 |
] |
|
267 |
||
268 |
! |
|
269 |
||
270 |
setIcon:anIcon |
|
271 |
"set the icon without any change notification |
|
272 |
" |
|
273 |
icon := anIcon |
|
274 |
! |
|
275 |
||
276 |
setLabel:aLabel |
|
277 |
"set the label without any change notification |
|
278 |
" |
|
279 |
label := aLabel |
|
280 |
! |
|
281 |
||
282 |
setLabel:aLabel icon:anIcon |
|
283 |
"set the label and icon without any change notification |
|
284 |
" |
|
285 |
label := aLabel. |
|
286 |
icon := anIcon. |
|
287 |
! ! |
|
288 |
||
289 |
!HierarchicalItem class methodsFor:'documentation'! |
|
290 |
||
291 |
version |
|
5291 | 292 |
^ '$Header$' |
3849
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
293 |
! |
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
294 |
|
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
295 |
version_CVS |
5291 | 296 |
^ '$Header$' |
1390 | 297 |
! ! |
4188 | 298 |