documentation
authorClaus Gittinger <cg@exept.de>
Mon, 29 Apr 1996 09:57:45 +0200
changeset 595 31cdbedb303d
parent 594 b9c5a5e5f905
child 596 bbcca426b401
documentation
FontPanel.st
--- a/FontPanel.st	Sat Apr 27 20:25:18 1996 +0200
+++ b/FontPanel.st	Mon Apr 29 09:57:45 1996 +0200
@@ -43,22 +43,70 @@
 "
     this class implements a font chooser.
 
-    usage:
+    [author:]
+        Claus Gittinger
+
+    [see also:]
+        Font FontDescription
+        View Dialog
+"
+!
+
+examples
+"
+    very simple:
+                                                                        [exBegin]
+        |font|
+        
+        font := FontPanel fontFromUser.
+        Transcript showCr:font
+                                                                        [exEnd]
+
+
+    with initial font:
+                                                                        [exBegin]
+        |font|
+
+        font := FontPanel 
+                    fontFromUserInitial:(Font 
+                                            family:'courier'
+                                            size:12).
+        Transcript showCr:font
+                                                                        [exEnd]
+
+
+    with initial font & title:
+                                                                        [exBegin]
+        |font|
+
+        font := FontPanel 
+                    fontFromUserInitial:(Font 
+                                            family:'courier'
+                                            size:12)
+                                  title:'select a fooBar font'.
+        Transcript showCr:font
+                                                                        [exEnd]
+
+
+    full setup; setting a filter to only present iso fonts
+    and callBack action:
+                                                                        [exBegin]
 
         |panel|
 
         panel := FontPanel new.
-        panel action:[:aFont | Transcript showCR:'the font is' , aFont printString].
-        panel show
-
-    or simply:
-
-        font := FontPanel fontFromUser
-
-    [author:]
-        Claus Gittinger
+        panel label:'hi there - which iso font ?'.
+        panel filter:[:fd | fd encoding notNil
+                            and:[fd encoding startsWith:'iso']].
+        panel action:[:family :face :style :size | 
+                        Transcript showCr:'family:' , family.
+                        Transcript showCr:'face:' , face.
+                        Transcript showCr:'style:' , style.
+                        Transcript showCr:'size:' , size printString.
+                     ].
+        panel open
+                                                                        [exEnd]
 "
-
 ! !
 
 !FontPanel class methodsFor:'defaults'!
@@ -74,6 +122,8 @@
 !
 
 defaultJISSampleString
