eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'MultiColListEntry':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: MultiColListEntry


Inheritance:

   Object
   |
   +--ListEntry
      |
      +--MultiColListEntry

Package:
stx:libwidg2
Category:
Views-Support
Version:
rev: 1.30 date: 2016/08/09 10:41:25
user: stefan
file: MultiColListEntry.st directory: libwidg2
module: stx stc-classLibrary: libwidg2
Author:
Claus Gittinger

Description:


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 ...


Class protocol:

instance creation
o  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' 

o  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:$:

o  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

o  fromStrings: aCollectionOfStrings
create and return a new listEntry with columns taken
from the given aStrings.
usage example(s):
     self fromStrings:#('hello' 'world')

o  fromStrings: aCollectionOfStrings tabulatorSpecification: aTabSpec
create and return a new listEntry with columns taken
from the given aStrings.

o  new: numberOfColumns
create and return a new listEntry with numberOfColumns empty columns

o  new: numberOfColumns tabulatorSpecification: aTabSpec
create and return a new listEntry with numberOfColumns empty columns
and the given tab-specification


Instance protocol:

accessing
o  colAt: index
return the substring at column index

o  colAt: index put: aString
replace the substring at column index

o  strings: aCollectionOfStrings
replace all substrings

o  tabulatorSpecification: aTabSpec
set the tabulator spec

converting
o  asString
return the receiver as a string with embedded tabs

defaults
o  defaultTabSpec
the default tabulators are 1 inch apart

drawing
o  displayOn: aGC x: x y: y opaque: opaque
display the receiver on a GC

queries
o  heightOn: aGC
return the height of the receiver when displayed in aGC

o  widthOn: aGC
return the width of the receiver when displayed in aGC


Examples:


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.


ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Sat, 17 Nov 2018 21:32:14 GMT