home *** CD-ROM | disk | FTP | other *** search
/ European Smalltalk User Group 2004 September / esugcd.iso / Books-Tutorial-Lectures / Books / FreeBooks / GuzdialBookDrafts / clock-ui3.cs < prev    next >
Text File  |  2003-03-31  |  2KB  |  87 lines

  1.  
  2. 'From Squeak 2.2 of Sept 23, 1998 on 2 November 1998 at 3:06:55 pm'!
  3. Object subclass: #Clock
  4.     instanceVariableNames: 'time timer displayFormat '
  5.     classVariableNames: ''
  6.     poolDictionaries: ''
  7.     category: 'ClockWorks'!
  8. Object subclass: #ClockText
  9.     instanceVariableNames: 'model position query '
  10.     classVariableNames: ''
  11.     poolDictionaries: ''
  12.     category: 'ClockWorks'!
  13. Object subclass: #ClockWindow
  14.     instanceVariableNames: 'position buttons '
  15.     classVariableNames: ''
  16.     poolDictionaries: ''
  17.     category: 'ClockWorks'!
  18.  
  19.  
  20. !Clock methodsFor: 'time management'!
  21. nextSecond
  22.     time _ time addTime: (Time fromSeconds: 1).
  23.     self changed: #time.
  24.  
  25.  ! !
  26.  
  27. !ClockWindow methodsFor: 'window processing'!
  28. openOn: aModel
  29.     | button  |
  30.     position isNil ifTrue: [self error: 'Must set position first.'].
  31.  
  32.     "Open the blank frame"
  33.     (Form extent: 200@200) fillWhite displayAt: position.
  34.  
  35.     "Setup the textArea"
  36.     ClockText at: (position + (50@50)) on: aModel for: #display.
  37.  
  38.     "Draw the Buttons"
  39.     button := ClockButton make: 'Hours +' at: ((position x) @ ((position y)+100) extent: 100@50) for: aModel triggering: #addHour.
  40.     self addButton: button.
  41.     button := ClockButton make: 'Hours -' at: (((position x)+100) @ ((position y)+100) extent: 100@50) for: aModel triggering: #subtractHour.
  42.     self addButton: button.
  43.     button := ClockButton make: 'Minutes +' at: ((position x) @ ((position y)+150) extent: 100@50) for: aModel triggering: #addMinute.
  44.     self addButton: button.
  45.     button := ClockButton make: 'Minutes -' at: (((position x)+100) @ ((position y)+150) extent: 100@50) for: aModel triggering: #subtractMinute.
  46.     self addButton: button.
  47. ! !
  48.  
  49. !ClockText methodsFor: 'changeProcessing'!
  50. update: anEvent
  51.     anEvent = #time ifTrue: [
  52.     '           ' displayAt: position .  "Erase whatever time was there before"
  53.     (model perform: query) displayAt: position.]! !
  54.  
  55. !ClockText methodsFor: 'accessing'!
  56. query: aMessage
  57.     query _ aMessage.!
  58. position: aPoint
  59.     position _ aPoint.
  60. !
  61. position
  62.     ^position
  63. !
  64. query
  65.     ^query!
  66. model: aModel
  67.     model := aModel.
  68.     aModel addDependent: self.
  69.  
  70. !
  71. model
  72.     ^model
  73. ! !
  74.  
  75. !ClockText class methodsFor: 'creation'!
  76. at: aPosition on: aModel for: aQuery
  77.     | text |
  78.     text := self new.
  79.     text position: aPosition.
  80.     text model: aModel.
  81.     text query: aQuery.
  82.     ^text
  83. ! !
  84.  
  85.  
  86.  
  87.