|
Class: MultiColListEntry
Object
|
+--ListEntry
|
+--MultiColListEntry
- Package:
- stx:libwidg2
- Category:
- Views-Support
- Version:
- rev:
1.36
date: 2023/11/16 21:48:02
- user: stefan
- file: MultiColListEntry.st directory: libwidg2
- module: stx stc-classLibrary: libwidg2
Instances of MultiColListEntry can be used in place of strings
as entries of the list in a ListView or SelectionInListView.
They allow data to be presented in table (or any other) form.
See example here and in TabulatorSpecs documentation.
Notice, that each entry can have its own tabulator specification;
although, usually all share a single spec.
Also, notice that each column may align different; making these
perfect elements to present table data.
MultiColListEntry and TabulatorSpec were originally created to
support nice tabular display of file-lists in the FileBrowser
(see its long list); you may find many other uses ...
copyrightCOPYRIGHT (c) 1994 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
instance creation
-
fromString: aString
-
create and return a new listEntry with columns taken
from the words of aString. Assumes that columns are
separated by spaces in the string
Usage example(s):
self fromString:'hello world a b'
|
-
fromString: aString separatedBy: separatorCharacter
-
create and return a new listEntry with columns taken
from the words of aString. Assumes that columns are
separated by separatorCharacter in the string
Usage example(s):
self fromString:'hello:world:a:b' separatedBy:$:
|
-
fromString: aString separatedBy: separatorCharacter tabulatorSpecification: aTabSpec
-
create and return a new listEntry with columns taken
from the words of aString. Assumes that columns are
separated by separatorCharacter in the string
Usage example(s):
|tabSpec|
tabSpec := TabulatorSpecification new.
tabSpec unit:#inch.
tabSpec positions:#(0 1.5 ).
tabSpec align: #(#left #right).
self fromString:'hello world a b' separatedBy:(Character space) tabulatorSpecification:tabSpec
|
-
fromStrings: aCollectionOfStrings
-
create and return a new listEntry with columns taken
from the given aStrings.
Usage example(s):
self fromStrings:#('hello' 'world')
|
-
fromStrings: aCollectionOfStrings tabulatorSpecification: aTabSpec
-
create and return a new listEntry with columns taken
from the given aStrings.
Usage example(s):
|tabSpec|
tabSpec := TabulatorSpecification new.
tabSpec unit:#inch.
tabSpec positions:#(0 1.5 ).
tabSpec align: #(#left #right).
self fromStrings:#('hello' 'world') tabulatorSpecification:tabSpec
|
-
new: numberOfColumns
-
create and return a new listEntry with numberOfColumns empty columns
Usage example(s):
|e|
e := self new:10.
e colAt:11 put:'abc'.
e
|
-
new: numberOfColumns tabulatorSpecification: aTabSpec
-
create and return a new listEntry with numberOfColumns empty columns
and the given tab-specification
accessing
-
colAt: index
-
return the substring at column index
-
colAt: index put: aString
-
replace the substring at column index
-
strings
-
return all substrings
-
strings: aCollectionOfStrings
-
replace all substrings
-
tabulatorSpecification: aTabSpec
-
set the tabulator spec
converting
-
asDragAndDropDisplayObjectOn: aDevice
-
convert myself to something that can be display by the DragAndDropManager on aDevice
-
asString
-
return the receiver as a string with embedded tabs
-
withoutAnyColorEmphasis
-
(comment from inherited method)
to be redefined in subclasses
defaults
-
defaultTabSpec
-
the default tabulators are 1 inch apart
drawing
-
displayOn: aGC x: x y: y opaque: opaque
-
display the receiver on a GC
queries
-
hasChangeOfEmphasis
-
return true, if the receiver contains non-empty emphasis information
i.e. any non-normal (=emphasized) characters
-
heightOn: aGC
-
return the height of the receiver when displayed in aGC
-
widthOn: aGC
-
return the width of the receiver when displayed in aGC
putting multiColListEntries into a ListView (instead of strings)
|v e myList tabs|
myList := OrderedCollection new.
tabs := TabulatorSpecification new.
tabs unit:#inch.
tabs positions:#(0 3 4).
tabs align:#(left #center #left).
e := MultiColListEntry fromString:'left centered left'.
e tabulatorSpecification:tabs.
myList add:e.
e := MultiColListEntry fromString:'| | |'.
e tabulatorSpecification:tabs.
myList add:e.
myList add:''.
e := MultiColListEntry fromString:'hello hallo salut'.
e tabulatorSpecification:tabs.
myList add:e.
e := MultiColListEntry
fromString:'good morning,guten Morgen,bon jour'
separatedBy:$,.
e tabulatorSpecification:tabs.
myList add:e.
e := MultiColListEntry new.
e colAt:1 put:'good bye'.
e colAt:2 put:'auf Wiedersehen'.
e colAt:3 put:'au revoir '.
e tabulatorSpecification:tabs.
myList add:e.
v := ListView new.
v setList:myList expandTabs:false.
v extent:500@100.
v open
|
many multiColListEntries in a scrollable ListView
|v l e myList tabs|
myList := OrderedCollection new.
tabs := TabulatorSpecification new.
tabs unit:#cm.
tabs positions:#(1 3 5).
tabs align:#(#right #center #left).
1 to:100 do:[:i|
e := MultiColListEntry new.
e colAt:1 put:i printString.
e colAt:2 put:i squared printString.
e colAt:3 put:i sqrt printString.
e tabulatorSpecification:tabs.
myList add:e.
].
l := ListView new.
l setList:myList expandTabs:false.
v := ScrollableView forView:l.
v extent:300@200.
v open
|
like above, but uses nicer decimal alignments
|v l e myList tabs|
myList := OrderedCollection new.
tabs := TabulatorSpecification new.
tabs unit:#cm.
tabs positions:#(1 3 6 9 12).
tabs align:#(#right #decimal #decimal #decimal #decimal).
1 to:100 do:[:i|
e := MultiColListEntry new.
e colAt:1 put:i printString.
e colAt:2 put:i log printString.
e colAt:3 put:i sqrt printString.
e colAt:4 put:i sin printString.
e colAt:5 put:i cos printString.
e tabulatorSpecification:tabs.
myList add:e.
].
l := ListView new.
l setList:myList expandTabs:false.
v := ScrollableView forView:l.
v extent:600@200.
v open
|
specifying tabs in inches
|v l e myList tabs|
myList := OrderedCollection new.
tabs := TabulatorSpecification new.
tabs unit:#inch.
tabs positions:#(0 2 3.5 4 6 8 10 12).
e := MultiColListEntry new.
e colAt:1 put:'2'.
e colAt:2 put:'3.5'.
e colAt:3 put:'4'.
e colAt:4 put:'6'.
e colAt:5 put:'8'.
e colAt:6 put:'10'.
e colAt:7 put:'12'.
e tabulatorSpecification:tabs.
myList add:e.
myList add:((MultiColListEntry fromString:'| | | | | | |')
tabulatorSpecification:tabs).
myList add:((MultiColListEntry fromString:'xxx xxx xxx xxx xxx xxx xxx')
tabulatorSpecification:tabs).
l := ListView new.
l setList:myList expandTabs:false.
v := HVScrollableView forView:l.
v extent:600@200.
v open
|
if you have the columns available as a collection,
setup can be done easier
|v l e myList tabs|
myList := OrderedCollection new.
tabs := TabulatorSpecification new.
tabs unit:#inch.
tabs positions:#(0 2 3.5 4 6 8 10 12).
e := MultiColListEntry new.
e strings:#('2' '3.5' '4' '6' '8' '10' '12').
e tabulatorSpecification:tabs.
myList add:e.
l := ListView new.
l setList:myList expandTabs:false.
v := HVScrollableView forView:l.
v extent:600@200.
v open
|
using icons instead of strings:
|v l e myList tabs i1 i2 i3|
myList := OrderedCollection new.
tabs := TabulatorSpecification new.
tabs unit:#cm.
tabs positions:#(1 3 5).
tabs align:#(#left #left #left).
i1 := Image fromFile:'bitmaps/xpmBitmaps/document_images/small_dir.xpm'.
i2 := Image fromFile:'bitmaps/xpmBitmaps/document_images/small_file.xpm'.
i3 := Image fromFile:'bitmaps/xpmBitmaps/document_images/small_file_binary.xpm'.
1 to:100 do:[:i|
e := MultiColListEntry new.
i odd ifTrue:[
e colAt:1 put:i1.
] ifFalse:[
e colAt:1 put:i2
].
e colAt:2 put:i printString.
e colAt:3 put:i3.
e tabulatorSpecification:tabs.
myList add:e.
].
l := SelectionInListView new.
l setList:myList expandTabs:false.
v := ScrollableView forView:l.
v extent:300@200.
v open
|
concrete example, show /etc/passwd in a table:
|v l s myList line e htabs tabs fingerEntry|
tabs := TabulatorSpecification new.
tabs unit:#inch.
tabs positions:#(0 2 3.5 4.5 5 8 11).
tabs align: #(left left right right left left left).
htabs := TabulatorSpecification new.
htabs unit:#inch.
htabs positions:#(0 2 3.5 4.5 5 8 11).
htabs align: #(left center center center left left left).
myList := OrderedCollection new.
e := MultiColListEntry
fromString:'login-name:password:uid:gid:finger-entry:home-dir:shell'
separatedBy:$:.
e tabulatorSpecification:htabs.
myList add:e.
myList add:''.
s := '/etc/passwd' asFilename readStream.
[s atEnd] whileFalse:[
line := s nextLine.
e := MultiColListEntry
fromString:line
separatedBy:$:.
fingerEntry := e colAt:5.
e colAt:5 put:(fingerEntry asCollectionOfSubstringsSeparatedBy:$,) first.
e tabulatorSpecification:tabs.
myList add:e.
].
s close.
l := ListView new.
l setList:myList expandTabs:false.
v := HVScrollableView forView:l.
v extent:600@200.
v open
|
a (dynamic) menu with aligned columns:
|menu item l tabSpec n1 n2 n3 n4|
menu := Menu new.
tabSpec := TabulatorSpecification new.
tabSpec unit:#inch.
tabSpec positions:#(0 1.5 ).
tabSpec align: #(#left #right).
n1 := 123456.
n2 := 123.
n3 := 11111.
n4 := 9876.
l := MultiColListEntry fromStrings:#('N1:' '') tabulatorSpecification:tabSpec.
l colAt:2 put:n1 printString.
item := MenuItem new.
item label:l.
menu addItem:item.
l := MultiColListEntry fromStrings:#('N2:' '') tabulatorSpecification:tabSpec.
l colAt:2 put:n2 printString.
item := MenuItem new.
item label:l.
menu addItem:item.
l := MultiColListEntry fromStrings:#('N3:' '') tabulatorSpecification:tabSpec.
l colAt:2 put:n3 printString.
item := MenuItem new.
item label:l.
menu addItem:item.
l := MultiColListEntry fromStrings:#('N4:' '') tabulatorSpecification:tabSpec.
l colAt:2 put:n4 printString.
item := MenuItem new.
item label:l.
menu addItem:item.
menu showAtPointer.
|
|