TabulatorSpecification.st
changeset 28 ca403f4c5b86
parent 25 e07adf47d209
child 36 160b8f0dfd7d
--- a/TabulatorSpecification.st	Thu Nov 17 15:42:58 1994 +0100
+++ b/TabulatorSpecification.st	Mon Nov 21 17:49:32 1994 +0100
@@ -9,6 +9,26 @@
 
 !TabulatorSpecification 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/TabulatorSpecification.st,v 1.3 1994-11-21 16:49:03 claus Exp $
+"
+!
+
 documentation
 "
     This is a helper class for table widgets and tabular data in
@@ -16,7 +36,11 @@
     A tabulatorSpecification keeps track of where the tabs are,
     and how they align. They are to be used un conjunction with
     MultiColumnListEntry or the upcoming tableWidget.
+"
+!
 
+examples 
+"
     Example use (in a ListView):
 
 	|listView tabSpec entry|
@@ -62,8 +86,99 @@
 	listView at:3 put:entry.
 	listView open
 
-		tabSpec widths:     #(2     0.3   2     1      0.7    0.5      1).
-		"                   name  type  mode  owner  group  size     type"
+
+    defining field positions in millimeter :
+
+	|listView tabSpec entry|
+
+	listView := ListView new.
+
+	tabSpec := TabulatorSpecification new.
+	tabSpec unit:#mm.
+	tabSpec positions:#(0 10 20 40).
+	tabSpec align:    #left.          
+
+	entry := MultiColListEntry new.
+	entry tabulatorSpecification:tabSpec.
+	entry colAt:1 put:'1';
+	      colAt:2 put:'2';
+	      colAt:3 put:'3';
+	      colAt:4 put:'4'.
+
+	listView at:1 put:entry.
+
+	entry := MultiColListEntry new.
+	entry tabulatorSpecification:tabSpec.
+	entry colAt:1 put:'aa';
+	      colAt:2 put:'bb';
+	      colAt:3 put:'cc';
+	      colAt:4 put:'dd'.
+
+	listView at:2 put:entry.
+
+	listView open
+
+    defining field widths in millimeter :
+
+	|listView tabSpec entry|
+
+	listView := ListView new.
+
+	tabSpec := TabulatorSpecification new.
+	tabSpec unit:#mm.
+	tabSpec widths:#(10 10 20 10).
+	tabSpec align:    #left.        
+
+	entry := MultiColListEntry new.
+	entry tabulatorSpecification:tabSpec.
+	entry colAt:1 put:'1';
+	      colAt:2 put:'2';
+	      colAt:3 put:'3';
+	      colAt:4 put:'4'.
+
+	listView at:1 put:entry.
+
+	entry := MultiColListEntry new.
+	entry tabulatorSpecification:tabSpec.
+	entry colAt:1 put:'aa';
+	      colAt:2 put:'bb';
+	      colAt:3 put:'cc';
+	      colAt:4 put:'dd'.
+
+	listView at:2 put:entry.
+
+	listView open
+
+    defining field widths in pixels :
+
+	|listView tabSpec entry|
+
+	listView := ListView new.
+
+	tabSpec := TabulatorSpecification new.
+	tabSpec unit:#pixel.
+	tabSpec widths:#(50 30 30 50).
+	tabSpec align:    #left.        
+
+	entry := MultiColListEntry new.
+	entry tabulatorSpecification:tabSpec.
+	entry colAt:1 put:'1';
+	      colAt:2 put:'2';
+	      colAt:3 put:'3';
+	      colAt:4 put:'4'.
+
+	listView at:1 put:entry.
+
+	entry := MultiColListEntry new.
+	entry tabulatorSpecification:tabSpec.
+	entry colAt:1 put:'aa';
+	      colAt:2 put:'bb';
+	      colAt:3 put:'cc';
+	      colAt:4 put:'dd'.
+
+	listView at:2 put:entry.
+
+	listView open
 "
 ! !
 
@@ -98,6 +213,20 @@
     ^ 1.
 !
 
+typeOfTab:index
+    "return the type of the tab at position index."
+
+    tabPositions isNil ifTrue:[^ #left].
+    tabTypes notNil ifTrue:[
+	(tabTypes isMemberOf:Symbol) ifTrue:[
+	    ^ tabTypes
+	].
+	^ tabTypes at:index.
+    ].
+    "default is left"
+    ^ #left
+!
+
 positionOfTab:index on:aGC
     "return the position (in device units) of the tab at index"
 
@@ -119,15 +248,7 @@
     pos := self positionOfTab:index on:aGC.
     pos isNil ifTrue:[^ nil].
 
-    tabTypes notNil ifTrue:[
-	(tabTypes isMemberOf:Symbol) ifTrue:[
-	    type := tabTypes
-	] ifFalse:[
-	    type := tabTypes at:(index).
-	].
-    ] ifFalse:[
-	type := #left
-    ].
+    type := self typeOfTab:index.
 
     type == #right ifTrue:[
 	^ pos - (aGC font widthOf:aString).
@@ -145,11 +266,16 @@
     ].
     "default is left"
     ^ pos
-
 ! !
 
 !TabulatorSpecification methodsFor:'accessing'!
 
+size
+    "return the number of tabs in this spec"
+
+    ^ tabPositions size
+!
+
 unit:aSymbol
     "set the unit.
      allowed are: #inch, #mm, #cm, #pixel and #col"
@@ -190,6 +316,25 @@
     ^ tabTypes
 !
 
+widths
+    "return a width-vector"
+
+    |prev|
+
+    prev := 0.
+    ^ tabPositions collect:[:p | |w| w := p - prev. prev := p. w].
+
+    "
+     |spec|
+
+     spec := TabulatorSpecification new.
+     spec unit:#inch.
+     spec positions:#(0     1     2.5    3.5    4       5        ).
+     spec align:    #(#left #left #right #right #center #decimal ).
+     spec widths
+    "
+!
+
 widths:fieldWidths
     "set the position-vector from a vector of field widths"