ColoredListEntry.st
author Claus Gittinger <cg@exept.de>
Thu, 25 Apr 1996 19:33:23 +0200
changeset 158 431e38dfc5ab
parent 108 b228b94be590
child 161 5b6e284959a4
permissions -rw-r--r--
documentation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58
claus
parents:
diff changeset
     1
"
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
claus
parents:
diff changeset
     3
	      All Rights Reserved
claus
parents:
diff changeset
     4
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    10
 hereby transferred.
claus
parents:
diff changeset
    11
"
claus
parents:
diff changeset
    12
claus
parents:
diff changeset
    13
ListEntry subclass:#ColoredListEntry
158
431e38dfc5ab documentation
Claus Gittinger <cg@exept.de>
parents: 108
diff changeset
    14
	instanceVariableNames:'color string bgColor'
431e38dfc5ab documentation
Claus Gittinger <cg@exept.de>
parents: 108
diff changeset
    15
	classVariableNames:''
431e38dfc5ab documentation
Claus Gittinger <cg@exept.de>
parents: 108
diff changeset
    16
	poolDictionaries:''
431e38dfc5ab documentation
Claus Gittinger <cg@exept.de>
parents: 108
diff changeset
    17
	category:'Views-Support'
58
claus
parents:
diff changeset
    18
!
claus
parents:
diff changeset
    19
claus
parents:
diff changeset
    20
!ColoredListEntry class methodsFor:'documentation'!
claus
parents:
diff changeset
    21
claus
parents:
diff changeset
    22
copyright
claus
parents:
diff changeset
    23
"
claus
parents:
diff changeset
    24
 COPYRIGHT (c) 1995 by Claus Gittinger
claus
parents:
diff changeset
    25
	      All Rights Reserved
claus
parents:
diff changeset
    26
claus
parents:
diff changeset
    27
 This software is furnished under a license and may be used
claus
parents:
diff changeset
    28
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
    30
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
    31
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    32
 hereby transferred.
claus
parents:
diff changeset
    33
"
claus
parents:
diff changeset
    34
!
claus
parents:
diff changeset
    35
claus
parents:
diff changeset
    36
documentation
claus
parents:
diff changeset
    37
"
claus
parents:
diff changeset
    38
    Instances of ColoredListEntry can be used in place of strings
claus
parents:
diff changeset
    39
    as entries of the list in a ListView or SelectionInListView.
88
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    40
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    41
    Notice: this is a temporary kludge class which will be made obsolete,
158
431e38dfc5ab documentation
Claus Gittinger <cg@exept.de>
parents: 108
diff changeset
    42
            once full-attributed strings are available.
431e38dfc5ab documentation
Claus Gittinger <cg@exept.de>
parents: 108
diff changeset
    43
431e38dfc5ab documentation
Claus Gittinger <cg@exept.de>
parents: 108
diff changeset
    44
    [author:]
431e38dfc5ab documentation
Claus Gittinger <cg@exept.de>
parents: 108
diff changeset
    45
        Claus Gittinger
431e38dfc5ab documentation
Claus Gittinger <cg@exept.de>
parents: 108
diff changeset
    46
431e38dfc5ab documentation
Claus Gittinger <cg@exept.de>
parents: 108
diff changeset
    47
    [see also:]
431e38dfc5ab documentation
Claus Gittinger <cg@exept.de>
parents: 108
diff changeset
    48
        ListView
58
claus
parents:
diff changeset
    49
"
claus
parents:
diff changeset
    50
!
claus
parents:
diff changeset
    51
claus
parents:
diff changeset
    52
examples
claus
parents:
diff changeset
    53
"
claus
parents:
diff changeset
    54
     putting colored entries into a SelectionInListView
claus
parents:
diff changeset
    55
     (instead of strings)'
claus
parents:
diff changeset
    56
claus
parents:
diff changeset
    57
	|v e myList tabs|
claus
parents:
diff changeset
    58
claus
parents:
diff changeset
    59
	myList := OrderedCollection new.
claus
parents:
diff changeset
    60
claus
parents:
diff changeset
    61
	myList add:(ColoredListEntry string:'red' color:Color red).
claus
parents:
diff changeset
    62
	myList add:(ColoredListEntry string:'green' color:Color green).
claus
parents:
diff changeset
    63
	myList add:(ColoredListEntry string:'blue' color:Color blue).
claus
parents:
diff changeset
    64
	myList add:(ColoredListEntry string:'white' color:Color white).
claus
parents:
diff changeset
    65
	myList add:(ColoredListEntry string:'black' color:Color black).
claus
parents:
diff changeset
    66
	myList add:(ColoredListEntry string:'yellow' color:Color yellow).
claus
parents:
diff changeset
    67
claus
parents:
diff changeset
    68
	v := SelectionInListView new.
claus
parents:
diff changeset
    69
	v setList:myList expandTabs:false.
claus
parents:
diff changeset
    70
	v open
claus
parents:
diff changeset
    71
claus
parents:
diff changeset
    72
