A question about views
Posted by Joseph Frippiat on Apr 14, 2006; 12:02pm
URL: https://forum.world.st/A-question-about-views-tp3378217.html
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> -------