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