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