author | Claus Gittinger <cg@exept.de> |
Mon, 04 May 2015 16:05:45 +0200 | |
changeset 4754 | 04b1da5a7647 |
parent 4748 | 997f7be95f45 |
child 4765 | 4074c0fef261 |
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. |
|
51 |
The class is used to build up hierarchical trees. |
|
52 |
||
53 |
[Instance variables:] |
|
54 |
parent <Item, List or nil> parent or my HierarchicalList. |
|
55 |
children <Collection or nil> list of children |
|
56 |
isExpanded <Boolean> indicates whether the item is |
|
57 |
expanded or collapsed |
|
4734 | 58 |
width <Integer> cached width of displayed label |
59 |
height <Integer> cached height of displayed label |
|
1390 | 60 |
|
61 |
[author:] |
|
62 |
Claus Atzkern |
|
63 |
||
64 |
[see also:] |
|
65 |
HierarchicalList |
|
66 |
HierarchicalListView |
|
67 |
" |
|
68 |
! ! |
|
69 |
||
4747 | 70 |
!HierarchicalItem methodsFor:'accessing'! |
71 |
||
72 |
height |
|
4748 | 73 |
"return the cached height" |
74 |
||
4747 | 75 |
^ height |
76 |
! |
|
77 |
||
78 |
height:something |
|
4748 | 79 |
"set the cached height" |
80 |
||
4747 | 81 |
height := something. |
82 |
! |
|
83 |
||
84 |
width |
|
4748 | 85 |
"return the cached width" |
86 |
||
4747 | 87 |
^ width |
88 |
! |
|
89 |
||
90 |
width:something |
|
4748 | 91 |
"set the cached width" |
92 |
||
4747 | 93 |
width := something. |
94 |
! ! |
|
95 |
||
1390 | 96 |
!HierarchicalItem methodsFor:'private'! |
97 |
||
4754 | 98 |
fetchChildren |
99 |
"should compute the list of children via the model. |
|
100 |
Be aware, that the somewhat stupid 'optimization' of how the model is fetched may lead to |
|
101 |
a O(n*log n) or even O(n^2) behavior here. |
|
102 |
*** to optimize: redefine by subClass" |
|
103 |
||
104 |
|model childrenFromModel| |
|
105 |
||
106 |
(model := self model) notNil ifTrue:[ |
|
107 |
childrenFromModel := model childrenFor:self |
|
108 |
]. |
|
109 |
^ childrenFromModel |
|
110 |
! |
|
111 |
||
4734 | 112 |
makeWidthAndHeightUnknown |
113 |
width := height := nil |
|
1390 | 114 |
! |
115 |
||
116 |
setExpanded:aBoolean |
|
2547 | 117 |
"set expanded flag without any computation or notification" |
118 |
||
1390 | 119 |
isExpanded := aBoolean |
120 |
! ! |
|
121 |
||
2851 | 122 |
!HierarchicalItem methodsFor:'protocol-displaying'! |
1390 | 123 |
|
124 |
heightOn:aGC |
|
4734 | 125 |
"return the height of the receiver, if it is to be displayed on aGC" |
3912 | 126 |
|
1606 | 127 |
height isNil ifTrue:[ |
128 |
height := self heightOf:(self label) on:aGC |
|
129 |
]. |
|
130 |
^ height |
|
1390 | 131 |
! |
132 |
||
133 |
widthOn:aGC |
|
3911 | 134 |
"return the width of the receiver, if it is to be displayed on aGC" |
135 |
||
1606 | 136 |
width isNil ifTrue:[ |
137 |
width := self widthOf:(self label) on:aGC |
|
138 |
]. |
|
139 |
^ width |
|
1390 | 140 |
! ! |
141 |
||
142 |
!HierarchicalItem methodsFor:'queries'! |
|
143 |
||
144 |
isExpanded |
|
2547 | 145 |
"returns true if the item is expanded" |
146 |
||
147 |
^ isExpanded |
|
2252 | 148 |
! ! |
149 |
||
1390 | 150 |
!HierarchicalItem::Example class methodsFor:'instance creation'! |
151 |
||
152 |
labeled:aLabel |
|
153 |
^ self new setLabel:aLabel |
|
154 |
||
155 |
||
156 |
! |
|
157 |
||
158 |
labeled:aLabel icon:anIcon |
|
159 |
^ self new setLabel:aLabel icon:anIcon |
|
160 |
||
161 |
||
162 |
! ! |
|
163 |
||
164 |
!HierarchicalItem::Example class methodsFor:'resources'! |
|
165 |
||
166 |
iconForLevel:aLevel |
|
167 |
"returns an icon |
|
168 |
" |
|
169 |
aLevel == 2 ifTrue:[ ^ ResourceSelectionBrowser iconPrivateClass ]. |
|
170 |
aLevel == 3 ifTrue:[ ^ ResourceSelectionBrowser iconClass ]. |
|
171 |
aLevel == 4 ifTrue:[ ^ ResourceSelectionBrowser iconCategory ]. |
|
172 |
||
173 |
^ nil |
|
174 |
! |
|
175 |
||
176 |
penguinIcon |
|
177 |
PenguinIcon isNil ifTrue:[ |
|
1794 | 178 |
PenguinIcon := Smalltalk imageFromFileNamed:'xpmBitmaps/misc_logos/linux_penguin.xpm' |
179 |
inPackage:'stx:goodies' |
|
1390 | 180 |
]. |
181 |
^ PenguinIcon |
|
182 |
! ! |
|
183 |
||
184 |
!HierarchicalItem::Example methodsFor:'accessing'! |
|
185 |
||
186 |
children |
|
2781 | 187 |
|lvl lbl txt image img icon| |
1390 | 188 |
|
189 |
children notNil ifTrue:[ |
|
190 |
^ children |
|
191 |
]. |
|
192 |
||
193 |
(lvl := self level) == 5 ifTrue:[ |
|
194 |
children := #(). |
|
195 |
^ children |
|
196 |
]. |
|
197 |
icon := self class iconForLevel:(lvl + 1). |
|
198 |
children := OrderedCollection new. |
|
199 |
||
200 |
lvl < 4 ifTrue:[ |
|
201 |
txt := (lvl + 1) printString, ' ['. |
|
2781 | 202 |
img := Icon saveIcon. |
1390 | 203 |
|
204 |
1 to:5 do:[:i| |
|
205 |
(i == 2 or:[i == 3]) ifTrue:[ |
|
206 |
lbl := img |
|
207 |
] ifFalse:[ |
|
208 |
i == 4 ifTrue:[ |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
209 |
lbl := Array with:(self class penguinIcon) |
4666 | 210 |
with:('penguin#and#text' copyReplaceAll:$# with:(Character cr)). |
1390 | 211 |
] ifFalse:[ |
212 |
lbl := txt, (i printString), ']' |
|
213 |
] |
|
214 |
]. |
|
215 |
children add:(self class labeled:lbl icon:icon) |
|
216 |
]. |
|
217 |
] ifFalse:[ |
|
218 |
image := ResourceSelectionBrowser iconPrivateClass. |
|
219 |
txt := LabelAndIcon icon:image string:'Text'. |
|
220 |
img := Icon copyIcon. |
|
221 |
||
222 |
1 to:5 do:[:i| |
|
223 |
lbl := i odd ifTrue:[txt] ifFalse:[img]. |
|
1398 | 224 |
lbl := Array with:lbl with:'test' with:img. |
1390 | 225 |
children add:(self class labeled:lbl icon:icon). |
3333 | 226 |
]. |
227 |
children add:(self class labeled:'Edit Text'). |
|
1390 | 228 |
]. |
229 |
||
230 |
children do:[:aChild| aChild parent:self ]. |
|
231 |
^ children |
|
232 |
! |
|
233 |
||
234 |
icon |
|
235 |
"returns the icon |
|
236 |
" |
|
237 |
^ icon |
|
238 |
! |
|
239 |
||
240 |
icon:anIcon |
|
241 |
"set the icon; if icon changed, a notification |
|
242 |
is raised. |
|
243 |
" |
|
244 |
icon ~= anIcon ifTrue:[ |
|
245 |
icon := anIcon. |
|
246 |
self iconChanged |
|
247 |
] |
|
248 |
! |
|
249 |
||
250 |
label |
|
251 |
"returns the label |
|
252 |
" |
|
253 |
^ label |
|
254 |
||
255 |
! |
|
256 |
||
257 |
label:aLabel |
|
258 |
"set the label; if label changed, a notification |
|
259 |
is raised. |
|
260 |
" |
|
261 |
label ~= aLabel ifTrue:[ |
|
262 |
label := aLabel. |
|
263 |
self changed. |
|
264 |
] |
|
265 |
||
266 |
! |
|
267 |
||
268 |
setIcon:anIcon |
|
269 |
"set the icon without any change notification |
|
270 |
" |
|
271 |
icon := anIcon |
|
272 |
! |
|
273 |
||
274 |
setLabel:aLabel |
|
275 |
"set the label without any change notification |
|
276 |
" |
|
277 |
label := aLabel |
|
278 |
! |
|
279 |
||
280 |
setLabel:aLabel icon:anIcon |
|
281 |
"set the label and icon without any change notification |
|
282 |
" |
|
283 |
label := aLabel. |
|
284 |
icon := anIcon. |
|
285 |
! ! |
|
286 |
||
287 |
!HierarchicalItem class methodsFor:'documentation'! |
|
288 |
||
289 |
version |
|
4754 | 290 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.114 2015-05-04 14:05:45 cg Exp $' |
3849
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
291 |
! |
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
292 |
|
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
293 |
version_CVS |
4754 | 294 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.114 2015-05-04 14:05:45 cg Exp $' |
1390 | 295 |
! ! |
4188 | 296 |