A question about views

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

A question about views

Joseph Frippiat
Hi,

I have "created" a little view (the code is below) to show a boolean as
a little colored disk.  The disk is green (== onColor) when the boolean
is true and gray (== offColor) otherwise.

What must I do, if it's possible, to change the onColor and the OffColor
in the View Composer when I add my little view to a "parent" view ?

Thanks,

Joseph

------- 8> ------- 8> -------
"Filed out from Dolphin Smalltalk X6"!

View subclass: #LedView
        instanceVariableNames: 'onColor offColor'
        classVariableNames: ''
        poolDictionaries: ''
        classInstanceVariableNames: ''!
LedView guid: (GUID fromString: '{55475C3F-115E-4F66-9CF1-607420E244E0}')!
LedView comment: 'I am the graphical representation of a Led:
        - false = off;
        - true = on.

* EXAMPLES:
LedView show.'!
!LedView categoriesForClass!MVP-Resources-Misc! !
!LedView methodsFor!

connectModel
        "Connect the receiver to its model, wiring events, etc."

        self model
                when: #valueChanged send: #refreshContents to: self!

initialize
        "Initialise the receiver."

        super initialize.
        onColor := Color green.
        offColor := Color gray.!

offColor
        ^offColor!

offColor: anObject
        offColor := anObject!

onColor
        ^onColor!

onColor: anObject
        onColor := anObject!

onPaintRequired: aPaintEvent
        "Private - Handler for paint event. Show the led"

        | canvas |
        canvas := aPaintEvent canvas.
        canvas pen: (Pen
                                withStyle: 0
                                width: 1
                                color: Color black).
        self model value
                ifTrue: [canvas brush: (Brush color: self onColor)]
                ifFalse: [canvas brush: (Brush color: self offColor)].
        canvas ellipse: (0 @ 0 corner: self width @ self height)! !
!LedView categoriesFor: #connectModel!public! !
!LedView categoriesFor: #initialize!initialize!public! !
!LedView categoriesFor: #offColor!accessing!private! !
!LedView categoriesFor: #offColor:!accessing!private! !
!LedView categoriesFor: #onColor!accessing!private! !
!LedView categoriesFor: #onColor:!accessing!private! !
!LedView categoriesFor: #onPaintRequired:!event handling!private! !

!LedView class methodsFor!

defaultModel
        "Answer a default model to be assigned to the receiver when it is
initialized."

        ^false asValue! !
!LedView class categoriesFor: #defaultModel!models!public! !
------- 8> ------- 8> -------


Reply | Threaded
Open this post in threaded view
|

Re: A question about views

Ian Bartholomew-21
Joseph,

> What must I do, if it's possible, to change the onColor and the OffColor
> in the View Composer when I add my little view to a "parent" view ?

Add the following *class* method and recreate the View.  You should find
that it now has two aspects, editable in the VC, for the on and off colour.

publishedAspectsOfInstances
        ^(super publishedAspectsOfInstances)
                add: (Aspect color: #onColor);
                add: (Aspect color: #offColor);
                yourself

--
Ian

Use the Reply-To address to contact me (limited validity).
Mail sent to the From address is ignored.