+    "return the sample jis preview text"
+
     ^ ('The quick brown fox
 jumps over the lazy dog
 1234567890
@@ -82,10 +132,12 @@
 \e$B$$$i$C$7$c$$$^$;\e(J \e$B@$4V\e(J
 ' withEscapes decodeFrom:#jis7)
 
-    "Modified: 23.2.1996 / 23:33:37 / cg"
+    "Modified: 29.4.1996 / 09:46:11 / cg"
 !
 
 defaultRomanSampleString
+    "return the sample roman preview text"
+
     ^ 'The quick brown fox
 jumps over the lazy dog
 1234567890
@@ -104,7 +156,7 @@
 (Character value:197) asString ,      "/ A
 (Character value:169) asString        "/ copyright
 
-    "Modified: 24.2.1996 / 22:45:16 / cg"
+    "Modified: 29.4.1996 / 09:46:19 / cg"
 ! !
 
 !FontPanel class methodsFor:'startup'!
@@ -123,8 +175,8 @@
 !
 
 fontFromUserInitial:aFont
-    "open a fontPanel and return the selected font, or nil
-     if abort is pressed"
+    "open a fontPanel showing aFont initially,
+     and return the selected font, or nil if abort is pressed"
 
     ^ self fontFromUserInitial:aFont title:nil
 
@@ -133,12 +185,12 @@
     "
 
     "Created: 27.2.1996 / 00:51:44 / cg"
-    "Modified: 27.2.1996 / 01:00:03 / cg"
+    "Modified: 29.4.1996 / 09:45:52 / cg"
 !
 
 fontFromUserInitial:aFont title:someTitle
-    "open a fontPanel and return the selected font, or nil
-     if abort is pressed"
+    "open a fontPanel with title and return the selected font, 
+     or nil if abort is pressed"
 
     ^ self fontFromUserInitial:aFont title:someTitle filter:nil
 
@@ -147,12 +199,12 @@
     "
 
     "Created: 27.2.1996 / 00:59:46 / cg"
-    "Modified: 27.2.1996 / 01:00:12 / cg"
+    "Modified: 29.4.1996 / 09:45:34 / cg"
 !
 
 fontFromUserInitial:aFont title:someTitle filter:aFilterBlock
-    "open a fontPanel and return the selected font, or nil
-     if abort is pressed"
+    "open a fontPanel with title and font-filter
+     and return the selected font, or nil if abort is pressed"
 
     |fontPanel|
 
@@ -179,33 +231,43 @@
     "
 
     "Created: 27.2.1996 / 00:59:46 / cg"
-    "Modified: 27.2.1996 / 01:00:12 / cg"
+    "Modified: 29.4.1996 / 09:45:23 / cg"
 ! !
 
 !FontPanel methodsFor:'accessing'!
 
-action:aBlock
-    okAction := aBlock
+action:aFourArgBlock
+    "set the action to be evaluated on ok.
+     The block will be evaluated with family, face, style and size."
+
+    okAction := aFourArgBlock
+
+    "Modified: 29.4.1996 / 09:44:35 / cg"
 !
 
 encoding:aPattern
+    "set the encoding goal"
+
     encoding := aPattern.
     shown ifTrue:[
         self updateFamilyList
     ].
 
-    "Modified: 27.2.1996 / 01:41:33 / cg"
     "Created: 29.2.1996 / 04:05:31 / cg"
+    "Modified: 29.4.1996 / 09:40:18 / cg"
 !
 
 filter:aOneArgBlock
+    "set a filter; if non-nil, only fonts for which the filterBlock
+     returns true will be offered"
+
     filter := aOneArgBlock.
     shown ifTrue:[
         self updateFamilyList
     ].
 
     "Created: 27.2.1996 / 01:40:08 / cg"
-    "Modified: 27.2.1996 / 01:41:33 / cg"
+    "Modified: 29.4.1996 / 09:40:49 / cg"
 !
 
 initialFont:aFont
@@ -221,6 +283,8 @@
 !FontPanel methodsFor:'initialization'!
 
 focusSequence
+    "return the sequence for tabbing through my components"
+
     |a|
 
     a := Array new:5.
@@ -230,6 +294,8 @@
     a at:4 put:abortButton.
     a at:5 put:okButton.
     ^ a
+
+    "Modified: 29.4.1996 / 09:41:08 / cg"
 !
 
 initialize
@@ -355,28 +421,35 @@
 !FontPanel methodsFor:'private'!
 
 clearPreview
+    "clear the preview subview"
+
     shown ifTrue:[
         previewField clear.
         encodingLabel label:''.
     ].
 
     "Created: 17.4.1996 / 15:19:16 / cg"
-    "Modified: 17.4.1996 / 15:20:56 / cg"
+    "Modified: 29.4.1996 / 09:41:27 / cg"
 !
 
 extractFaceAndStyleFrom:aString
+    "given a string, extract currentFace and currentStyle"
+
     |index|
 
     index := aString indexOf:$-.
     (index ~~ 0) ifTrue:[
-	currentFaceAndStyle := aString.
-	currentFace := aString copyTo:(index - 1).
-	currentStyle := aString copyFrom:(index + 1)
+        currentFaceAndStyle := aString.
+        currentFace := aString copyTo:(index - 1).
+        currentStyle := aString copyFrom:(index + 1)
     ]
 
+    "Modified: 29.4.1996 / 09:41:47 / cg"
 !
 
 showPreview
+    "show the preview text"
+
     |f enc s all fonts scalable|
 
     self clearPreview.
@@ -429,7 +502,7 @@
         previewField contents:s.
     ]
 
-    "Modified: 17.4.1996 / 15:19:29 / cg"
+    "Modified: 29.4.1996 / 09:42:01 / cg"
 !
 
 showSelectedFont
@@ -455,16 +528,18 @@
 !FontPanel methodsFor:'queries'!
 
 preferredExtent
-    "compute the boxes preferredExtent"
+    "return the boxes preferredExtent"
 
     ^ 400@350
 
-    "Modified: 23.4.1996 / 00:14:40 / cg"
+    "Modified: 29.4.1996 / 09:42:30 / cg"
 ! !
 
 !FontPanel methodsFor:'user interaction'!
 
 faceSelected:aFaceAndStyleName
+    "a fonts face was seleted; find available sizes and update lists"
+
     |sizes|
 
     aFaceAndStyleName notNil ifTrue:[    
@@ -494,10 +569,12 @@
         ]
     ]
 
-    "Modified: 17.4.1996 / 15:20:20 / cg"
+    "Modified: 29.4.1996 / 09:42:52 / cg"
 !
 
 familySelected:aFamilyName
+    "a fonts family was seleted; find available faces and update lists"
+
     |faces styles list|
 
     familyList selectElement:aFamilyName.
@@ -530,34 +607,42 @@
     sizeList list:nil.
     self clearPreview.
 
-    "Modified: 17.4.1996 / 15:20:04 / cg"
+    "Modified: 29.4.1996 / 09:43:27 / cg"
 !
 
 okPressed
+    "ok was pressed; hide myself and evaluate the okAction, passing
+     family, face, style and size as arguments"
+
     self hide.
     okAction notNil ifTrue:[
         currentFamily notNil ifTrue:[
-            okAction value:currentFamily
+            okAction 
+                 value:currentFamily
                  value:currentFace
                  value:currentStyle
                  value:currentSize
         ]
     ]
 
-    "Modified: 27.2.1996 / 00:50:19 / cg"
+    "Modified: 29.4.1996 / 09:44:08 / cg"
 !
 
 sizeSelected:aNumberOrString
+    "a size was seleted; update preview"
+
     aNumberOrString isNumber ifTrue:[
-	currentSize := aNumberOrString
+        currentSize := aNumberOrString
     ] ifFalse:[
-	currentSize := Number readFromString:aNumberOrString
+        currentSize := Number readFromString:aNumberOrString
     ].
     self showPreview
+
+    "Modified: 29.4.1996 / 09:43:23 / cg"
 ! !
 
 !FontPanel class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/FontPanel.st,v 1.32 1996-04-25 17:20:49 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/FontPanel.st,v 1.33 1996-04-29 07:57:45 cg Exp $'
 ! !