redrawNow, when colors change.
SimpleView subclass:#UpDownButton
instanceVariableNames:'orientation upButton downButton'
classVariableNames:''
poolDictionaries:''
category:'Views-Interactors'
!
!UpDownButton class methodsFor:'documentation'!
documentation
"
an up/down button - simply two buttons in one view.
[author:]
Claus Gittinger
[see also:]
ArrowButton
ComboUpDownView
"
!
examples
"
[exBegin]
|top ud|
top := StandardSystemView new.
top extent:(300 @ 200).
ud := UpDownButton in:top.
ud origin:(10 @ 10).
ud upAction:[Transcript showCR:'up'].
ud downAction:[Transcript showCR:'down'].
top open.
[exEnd]
[exBegin]
|top ud|
top := StandardSystemView new.
top extent:(300 @ 200).
ud := UpDownButton in:top.
ud orientation:#horizontal.
ud origin:(10 @ 10).
ud upAction:[Transcript showCR:'up'].
ud downAction:[Transcript showCR:'down'].
top open.
[exEnd]
"
! !
!UpDownButton methodsFor:'accessing-behavior'!
disable
"disable the upDown button"
upButton disable.
downButton disable.
!
downAction:aBlock
"set the down-action"
downButton action:aBlock
!
enable
upButton enable.
downButton enable.
!
upAction:aBlock
"set the up-action"
upButton action:aBlock
! !
!UpDownButton methodsFor:'accessing-channels'!
backgroundChannel
"return a valueHolder for the background color"
^ upButton backgroundChannel
!
backgroundChannel: aValueHolder
"set a valueHolder for the background color"
upButton backgroundChannel: aValueHolder.
downButton backgroundChannel: aValueHolder
!
enableChannel
"return a valueHolder for the enabled-state"
upButton enableChannel
!
enableChannel: aValueHolder
"set a valueHolder for the enabled-state"
upButton enableChannel: aValueHolder.
downButton enableChannel: aValueHolder
!
foregroundChannel
"return a valueHolder for the foreground color"
^ upButton foregroundChannel
!
foregroundChannel: aValueHolder
"set a valueHolder for the foreground color"
upButton foregroundChannel: aValueHolder.
downButton foregroundChannel: aValueHolder
! !
!UpDownButton methodsFor:'accessing-colors'!
backgroundColor
"return the backgroundColor"
^upButton backgroundColor
!
backgroundColor:aColor
"set the backgroundColor"
aColor ~~ upButton backgroundColor ifTrue:[
upButton backgroundColor:aColor.
downButton backgroundColor:aColor.
shown ifTrue:[
self invalidateRepairNow:true
]
]
"Modified: / 6.6.1998 / 19:53:50 / cg"
!
foregroundColor
"return the foregroundColor"
^upButton foregroundColor
!
foregroundColor:aColor
"set the foregroundColor"
aColor ~~ upButton foregroundColor ifTrue:[
upButton foregroundColor:aColor.
downButton foregroundColor:aColor.
shown ifTrue:[
self invalidateRepairNow:true
]
]
"Modified: / 6.6.1998 / 19:53:44 / cg"
!
model:aModel
"ignore models"
! !
!UpDownButton methodsFor:'accessing-components'!
downButton
"return the downButton"
^ downButton
!
upButton
"return the upButton"
^ upButton
! !
!UpDownButton methodsFor:'accessing-look'!
orientation
"return the orientation (a symbol)"
^ orientation
!
orientation:aSymbol
"set the orientation (#horizontal or #vertical)"
orientation := aSymbol.
self initializeButtonDimensions.
self initializeButtonForms
! !
!UpDownButton methodsFor:'change & update'!
sizeChanged:how
super sizeChanged:how.
self initializeButtonDimensions
! !
!UpDownButton methodsFor:'displaying'!
showFocus:explicit
"display myself as having-focus"
(upButton enabled or:[downButton enabled]) ifTrue: [super showFocus:explicit]
! !
!UpDownButton methodsFor:'event handling'!
keyPress:aKey x:x y:y
"simulate a buttonPress/release"
|theButton theController|
((aKey == #CursorUp)
or:[aKey == #CursorRight
or:[aKey == $+]]) ifTrue:[
theButton := upButton
] ifFalse:[
((aKey == #CursorDown)
or:[aKey == #CursorLeft
or:[aKey == $-]]) ifTrue:[
theButton := downButton
].
].
theButton notNil ifTrue:[
theController := theButton controller.
theController pressed:true.
theController pressed:false.
^ self
].
^ super keyPress:aKey x:x y:y
"Created: / 21.4.1998 / 19:48:28 / cg"
"Modified: / 21.4.1998 / 19:56:28 / cg"
! !
!UpDownButton methodsFor:'initialization'!
initialize
orientation := #vertical.
super initialize.
self initializeButtons
!
initializeButtonDimensions
|upOrigin downOrigin upCorner downCorner|
upOrigin := 0@0.
orientation == #vertical ifTrue:[
upCorner := (width - 1) @ (height // 2).
downOrigin := 0 @ (height // 2 + 1).
downCorner := (width - 1) @ (height - 1)
] ifFalse:[
upCorner := (width // 2) @ (height - 1).
downOrigin := (width // 2 + 1) @ 0.
downCorner := (width - 1) @ (height - 1)
].
upButton origin:upOrigin.
upButton corner:upCorner.
downButton origin:downOrigin.
downButton corner:downCorner.
!
initializeButtonForms
|upLabel downLabel|
orientation == #vertical ifTrue:[
upLabel := ArrowButton UpArrowForm.
downLabel := ArrowButton DownArrowForm.
] ifFalse:[
upLabel := ArrowButton LeftArrowForm.
downLabel := ArrowButton RightArrowForm.
].
upButton label:upLabel.
downButton label:downLabel.
!
initializeButtons
upButton := ArrowButton upIn:self.
upButton autoRepeat:true.
downButton := ArrowButton downIn:self.
downButton autoRepeat:true.
self initializeButtonDimensions.
self initializeButtonForms
! !
!UpDownButton class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libwidg2/UpDownButton.st,v 1.11 1998-06-06 17:54:02 cg Exp $'
! !