author | Claus Gittinger <cg@exept.de> |
Fri, 01 May 2015 16:38:36 +0200 | |
changeset 4734 | d2234ef436c3 |
parent 4719 | 46891483e90a |
child 4747 | 81aeb56b090c |
permissions | -rw-r--r-- |
4734 | 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 |
||
4734 | 18 |
AbstractHierarchicalItem subclass:#HierarchicalItem |
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. |
|
53 |
The class is used to build up hierarchical trees. |
|
54 |
||
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 |
||
72 |
!HierarchicalItem methodsFor:'private'! |
|
73 |
||
4734 | 74 |
makeWidthAndHeightUnknown |
75 |
width := height := nil |
|
1390 | 76 |
! |
77 |
||
78 |
setExpanded:aBoolean |
|
2547 | 79 |
"set expanded flag without any computation or notification" |
80 |
||
1390 | 81 |
isExpanded := aBoolean |
82 |
! ! |
|
83 |
||
2851 | 84 |
!HierarchicalItem methodsFor:'protocol-displaying'! |
1390 | 85 |
|
86 |
heightOn:aGC |
|
4734 | 87 |
"return the height of the receiver, if it is to be displayed on aGC" |
3912 | 88 |
|
1606 | 89 |
height isNil ifTrue:[ |
90 |
height := self heightOf:(self label) on:aGC |
|
91 |
]. |
|
92 |
^ height |
|
1390 | 93 |
! |
94 |
||
95 |
widthOn:aGC |
|
3911 | 96 |
"return the width of the receiver, if it is to be displayed on aGC" |
97 |
||
1606 | 98 |
width isNil ifTrue:[ |
99 |
width := self widthOf:(self label) on:aGC |
|
100 |
]. |
|
101 |
^ width |
|
1390 | 102 |
! ! |
103 |
||
104 |
!HierarchicalItem methodsFor:'queries'! |
|
105 |
||
106 |
isExpanded |
|
2547 | 107 |
"returns true if the item is expanded" |
108 |
||
109 |
^ isExpanded |
|
2252 | 110 |
! ! |
111 |
||
1390 | 112 |
!HierarchicalItem::Example class methodsFor:'instance creation'! |
113 |
||
114 |
labeled:aLabel |
|
115 |
^ self new setLabel:aLabel |
|
116 |
||
117 |
||
118 |
! |
|
119 |
||
120 |
labeled:aLabel icon:anIcon |
|
121 |
^ self new setLabel:aLabel icon:anIcon |
|
122 |
||
123 |
||
124 |
! ! |
|
125 |
||
126 |
!HierarchicalItem::Example class methodsFor:'resources'! |
|
127 |
||
128 |
iconForLevel:aLevel |
|
129 |
"returns an icon |
|
130 |
" |
|
131 |
aLevel == 2 ifTrue:[ ^ ResourceSelectionBrowser iconPrivateClass ]. |
|
132 |
aLevel == 3 ifTrue:[ ^ ResourceSelectionBrowser iconClass ]. |
|
133 |
aLevel == 4 ifTrue:[ ^ ResourceSelectionBrowser iconCategory ]. |
|
134 |
||
135 |
^ nil |
|
136 |
! |
|
137 |
||
138 |
penguinIcon |
|
139 |
PenguinIcon isNil ifTrue:[ |
|
1794 | 140 |
PenguinIcon := Smalltalk imageFromFileNamed:'xpmBitmaps/misc_logos/linux_penguin.xpm' |
141 |
inPackage:'stx:goodies' |
|
1390 | 142 |
]. |
143 |
^ PenguinIcon |
|
144 |
! ! |
|
145 |
||
146 |
!HierarchicalItem::Example methodsFor:'accessing'! |
|
147 |
||
148 |
children |
|
2781 | 149 |
|lvl lbl txt image img icon| |
1390 | 150 |
|
151 |
children notNil ifTrue:[ |
|
152 |
^ children |
|
153 |
]. |
|
154 |
||
155 |
(lvl := self level) == 5 ifTrue:[ |
|
156 |
children := #(). |
|
157 |
^ children |
|
158 |
]. |
|
159 |
icon := self class iconForLevel:(lvl + 1). |
|
160 |
children := OrderedCollection new. |
|
161 |
||
162 |
lvl < 4 ifTrue:[ |
|
163 |
txt := (lvl + 1) printString, ' ['. |
|
2781 | 164 |
img := Icon saveIcon. |
1390 | 165 |
|
166 |
1 to:5 do:[:i| |
|
167 |
(i == 2 or:[i == 3]) ifTrue:[ |
|
168 |
lbl := img |
|
169 |
] ifFalse:[ |
|
170 |
i == 4 ifTrue:[ |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
171 |
lbl := Array with:(self class penguinIcon) |
4666 | 172 |
with:('penguin#and#text' copyReplaceAll:$# with:(Character cr)). |
1390 | 173 |
] ifFalse:[ |
174 |
lbl := txt, (i printString), ']' |
|
175 |
] |
|
176 |
]. |
|
177 |
children add:(self class labeled:lbl icon:icon) |
|
178 |
]. |
|
179 |
] ifFalse:[ |
|
180 |
image := ResourceSelectionBrowser iconPrivateClass. |
|
181 |
txt := LabelAndIcon icon:image string:'Text'. |
|
182 |
img := Icon copyIcon. |
|
183 |
||
184 |
1 to:5 do:[:i| |
|
185 |
lbl := i odd ifTrue:[txt] ifFalse:[img]. |
|
1398 | 186 |
lbl := Array with:lbl with:'test' with:img. |
1390 | 187 |
children add:(self class labeled:lbl icon:icon). |
3333 | 188 |
]. |
189 |
children add:(self class labeled:'Edit Text'). |
|
1390 | 190 |
]. |
191 |
||
192 |
children do:[:aChild| aChild parent:self ]. |
|
193 |
^ children |
|
194 |
! |
|
195 |
||
196 |
icon |
|
197 |
"returns the icon |
|
198 |
" |
|
199 |
^ icon |
|
200 |
! |
|
201 |
||
202 |
icon:anIcon |
|
203 |
"set the icon; if icon changed, a notification |
|
204 |
is raised. |
|
205 |
" |
|
206 |
icon ~= anIcon ifTrue:[ |
|
207 |
icon := anIcon. |
|
208 |
self iconChanged |
|
209 |
] |
|
210 |
! |
|
211 |
||
212 |
label |
|
213 |
"returns the label |
|
214 |
" |
|
215 |
^ label |
|
216 |
||
217 |
! |
|
218 |
||
219 |
label:aLabel |
|
220 |
"set the label; if label changed, a notification |
|
221 |
is raised. |
|
222 |
" |
|
223 |
label ~= aLabel ifTrue:[ |
|
224 |
label := aLabel. |
|
225 |
self changed. |
|
226 |
] |
|
227 |
||
228 |
! |
|
229 |
||
230 |
setIcon:anIcon |
|
231 |
"set the icon without any change notification |
|
232 |
" |
|
233 |
icon := anIcon |
|
234 |
! |
|
235 |
||
236 |
setLabel:aLabel |
|
237 |
"set the label without any change notification |
|
238 |
" |
|
239 |
label := aLabel |
|
240 |
! |
|
241 |
||
242 |
setLabel:aLabel icon:anIcon |
|
243 |
"set the label and icon without any change notification |
|
244 |
" |
|
245 |
label := aLabel. |
|
246 |
icon := anIcon. |
|
247 |
! ! |
|
248 |
||
249 |
!HierarchicalItem class methodsFor:'documentation'! |
|
250 |
||
251 |
version |
|
4734 | 252 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.111 2015-05-01 14:38:36 cg Exp $' |
3849
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
253 |
! |
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
254 |
|
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
255 |
version_CVS |
4734 | 256 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.111 2015-05-01 14:38:36 cg Exp $' |
1390 | 257 |
! ! |
4188 | 258 |