Label.st
changeset 133 e58c7c979f33
parent 132 596439fe4efd
child 144 a86f474be012
equal deleted inserted replaced
132:596439fe4efd 133:e58c7c979f33
    12 
    12 
    13 'From Smalltalk/X, Version:2.10.5 on 14-mar-1995 at 11:13:27 am'!
    13 'From Smalltalk/X, Version:2.10.5 on 14-mar-1995 at 11:13:27 am'!
    14 
    14 
    15 View subclass:#Label
    15 View subclass:#Label
    16 	 instanceVariableNames:'logo labelWidth labelHeight labelOriginX labelOriginY adjust
    16 	 instanceVariableNames:'logo labelWidth labelHeight labelOriginX labelOriginY adjust
    17 		hSpace vSpace bgColor fgColor fixSize labelMsg'
    17 		hSpace vSpace bgColor fgColor fixSize labelMsg converter'
    18 	 classVariableNames:'DefaultFont DefaultForegroundColor DefaultBackgroundColor'
    18 	 classVariableNames:'DefaultFont DefaultForegroundColor DefaultBackgroundColor'
    19 	 poolDictionaries:''
    19 	 poolDictionaries:''
    20 	 category:'Views-Layout'
    20 	 category:'Views-Layout'
    21 !
    21 !
    22 
    22 
    23 Label comment:'
    23 Label comment:'
    24 COPYRIGHT (c) 1989 by Claus Gittinger
    24 COPYRIGHT (c) 1989 by Claus Gittinger
    25 	      All Rights Reserved
    25 	      All Rights Reserved
    26 
    26 
    27 $Header: /cvs/stx/stx/libwidg/Label.st,v 1.26 1995-07-03 02:33:10 claus Exp $
    27 $Header: /cvs/stx/stx/libwidg/Label.st,v 1.27 1995-07-23 03:01:52 claus Exp $
    28 '!
    28 '!
    29 
    29 
    30 !Label class methodsFor:'documentation'!
    30 !Label class methodsFor:'documentation'!
    31 
    31 
    32 copyright
    32 copyright
    43 "
    43 "
    44 !
    44 !
    45 
    45 
    46 version
    46 version
    47 "
    47 "
    48 $Header: /cvs/stx/stx/libwidg/Label.st,v 1.26 1995-07-03 02:33:10 claus Exp $
    48 $Header: /cvs/stx/stx/libwidg/Label.st,v 1.27 1995-07-23 03:01:52 claus Exp $
    49 "
    49 "
    50 !
    50 !
    51 
    51 
    52 documentation
    52 documentation
    53 "
    53 "
   445 	top := StandardSystemView new.
   445 	top := StandardSystemView new.
   446 	top extent:(200 @ 200).
   446 	top extent:(200 @ 200).
   447 
   447 
   448 	l := Label in:top.
   448 	l := Label in:top.
   449 	l level:-1.
   449 	l level:-1.
       
   450 	l model:model; labelMessage:#value.
       
   451 
       
   452 	top open
       
   453 
       
   454 
       
   455       with a printConverter:
       
   456 
       
   457 	|top l model|
       
   458 
       
   459 	model := Date today asValue.
       
   460 	[
       
   461 	    1 to:50 do:[:i |
       
   462 		(Delay forSeconds:1) wait.
       
   463 		model value:(model value addDays:1) 
       
   464 	    ].
       
   465 	    top destroy
       
   466 	] fork.
       
   467 
       
   468 	top := StandardSystemView new.
       
   469 	top extent:(200 @ 200).
       
   470 
       
   471 	l := Label in:top.
       
   472 	l level:-1.
       
   473 	l converter:(PrintConverter new initForDate).
   450 	l model:model; labelMessage:#value.
   474 	l model:model; labelMessage:#value.
   451 
   475 
   452 	top open
   476 	top open
   453 
   477 
   454 
   478 
   681 addModelInterfaceTo:aDictionary
   705 addModelInterfaceTo:aDictionary
   682     "see comment in View>>modelInterface"
   706     "see comment in View>>modelInterface"
   683 
   707 
   684     super addModelInterfaceTo:aDictionary.
   708     super addModelInterfaceTo:aDictionary.
   685     aDictionary at:#labelMessage put:labelMsg
   709     aDictionary at:#labelMessage put:labelMsg
   686 ! !
   710 !
   687 
   711 
   688 !Label methodsFor:'accessing'!
   712 converter:aConverter
       
   713     "set the printConverter;
       
   714      that one is asked to convert the models value to a printed
       
   715      representation (if non-nil). If nil, the model is supposed to
       
   716      return a string or bitmap image."
       
   717 
       
   718     converter := aConverter
       
   719 ! !
       
   720 
       
   721 !Label methodsFor:'accessing-colors'!
   689 
   722 
   690 foregroundColor:aColor
   723 foregroundColor:aColor
   691     "set the foreground color"
   724     "set the foreground color"
   692 
   725 
   693     fgColor := aColor on:device.
   726     fgColor := aColor on:device.
   717     "set the colors to be used for drawing"
   750     "set the colors to be used for drawing"
   718 
   751 
   719     fgColor := fg on:device.
   752     fgColor := fg on:device.
   720     bgColor := bg on:device.
   753     bgColor := bg on:device.
   721     shown ifTrue:[self redraw]
   754     shown ifTrue:[self redraw]
   722 !
   755 ! !
       
   756 
       
   757 !Label methodsFor:'accessing-contents'!
   723 
   758 
   724 labelString:aString
   759 labelString:aString
   725     "for ST-80 compatibility: same as #label:
   760     "for ST-80 compatibility: same as #label:
   726      set the label-string; adjust extent if not already realized and not fixedSize"
   761      set the label-string; adjust extent if not already realized and not fixedSize"
   727 
   762 
   775     "return the labels string or image"
   810     "return the labels string or image"
   776 
   811 
   777     ^ logo
   812     ^ logo
   778 !
   813 !
   779 
   814 
       
   815 labelWidth
       
   816     "return the logos width in pixels"
       
   817 
       
   818     ^ labelWidth
       
   819 ! !
       
   820 
       
   821 !Label methodsFor:'accessing-layout'!
       
   822 
   780 sizeFixed:aBoolean
   823 sizeFixed:aBoolean
   781     "set/clear the fix-size attribute. 
   824     "set/clear the fix-size attribute. 
   782      If true, the receiver will not change its size when the labelString/logo
   825      If true, the receiver will not change its size when the labelString/logo
   783      changes. If false (the default), it will resize itself to make the logo
   826      changes. If false (the default), it will resize itself to make the logo
   784      fit."
   827      fit."
   788 
   831 
   789 sizeFixed
   832 sizeFixed
   790     "return the fix-size attribute"
   833     "return the fix-size attribute"
   791 
   834 
   792     ^ fixSize
   835     ^ fixSize
   793 !
       
   794 
       
   795 labelWidth
       
   796     "return the logos width in pixels"
       
   797 
       
   798     ^ labelWidth
       
   799 !
   836 !
   800 
   837 
   801 layout:how
   838 layout:how
   802     "for protocol compatibility: alias for #adjust:.
   839     "for protocol compatibility: alias for #adjust:.
   803      Please use #adjust:, since #layout: conflicts with a method
   840      Please use #adjust:, since #layout: conflicts with a method
   840 
   877 
   841 adjust
   878 adjust
   842     "return the adjust symbol"
   879     "return the adjust symbol"
   843 
   880 
   844     ^ adjust
   881     ^ adjust
       
   882 !
       
   883 
       
   884 verticalSpace:aNumber
       
   885     "set the number of pixels by which the logo
       
   886      is vertically inset from the border"
       
   887 
       
   888     vSpace := aNumber
       
   889 !
       
   890 
       
   891 horizontalSpace:aNumber
       
   892     "set the number of pixels by which the logo
       
   893      is horizontally inset from the border"
       
   894 
       
   895     hSpace := aNumber
   845 !
   896 !
   846 
   897 
   847 font:aFont
   898 font:aFont
   848     "set the font - if I'm not realized and not fixedSize, adjust my size"
   899     "set the font - if I'm not realized and not fixedSize, adjust my size"
   849 
   900 
   932     self clearInsideWith:bg.
   983     self clearInsideWith:bg.
   933 
   984 
   934     logo notNil ifTrue:[
   985     logo notNil ifTrue:[
   935 	self paint:fg on:bg.
   986 	self paint:fg on:bg.
   936 
   987 
       
   988 	m2 := margin * 2.
       
   989 	hSep := (hSpace*2).
       
   990 	vSep := (vSpace*2).
       
   991 
   937 	logo isImageOrForm ifTrue:[
   992 	logo isImageOrForm ifTrue:[
   938 	    x := labelOriginX.
   993 	    x := labelOriginX.
   939 	    y := labelOriginY.
   994 	    y := labelOriginY.
   940 
   995 
   941 	    adjust == #fit ifTrue:[
   996 	    adjust == #fit ifTrue:[
   942 		hSep := (hSpace*2).
       
   943 		vSep := (vSpace*2).
       
   944 		m2 := margin * 2.
       
   945 
       
   946 		scaleH := ((width - hSep) / (logo width)) asFloat.
   997 		scaleH := ((width - hSep) / (logo width)) asFloat.
   947 		scaleV := ((height - vSep) / (logo height)) asFloat.
   998 		scaleV := ((height - vSep) / (logo height)) asFloat.
   948 		self scale:(scaleH @ scaleV).
   999 		self scale:(scaleH @ scaleV).
   949 		x := transformation applyInverseScaleX:x.
  1000 		x := transformation applyInverseScaleX:x.
   950 		y := transformation applyInverseScaleY:y.
  1001 		y := transformation applyInverseScaleY:y.
  1004 
  1055 
  1005 !Label methodsFor:'private'!
  1056 !Label methodsFor:'private'!
  1006 
  1057 
  1007 getLabelFromModel
  1058 getLabelFromModel
  1008     "ask my model for the label to show.
  1059     "ask my model for the label to show.
  1009      Here, we use labelMsg. 
  1060      Here, we use labelMsg (instead of aspectMsg). 
  1010      This allows multiple labels to react on the same aspect, 
  1061      This allows multiple labels to react on the same aspect, 
  1011      but show different labels when changed (also, constant labels
  1062      but show different labels when changed 
  1012      which have a nil labelMsg will not try to aquire a labelString)."
  1063      (also, since labelMsg defaults to nil, constant labels
       
  1064       which have a nil labelMsg will not try to aquire a labelString)."
       
  1065 
       
  1066     |val|
  1013 
  1067 
  1014     (model notNil 
  1068     (model notNil 
  1015     and:[labelMsg notNil]) ifTrue:[
  1069     and:[labelMsg notNil]) ifTrue:[
  1016 	self label:(model perform:labelMsg) printString.
  1070 	val := model perform:labelMsg.
       
  1071 	converter notNil ifTrue:[
       
  1072 	    val := converter printStringFor:val
       
  1073 	].
       
  1074 	self label:val.
  1017     ].
  1075     ].
  1018 !
  1076 !
  1019 
  1077 
  1020 newLayout
  1078 newLayout
  1021     "recompute position/size after a change
  1079     "recompute position/size after a change