home *** CD-ROM | disk | FTP | other *** search
/ European Smalltalk User Group 2004 September / esugcd.iso / Books-Tutorial-Lectures / Tutorials / vw-tutorials / AnApplikationAproach / Calculator.st next >
Text File  |  1995-10-20  |  5KB  |  215 lines

  1. 'From VisualWorks(R) Release 2.0 of 4 August 1994 on 16 October 1995 at 8:51:11 pm'!
  2.  
  3. Object subclass: #Calculator
  4.     instanceVariableNames: 'operand1 operand2 '
  5.     classVariableNames: ''
  6.     poolDictionaries: ''
  7.     category: 'UIApplications-New'!
  8. Calculator comment:
  9. 'This class implements a money calculator with amounts in dollars and cents.'!
  10.  
  11.  
  12. !Calculator methodsFor: 'actions'!
  13.  
  14. add
  15.     ^(operand1 + operand2)!
  16.  
  17. sub
  18.     ^(operand1 - operand2)! !
  19.  
  20. !Calculator methodsFor: 'accessing'!
  21.  
  22. operand1
  23.     ^operand1!
  24.  
  25. operand1: aValue
  26.     operand1 := aValue!
  27.  
  28. operand2
  29.     ^operand2!
  30.  
  31. operand2: aValue
  32.     operand2 := aValue! !
  33.  
  34. 'From VisualWorks(R) Release 2.0 of 4 August 1994 on 20 October 1995 at 6:52:56 pm'!
  35.  
  36. ApplicationModel subclass: #CalculatorInterface
  37.     instanceVariableNames: 'calculator value1 value2 result '
  38.     classVariableNames: ''
  39.     poolDictionaries: ''
  40.     category: 'UIApplications-New'!
  41.  
  42.  
  43. !CalculatorInterface methodsFor: 'initialize'!
  44.  
  45. initialize
  46.     calculator := Calculator new! !
  47.  
  48. !CalculatorInterface methodsFor: 'aspects'!
  49.  
  50. result
  51.     "This method was generated by UIDefiner.  Any edits made here
  52.     may be lost whenever methods are automatically defined.  The
  53.     initialization provided below may have been preempted by an
  54.     initialize method."
  55.  
  56.     ^result isNil
  57.         ifTrue:
  58.             [result := 0 asValue]
  59.         ifFalse:
  60.             [result]!
  61.  
  62. value1
  63.     "This method was generated by UIDefiner.  Any edits made here
  64.     may be lost whenever methods are automatically defined.  The
  65.     initialization provided below may have been preempted by an
  66.     initialize method."
  67.  
  68.     ^value1 isNil
  69.         ifTrue:
  70.             [value1 := 0 asValue]
  71.         ifFalse:
  72.             [value1]!
  73.  
  74. value2
  75.     "This method was generated by UIDefiner.  Any edits made here
  76.     may be lost whenever methods are automatically defined.  The
  77.     initialization provided below may have been preempted by an
  78.     initialize method."
  79.  
  80.     ^value2 isNil
  81.         ifTrue:
  82.             [value2 := 0 asValue]
  83.         ifFalse:
  84.             [value2]! !
  85.  
  86. !CalculatorInterface methodsFor: 'actions'!
  87.  
  88. add
  89.  
  90.     calculator operand1: value1 value.
  91.       calculator operand2: value2 value.
  92.       result value: calculator add!
  93.  
  94. clear
  95.  
  96.     |accepted|
  97.     accepted := self openDialogInterface: #dialogSpec.
  98.     accepted
  99.         ifTrue: [ value1 value: 0.
  100.                 value2 value: 0.
  101.                 result value: 0]!
  102.  
  103. sub
  104.  
  105.     calculator operand1: value1 value.
  106.       calculator operand2: value2 value.
  107.       result value: calculator sub! !
  108. "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
  109.  
  110. CalculatorInterface class
  111.     instanceVariableNames: ''!
  112.  
  113.  
  114. !CalculatorInterface class methodsFor: 'interface specs'!
  115.  
  116. dialogSpec
  117.     "UIPainter new openOnClass: self andSelector: #dialogSpec"
  118.  
  119.     <resource: #canvas>
  120.     ^#(#FullSpec 
  121.         #window: 
  122.         #(#WindowSpec 
  123.             #label: 'Dialog Window' 
  124.             #bounds: #(#Rectangle 620 233 820 352 ) 
  125.             #flags: 8 ) 
  126.         #component: 
  127.         #(#SpecCollection 
  128.             #collection: #(
  129.                 #(#ActionButtonSpec 
  130.                     #layout: #(#Rectangle 29 56 84 86 ) 
  131.                     #model: #cancel 
  132.                     #label: 'No' 
  133.                     #defaultable: true ) 
  134.                 #(#ActionButtonSpec 
  135.                     #layout: #(#Rectangle 115 56 170 86 ) 
  136.                     #model: #accept 
  137.                     #label: 'Yes' 
  138.                     #defaultable: true ) 
  139.                 #(#LabelSpec 
  140.                     #layout: #(#Point 12 22 ) 
  141.                     #label: 'Do you really want to Clear?' ) ) ) )!
  142.  
  143. windowSpec
  144.     "UIPainter new openOnClass: self andSelector: #windowSpec"
  145.  
  146.     <resource: #canvas>
  147.     ^#(#FullSpec 
  148.         #window: 
  149.         #(#WindowSpec 
  150.             #label: 'Money Calculator' 
  151.             #bounds: #(#Rectangle 744 474 1050 788 ) 
  152.             #flags: 4 
  153.             #menu: #menuBar ) 
  154.         #component: 
  155.         #(#SpecCollection 
  156.             #collection: #(
  157.                 #(#InputFieldSpec 
  158.                     #layout: #(#Rectangle 59 29 241 64 ) 
  159.                     #model: #value1 
  160.                     #alignment: #right 
  161.                     #type: #number 
  162.                     #formatString: '$#,##0.00;[Red]($#,##0.00)' ) 
  163.                 #(#InputFieldSpec 
  164.                     #layout: #(#Rectangle 60 80 240 115 ) 
  165.                     #model: #value2 
  166.                     #alignment: #right 
  167.                     #type: #number 
  168.                     #formatString: '$#,##0.00;[Red]($#,##0.00)' ) 
  169.                 #(#InputFieldSpec 
  170.                     #layout: #(#Rectangle 59 168 244 201 ) 
  171.                     #model: #result 
  172.                     #tabable: false 
  173.                     #menu: #menuBar 
  174.                     #alignment: #right 
  175.                     #isReadOnly: true 
  176.                     #type: #number 
  177.                     #formatString: '$#,##0.00;[Red]($#,##0.00)' ) 
  178.                 #(#DividerSpec 
  179.                     #layout: #(#Rectangle 71 135 231 139 ) ) 
  180.                 #(#ActionButtonSpec 
  181.                     #layout: #(#Rectangle 40 242 104 278 ) 
  182.                     #model: #add 
  183.                     #label: '+' 
  184.                     #defaultable: true ) 
  185.                 #(#ActionButtonSpec 
  186.                     #layout: #(#Rectangle 123 244 187 279 ) 
  187.                     #model: #sub 
  188.                     #label: '-' 
  189.                     #defaultable: true ) 
  190.                 #(#ActionButtonSpec 
  191.                     #layout: #(#Rectangle 204 245 267 280 ) 
  192.                     #model: #clear 
  193.                     #label: 'Clear' 
  194.                     #defaultable: true ) ) ) )! !
  195.  
  196. !CalculatorInterface class methodsFor: 'resources'!
  197.  
  198. menuBar
  199.     "UIMenuEditor new openOnClass: self andSelector: #menuBar"
  200.  
  201.     <resource: #menu>
  202.     ^#(#Menu #(
  203.             #(#MenuItem 
  204.                 #label: 'File' 
  205.                 #submenu: #(#Menu #(
  206.                         #(#MenuItem 
  207.                             #label: 'Exit' ) ) #(1 ) #(#closeRequest ) ) ) 
  208.             #(#MenuItem 
  209.                 #label: 'Action' 
  210.                 #submenu: #(#Menu #(
  211.                         #(#MenuItem 
  212.                             #label: 'Add' ) 
  213.                         #(#MenuItem 
  214.                             #label: 'Subtract' ) ) #(2 ) #(#add #sub ) ) ) ) #(2 ) #(nil nil ) ) decodeAsLiteralArray! !
  215.