Label.st
changeset 125 3ffa271732f7
parent 118 3ee5ea99d0e2
child 128 06a050529335
--- a/Label.st	Mon May 08 17:19:27 1995 +0200
+++ b/Label.st	Tue May 09 03:57:16 1995 +0200
@@ -24,7 +24,7 @@
 COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libwidg/Label.st,v 1.21 1995-05-03 00:29:53 claus Exp $
+$Header: /cvs/stx/stx/libwidg/Label.st,v 1.22 1995-05-09 01:56:01 claus Exp $
 '!
 
 !Label class methodsFor:'documentation'!
@@ -45,7 +45,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libwidg/Label.st,v 1.21 1995-05-03 00:29:53 claus Exp $
+$Header: /cvs/stx/stx/libwidg/Label.st,v 1.22 1995-05-09 01:56:01 claus Exp $
 "
 !
 
@@ -72,6 +72,9 @@
     to hold any changed logos later. (usually, you create the label first with
     the longest string first to have it compute its size, then set the fixSize 
     attribute to avoid resizing later).
+    Be careful when placing self-resizing labels into panels - by default,
+    panels do not react on the size change - leading to ugly looking geometry.
+    (but you can tell the panel to watch for changes with #elementsCHangeSize:)
 
     The placement of the contents within the label is controlled by
     the adjust attribute, it can be set with:
@@ -109,6 +112,7 @@
       so the label does NOT update its shown contents.
       The aspectMsg defaults to #value.
 
+
     Instance variables:
 
 	logo                <Object>        the logo, can be a Form, String or Text
@@ -368,9 +372,10 @@
 	top open
 
 
-     MVC operation (model provides the label):
-     (have to use a plug to simulate a model which responds to
-      the #someAspect message):
+     MVC operation 
+       model provides the label):
+       (have to use a plug to simulate a model which responds to
+	the #someAspect message):
 
 	|top l model|
 
@@ -391,8 +396,8 @@
 
 
     concrete example (track a counters value):
-    (here, the default aspect #value is used both to notify the label about
-    changes and to aquire a new value from the model).
+      (here, the default aspect #value is used both to notify the label about
+       changes and to aquire a new value from the model).
 
 	|top l model|
 
@@ -410,13 +415,13 @@
 	top extent:(200 @ 200).
 
 	l := Label in:top.
+	l level:-1.
 	l model:model; labelMessage:#value.
 
 	top open
 
 
-     MVC operation (model changes aspect after a while; 
-     two labels on the same model):
+       model changes aspect after a while; two labels on the same model:
 
 	|top l model|
 
@@ -441,7 +446,7 @@
 	model changed:#someAspect 
 
 
-     plugged MVC operation (getBlock returns the label): 
+      plugged MVC operation (getBlock returns the label): 
 
 	|top l model|
 
@@ -457,6 +462,97 @@
 	l model:model; labelMessage:#value.
 
 	top open.
+
+
+      use different label-selectors to access fields of a complex model:
+
+	|top panel model|
+
+	model := Plug new.
+	model respondTo:#field1 with:['value1'].
+	model respondTo:#field2 with:['value2'].
+	model respondTo:#field3 with:['value3'].
+	model respondTo:#field4 with:['value4'].
+
+	top := StandardSystemView new.
+
+	panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
+	panel elementsChangeSize:true.
+
+	panel addSubView:((Label on:model) labelMessage:#field1).
+	panel addSubView:((Label on:model) labelMessage:#field2).
+	panel addSubView:((Label on:model) labelMessage:#field3).
+	panel addSubView:((Label on:model) labelMessage:#field4).
+
+	top extent:(200 @ 200).
+	top open.
+
+	(Delay forSeconds:5) wait.
+
+	model respondTo:#field2 with:['new value2'].
+	model changed:#value  
+
+
+      same as above, using default aspects in the label, and an adaptor
+      to translate aspects:
+
+	|top panel model v1|
+
+	model := Plug new.
+	model respondTo:#field1 with:[v1].
+	model respondTo:#field1: with:[:arg | v1 := arg. model changed:#field1].
+	model respondTo:#field2 with:['value2'].
+	model respondTo:#field2: with:[:arg |].
+	model respondTo:#field3 with:['value3'].
+	model respondTo:#field3: with:[:arg |].
+	model respondTo:#field4 with:['value4'].
+	model respondTo:#field4: with:[:arg |].
+
+	top := StandardSystemView new.
+
+	panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
+	panel elementsChangeSize:true.
+
+	panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field1)) labelMessage:#value).
+	panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field2)) labelMessage:#value).
+	panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field3)) labelMessage:#value).
+	panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field4)) labelMessage:#value).
+
+	top extent:(200 @ 200).
+	top open.
+
+	(Delay forSeconds:5) wait.
+
+	model field1:'new value1'.
+
+
+      use an adapter to access fields of a complex model:
+
+	|top l panel model|
+
+	model := #('one' 'two' 'three') asValue.
+
+	top := StandardSystemView new.
+
+	panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
+	panel elementsChangeSize:true.
+
+	panel addSubView:((Label on:(ProtocolAdaptor
+					subjectChannel:model
+					accessPath:#(1))) labelMessage:#value).
+	panel addSubView:((Label on:(ProtocolAdaptor
+					subjectChannel:model
+					accessPath:#(2))) labelMessage:#value).
+	panel addSubView:((Label on:(ProtocolAdaptor
+					subjectChannel:model
+					accessPath:#(3))) labelMessage:#value).
+
+	top extent:(200 @ 200).
+	top open.
+
+	(Delay forSeconds:5) wait.
+
+	model value:#('oneone' 'twotwo' 'threethree').
 "
 ! !
 
@@ -522,6 +618,40 @@
     ]
 ! !
 
+!
+
+!Label methodsFor:'accessing-mvc'!
+
+model:aModel
+    super model:aModel.
+    self getLabelFromModel.
+!
+
+labelMessage 
+    "return the symbol used to aquire the labelString/image from the model
+     when the aspect changes.
+     The default is nil, which means: leave the label unchanged."
+
+    ^ labelMsg
+!
+
+labelMessage:aSymbol 
+    "set the symbol used to aquire the labelString/image from the model.
+     The default is nil, which means: leave the label unchanged."
+
+    labelMsg ~~ aSymbol ifTrue:[
+	labelMsg := aSymbol.
+	self getLabelFromModel
+    ]
+!
+
+addModelInterfaceTo:aDictionary
+    "see comment in View>>modelInterface"
+
+    super addModelInterfaceTo:aDictionary.
+    aDictionary at:#labelMessage put:labelMsg
+! !
+
 !Label methodsFor:'accessing'!
 
 foregroundColor:aColor
@@ -558,13 +688,6 @@
     self redraw
 !
 
-labelMessage:aSymbol 
-    "set the symbol used to aquire the labelString/image from the model.
-     The default is nil, which means: leave the label unchanged."
-
-    labelMsg := aSymbol
-!
-
 labelString:aString
     "for ST-80 compatibility: same as #label:
      set the label-string; adjust extent if not already realized and not fixedSize"
@@ -639,6 +762,18 @@
     ^ labelWidth
 !
 
+layout:how
+    "for protocol compatibility: alias for #adjust:"
+
+    self adjust:how
+!
+
+layout
+    "for protocol compatibility: alias for #adjust"
+
+    ^ self adjust
+!
+
 adjust:how
     "set the adjust, how which must be one of
 
@@ -659,6 +794,12 @@
     ]
 !
 
+adjust
+    "return the adjust symbol"
+
+    ^ adjust
+!
+
 font:aFont
     "set the font - if I'm not realized and not fixedSize, adjust my size"
 
@@ -690,10 +831,6 @@
     super realize.
 "/    fgColor := fgColor on:device.
 "/    bgColor := bgColor on:device.
-    (model notNil 
-    and:[aspectMsg notNil]) ifTrue:[
-	self getLabelFromModel.
-    ]
 !
 
 initialize
@@ -795,14 +932,9 @@
      but show different labels when changed (also, constant labels
      which have a nil labelMsg will not try to aquire a labelString)."
 
-    |sym|
-
-    model notNil ifTrue:[
-	sym := labelMsg.
-"/        sym isNil ifTrue:[sym := aspect<sg].
-	sym notNil ifTrue:[
-	    self label:(model perform:sym) printString.
-	]
+    (model notNil 
+    and:[labelMsg notNil]) ifTrue:[
+	self label:(model perform:labelMsg) printString.
     ].
 !
 
@@ -937,13 +1069,11 @@
 
     changedObject == model ifTrue:[
 	something == aspectMsg ifTrue:[
-	    labelMsg notNil ifTrue:[
-		self getLabelFromModel.
-	    ].
+	    self getLabelFromModel.
 	    ^ self.
 	]
     ].
-    super update:something
+    ^ super update:something with:aParameter from:changedObject
 ! !
 
 !Label methodsFor:'queries'!