60
claus
parents: 58
diff changeset
    73
     in a popUpList (sorry, Labels do not (yet) know how to display
claus
parents: 58
diff changeset
    74
     non-strings.
58
claus
parents:
diff changeset
    75
claus
parents:
diff changeset
    76
	|v e myList selList tabs|
claus
parents:
diff changeset
    77
claus
parents:
diff changeset
    78
	myList := OrderedCollection new.
claus
parents:
diff changeset
    79
claus
parents:
diff changeset
    80
	myList add:(ColoredListEntry string:'red' color:Color red).
claus
parents:
diff changeset
    81
	myList add:(ColoredListEntry string:'green' color:Color green).
claus
parents:
diff changeset
    82
	myList add:(ColoredListEntry string:'blue' color:Color blue).
claus
parents:
diff changeset
    83
	myList add:(ColoredListEntry string:'white' color:Color white).
claus
parents:
diff changeset
    84
	myList add:(ColoredListEntry string:'black' color:Color black).
claus
parents:
diff changeset
    85
	myList add:(ColoredListEntry string:'yellow' color:Color yellow).
claus
parents:
diff changeset
    86
claus
parents:
diff changeset
    87
	selList := SelectionInList new list:myList.
claus
parents:
diff changeset
    88
claus
parents:
diff changeset
    89
	v := PopUpList on:selList.
claus
parents:
diff changeset
    90
	v open
claus
parents:
diff changeset
    91
"
claus
parents:
diff changeset
    92
! !
claus
parents:
diff changeset
    93
claus
parents:
diff changeset
    94
!ColoredListEntry class methodsFor:'instance creation'!
claus
parents:
diff changeset
    95
claus
parents:
diff changeset
    96
string:aString color:aColor
claus
parents:
diff changeset
    97
    ^ self new string:aString color:aColor
88
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    98
!
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    99
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   100
string:aString foregroundColor:fgColor backgroundColor:bgColor
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   101
    ^ self new string:aString foregroundColor:fgColor backgroundColor:bgColor
58
claus
parents:
diff changeset
   102
! !
claus
parents:
diff changeset
   103
97
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   104
!ColoredListEntry methodsFor:'accessing'!
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   105
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   106
string:aString color:aColor
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   107
    string := aString.
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   108
    color := aColor
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   109
!
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   110
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   111
string:aString foregroundColor:fg backgroundColor:bg
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   112
    string := aString.
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   113
    color := fg.
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   114
    bgColor := bg.
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   115
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   116
    "Created: 16.11.1995 / 16:53:17 / cg"
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   117
! !
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   118
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   119
!ColoredListEntry methodsFor:'converting'!
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   120
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   121
asString
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   122
    ^ string
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   123
!
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   124
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   125
string
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   126
    ^ string
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   127
! !
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   128
58
claus
parents:
diff changeset
   129
!ColoredListEntry methodsFor:'drawing'!
claus
parents:
diff changeset
   130
108
b228b94be590 displayOpaque fixes
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   131
displayOn:aGC x:x y:y opaque:opaque
58
claus
parents:
diff changeset
   132
    "display the receiver on a GC"
claus
parents:
diff changeset
   133
88
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   134
    |savedPaint savedBgPaint|
73
claus
parents: 60
diff changeset
   135
claus
parents: 60
diff changeset
   136
    savedPaint := aGC paint.
88
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   137
    bgColor notNil ifTrue:[
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   138
	savedBgPaint := aGC backgroundPaint.
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   139
	aGC paint:color on:bgColor.
93
f3158d8e67d0 handle tabs in strings
Claus Gittinger <cg@exept.de>
parents: 88
diff changeset
   140
	aGC displayOpaqueString:(string withTabsExpanded) x:x y:y.
88
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   141
	aGC paint:savedPaint on:savedBgPaint
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   142
    ] ifFalse:[
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   143
	aGC paint:color.
108
b228b94be590 displayOpaque fixes
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   144
	opaque ifTrue:[
b228b94be590 displayOpaque fixes
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   145
	    aGC displayOpaqueString:(string withTabsExpanded) x:x y:y.
b228b94be590 displayOpaque fixes
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   146
	] ifFalse:[
b228b94be590 displayOpaque fixes
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   147
	    aGC displayString:(string withTabsExpanded) x:x y:y.
b228b94be590 displayOpaque fixes
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   148
	].
88
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   149
	aGC paint:savedPaint
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   150
    ]
d591b16c8f46 allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   151
93
f3158d8e67d0 handle tabs in strings
Claus Gittinger <cg@exept.de>
parents: 88
diff changeset
   152
    "Modified: 16.11.1995 / 16:54:40 / cg"
58
claus
parents:
diff changeset
   153
! !
claus
parents:
diff changeset
   154
claus
parents:
diff changeset
   155
!ColoredListEntry methodsFor:'queries'!
claus
parents:
diff changeset
   156
claus
parents:
diff changeset
   157
widthIn:aGC
claus
parents:
diff changeset
   158
    "return the width of the receiver when displayed in aGC"
claus
parents:
diff changeset
   159
93
f3158d8e67d0 handle tabs in strings
Claus Gittinger <cg@exept.de>
parents: 88
diff changeset
   160
    ^ aGC font widthOf:(string withTabsExpanded)
58
claus
parents:
diff changeset
   161
! !
97
306cb0aa67be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 93
diff changeset
   162
98
de14b996ee80 version at the end
Claus Gittinger <cg@exept.de>
parents: 97
diff changeset
   163
!ColoredListEntry class methodsFor:'documentation'!
de14b996ee80 version at the end
Claus Gittinger <cg@exept.de>
parents: 97
diff changeset
   164
de14b996ee80 version at the end
Claus Gittinger <cg@exept.de>
parents: 97
diff changeset
   165
version
158
431e38dfc5ab documentation
Claus Gittinger <cg@exept.de>
parents: 108
diff changeset
   166
    ^ '$Header: /cvs/stx/stx/libwidg2/ColoredListEntry.st,v 1.10 1996-04-25 17:31:23 cg Exp $'
98
de14b996ee80 version at the end
Claus Gittinger <cg@exept.de>
parents: 97
diff changeset
   167
! !