home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
European Smalltalk User Group 2004 September
/
esugcd.iso
/
Books-Tutorial-Lectures
/
Books
/
FreeBooks
/
GuzdialBookDrafts
/
clock-ui2.cs
< prev
next >
Wrap
Text File
|
2003-03-31
|
4KB
|
142 lines
'From Squeak 2.2 of Sept 23, 1998 on 2 November 1998 at 2:47:18 pm'!
Object subclass: #Clock
instanceVariableNames: 'time timer window displayFormat '
classVariableNames: ''
poolDictionaries: ''
category: 'ClockWorks'!
Object subclass: #ClockButton
instanceVariableNames: 'model frame action name '
classVariableNames: ''
poolDictionaries: ''
category: 'ClockWorks'!
Object subclass: #ClockWindow
instanceVariableNames: 'position clock buttons '
classVariableNames: ''
poolDictionaries: ''
category: 'ClockWorks'!
!Clock methodsFor: 'accessing'!
window
^window!
window: aWindow
window := aWindow.
! !
!Clock methodsFor: 'time management'!
nextSecond
time _ time addTime: (Time fromSeconds: 1).
window timeDisplay.
! !
!ClockButton methodsFor: 'accessing'!
name
^name!
action
^action!
model: aModel
model _ aModel.
!
action: aMessage
action _ aMessage
!
frame: aRect
frame _ aRect!
model
^model!
frame
^frame!
name: aString
name _ aString
! !
!ClockButton methodsFor: 'processing'!
draw
| pen |
pen := Pen new.
pen color: (Color black).
pen up. pen goto: (frame origin).
pen north. pen turn: 90. pen down.
pen goto: (frame topRight).
pen turn: 90. pen goto: (frame bottomRight).
pen turn: 90. pen goto: (frame bottomLeft).
pen turn: 90. pen goto: (frame origin).
name displayAt: (frame leftCenter) + (25@-10). "Offset in a bit, and up a bit for aesthetics"
!
inControl: aPoint
^frame containsPoint: aPoint!
process
model perform: action
! !
!ClockButton class methodsFor: 'creation'!
make: aName at: aRect for: aModel triggering: aMessage
| newButton |
newButton _ self new.
newButton name: aName.
newButton frame: aRect.
newButton model: aModel.
newButton action: aMessage.
newButton draw.
^newButton.
! !
!ClockWindow methodsFor: 'accessing'!
position: aPoint
position := aPoint.!
addButton: aButton
buttons isNil ifTrue: [buttons := OrderedCollection new].
buttons add: aButton.
!
clock
^clock!
position
^position!
buttons
^buttons
!
clock: aClock
clock := aClock.
! !
!ClockWindow methodsFor: 'window processing'!
timeDisplay
' ' displayAt: position + (50@50). "Erase whatever time was there before"
(clock display) displayAt: position + (50 @ 50).!
openOn: aModel
| button |
position isNil ifTrue: [self error: 'Must set position first.'].
"Set this model as this window's clock"
clock := aModel.
"Open the blank frame"
(Form extent: 200@200) fillWhite displayAt: position.
"Draw the Buttons"
button := ClockButton make: 'Hours +' at: ((position x) @ ((position y)+100) extent: 100@50) for: aModel triggering: #addHour.
self addButton: button.
button := ClockButton make: 'Hours -' at: (((position x)+100) @ ((position y)+100) extent: 100@50) for: aModel triggering: #subtractHour.
self addButton: button.
button := ClockButton make: 'Minutes +' at: ((position x) @ ((position y)+150) extent: 100@50) for: aModel triggering: #addMinute.
self addButton: button.
button := ClockButton make: 'Minutes -' at: (((position x)+100) @ ((position y)+150) extent: 100@50) for: aModel triggering: #subtractMinute.
self addButton: button.
!
processEvents
"Enter into an event loop"
| click |
[Sensor yellowButtonPressed] whileFalse: "Yellow button press ends the clock"
["Give other processes a chance, and give user a chance to pick up."
(Delay forMilliseconds: 500) wait.
(Sensor redButtonPressed) ifTrue: "Red button press could go to a button"
[click _ Sensor mousePoint.
buttons do: [:b |
(b inControl: click) ifTrue: [b process]].]].
! !