home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LANGUAGE / SMALTALK / TEXTBOOK / AP01.ST (.txt) < prev    next >
Text File  |  1997-04-22  |  8KB  |  312 lines

  1.  
  2. 'Smalltalk Textbook Appendix 01'!
  3.  
  4.  
  5.  
  6.  
  7.  
  8. CompositePart subclass: #EngiTopView
  9.     instanceVariableNames: 'model label extent '
  10.     classVariableNames: ''
  11.     poolDictionaries: ''
  12.     category: 'Engi-Interface'!
  13. EngiTopView comment:
  14. '
  15.  
  16. Engi 0.01 (10 January 1994)
  17. Copyright (C) 1994 by Atsushi Aoki
  18.  
  19. '!
  20.  
  21.  
  22. !EngiTopView methodsFor: 'accessing'!
  23.  
  24. label
  25.     ^label!
  26.  
  27. label: aString 
  28.     label := aString.
  29.     self topComponent isNil ifFalse: [self topComponent label: aString]!
  30.  
  31. minimumSize
  32.     ^extent!
  33.  
  34. minimumSize: aPoint 
  35.     extent := aPoint.
  36.     self topComponent isNil ifFalse: [self topComponent minimumSize: aPoint]!
  37.  
  38. model
  39.     ^model!
  40.  
  41. model: aModel 
  42.     model := aModel.
  43.     self topComponent isNil ifFalse: [self topComponent model: aModel]! !
  44.  
  45. !EngiTopView methodsFor: 'scheduling'!
  46.  
  47. close
  48.     self topComponent isNil ifFalse: [self topComponent close]!
  49.  
  50. open
  51.     | topWindow |
  52.     topWindow := ScheduledWindow
  53.                 model: model
  54.                 label: label
  55.                 minimumSize: extent.
  56.     topWindow component: self.
  57.     topWindow open!
  58.  
  59. popUp
  60.     ^self
  61.         popUp: true
  62.         trueLabel: 'accept'
  63.         falseLabel: 'cancel'!
  64.  
  65. popUp: aBooleanOrNil label: labelString 
  66.     | topWindow compositePart aModel trueButton aRectangle |
  67.     topWindow := ScheduledWindow
  68.                 model: model
  69.                 label: label
  70.                 minimumSize: extent.
  71.     topWindow controller: EngiTopPreemptor new.
  72.     compositePart := CompositePart new.
  73.     aModel := ValueHolder new.
  74.     trueButton := Button trigger.
  75.     aBooleanOrNil = true ifTrue: [trueButton beDefault].
  76.     trueButton label: labelString.
  77.     trueButton model: ((PluggableAdaptor on: aModel)
  78.             getBlock: [:m | false]
  79.             putBlock: 
  80.                 [:m :v | 
  81.                 aModel value: true.
  82.                 self close]
  83.             updateBlock: [:m :a :v | false]).
  84.     compositePart add: self in: (self frameFraction: (0 @ 0 corner: 1 @ 1)
  85.             offset: (0 @ 0 corner: 0 @ -40)).
  86.     compositePart add: trueButton in: (self frameFraction: (0.5 @ 1 corner: 0.5 @ 1)
  87.             offset: (-40 @ -35 corner: 40 @ -5)).
  88.     topWindow component: compositePart.
  89.     aRectangle := Point zero extent: (topWindow minimumSize max: self defaultPopUpMinimumSize).
  90.     aRectangle := aRectangle align: aRectangle center with: InputState default mousePoint.
  91.     topWindow openDialogIn: aRectangle.
  92.     ^aModel value!
  93.  
  94. popUp: aBooleanOrNil trueLabel: trueString falseLabel: falseString 
  95.     | topWindow compositePart aModel trueButton falseButton aRectangle |
  96.     topWindow := ScheduledWindow
  97.                 model: model
  98.                 label: label
  99.                 minimumSize: extent.
  100.     topWindow controller: EngiTopPreemptor new.
  101.     compositePart := CompositePart new.
  102.     aModel := ValueHolder new.
  103.     trueButton := Button trigger.
  104.     aBooleanOrNil = true ifTrue: [trueButton beDefault].
  105.     trueButton label: trueString.
  106.     trueButton model: ((PluggableAdaptor on: aModel)
  107.             getBlock: [:m | false]
  108.             putBlock: 
  109.                 [:m :v | 
  110.                 aModel value: true.
  111.                 self close]
  112.             updateBlock: [:m :a :v | false]).
  113.     falseButton := Button trigger.
  114.     aBooleanOrNil = false ifTrue: [falseButton beDefault].
  115.     falseButton label: falseString.
  116.     falseButton model: ((PluggableAdaptor on: aModel)
  117.             getBlock: [:m | false]
  118.             putBlock: 
  119.                 [:m :v | 
  120.                 aModel value: false.
  121.                 self close]
  122.             updateBlock: [:m :a :v | false]).
  123.     compositePart add: self in: (self frameFraction: (0 @ 0 corner: 1 @ 1)
  124.             offset: (0 @ 0 corner: 0 @ -40)).
  125.     compositePart add: trueButton in: (self frameFraction: (0.3 @ 1 corner: 0.3 @ 1)
  126.             offset: (-40 @ -35 corner: 40 @ -5)).
  127.     compositePart add: falseButton in: (self frameFraction: (0.7 @ 1 corner: 0.7 @ 1)
  128.             offset: (-40 @ -35 corner: 40 @ -5)).
  129.     topWindow component: compositePart.
  130.     aRectangle := Point zero extent: (topWindow minimumSize max: self defaultPopUpMinimumSize).
  131.     aRectangle := aRectangle align: aRectangle center with: InputState default mousePoint.
  132.     topWindow openDialogIn: aRectangle.
  133.     ^aModel value!
  134.  
  135. popUpAcceptCancel: aBooleanOrNil 
  136.     ^self
  137.         popUp: aBooleanOrNil
  138.         trueLabel: 'accept'
  139.         falseLabel: 'cancel'!
  140.  
  141. popUpOkay: aBooleanOrNil 
  142.     ^self popUp: aBooleanOrNil label: 'okay'!
  143.  
  144. popUpYesNo: aBooleanOrNil 
  145.     ^self
  146.         popUp: aBooleanOrNil
  147.         trueLabel: 'yes'
  148.         falseLabel: 'no'! !
  149.  
  150. !EngiTopView methodsFor: 'framing'!
  151.  
  152. frameFraction: fractionRectangle 
  153.     ^self class frameFraction: fractionRectangle!
  154.  
  155. frameFraction: fractionRectangle offset: offsetRectangle 
  156.     ^self class frameFraction: fractionRectangle offset: offsetRectangle!
  157.  
  158. frameFractionOffset: offsetRectangle 
  159.     ^self class frameOffset: offsetRectangle! !
  160.  
  161. !EngiTopView methodsFor: 'defaults'!
  162.  
  163. defaultPopUpMinimumSize
  164.     ^250 @ 100! !
  165.  
  166. !EngiTopView methodsFor: 'private'!
  167.  
  168. model: aModel label: labelText minimumSize: minimumSize 
  169.     model := aModel.
  170.     label := labelText.
  171.     extent := minimumSize.
  172.     ^self! !
  173. "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
  174.  
  175. EngiTopView class
  176.     instanceVariableNames: ''!
  177.  
  178.  
  179. !EngiTopView class methodsFor: 'instance creation'!
  180.  
  181. model: aModel label: labelString minimumSize: minimumSize 
  182.     ^super new
  183.         model: aModel
  184.         label: labelString
  185.         minimumSize: minimumSize!
  186.  
  187. new
  188.     ^self
  189.         model: nil
  190.         label: nil
  191.         minimumSize: 100 @ 100! !
  192.  
  193. !EngiTopView class methodsFor: 'framing'!
  194.  
  195. frameFraction: fractionRectangle 
  196.     ^self frameFraction: fractionRectangle offset: (0 @ 0 corner: 0 @ 0)!
  197.  
  198. frameFraction: fractionRectangle offset: offsetRectangle 
  199.     ^LayoutFrame
  200.         leftFraction: fractionRectangle left
  201.         offset: offsetRectangle left
  202.         rightFraction: fractionRectangle right
  203.         offset: offsetRectangle right
  204.         topFraction: fractionRectangle top
  205.         offset: offsetRectangle top
  206.         bottomFraction: fractionRectangle bottom
  207.         offset: offsetRectangle bottom!
  208.  
  209. frameOffset: offsetRectangle 
  210.     ^self frameFraction: (0 @ 0 corner: 0 @ 0)
  211.         offset: offsetRectangle! !
  212.  
  213. !EngiTopView class methodsFor: 'examples'!
  214.  
  215. example1
  216.     "EngiTopView example1."
  217.  
  218.     | topView edgeDecorator1 edgeDecorator2 |
  219.     topView := EngiTopView
  220.                 model: nil
  221.                 label: 'TopView'
  222.                 minimumSize: 250 @ 250.
  223.     edgeDecorator1 := LookPreferences edgeDecorator on: View new.
  224.     edgeDecorator1 noMenuBar.
  225.     edgeDecorator1 noVerticalScrollBar.
  226.     edgeDecorator1 noHorizontalScrollBar.
  227.     edgeDecorator2 := LookPreferences edgeDecorator on: View new.
  228.     edgeDecorator2 noMenuBar.
  229.     edgeDecorator2 noVerticalScrollBar.
  230.     edgeDecorator2 noHorizontalScrollBar.
  231.     topView add: edgeDecorator1 in: (0 @ 0 corner: 1 @ 0.5).
  232.     topView add: edgeDecorator2 in: (0 @ 0.5 corner: 1 @ 1).
  233.     topView open!
  234.  
  235. example2
  236.     "EngiTopView example2."
  237.  
  238.     | topView edgeDecorator1 edgeDecorator2 aBoolan |
  239.     topView := EngiTopView new.
  240.     topView minimumSize: 250 @ 290.
  241.     edgeDecorator1 := LookPreferences edgeDecorator on: View new.
  242.     edgeDecorator1 noMenuBar.
  243.     edgeDecorator1 noVerticalScrollBar.
  244.     edgeDecorator1 noHorizontalScrollBar.
  245.     edgeDecorator2 := LookPreferences edgeDecorator on: View new.
  246.     edgeDecorator2 noMenuBar.
  247.     edgeDecorator2 noVerticalScrollBar.
  248.     edgeDecorator2 noHorizontalScrollBar.
  249.     topView add: edgeDecorator1 in: (0 @ 0 corner: 1 @ 0.5).
  250.     topView add: edgeDecorator2 in: (0 @ 0.5 corner: 1 @ 1).
  251.     aBoolan := topView popUp.
  252.     ^aBoolan!
  253.  
  254. example3
  255.     "EngiTopView example3."
  256.  
  257.     EngiTopView new popUpAcceptCancel: true.
  258.     EngiTopView new popUpAcceptCancel: nil.
  259.     EngiTopView new popUpAcceptCancel: false.
  260.     EngiTopView new popUpYesNo: true.
  261.     EngiTopView new popUpYesNo: nil.
  262.     EngiTopView new popUpYesNo: false.
  263.     EngiTopView new
  264.         popUp: true
  265.         trueLabel: 'agree'
  266.         falseLabel: 'retract'.
  267.     EngiTopView new popUpOkay: true.
  268.     EngiTopView new popUpOkay: nil.
  269.     EngiTopView new popUp: true label: 'I see'! !
  270.  
  271.  
  272.  
  273.  
  274.  
  275. StandardSystemController subclass: #EngiTopPreemptor
  276.     instanceVariableNames: ''
  277.     classVariableNames: ''
  278.     poolDictionaries: ''
  279.     category: 'Engi-Interface'!
  280. EngiTopPreemptor comment:
  281. '
  282.  
  283. Engi 0.01 (10 January 1994)
  284. Copyright (C) 1994 by Atsushi Aoki
  285.  
  286. '!
  287.  
  288.  
  289. !EngiTopPreemptor methodsFor: 'accessing'!
  290.  
  291. restartAfterError
  292.     self locked: false!
  293.  
  294. shutdownBecauseOfError
  295.     self locked: true! !
  296.  
  297. !EngiTopPreemptor methodsFor: 'control defaults'!
  298.  
  299. controlActivity
  300.     ^self controlToNextLevel!
  301.  
  302. controlInitialize
  303.     self locked: false.
  304.     super controlInitialize!
  305.  
  306. controlTerminate
  307.     self locked: true.
  308.     super controlTerminate!
  309.  
  310. isControlActive
  311.     ^true! !
  312.