70 This can be used, if resizing of the label is not wanted. |
70 This can be used, if resizing of the label is not wanted. |
71 However, in this case you have to make certain that the size is big enough |
71 However, in this case you have to make certain that the size is big enough |
72 to hold any changed logos later. (usually, you create the label first with |
72 to hold any changed logos later. (usually, you create the label first with |
73 the longest string first to have it compute its size, then set the fixSize |
73 the longest string first to have it compute its size, then set the fixSize |
74 attribute to avoid resizing later). |
74 attribute to avoid resizing later). |
|
75 Be careful when placing self-resizing labels into panels - by default, |
|
76 panels do not react on the size change - leading to ugly looking geometry. |
|
77 (but you can tell the panel to watch for changes with #elementsCHangeSize:) |
75 |
78 |
76 The placement of the contents within the label is controlled by |
79 The placement of the contents within the label is controlled by |
77 the adjust attribute, it can be set with: |
80 the adjust attribute, it can be set with: |
78 |
81 |
79 aLabel adjust:how |
82 aLabel adjust:how |
106 Having a labelSymbol different from the aspectSymbol allows for two labels |
109 Having a labelSymbol different from the aspectSymbol allows for two labels |
107 to react on the same aspect-change, but use different messages when asking |
110 to react on the same aspect-change, but use different messages when asking |
108 the model for a new label contents. By default, the labelMsg is nil, |
111 the model for a new label contents. By default, the labelMsg is nil, |
109 so the label does NOT update its shown contents. |
112 so the label does NOT update its shown contents. |
110 The aspectMsg defaults to #value. |
113 The aspectMsg defaults to #value. |
|
114 |
111 |
115 |
112 Instance variables: |
116 Instance variables: |
113 |
117 |
114 logo <Object> the logo, can be a Form, String or Text |
118 logo <Object> the logo, can be a Form, String or Text |
115 labelWidth <Integer> the width of the logo in device units |
119 labelWidth <Integer> the width of the logo in device units |
455 |
460 |
456 l := Label origin:0.0@0.0 corner:1.0@0.5 in:top. |
461 l := Label origin:0.0@0.0 corner:1.0@0.5 in:top. |
457 l model:model; labelMessage:#value. |
462 l model:model; labelMessage:#value. |
458 |
463 |
459 top open. |
464 top open. |
|
465 |
|
466 |
|
467 use different label-selectors to access fields of a complex model: |
|
468 |
|
469 |top panel model| |
|
470 |
|
471 model := Plug new. |
|
472 model respondTo:#field1 with:['value1']. |
|
473 model respondTo:#field2 with:['value2']. |
|
474 model respondTo:#field3 with:['value3']. |
|
475 model respondTo:#field4 with:['value4']. |
|
476 |
|
477 top := StandardSystemView new. |
|
478 |
|
479 panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
480 panel elementsChangeSize:true. |
|
481 |
|
482 panel addSubView:((Label on:model) labelMessage:#field1). |
|
483 panel addSubView:((Label on:model) labelMessage:#field2). |
|
484 panel addSubView:((Label on:model) labelMessage:#field3). |
|
485 panel addSubView:((Label on:model) labelMessage:#field4). |
|
486 |
|
487 top extent:(200 @ 200). |
|
488 top open. |
|
489 |
|
490 (Delay forSeconds:5) wait. |
|
491 |
|
492 model respondTo:#field2 with:['new value2']. |
|
493 model changed:#value |
|
494 |
|
495 |
|
496 same as above, using default aspects in the label, and an adaptor |
|
497 to translate aspects: |
|
498 |
|
499 |top panel model v1| |
|
500 |
|
501 model := Plug new. |
|
502 model respondTo:#field1 with:[v1]. |
|
503 model respondTo:#field1: with:[:arg | v1 := arg. model changed:#field1]. |
|
504 model respondTo:#field2 with:['value2']. |
|
505 model respondTo:#field2: with:[:arg |]. |
|
506 model respondTo:#field3 with:['value3']. |
|
507 model respondTo:#field3: with:[:arg |]. |
|
508 model respondTo:#field4 with:['value4']. |
|
509 model respondTo:#field4: with:[:arg |]. |
|
510 |
|
511 top := StandardSystemView new. |
|
512 |
|
513 panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
514 panel elementsChangeSize:true. |
|
515 |
|
516 panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field1)) labelMessage:#value). |
|
517 panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field2)) labelMessage:#value). |
|
518 panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field3)) labelMessage:#value). |
|
519 panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field4)) labelMessage:#value). |
|
520 |
|
521 top extent:(200 @ 200). |
|
522 top open. |
|
523 |
|
524 (Delay forSeconds:5) wait. |
|
525 |
|
526 model field1:'new value1'. |
|
527 |
|
528 |
|
529 use an adapter to access fields of a complex model: |
|
530 |
|
531 |top l panel model| |
|
532 |
|
533 model := #('one' 'two' 'three') asValue. |
|
534 |
|
535 top := StandardSystemView new. |
|
536 |
|
537 panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
538 panel elementsChangeSize:true. |
|
539 |
|
540 panel addSubView:((Label on:(ProtocolAdaptor |
|
541 subjectChannel:model |
|
542 accessPath:#(1))) labelMessage:#value). |
|
543 panel addSubView:((Label on:(ProtocolAdaptor |
|
544 subjectChannel:model |
|
545 accessPath:#(2))) labelMessage:#value). |
|
546 panel addSubView:((Label on:(ProtocolAdaptor |
|
547 subjectChannel:model |
|
548 accessPath:#(3))) labelMessage:#value). |
|
549 |
|
550 top extent:(200 @ 200). |
|
551 top open. |
|
552 |
|
553 (Delay forSeconds:5) wait. |
|
554 |
|
555 model value:#('oneone' 'twotwo' 'threethree'). |
460 " |
556 " |
461 ! ! |
557 ! ! |
462 |
558 |
463 !Label class methodsFor:'instance creation'! |
559 !Label class methodsFor:'instance creation'! |
464 |
560 |
520 self redraw |
616 self redraw |
521 ] |
617 ] |
522 ] |
618 ] |
523 ! ! |
619 ! ! |
524 |
620 |
|
621 ! |
|
622 |
|
623 !Label methodsFor:'accessing-mvc'! |
|
624 |
|
625 model:aModel |
|
626 super model:aModel. |
|
627 self getLabelFromModel. |
|
628 ! |
|
629 |
|
630 labelMessage |
|
631 "return the symbol used to aquire the labelString/image from the model |
|
632 when the aspect changes. |
|
633 The default is nil, which means: leave the label unchanged." |
|
634 |
|
635 ^ labelMsg |
|
636 ! |
|
637 |
|
638 labelMessage:aSymbol |
|
639 "set the symbol used to aquire the labelString/image from the model. |
|
640 The default is nil, which means: leave the label unchanged." |
|
641 |
|
642 labelMsg ~~ aSymbol ifTrue:[ |
|
643 labelMsg := aSymbol. |
|
644 self getLabelFromModel |
|
645 ] |
|
646 ! |
|
647 |
|
648 addModelInterfaceTo:aDictionary |
|
649 "see comment in View>>modelInterface" |
|
650 |
|
651 super addModelInterfaceTo:aDictionary. |
|
652 aDictionary at:#labelMessage put:labelMsg |
|
653 ! ! |
|
654 |
525 !Label methodsFor:'accessing'! |
655 !Label methodsFor:'accessing'! |
526 |
656 |
527 foregroundColor:aColor |
657 foregroundColor:aColor |
528 "set the foreground color" |
658 "set the foreground color" |
529 |
659 |
554 "set the colors to be used for drawing" |
684 "set the colors to be used for drawing" |
555 |
685 |
556 fgColor := fg on:device. |
686 fgColor := fg on:device. |
557 bgColor := bg on:device. |
687 bgColor := bg on:device. |
558 self redraw |
688 self redraw |
559 ! |
|
560 |
|
561 labelMessage:aSymbol |
|
562 "set the symbol used to aquire the labelString/image from the model. |
|
563 The default is nil, which means: leave the label unchanged." |
|
564 |
|
565 labelMsg := aSymbol |
|
566 ! |
689 ! |
567 |
690 |
568 labelString:aString |
691 labelString:aString |
569 "for ST-80 compatibility: same as #label: |
692 "for ST-80 compatibility: same as #label: |
570 set the label-string; adjust extent if not already realized and not fixedSize" |
693 set the label-string; adjust extent if not already realized and not fixedSize" |
793 Here, we use labelMsg. |
930 Here, we use labelMsg. |
794 This allows multiple labels to react on the same aspect, |
931 This allows multiple labels to react on the same aspect, |
795 but show different labels when changed (also, constant labels |
932 but show different labels when changed (also, constant labels |
796 which have a nil labelMsg will not try to aquire a labelString)." |
933 which have a nil labelMsg will not try to aquire a labelString)." |
797 |
934 |
798 |sym| |
935 (model notNil |
799 |
936 and:[labelMsg notNil]) ifTrue:[ |
800 model notNil ifTrue:[ |
937 self label:(model perform:labelMsg) printString. |
801 sym := labelMsg. |
|
802 "/ sym isNil ifTrue:[sym := aspect<sg]. |
|
803 sym notNil ifTrue:[ |
|
804 self label:(model perform:sym) printString. |
|
805 ] |
|
806 ]. |
938 ]. |
807 ! |
939 ! |
808 |
940 |
809 newLayout |
941 newLayout |
810 "recompute position/size after a change |
942 "recompute position/size after a change |
935 update:something with:aParameter from:changedObject |
1067 update:something with:aParameter from:changedObject |
936 "the MVC way of changing the label ..." |
1068 "the MVC way of changing the label ..." |
937 |
1069 |
938 changedObject == model ifTrue:[ |
1070 changedObject == model ifTrue:[ |
939 something == aspectMsg ifTrue:[ |
1071 something == aspectMsg ifTrue:[ |
940 labelMsg notNil ifTrue:[ |
1072 self getLabelFromModel. |
941 self getLabelFromModel. |
|
942 ]. |
|
943 ^ self. |
1073 ^ self. |
944 ] |
1074 ] |
945 ]. |
1075 ]. |
946 super update:something |
1076 ^ super update:something with:aParameter from:changedObject |
947 ! ! |
1077 ! ! |
948 |
1078 |
949 !Label methodsFor:'queries'! |
1079 !Label methodsFor:'queries'! |
950 |
1080 |
951 preferedExtent |
1081 preferedExtent |