LabelAndIcon.st
changeset 172 c30e1ff9f9dd
child 175 44a363de85f5
equal deleted inserted replaced
171:a5b9435e3bee 172:c30e1ff9f9dd
       
     1 "
       
     2  COPYRIGHT (c) 1996 by Claus Gittinger
       
     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 
       
    14 ListEntry subclass:#LabelAndIcon
       
    15 	instanceVariableNames:'icon gap string'
       
    16 	classVariableNames:''
       
    17 	poolDictionaries:''
       
    18 	category:'Views-Support'
       
    19 !
       
    20 
       
    21 !LabelAndIcon class methodsFor:'documentation'!
       
    22 
       
    23 copyright
       
    24 "
       
    25  COPYRIGHT (c) 1996 by Claus Gittinger
       
    26               All Rights Reserved
       
    27 
       
    28  This software is furnished under a license and may be used
       
    29  only in accordance with the terms of that license and with the
       
    30  inclusion of the above copyright notice.   This software may not
       
    31  be provided or otherwise made available to, or used by, any
       
    32  other person.  No title to or ownership of the software is
       
    33  hereby transferred.
       
    34 "
       
    35 
       
    36 !
       
    37 
       
    38 documentation
       
    39 "
       
    40     an icon and a string, side by side.
       
    41     Usable as list entries in a fileList.
       
    42 
       
    43     This is an example class - currently not used by the system.
       
    44 
       
    45     [author:]
       
    46         Claus Gittinger
       
    47 
       
    48     [see also:]
       
    49         ListEntry Text String Icon
       
    50         ListView SelectionInListView
       
    51 "
       
    52 
       
    53 !
       
    54 
       
    55 examples
       
    56 "
       
    57                                                                         [exBegin]
       
    58     |top slv wrapper l fileImage dirImage|
       
    59 
       
    60     fileImage := Image 
       
    61                    width:16 
       
    62                    height:16
       
    63                    depth:1
       
    64                    fromArray:#[2r00000000 2r00000000
       
    65                                2r00000000 2r00000000
       
    66                                2r00011111 2r11100000
       
    67                                2r00010000 2r00100000
       
    68                                2r00010000 2r00011000
       
    69                                2r00010000 2r00001000
       
    70                                2r00010000 2r00001000
       
    71                                2r00010000 2r00001000
       
    72                                2r00010000 2r00001000
       
    73                                2r00010000 2r00001000
       
    74                                2r00010000 2r00001000
       
    75                                2r00010000 2r00001000
       
    76                                2r00010000 2r00001000
       
    77                                2r00011111 2r11111000
       
    78                                2r00000000 2r00000000
       
    79                                2r00000000 2r00000000].
       
    80     fileImage photometric:#whiteIs0.
       
    81 
       
    82     dirImage := Image 
       
    83                    width:16 
       
    84                    height:16
       
    85                    depth:1
       
    86                    fromArray:#[2r00000000 2r00000000
       
    87                                2r00000000 2r00000000
       
    88                                2r00000000 2r00000000
       
    89                                2r01111111 2r11110000
       
    90                                2r01000000 2r00001000
       
    91                                2r01000000 2r00000100
       
    92                                2r01000000 2r00000010
       
    93                                2r01000000 2r00000010
       
    94                                2r01000000 2r00000010
       
    95                                2r01000000 2r00000010
       
    96                                2r01000000 2r00000010
       
    97                                2r01000000 2r00000010
       
    98                                2r01111111 2r11111110
       
    99                                2r00000000 2r00000000
       
   100                                2r00000000 2r00000000
       
   101                                2r00000000 2r00000000].
       
   102     dirImage photometric:#whiteIs0.
       
   103 
       
   104 
       
   105     l := OrderedCollection new.
       
   106     Filename currentDirectory directoryContents do:[:s |
       
   107         s asFilename isDirectory ifTrue:[
       
   108             l add:(LabelAndIcon icon:dirImage string:s)
       
   109         ] ifFalse:[
       
   110             l add:(LabelAndIcon icon:fileImage string:s)
       
   111         ]
       
   112     ].
       
   113 
       
   114     slv := SelectionInListView new.
       
   115     slv list:l.
       
   116     wrapper := HVScrollableView forView:slv miniScrollerH:true.
       
   117 
       
   118     top := StandardSystemView extent:150@200.
       
   119     top add:wrapper in:(0.0@0.0 corner:1.0@1.0).
       
   120     top open.
       
   121                                                                         [exEnd]
       
   122                                                                         [exBegin]
       
   123     |top slv wrapper l fileImage dirImage|
       
   124 
       
   125     dirImage := Image fromFile:'DirObj.xbm'.
       
   126     fileImage := Image fromFile:'FileObj.xbm'.
       
   127 
       
   128 
       
   129     l := OrderedCollection new.
       
   130     Filename currentDirectory directoryContents do:[:s |
       
   131         s asFilename isDirectory ifTrue:[
       
   132             l add:(LabelAndIcon icon:dirImage string:s)
       
   133         ] ifFalse:[
       
   134             l add:(LabelAndIcon icon:fileImage string:s)
       
   135         ]
       
   136     ].
       
   137 
       
   138     slv := SelectionInListView new.
       
   139     slv list:l.
       
   140     wrapper := HVScrollableView forView:slv miniScrollerH:true.
       
   141 
       
   142     top := StandardSystemView extent:150@200.
       
   143     top add:wrapper in:(0.0@0.0 corner:1.0@1.0).
       
   144     top open.
       
   145                                                                         [exEnd]
       
   146 "
       
   147 ! !
       
   148 
       
   149 !LabelAndIcon class methodsFor:'instance creation'!
       
   150 
       
   151 icon:anIcon string:aString
       
   152     ^ self new icon:anIcon string:aString
       
   153 
       
   154     "Created: 12.5.1996 / 20:00:58 / cg"
       
   155 !
       
   156 
       
   157 new
       
   158     ^ self basicNew initialize
       
   159 
       
   160     "Created: 12.5.1996 / 20:00:58 / cg"
       
   161 ! !
       
   162 
       
   163 !LabelAndIcon methodsFor:'accessing'!
       
   164 
       
   165 gap:pixels
       
   166     "set the spacing between the icon and the labelString.
       
   167      The default is 4."
       
   168 
       
   169     gap := pixels.
       
   170 
       
   171     "Created: 12.5.1996 / 20:00:52 / cg"
       
   172 !
       
   173 
       
   174 icon:anIcon
       
   175     "set the icon image"
       
   176 
       
   177     icon := anIcon.
       
   178 
       
   179     "Created: 12.5.1996 / 20:00:52 / cg"
       
   180 !
       
   181 
       
   182 icon:anIcon string:aString
       
   183     "set both iconImage and the labelString"
       
   184 
       
   185     icon := anIcon.
       
   186     string := aString
       
   187 
       
   188     "Created: 12.5.1996 / 20:00:52 / cg"
       
   189 ! !
       
   190 
       
   191 !LabelAndIcon methodsFor:'displaying'!
       
   192 
       
   193 displayOn:aGC x:x y:y opaque:opaque
       
   194     "display the receiver on a GC"
       
   195 
       
   196     |yOffs|
       
   197 
       
   198     icon displayOn:aGC
       
   199         x:x 
       
   200         y:y-aGC font ascent+(aGC font descent//2).
       
   201         
       
   202     (icon height > aGC font height) ifTrue:[
       
   203         yOffs := (icon height - aGC font height) // 2
       
   204     ] ifFalse:[
       
   205         yOffs := 0
       
   206     ].
       
   207     string 
       
   208         displayOn:aGC 
       
   209         x:x + icon width + gap
       
   210         y:y+yOffs.
       
   211 
       
   212     "Modified: 12.5.1996 / 20:36:43 / cg"
       
   213 ! !
       
   214 
       
   215 !LabelAndIcon methodsFor:'initialization'!
       
   216 
       
   217 initialize
       
   218     gap := 4
       
   219 ! !
       
   220 
       
   221 !LabelAndIcon methodsFor:'queries'!
       
   222 
       
   223 heightOn:aGC
       
   224     "return the height of the receiver, if it is to be displayed on aGC"
       
   225 
       
   226     ^ icon height + (aGC device pixelPerMillimeter x rounded) 
       
   227       max:(string heightOn:aGC)
       
   228 
       
   229     "Created: 12.5.1996 / 20:26:20 / cg"
       
   230     "Modified: 12.5.1996 / 20:34:23 / cg"
       
   231 !
       
   232 
       
   233 widthOn:aGC
       
   234     "return the width of the receiver, if it is to be displayed on aGC"
       
   235 
       
   236     ^ icon width + gap + (string widthOn:aGC)
       
   237 
       
   238     "Created: 12.5.1996 / 20:10:06 / cg"
       
   239     "Modified: 12.5.1996 / 20:13:49 / cg"
       
   240 ! !
       
   241 
       
   242 !LabelAndIcon class methodsFor:'documentation'!
       
   243 
       
   244 version
       
   245     ^ '$Header: /cvs/stx/stx/libwidg2/LabelAndIcon.st,v 1.1 1996-05-12 19:05:36 cg Exp $'
       
   246 ! !