author | ca |
Wed, 27 Oct 1999 16:27:43 +0200 | |
changeset 1606 | b46b9ec4b5d8 |
parent 1602 | 00fe8b9b81d6 |
child 1607 | 70971b7e81cc |
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 |
" |
|
12 |
||
13 |
||
1390 | 14 |
Object subclass:#HierarchicalItem |
1606 | 15 |
instanceVariableNames:'parent children isExpanded height width' |
1390 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
1430 | 18 |
category:'Views-Support' |
1390 | 19 |
! |
20 |
||
21 |
HierarchicalItem subclass:#Example |
|
22 |
instanceVariableNames:'label icon' |
|
23 |
classVariableNames:'PenguinIcon' |
|
24 |
poolDictionaries:'' |
|
25 |
privateIn:HierarchicalItem |
|
26 |
! |
|
27 |
||
28 |
!HierarchicalItem class methodsFor:'documentation'! |
|
29 |
||
1431 | 30 |
copyright |
31 |
" |
|
32 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
33 |
All Rights Reserved |
|
34 |
||
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
||
43 |
! |
|
44 |
||
1390 | 45 |
documentation |
46 |
" |
|
47 |
Hierarchical Items are mostly like Models, but the list of |
|
48 |
dependencies are kept by its HierarchicalList. |
|
49 |
The class is used to build up hierarchical trees. |
|
50 |
||
51 |
[Instance variables:] |
|
52 |
parent <Item, List or nil> parent or my HierarchicalList. |
|
53 |
children <Collection or nil> list of children |
|
54 |
isExpanded <Boolean> indicates whether the item is |
|
55 |
expanded or collapsed |
|
56 |
||
57 |
[author:] |
|
58 |
Claus Atzkern |
|
59 |
||
60 |
[see also:] |
|
61 |
HierarchicalList |
|
62 |
HierarchicalListView |
|
63 |
" |
|
64 |
||
65 |
||
66 |
! ! |
|
67 |
||
68 |
!HierarchicalItem class methodsFor:'instance creation'! |
|
69 |
||
70 |
new |
|
71 |
^ (self basicNew) initialize |
|
72 |
! ! |
|
73 |
||
74 |
!HierarchicalItem methodsFor:'accessing'! |
|
75 |
||
76 |
level |
|
77 |
"returns the level starting with 1 |
|
78 |
" |
|
79 |
|parent |
|
80 |
level "{ Class:SmallInteger }" |
|
81 |
| |
|
82 |
level := 0. |
|
83 |
parent := self. |
|
84 |
||
85 |
[(parent := parent parentOrModel) notNil] whileTrue:[ |
|
86 |
level := level + 1 |
|
87 |
]. |
|
88 |
^ level |
|
89 |
||
90 |
! |
|
91 |
||
92 |
parent |
|
93 |
"returns the parent or nil |
|
94 |
" |
|
95 |
^ (parent notNil and:[parent isHierarchicalItem]) ifTrue:[parent] |
|
96 |
ifFalse:[nil] |
|
97 |
! |
|
98 |
||
99 |
parent:aParent |
|
100 |
"set the parent (or the model if the item is the root item) |
|
101 |
" |
|
102 |
parent := aParent |
|
103 |
||
104 |
! ! |
|
105 |
||
106 |
!HierarchicalItem methodsFor:'accessing children'! |
|
107 |
||
108 |
at:anIndex |
|
109 |
"returns the child under an index or nil |
|
110 |
" |
|
111 |
^ self children notNil ifTrue:[children at:anIndex ifAbsent:nil] |
|
112 |
ifFalse:[nil] |
|
113 |
! |
|
114 |
||
115 |
at:anIndex put:anItem |
|
116 |
"replace a child by a new item |
|
117 |
" |
|
118 |
|oldItem itemExpanded size| |
|
119 |
||
120 |
size := self children size. |
|
121 |
||
122 |
(anIndex between:1 and:size) ifFalse:[ |
|
123 |
^ self subscriptBoundsError |
|
124 |
]. |
|
125 |
||
126 |
anItem isNil ifTrue:[ |
|
127 |
^ self removeFromIndex:anIndex toIndex:anIndex. |
|
128 |
]. |
|
129 |
||
130 |
oldItem := children at:anIndex. |
|
131 |
oldItem collapse. |
|
132 |
itemExpanded := anItem isExpanded. |
|
133 |
anItem setExpanded:false. |
|
134 |
children at:anIndex put:anItem. |
|
135 |
self changed. |
|
136 |
||
137 |
itemExpanded ifTrue:[ |
|
138 |
anItem expand |
|
139 |
]. |
|
140 |
! |
|
141 |
||
142 |
children:aListOfChildren |
|
143 |
"set a new list of children |
|
144 |
" |
|
145 |
self removeAll. |
|
146 |
^ self addAll:aListOfChildren beforeIndex:1 |
|
147 |
! |
|
148 |
||
149 |
first |
|
150 |
"returns the first child |
|
151 |
" |
|
152 |
^ self at:1 |
|
153 |
! |
|
154 |
||
155 |
last |
|
156 |
"returns the last child |
|
157 |
" |
|
158 |
^ self at:(self children size) |
|
159 |
! ! |
|
160 |
||
161 |
!HierarchicalItem methodsFor:'accessing hierarchy'! |
|
162 |
||
163 |
collapse |
|
164 |
"hide children |
|
165 |
" |
|
166 |
|visChd model index| |
|
167 |
||
168 |
self canCollapse ifTrue:[ |
|
169 |
isExpanded := false. |
|
170 |
||
171 |
(index := self listIndex) notNil ifTrue:[ |
|
172 |
(visChd := children size) ~~ 0 ifTrue:[ |
|
173 |
children do:[:aChild| |
|
174 |
visChd := visChd + aChild numberOfVisibleChildren |
|
175 |
]. |
|
176 |
self model itemRemoveFromIndex:(index + 1) |
|
177 |
toIndex:(index + visChd). |
|
178 |
||
179 |
index ~~ 0 ifTrue:[ |
|
180 |
self hierarchyChanged |
|
181 |
] |
|
182 |
] |
|
183 |
] |
|
184 |
] |
|
185 |
! |
|
186 |
||
187 |
expand |
|
188 |
"expand children |
|
189 |
" |
|
190 |
|index list| |
|
191 |
||
192 |
self canExpand ifTrue:[ |
|
193 |
isExpanded := true. |
|
194 |
||
195 |
(index := self listIndex) notNil ifTrue:[ |
|
196 |
(children notNil or:[self children notNil]) ifTrue:[ |
|
197 |
children notEmpty ifTrue:[ |
|
198 |
list := OrderedCollection new:64. |
|
199 |
self addVisibleChildrenTo:list. |
|
200 |
self model itemAddAll:list beforeIndex:(index + 1). |
|
201 |
]. |
|
202 |
index ~~ 0 ifTrue:[ |
|
203 |
self hierarchyChanged |
|
204 |
] |
|
205 |
] |
|
206 |
] |
|
207 |
] |
|
208 |
||
209 |
! |
|
210 |
||
1409 | 211 |
makeVisible |
212 |
"expand all my parents |
|
213 |
" |
|
214 |
(parent notNil and:[parent isHierarchicalItem]) ifTrue:[ |
|
215 |
parent expand. |
|
216 |
parent makeVisible |
|
217 |
]. |
|
218 |
! |
|
219 |
||
1390 | 220 |
recursiveCollapse |
221 |
"collapse children and sub-children |
|
222 |
**** must be expanded |
|
223 |
" |
|
224 |
|visChd index| |
|
225 |
||
226 |
self canCollapse ifTrue:[ |
|
227 |
(index := self listIndex) notNil ifTrue:[ |
|
228 |
(visChd := children size) ~~ 0 ifTrue:[ |
|
229 |
children do:[:aChild| |
|
230 |
visChd := visChd + aChild numberOfVisibleChildren |
|
231 |
] |
|
232 |
]. |
|
233 |
self recursiveSetCollapsed. |
|
234 |
||
235 |
visChd ~~ 0 ifTrue:[ |
|
236 |
self model itemRemoveFromIndex:(index + 1) |
|
237 |
toIndex:(index + visChd) |
|
238 |
]. |
|
239 |
index ~~ 0 ifTrue:[ |
|
240 |
self hierarchyChanged |
|
241 |
] |
|
242 |
] ifFalse:[ |
|
243 |
self recursiveSetCollapsed |
|
244 |
] |
|
245 |
] |
|
246 |
||
247 |
! |
|
248 |
||
249 |
recursiveExpand |
|
250 |
"expand children and sub-children |
|
251 |
**** must be collapsed |
|
252 |
" |
|
253 |
|model index list| |
|
254 |
||
255 |
self canExpand ifTrue:[ |
|
256 |
isExpanded := true. |
|
257 |
||
258 |
self children size ~~ 0 ifTrue:[ |
|
259 |
(index := self listIndex) isNil ifTrue:[ |
|
260 |
children do:[:aChild| aChild setExpanded:true ] |
|
261 |
] ifFalse:[ |
|
262 |
list := OrderedCollection new:512. |
|
263 |
self recursiveSetExpandedAndAddToList:list. |
|
264 |
self model itemAddAll:list beforeIndex:(index + 1). |
|
265 |
||
266 |
index ~~ 0 ifTrue:[ |
|
267 |
self hierarchyChanged |
|
268 |
] |
|
269 |
] |
|
270 |
] |
|
271 |
] |
|
272 |
! |
|
273 |
||
274 |
recursiveToggleExpand |
|
275 |
"if the item is collapsed, the children and all sub-children |
|
276 |
are expanded otherwise collapsed |
|
277 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
278 |
(isExpanded == true) ifTrue:[ |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
279 |
self recursiveCollapse |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
280 |
] ifFalse:[ |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
281 |
self recursiveExpand |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
282 |
] |
1390 | 283 |
|
284 |
! |
|
285 |
||
286 |
toggleExpand |
|
287 |
"if the item is collapsed, the children are expanded |
|
288 |
otherwise collapsed |
|
289 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
290 |
(isExpanded == true) ifTrue:[ |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
291 |
self collapse |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
292 |
] ifFalse:[ |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
293 |
self expand |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
294 |
] |
1390 | 295 |
|
296 |
! ! |
|
297 |
||
298 |
!HierarchicalItem methodsFor:'accessing mvc'! |
|
299 |
||
300 |
application |
|
301 |
"returns the responsible application or nil |
|
302 |
" |
|
303 |
|model| |
|
304 |
||
305 |
(model := self model) notNil ifTrue:[ |
|
306 |
^ model application |
|
307 |
]. |
|
308 |
^ nil |
|
309 |
! |
|
310 |
||
311 |
applicationsDo:aOneArgBlock |
|
312 |
"evaluate the block on each dependent application |
|
313 |
" |
|
314 |
|model| |
|
315 |
||
316 |
(model := self model) notNil ifTrue:[ |
|
317 |
model applicationsDo:aOneArgBlock |
|
318 |
] |
|
319 |
||
320 |
! |
|
321 |
||
322 |
model |
|
323 |
"returns the hierachicalList model or nil |
|
324 |
" |
|
325 |
|p model| |
|
326 |
||
327 |
model := self. |
|
328 |
[(p := model parentOrModel) notNil] whileTrue:[model := p]. |
|
329 |
^ model isHierarchicalItem ifFalse:[model] ifTrue:[nil] |
|
330 |
! ! |
|
331 |
||
332 |
!HierarchicalItem methodsFor:'adding & removing'! |
|
333 |
||
334 |
add:aChildItem |
|
335 |
"add a child at end |
|
336 |
" |
|
337 |
^ self add:aChildItem beforeIndex:(self children size + 1). |
|
338 |
||
339 |
! |
|
340 |
||
341 |
add:aChildItem after:aChild |
|
342 |
"add an item after an existing item |
|
343 |
" |
|
344 |
|index| |
|
345 |
||
1539 | 346 |
(index := self identityIndexOf:aChild) ~~ 0 ifTrue:[ |
1390 | 347 |
self subscriptBoundsError |
348 |
] ifFalse:[ |
|
349 |
self add:aChildItem beforeIndex:(index + 1) |
|
350 |
]. |
|
351 |
^ aChildItem |
|
352 |
! |
|
353 |
||
354 |
add:aChildItem afterIndex:anIndex |
|
355 |
"add an item after an index |
|
356 |
" |
|
357 |
^ self add:aChildItem beforeIndex:(anIndex + 1). |
|
358 |
! |
|
359 |
||
360 |
add:aChildItem before:aChild |
|
361 |
"add an item before an existing item |
|
362 |
" |
|
363 |
|index| |
|
364 |
||
365 |
(index := self identityIndexOf:aChild) ~~ 0 ifTrue:[ |
|
366 |
^ self add:aChildItem beforeIndex:index |
|
367 |
]. |
|
368 |
self subscriptBoundsError |
|
369 |
! |
|
370 |
||
371 |
add:aChildItem beforeIndex:anIndex |
|
372 |
"add an item before an index |
|
373 |
" |
|
374 |
aChildItem notNil ifTrue:[ |
|
375 |
self addAll:(Array with:aChildItem) beforeIndex:anIndex |
|
376 |
]. |
|
377 |
^ aChildItem |
|
378 |
! |
|
379 |
||
1488 | 380 |
add:aChild sortBlock:aBlock |
381 |
"add a child sorted |
|
382 |
" |
|
383 |
(aBlock notNil and:[children size ~~ 0]) ifTrue:[ |
|
384 |
children keysAndValuesDo:[:index :child| |
|
385 |
(aBlock value:aChild value:child) ifTrue:[ |
|
386 |
^ self add:aChild beforeIndex:index |
|
387 |
] |
|
388 |
] |
|
389 |
]. |
|
390 |
^ self add:aChild |
|
391 |
! |
|
392 |
||
1390 | 393 |
addAll:aList |
394 |
"add children at the end |
|
395 |
" |
|
396 |
^ self addAll:aList beforeIndex:(self children size + 1) |
|
397 |
! |
|
398 |
||
399 |
addAll:aList beforeIndex:anIndex |
|
400 |
"add children before an index |
|
401 |
" |
|
1602 | 402 |
|coll model notify index size| |
1390 | 403 |
|
404 |
(aList isNil or:[aList isEmpty]) ifTrue:[ |
|
405 |
^ aList |
|
406 |
]. |
|
407 |
size := self children size. |
|
408 |
||
409 |
anIndex == 1 ifTrue:[ |
|
410 |
notify := self |
|
411 |
] ifFalse:[ |
|
412 |
anIndex > size ifTrue:[ |
|
413 |
anIndex > (1 + size) ifTrue:[ |
|
414 |
^ self subscriptBoundsError |
|
415 |
]. |
|
416 |
notify := self at:size |
|
417 |
] ifFalse:[ |
|
418 |
notify := nil |
|
419 |
] |
|
420 |
]. |
|
421 |
||
422 |
size == 0 ifTrue:[ |
|
423 |
children := OrderedCollection new |
|
424 |
]. |
|
425 |
aList do:[:anItem| anItem parent:self ]. |
|
426 |
children addAll:aList beforeIndex:anIndex. |
|
427 |
||
428 |
(model := self model) isNil ifTrue:[ |
|
429 |
^ aList |
|
430 |
]. |
|
431 |
||
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
432 |
(isExpanded == true) ifFalse:[ |
1390 | 433 |
notify notNil ifTrue:[ |
434 |
notify changed |
|
435 |
]. |
|
436 |
^ aList |
|
437 |
]. |
|
438 |
(index := self listIndex) isNil ifTrue:[ |
|
439 |
^ aList |
|
440 |
]. |
|
441 |
||
442 |
children from:1 to:(anIndex - 1) do:[:anItem| |
|
443 |
index := 1 + index + anItem numberOfVisibleChildren |
|
444 |
]. |
|
445 |
coll := OrderedCollection new. |
|
446 |
||
447 |
aList do:[:anItem| |
|
448 |
coll add:anItem. |
|
449 |
anItem addVisibleChildrenTo:coll. |
|
450 |
]. |
|
451 |
model itemAddAll:coll beforeIndex:(index + 1). |
|
452 |
||
453 |
notify notNil ifTrue:[ |
|
454 |
notify changed |
|
455 |
]. |
|
456 |
^ aList |
|
457 |
! |
|
458 |
||
1489 | 459 |
addAll:aList sortBlock:aBlock |
460 |
"add children sorted |
|
461 |
" |
|
462 |
aList notNil ifTrue:[ |
|
463 |
aBlock isNil ifTrue:[ |
|
464 |
^ self addAll:aList |
|
465 |
]. |
|
466 |
aList do:[:el|self add:el sortBlock:aBlock] |
|
467 |
]. |
|
468 |
^ aList |
|
469 |
! |
|
470 |
||
1390 | 471 |
addAllFirst:aCollectionOfItems |
472 |
"add children at the beginning |
|
473 |
" |
|
474 |
^ self addAll:aCollectionOfItems beforeIndex:1 |
|
475 |
! |
|
476 |
||
477 |
addAllLast:aCollectionOfItems |
|
478 |
"add children at the end |
|
479 |
" |
|
480 |
^ self addAll:aCollectionOfItems |
|
481 |
! |
|
482 |
||
483 |
addFirst:aChildItem |
|
484 |
"add a child at begin |
|
485 |
" |
|
486 |
^ self add:aChildItem beforeIndex:1. |
|
487 |
||
488 |
! |
|
489 |
||
490 |
addLast:anItem |
|
491 |
"add a child at end |
|
492 |
" |
|
493 |
^ self add:anItem |
|
494 |
! |
|
495 |
||
496 |
remove:aChild |
|
497 |
"remove a child |
|
498 |
" |
|
499 |
self removeIndex:(self identityIndexOf:aChild) |
|
500 |
||
501 |
! |
|
502 |
||
503 |
removeAll |
|
504 |
"remove all children |
|
505 |
" |
|
506 |
|size| |
|
507 |
||
508 |
(size := self children size) ~~ 0 ifTrue:[ |
|
509 |
self removeFromIndex:1 toIndex:size |
|
510 |
] |
|
511 |
! |
|
512 |
||
1489 | 513 |
removeAll:aList |
514 |
"remove all children in the collection |
|
515 |
" |
|
516 |
|index| |
|
517 |
||
518 |
aList size ~~ 0 ifTrue:[ |
|
519 |
aList do:[:el| |
|
520 |
index := self identityIndexOf:el. |
|
521 |
index ~~ 0 ifTrue:[ |
|
522 |
self removeIndex:index |
|
523 |
] |
|
524 |
] |
|
525 |
] |
|
526 |
! |
|
527 |
||
1390 | 528 |
removeFromIndex:startIndex toIndex:stopIndex |
529 |
"remove the children from startIndex up to and including |
|
530 |
the child under stopIndex. |
|
531 |
" |
|
532 |
|model notify |
|
533 |
index "{ Class:SmallInteger }" |
|
534 |
start "{ Class:SmallInteger }" |
|
535 |
stop "{ Class:SmallInteger }" |
|
536 |
size "{ Class:SmallInteger }" |
|
537 |
| |
|
538 |
size := self children size. |
|
539 |
stop := stopIndex. |
|
540 |
start := startIndex. |
|
541 |
||
542 |
(stop <= size and:[start between:1 and:stop]) ifFalse:[ |
|
543 |
^ self subscriptBoundsError |
|
544 |
]. |
|
545 |
start == 1 ifTrue:[ |
|
546 |
notify := self |
|
547 |
] ifFalse:[ |
|
548 |
stop == size ifTrue:[ |
|
549 |
notify := self at:(start - 1) |
|
550 |
] ifFalse:[ |
|
551 |
notify := nil |
|
552 |
] |
|
553 |
]. |
|
554 |
||
555 |
(model := self model) notNil ifTrue:[ |
|
556 |
index := model identityIndexOf:(children at:start). |
|
557 |
size := stop - start + 1. |
|
558 |
] ifFalse:[ |
|
559 |
index := 0 |
|
560 |
]. |
|
561 |
children from:start to:stop do:[:aChild| |
|
562 |
index ~~ 0 ifTrue:[ |
|
563 |
size := size + aChild numberOfVisibleChildren |
|
564 |
]. |
|
565 |
aChild parent:nil |
|
566 |
]. |
|
567 |
children removeFromIndex:start toIndex:stop. |
|
568 |
||
569 |
index ~~ 0 ifTrue:[ |
|
570 |
model itemRemoveFromIndex:index toIndex:(index + size - 1) |
|
571 |
]. |
|
572 |
notify notNil ifTrue:[ |
|
573 |
notify changed |
|
574 |
]. |
|
575 |
! |
|
576 |
||
577 |
removeIndex:anIndex |
|
578 |
"remove the child at an index |
|
579 |
" |
|
580 |
anIndex > 0 ifTrue:[ |
|
581 |
self removeFromIndex:anIndex toIndex:anIndex |
|
582 |
] |
|
583 |
! ! |
|
584 |
||
585 |
!HierarchicalItem methodsFor:'change & update'! |
|
586 |
||
587 |
changed |
|
588 |
"the item changed; raise change notification |
|
589 |
" |
|
590 |
self changed:nil with:nil |
|
591 |
! |
|
592 |
||
593 |
changed:aParameter |
|
594 |
"the item changed; raise change notification |
|
595 |
" |
|
596 |
self changed:aParameter with:nil |
|
597 |
||
598 |
! |
|
599 |
||
1606 | 600 |
changed:what with:anArgument |
1390 | 601 |
"the item changed; raise change notification |
602 |
" |
|
603 |
|model| |
|
604 |
||
1606 | 605 |
(what ~~ #hierarchy and:[what ~~ #icon]) ifTrue:[ |
606 |
width := nil |
|
607 |
]. |
|
1390 | 608 |
|
1606 | 609 |
(model := self model) notNil ifTrue:[ |
610 |
model itemChanged:what with:anArgument from:self |
|
1390 | 611 |
]. |
1606 | 612 |
super changed:what with:anArgument |
1390 | 613 |
! |
614 |
||
615 |
hierarchyChanged |
|
616 |
"hierarchy changed; optimize redrawing |
|
617 |
" |
|
618 |
self changed:#hierarchy with:nil |
|
619 |
! |
|
620 |
||
621 |
iconChanged |
|
622 |
"icon changed; optimize redrawing |
|
623 |
" |
|
624 |
self changed:#icon with:nil |
|
625 |
! ! |
|
626 |
||
627 |
!HierarchicalItem methodsFor:'enumerating'! |
|
628 |
||
629 |
do:aOneArgBlock |
|
630 |
"evaluate a block on each child |
|
631 |
" |
|
632 |
self children notNil ifTrue:[ children do:aOneArgBlock ] |
|
633 |
||
634 |
! |
|
635 |
||
636 |
from:startIndex do:aOneArgBlock |
|
637 |
"evaluate a block on each child starting with the |
|
638 |
child at startIndex to the end. |
|
639 |
" |
|
640 |
self from:startIndex to:self size do:aOneArgBlock |
|
641 |
! |
|
642 |
||
643 |
from:startIndex to:endIndex do:aOneArgBlock |
|
644 |
"evaluate a block on each child starting with the |
|
645 |
child at startIndex to the endIndex. |
|
646 |
" |
|
647 |
self children notNil ifTrue:[ |
|
648 |
children from:startIndex to:endIndex do:aOneArgBlock |
|
649 |
] |
|
650 |
||
651 |
! |
|
652 |
||
653 |
from:startIndex to:endIndex reverseDo:aOneArgBlock |
|
654 |
"evaluate a block on each child starting with the |
|
655 |
child at endIndex to the startIndex. |
|
656 |
" |
|
657 |
self children notNil ifTrue:[ |
|
658 |
children from:startIndex to:endIndex reverseDo:aOneArgBlock |
|
659 |
] |
|
660 |
||
661 |
! |
|
662 |
||
663 |
recursiveDo:aOneArgBlock |
|
664 |
"evaluate a block on each item and all the sub-items |
|
665 |
" |
|
666 |
self do:[:aChild| |
|
667 |
aOneArgBlock value:aChild. |
|
668 |
aChild recursiveDo:aOneArgBlock |
|
669 |
]. |
|
670 |
||
671 |
! |
|
672 |
||
673 |
reverseDo:aOneArgBlock |
|
674 |
"evaluate a block on each child |
|
675 |
procesing children in reverse direction |
|
676 |
" |
|
677 |
self children notNil ifTrue:[ children reverseDo:aOneArgBlock ] |
|
678 |
||
679 |
! ! |
|
680 |
||
681 |
!HierarchicalItem methodsFor:'initialization'! |
|
682 |
||
683 |
initialize |
|
684 |
isExpanded := false |
|
685 |
! ! |
|
686 |
||
687 |
!HierarchicalItem methodsFor:'private'! |
|
688 |
||
689 |
addVisibleChildrenTo:aList |
|
690 |
"add all visible children and sub-children to the list |
|
691 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
692 |
isExpanded == true ifTrue:[ |
1390 | 693 |
(children notNil or:[self children notNil]) ifTrue:[ |
694 |
children do:[:aChild| |
|
695 |
aList add:aChild. |
|
696 |
aChild addVisibleChildrenTo:aList |
|
697 |
] |
|
698 |
] |
|
699 |
] |
|
700 |
||
701 |
||
702 |
||
703 |
||
704 |
||
705 |
! |
|
706 |
||
707 |
listIndex |
|
708 |
"returns the visible index or nil; for a none visible root |
|
709 |
0 is returned |
|
710 |
" |
|
711 |
|index model| |
|
712 |
||
713 |
(model := self model) notNil ifTrue:[ |
|
714 |
index := model identityIndexOf:self. |
|
715 |
||
716 |
(index ~~ 0 or:[parent == model]) ifTrue:[ |
|
717 |
^ index |
|
718 |
] |
|
719 |
]. |
|
720 |
^ nil |
|
721 |
! |
|
722 |
||
723 |
numberOfVisibleChildren |
|
724 |
"returns number of all visible children including subchildren |
|
725 |
" |
|
726 |
|size "{ Class: SmallInteger }" |
|
727 |
| |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
728 |
(isExpanded == true) ifTrue:[ |
1390 | 729 |
(children notNil or:[self children notNil]) ifTrue:[ |
730 |
(size := children size) ~~ 0 ifTrue:[ |
|
731 |
children do:[:el| size := size + el numberOfVisibleChildren ]. |
|
732 |
^ size |
|
733 |
] |
|
734 |
] |
|
735 |
]. |
|
736 |
^ 0 |
|
737 |
||
738 |
||
739 |
||
740 |
||
741 |
! |
|
742 |
||
743 |
parentOrModel |
|
744 |
"returns the parent without checking for item or model |
|
745 |
" |
|
746 |
^ parent |
|
747 |
! |
|
748 |
||
749 |
setExpanded:aBoolean |
|
750 |
"set expanded flag without any computation or notification |
|
751 |
" |
|
752 |
isExpanded := aBoolean |
|
753 |
! ! |
|
754 |
||
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
755 |
!HierarchicalItem methodsFor:'private displaying'! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
756 |
|
1606 | 757 |
displayLabel:aLabel h:lH on:aGC x:x y:y h:h |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
758 |
"display the label at x@y |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
759 |
" |
1606 | 760 |
|y0 hF| |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
761 |
|
1606 | 762 |
lH ~~ 0 ifTrue:[ |
763 |
y0 := y - (lH + 1 - h // 2). |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
764 |
|
1606 | 765 |
aLabel isImageOrForm ifTrue:[ |
766 |
^ aLabel displayOn:aGC x:x y:y0 |
|
767 |
]. |
|
768 |
y0 := y0 + (aGC font ascent). |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
769 |
|
1606 | 770 |
aLabel isString ifFalse:[ |
771 |
^ aLabel displayOn:aGC x:x y:y0 |
|
772 |
]. |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
773 |
|
1606 | 774 |
(aLabel indexOf:(Character cr)) == 0 ifTrue:[ |
775 |
^ aLabel displayOn:aGC x:x y:y0 |
|
776 |
]. |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
777 |
|
1606 | 778 |
hF := aGC font height. |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
779 |
|
1606 | 780 |
aLabel asCollectionOfLines do:[:el| |
781 |
el displayOn:aGC x:x y:y0. |
|
782 |
y0 := y0 + hF |
|
783 |
] |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
784 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
785 |
! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
786 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
787 |
heightOf:aLabel on:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
788 |
"returns the height of the label or 0 |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
789 |
" |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
790 |
|h| |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
791 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
792 |
aLabel isSequenceable ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
793 |
^ aLabel notNil ifTrue:[aLabel heightOn:aGC] ifFalse:[0] |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
794 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
795 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
796 |
aLabel isString ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
797 |
h := 0. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
798 |
aLabel do:[:el|h := h max:(self heightOf:el on:aGC)]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
799 |
^ h |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
800 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
801 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
802 |
h := 1 + (aLabel occurrencesOf:(Character cr)). |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
803 |
^ h * (aGC font height) |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
804 |
! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
805 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
806 |
widthOf:aLabel on:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
807 |
"returns the height of the label or 0 |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
808 |
" |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
809 |
|w| |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
810 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
811 |
aLabel isSequenceable ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
812 |
^ aLabel notNil ifTrue:[aLabel widthOn:aGC] ifFalse:[0] |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
813 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
814 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
815 |
aLabel isString ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
816 |
w := -5. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
817 |
aLabel do:[:el|w := w + 5 + (self widthOf:el on:aGC)]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
818 |
^ w |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
819 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
820 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
821 |
(aLabel indexOf:(Character cr)) == 0 ifTrue:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
822 |
^ aLabel widthOn:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
823 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
824 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
825 |
w := 0. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
826 |
aLabel asCollectionOfLines do:[:el|w := w max:(el widthOn:aGC)]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
827 |
^ w |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
828 |
! ! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
829 |
|
1390 | 830 |
!HierarchicalItem methodsFor:'private hierarchy'! |
831 |
||
832 |
recursiveSetCollapsed |
|
833 |
"collapse all children and sub-children without notifications |
|
834 |
" |
|
835 |
isExpanded := false. |
|
836 |
||
837 |
children notNil ifTrue:[ |
|
838 |
children do:[:aChild| aChild recursiveSetCollapsed ] |
|
839 |
] |
|
840 |
! |
|
841 |
||
842 |
recursiveSetExpandedAndAddToList:aList |
|
843 |
"expand all children and sub-children without notifications; |
|
844 |
add children to list |
|
845 |
" |
|
846 |
isExpanded := true. |
|
847 |
||
848 |
(children notNil or:[self children notNil]) ifTrue:[ |
|
849 |
children do:[:aChild| |
|
850 |
aList add:aChild. |
|
851 |
aChild recursiveSetExpandedAndAddToList:aList. |
|
852 |
] |
|
853 |
] |
|
854 |
||
855 |
! ! |
|
856 |
||
857 |
!HierarchicalItem methodsFor:'protocol accessing'! |
|
858 |
||
859 |
children |
|
860 |
"returns list of children |
|
861 |
*** to optimize:redefine by subClass |
|
862 |
" |
|
863 |
|model| |
|
864 |
||
865 |
children isNil ifTrue:[ |
|
866 |
(model := self model) notNil ifTrue:[ |
|
1486 | 867 |
children := model childrenFor:self |
1390 | 868 |
]. |
869 |
]. |
|
870 |
^ children |
|
871 |
! |
|
872 |
||
873 |
icon |
|
874 |
"returns the icon or nil; |
|
875 |
*** to optimize:redefine by subClass |
|
876 |
" |
|
877 |
|model| |
|
878 |
||
879 |
(model := self model) notNil ifTrue:[ |
|
880 |
^ model iconFor:self |
|
881 |
]. |
|
882 |
^ nil |
|
883 |
! |
|
884 |
||
885 |
label |
|
886 |
"returns the label displayed on aGC; |
|
887 |
*** to optimize:redefine by subClass |
|
888 |
" |
|
889 |
|model| |
|
890 |
||
891 |
(model := self model) notNil ifTrue:[ |
|
892 |
^ model labelFor:self |
|
893 |
]. |
|
894 |
^ nil |
|
895 |
||
896 |
! |
|
897 |
||
898 |
middleButtonMenu |
|
899 |
"returns the middleButtonMenu or nil if no menu is defined |
|
900 |
" |
|
901 |
|model| |
|
902 |
||
903 |
(model := self model) notNil ifTrue:[ |
|
904 |
^ model middleButtonMenuFor:self |
|
905 |
]. |
|
906 |
^ nil |
|
907 |
! ! |
|
908 |
||
909 |
!HierarchicalItem methodsFor:'protocol displaying'! |
|
910 |
||
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1489
diff
changeset
|
911 |
displayOn:aGC x:x y:y h:h |
1390 | 912 |
"draw the receiver in the graphicsContext, aGC. |
913 |
" |
|
914 |
|label |
|
1398 | 915 |
x0 "{ Class:SmallInteger }" |
1390 | 916 |
| |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
917 |
(label := self label) isNil ifTrue:[^ self]. |
1398 | 918 |
|
919 |
(label isSequenceable and:[label isString not]) ifFalse:[ |
|
1606 | 920 |
^ self displayLabel:label h:(self heightOn:aGC) on:aGC x:x y:y h:h |
1398 | 921 |
]. |
922 |
||
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
923 |
x0 := x. |
1398 | 924 |
label do:[:el| |
925 |
el notNil ifTrue:[ |
|
1606 | 926 |
self displayLabel:el h:(self heightOf:el on:aGC) on:aGC x:x0 y:y h:h. |
1398 | 927 |
x0 := x0 + 5 + (el widthOn:aGC). |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
928 |
]. |
1390 | 929 |
] |
930 |
! |
|
931 |
||
932 |
heightOn:aGC |
|
933 |
"return the width of the receiver, if it is to be displayed on aGC |
|
934 |
" |
|
1606 | 935 |
|height| |
936 |
||
937 |
height isNil ifTrue:[ |
|
938 |
height := self heightOf:(self label) on:aGC |
|
939 |
]. |
|
940 |
^ height |
|
1390 | 941 |
! |
942 |
||
943 |
widthOn:aGC |
|
944 |
"return the width of the receiver, if it is to be displayed on aGC |
|
945 |
" |
|
1606 | 946 |
|width| |
947 |
||
948 |
width isNil ifTrue:[ |
|
949 |
width := self widthOf:(self label) on:aGC |
|
950 |
]. |
|
951 |
^ width |
|
952 |
||
1390 | 953 |
! ! |
954 |
||
955 |
!HierarchicalItem methodsFor:'protocol monitoring'! |
|
956 |
||
957 |
monitoringCycle |
|
958 |
"called all 'n' seconds by the model, if the monitoring |
|
959 |
cycle is enabled. The item can perform some checks, .. |
|
960 |
**** can be redefined by subclass to perform some actions |
|
961 |
" |
|
962 |
! ! |
|
963 |
||
964 |
!HierarchicalItem methodsFor:'protocol queries'! |
|
965 |
||
1571 | 966 |
drawHorizontalLineUpToText |
967 |
"draw the horizizontal line for the selected item up to the text |
|
968 |
or on default to the start of the the vertical line; only used by |
|
969 |
the hierarchical view |
|
970 |
" |
|
971 |
^ false |
|
972 |
! |
|
973 |
||
1390 | 974 |
hasChildren |
975 |
"checks whether the item has a list of children; the list must not |
|
976 |
be loaded yet( ex. FileDirectory ). |
|
977 |
*** to optimize:redefine by subClass |
|
978 |
" |
|
979 |
^ children notNil ifTrue:[children notEmpty] |
|
980 |
ifFalse:[self children size ~~ 0] |
|
981 |
! |
|
982 |
||
983 |
string |
|
984 |
"access the printable string used for steping through a list |
|
985 |
searching for an entry starting with a character. |
|
986 |
*** to optimize:redefine by subClass |
|
987 |
" |
|
1398 | 988 |
|label| |
989 |
||
990 |
(label := self label) notNil ifTrue:[ |
|
991 |
label isString ifTrue:[ ^ label string ]. |
|
992 |
label isImageOrForm ifTrue:[ ^ nil ]. |
|
993 |
||
994 |
label isSequenceable ifFalse:[ |
|
995 |
^ label perform:#string ifNotUnderstood:nil |
|
996 |
]. |
|
997 |
||
998 |
label do:[:el||s| |
|
999 |
(el notNil and:[el isImageOrForm not]) ifTrue:[ |
|
1000 |
s := el perform:#string ifNotUnderstood:nil. |
|
1001 |
s notNil ifTrue:[^ s]. |
|
1002 |
] |
|
1003 |
] |
|
1004 |
]. |
|
1005 |
^ nil |
|
1006 |
||
1390 | 1007 |
|
1008 |
! ! |
|
1009 |
||
1010 |
!HierarchicalItem methodsFor:'queries'! |
|
1011 |
||
1012 |
canCollapse |
|
1013 |
"called before collapsing the item |
|
1014 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
1015 |
^ (isExpanded == true) |
1390 | 1016 |
! |
1017 |
||
1018 |
canExpand |
|
1019 |
"called before expanding the item |
|
1020 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
1021 |
^ (isExpanded == true) not and:[self hasChildren] |
1390 | 1022 |
! |
1023 |
||
1024 |
isExpanded |
|
1025 |
"return true if item is expanded |
|
1026 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
1027 |
^ (isExpanded == true) |
1390 | 1028 |
! |
1029 |
||
1030 |
isHierarchicalItem |
|
1031 |
"used to decide if the parent is a hierarchical item |
|
1032 |
or the model |
|
1033 |
" |
|
1034 |
^ true |
|
1035 |
! |
|
1036 |
||
1037 |
size |
|
1038 |
"return the number of children |
|
1039 |
" |
|
1040 |
^ children notNil ifTrue:[children size] |
|
1041 |
ifFalse:[self children size] |
|
1042 |
! ! |
|
1043 |
||
1044 |
!HierarchicalItem methodsFor:'searching'! |
|
1045 |
||
1046 |
detect:aOneArgBlock |
|
1047 |
"find the first child, for which evaluation of the block returns |
|
1048 |
true; if none does so, report an error |
|
1049 |
" |
|
1050 |
^ self detect:aOneArgBlock ifNone:[self errorNotFound] |
|
1051 |
||
1052 |
! |
|
1053 |
||
1054 |
detect:aOneArgBlock ifNone:anExceptionBlock |
|
1055 |
"find the first child, for which evaluation of the block returns |
|
1056 |
true; if none does so, return the evaluation of anExceptionBlock |
|
1057 |
" |
|
1058 |
self children notNil ifTrue:[ |
|
1059 |
^ children detect:aOneArgBlock ifNone:anExceptionBlock |
|
1060 |
]. |
|
1061 |
^ anExceptionBlock value |
|
1062 |
||
1063 |
||
1064 |
! |
|
1065 |
||
1066 |
identityIndexOf:aChild |
|
1067 |
"return the index of aChild or 0 if not found. Compare using == |
|
1068 |
" |
|
1069 |
self children notNil ifTrue:[ |
|
1070 |
^ children identityIndexOf:aChild |
|
1071 |
]. |
|
1072 |
^ 0 |
|
1073 |
! |
|
1074 |
||
1075 |
identityIndexOf:aChild startingAt:startIndex |
|
1076 |
"return the index of aChild, starting search at startIndex. |
|
1077 |
Compare using ==; return 0 if not found |
|
1078 |
" |
|
1079 |
self children notNil ifTrue:[ |
|
1080 |
^ children identityIndexOf:aChild startingAt:startIndex |
|
1081 |
]. |
|
1082 |
^ 0 |
|
1489 | 1083 |
! |
1084 |
||
1085 |
recursiveDetect:aOneArgBlock |
|
1086 |
"recursive find the first child, for which evaluation |
|
1087 |
of the block returns true; if none nil is returned |
|
1088 |
" |
|
1089 |
|child| |
|
1090 |
||
1091 |
self children notNil ifTrue:[ |
|
1092 |
children do:[:aChild| |
|
1093 |
(aOneArgBlock value:aChild) ifTrue:[ |
|
1094 |
^ aChild |
|
1095 |
]. |
|
1096 |
||
1097 |
(child := aChild recursiveDetect:aOneArgBlock) notNil ifTrue:[ |
|
1098 |
^ child |
|
1099 |
] |
|
1100 |
] |
|
1101 |
]. |
|
1102 |
^ nil |
|
1390 | 1103 |
! ! |
1104 |
||
1105 |
!HierarchicalItem::Example class methodsFor:'instance creation'! |
|
1106 |
||
1107 |
labeled:aLabel |
|
1108 |
^ self new setLabel:aLabel |
|
1109 |
||
1110 |
||
1111 |
! |
|
1112 |
||
1113 |
labeled:aLabel icon:anIcon |
|
1114 |
^ self new setLabel:aLabel icon:anIcon |
|
1115 |
||
1116 |
||
1117 |
! ! |
|
1118 |
||
1119 |
!HierarchicalItem::Example class methodsFor:'resources'! |
|
1120 |
||
1121 |
iconForLevel:aLevel |
|
1122 |
"returns an icon |
|
1123 |
" |
|
1124 |
aLevel == 2 ifTrue:[ ^ ResourceSelectionBrowser iconPrivateClass ]. |
|
1125 |
aLevel == 3 ifTrue:[ ^ ResourceSelectionBrowser iconClass ]. |
|
1126 |
aLevel == 4 ifTrue:[ ^ ResourceSelectionBrowser iconCategory ]. |
|
1127 |
||
1128 |
^ nil |
|
1129 |
||
1130 |
! |
|
1131 |
||
1132 |
penguinIcon |
|
1133 |
PenguinIcon isNil ifTrue:[ |
|
1134 |
PenguinIcon := Image fromFile:'bitmaps/xpmBitmaps/misc_logos/linux_penguin.xpm'. |
|
1135 |
]. |
|
1136 |
^ PenguinIcon |
|
1137 |
! ! |
|
1138 |
||
1139 |
!HierarchicalItem::Example methodsFor:'accessing'! |
|
1140 |
||
1141 |
children |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1142 |
|lvl lbl txt image img icon tmp| |
1390 | 1143 |
|
1144 |
children notNil ifTrue:[ |
|
1145 |
^ children |
|
1146 |
]. |
|
1147 |
||
1148 |
(lvl := self level) == 5 ifTrue:[ |
|
1149 |
children := #(). |
|
1150 |
^ children |
|
1151 |
]. |
|
1152 |
icon := self class iconForLevel:(lvl + 1). |
|
1153 |
children := OrderedCollection new. |
|
1154 |
||
1155 |
lvl < 4 ifTrue:[ |
|
1156 |
txt := (lvl + 1) printString, ' ['. |
|
1157 |
img := NewLauncher saveImageIcon. |
|
1158 |
||
1159 |
1 to:5 do:[:i| |
|
1160 |
(i == 2 or:[i == 3]) ifTrue:[ |
|
1161 |
lbl := img |
|
1162 |
] ifFalse:[ |
|
1163 |
i == 4 ifTrue:[ |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1164 |
tmp := #( 'penguin' 'and' 'text') asStringCollection asString. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1165 |
tmp removeLast. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1166 |
lbl := Array with:(self class penguinIcon) |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1167 |
with:tmp. |
1390 | 1168 |
] ifFalse:[ |
1169 |
lbl := txt, (i printString), ']' |
|
1170 |
] |
|
1171 |
]. |
|
1172 |
children add:(self class labeled:lbl icon:icon) |
|
1173 |
]. |
|
1174 |
] ifFalse:[ |
|
1175 |
image := ResourceSelectionBrowser iconPrivateClass. |
|
1176 |
txt := LabelAndIcon icon:image string:'Text'. |
|
1177 |
img := Icon copyIcon. |
|
1178 |
||
1179 |
1 to:5 do:[:i| |
|
1180 |
lbl := i odd ifTrue:[txt] ifFalse:[img]. |
|
1398 | 1181 |
lbl := Array with:lbl with:'test' with:img. |
1390 | 1182 |
children add:(self class labeled:lbl icon:icon). |
1183 |
] |
|
1184 |
]. |
|
1185 |
||
1186 |
children do:[:aChild| aChild parent:self ]. |
|
1187 |
^ children |
|
1188 |
! |
|
1189 |
||
1190 |
icon |
|
1191 |
"returns the icon |
|
1192 |
" |
|
1193 |
^ icon |
|
1194 |
! |
|
1195 |
||
1196 |
icon:anIcon |
|
1197 |
"set the icon; if icon changed, a notification |
|
1198 |
is raised. |
|
1199 |
" |
|
1200 |
icon ~= anIcon ifTrue:[ |
|
1201 |
icon := anIcon. |
|
1202 |
self iconChanged |
|
1203 |
] |
|
1204 |
! |
|
1205 |
||
1206 |
label |
|
1207 |
"returns the label |
|
1208 |
" |
|
1209 |
^ label |
|
1210 |
||
1211 |
! |
|
1212 |
||
1213 |
label:aLabel |
|
1214 |
"set the label; if label changed, a notification |
|
1215 |
is raised. |
|
1216 |
" |
|
1217 |
label ~= aLabel ifTrue:[ |
|
1218 |
label := aLabel. |
|
1219 |
self changed. |
|
1220 |
] |
|
1221 |
||
1222 |
! |
|
1223 |
||
1224 |
setIcon:anIcon |
|
1225 |
"set the icon without any change notification |
|
1226 |
" |
|
1227 |
icon := anIcon |
|
1228 |
! |
|
1229 |
||
1230 |
setLabel:aLabel |
|
1231 |
"set the label without any change notification |
|
1232 |
" |
|
1233 |
label := aLabel |
|
1234 |
! |
|
1235 |
||
1236 |
setLabel:aLabel icon:anIcon |
|
1237 |
"set the label and icon without any change notification |
|
1238 |
" |
|
1239 |
label := aLabel. |
|
1240 |
icon := anIcon. |
|
1241 |
! ! |
|
1242 |
||
1243 |
!HierarchicalItem class methodsFor:'documentation'! |
|
1244 |
||
1245 |
version |
|
1606 | 1246 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.16 1999-10-27 14:27:43 ca Exp $' |
1390 | 1247 |
! ! |