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

  1.  
  2. 'From Squeak2.6 of 11 October 1999 [latest update: #1559] on 21 October 1999 at 3:48:21 pm'!
  3.  
  4. !Clock methodsFor: 'time management' stamp: 'mjg 10/21/1999 14:20'!
  5. nextSecond
  6.     time _ time addTime: (Time fromSeconds: 1).
  7.     self changed: #display.
  8. ! !
  9.  
  10.  
  11. !ClockWindow methodsFor: 'window processing' stamp: 'mjg 10/21/1999 14:20'!
  12. openAsMorph
  13.     | win component clock |
  14.     
  15.     "Create the clock"
  16.     clock := Clock new.
  17.     clock setTime: (Time now printString).
  18.     clock start.
  19.  
  20.     "Create a window for it"
  21.     win := SystemWindow labelled: 'Clock'.
  22.     win model: self.
  23.  
  24.     "Set up the text view and the various pieces"
  25.     component := PluggableTextMorph on: clock text: #display accept: nil.
  26.     win addMorph: component frame: (0.3@0.3 extent: 0.3@0.3).
  27.  
  28.     component := PluggableButtonMorph new
  29.         model: clock;
  30.         action: #addHour;
  31.         label: 'Hours +';
  32.         borderWidth: 1.
  33.     win addMorph: component frame: (0@0.6 extent: 0.5@0.2).
  34.     component := PluggableButtonMorph new
  35.         model: clock;
  36.         action: #subtractHour;
  37.         label: 'Hours -';
  38.         borderWidth: 1.
  39.     win addMorph: component frame: (0.5@0.6 extent: 0.5@0.2).
  40.     component := PluggableButtonMorph new
  41.         model: clock;
  42.         action: #addMinute;
  43.         label: 'Minutes +';
  44.         borderWidth: 1.
  45.     win addMorph: component frame: (0@0.8 extent: 0.5@0.1).
  46.     component := PluggableButtonMorph new
  47.         model: clock;
  48.         action: #subtractMinute;
  49.         label: 'Minutes -';
  50.         borderWidth: 1.
  51.     win addMorph: component frame: (0.5@0.8 extent: 0.5@0.1).
  52.  
  53.     component := PluggableButtonMorph new
  54.         model: clock;
  55.         action: #stop;
  56.         label: 'STOP';
  57.         borderWidth: 1.
  58.     win addMorph: component frame: (0@0.9 extent: 1@0.1).
  59.     
  60.     win openInWorld.
  61.     ^win! !
  62.  
  63. !ClockWindow methodsFor: 'window processing' stamp: 'mjg 10/21/1999 15:26'!
  64. openAsMorph2
  65.     | win component filler clock |
  66.     
  67.     "Create the clock"
  68.     clock := Clock new.
  69.     clock setTime: (Time now printString).
  70.     clock start.
  71.  
  72.     "Create a window for it"
  73.     win := SystemWindow labelled: 'Clock'.
  74.     win model: self.
  75.  
  76.     "Set up the text view and the various pieces"
  77.     filler := AlignmentMorph newRow.
  78.     filler centering: #center.
  79.     win addMorph: filler frame: (0@0 extent: 1.0@0.6).
  80.     component := PluggableTextMorph on: clock text: #display accept: nil.
  81.     filler addMorph: component.
  82.  
  83.     component := PluggableButtonMorph new
  84.         model: clock;
  85.         action: #addHour;
  86.         label: 'Hours +';
  87.         borderWidth: 1.
  88.     win addMorph: component frame: (0@0.6 extent: 0.5@0.2).
  89.     component := PluggableButtonMorph new
  90.         model: clock;
  91.         action: #subtractHour;
  92.         label: 'Hours -';
  93.         borderWidth: 1.
  94.     win addMorph: component frame: (0.5@0.6 extent: 0.5@0.2).
  95.     component := PluggableButtonMorph new
  96.         model: clock;
  97.         action: #addMinute;
  98.         label: 'Minutes +';
  99.         borderWidth: 1.
  100.     win addMorph: component frame: (0@0.8 extent: 0.5@0.1).
  101.     component := PluggableButtonMorph new
  102.         model: clock;
  103.         action: #subtractMinute;
  104.         label: 'Minutes -';
  105.         borderWidth: 1.
  106.     win addMorph: component frame: (0.5@0.8 extent: 0.5@0.1).
  107.  
  108.     component := PluggableButtonMorph new
  109.         model: clock;
  110.         action: #stop;
  111.         label: 'STOP';
  112.         borderWidth: 1.
  113.     win addMorph: component frame: (0@0.9 extent: 1@0.1).
  114.     
  115.     win openInWorld.
  116.     ^win! !
  117.  
  118. !ClockWindow methodsFor: 'window processing' stamp: 'mjg 10/21/1999 14:59'!
  119. openInMVC
  120.     | win component clock textArea hoursPlusButton minutesPlusButton|
  121.     
  122.     "Create the clock"
  123.     clock := Clock new.
  124.     clock setTime: (Time now printString).
  125.     clock start.
  126.  
  127.     "Create a window for it"
  128.     win := (StandardSystemView new) model: self.
  129.     win borderWidth: 1.
  130.  
  131.     "Set up the text view and the various pieces"
  132.     textArea := PluggableTextView on: clock text: #display accept: nil.
  133.     textArea window: (0@0 extent: 100@100).
  134.     win addSubView: textArea.
  135.  
  136.     hoursPlusButton := PluggableButtonView new
  137.         model: clock;
  138.         action: #addHour;
  139.         label: 'Hours +';
  140.         borderWidth: 1.
  141.     hoursPlusButton window: (0@100 extent: 100@50).
  142.     win addSubView: hoursPlusButton below: textArea.
  143.     component := PluggableButtonView new
  144.         model: clock;
  145.         action: #subtractHour;
  146.         label: 'Hours -';
  147.         borderWidth: 1.
  148.     component window: (100@100 extent: 100@50).
  149.     win addSubView: component toRightOf: hoursPlusButton.
  150.     minutesPlusButton := PluggableButtonView new
  151.         model: clock;
  152.         action: #addMinute;
  153.         label: 'Minutes +';
  154.         borderWidth: 1.
  155.     minutesPlusButton window: (0@150 extent: 100@50).
  156.     win addSubView: minutesPlusButton below: hoursPlusButton.
  157.     component := PluggableButtonView new
  158.         model: clock;
  159.         action: #subtractMinute;
  160.         label: 'Minutes -';
  161.         borderWidth: 1.
  162.     component window: (100@150 extent: 100@50).
  163.     win addSubView: component toRightOf: minutesPlusButton.
  164.  
  165.     component := PluggableButtonView new
  166.         model: clock;
  167.         action: #stop;
  168.         label: 'STOP';
  169.         borderWidth: 1.
  170.     component window: (0@200 extent: 200@100).
  171.     win addSubView: component below: minutesPlusButton.
  172.     
  173.     win label: 'Clock'.
  174.     win minimumSize: 300 @ 300.
  175.     win controller open! !
  176.  
  177.  
  178.  
  179.