MCLEntry.st
changeset 36 160b8f0dfd7d
parent 34 159147b254e1
child 58 2bdd35f8aef0
--- a/MCLEntry.st	Sat Feb 11 17:52:33 1995 +0100
+++ b/MCLEntry.st	Fri Feb 17 14:24:24 1995 +0100
@@ -1,4 +1,14 @@
-'From Smalltalk/X, Version:2.10.3 on 12-aug-1994 at 10:44:03 pm'!
+"
+ COPYRIGHT (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.
+"
 
 Object subclass:#MultiColListEntry
 	 instanceVariableNames:'strings tabSpec'
@@ -9,79 +19,48 @@
 
 !MultiColListEntry class methodsFor:'documentation'!
 
+copyright
+"
+ COPYRIGHT (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.
+"
+!
+
+version
+"
+$Header: /cvs/stx/stx/libwidg2/Attic/MCLEntry.st,v 1.4 1995-02-17 13:23:47 claus Exp $
+"
+!
+
 documentation
 "
     Instances of MultiColListEntry can be used in place of strings
-    of a list in a ListView or SelectionInListView.
+    as entries of the list in a ListView or SelectionInListView.
     They allow data to be presented in table (or any other) form.
-    See example in TabulatorSpecs documentation.
-    Notice, that each entry can have its own (or a shared) tabulator specification.
-"
-! !
+    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 methodsFor:'accessing'!
-
-colAt:index put:aString
-    strings isNil ifTrue:[
-	strings := OrderedCollection new:index
-    ].
-    strings grow:index.
-    strings at:index put:aString
+    MultiColListEntry and TabulatorSpec were originally created to
+    support nice tabular display of file-lists in the FileBrowser;
+    you may many other uses ...
+"
 !
 
-tabulatorSpecification:aTabSpec
-    tabSpec := aTabSpec
-! !
-
-!MultiColListEntry methodsFor:'converting'!
-
-asString
-    "return the receiver as a string with embedded tabs"
-
-    |s sub tab|
-
-    s := ''.
-    tab := Character tab asString.
-    1 to:strings size do:[:subStringIndex |
-	sub := strings at:subStringIndex.
-	sub notNil ifTrue:[
-	    s := s , (strings at:subStringIndex).
-	].
-	subStringIndex == strings size ifFalse:[
-	    s := s , tab
-	]
-    ].
-
-    ^ s
-! !
+examples
+"
+     'putting multiColListEntries into a ListView
+      (instead of strings)'
 
-!MultiColListEntry methodsFor:'drawing'!
-
-displayOn:aGC x:x y:y
-    |xPos subString tabPos w prevString|
-
-    xPos := x.
-    prevString := ''.
-    strings keysAndValuesDo:[:index :subString |
-	subString notNil ifTrue:[
-	    "
-	     find next tab
-	    "
-	    tabPos := tabSpec positionOfTab:index forString:subString on:aGC.
-	    tabPos isNil ifTrue:[
-		"
-		 no tab - just continue where we are ...
-		"
-		xPos := xPos + (aGC font widthOf:prevString).
-	    ] ifFalse:[
-		xPos := tabPos + x.
-	    ].
-	    aGC displayString:subString x:xPos y:y.
-	    prevString := subString.
-	]
-    ].
-
-    "
      |v e myList tabs|
 
      myList := OrderedCollection new.
@@ -115,8 +94,11 @@
      v := ListView new.
      v setList:myList expandTabs:false.
      v open
-    "
-    "
+
+
+
+     'many multiColListEntries in a scrollable ListView'
+
      |v e myList tabs|
 
      myList := OrderedCollection new.
@@ -137,8 +119,11 @@
      v := ScrollableView for:ListView.
      v setList:myList expandTabs:false.
      v open
-    "
-    "
+
+
+
+     'like above, but adds nice alignments'
+
      |v e myList tabs|
 
      myList := OrderedCollection new.
@@ -161,12 +146,19 @@
      v := ScrollableView for:ListView.
      v setList:myList expandTabs:false.
      v open
-    "
-    "
+
+
+
+     'specifying tabs in inches'
+
      |v 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'.
@@ -175,12 +167,118 @@
      e colAt:5 put:'8'.
      e colAt:6 put:'10'.
      e colAt:7 put:'12'.
-     e tabPositions:#(0 2 3.5 4 6 8 10 12); tabUnit:#inch.
+     e tabulatorSpecification:tabs.
+     myList add:e.
+
+     v := ScrollableView for:ListView.
+     v setList:myList expandTabs:false.
+     v open
+
+
+     'if you have the columns available as a collection, 
+      setup can be done easier'
+
+     |v 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.
 
      v := ScrollableView for:ListView.
      v setList:myList expandTabs:false.
      v open
-    "
+"
+! !
+
+!MultiColListEntry methodsFor:'accessing'!
+
+strings:aCollectionOfStrings
+    "replace all substrings"
+
+    strings := OrderedCollection withAll:aCollectionOfStrings. 
+!
+
+colAt:index
+    "return the substring at column index"
+
+    index > strings size ifTrue:[^ nil].
+    ^ strings at:index
+!
+
+colAt:index put:aString
+    "replace the substring at column index"
+
+    strings isNil ifTrue:[
+	strings := OrderedCollection new:index
+    ].
+    strings grow:index.
+    strings at:index put:aString
+!
+
+tabulatorSpecification:aTabSpec
+    "set the tabulator spec"
+
+    tabSpec := aTabSpec
 ! !
 
+!MultiColListEntry methodsFor:'converting'!
+
+asString
+    "return the receiver as a string with embedded tabs"
+
+    |s sub tab 
+     nSub "{ Class: SmallInteger }"|
+
+    s := ''.
+    tab := Character tab asString.
+    nSub := strings size.
+    1 to:nSub do:[:subStringIndex |
+	sub := strings at:subStringIndex.
+	sub notNil ifTrue:[
+	    s := s , sub.
+	].
+	subStringIndex == strings size ifFalse:[
+	    s := s , tab
+	]
+    ].
+
+    ^ s
+! !
+
+!MultiColListEntry methodsFor:'drawing'!
+
+displayOn:aGC x:x y:y
+    "display the receiver on a GC"
+
+    |xPos subString tabPos w prevString|
+
+    xPos := x.
+    prevString := ''.
+    strings keysAndValuesDo:[:index :subString |
+	subString notNil ifTrue:[
+	    "
+	     find next tab
+	    "
+	    tabPos := tabSpec positionOfTab:index forString:subString on:aGC.
+	    tabPos isNil ifTrue:[
+		"
+		 no tab - just continue where we are ...
+		"
+		xPos := xPos + (aGC font widthOf:prevString).
+	    ] ifFalse:[
+		xPos := tabPos + x.
+	    ].
+	    aGC displayString:subString x:xPos y:y.
+	    prevString := subString.
+	]
+    ].
+
+! !
+