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 >
Wrap
Text File
|
1995-10-20
|
5KB
|
215 lines
'From VisualWorks(R) Release 2.0 of 4 August 1994 on 16 October 1995 at 8:51:11 pm'!
Object subclass: #Calculator
instanceVariableNames: 'operand1 operand2 '
classVariableNames: ''
poolDictionaries: ''
category: 'UIApplications-New'!
Calculator comment:
'This class implements a money calculator with amounts in dollars and cents.'!
!Calculator methodsFor: 'actions'!
add
^(operand1 + operand2)!
sub
^(operand1 - operand2)! !
!Calculator methodsFor: 'accessing'!
operand1
^operand1!
operand1: aValue
operand1 := aValue!
operand2
^operand2!
operand2: aValue
operand2 := aValue! !
'From VisualWorks(R) Release 2.0 of 4 August 1994 on 20 October 1995 at 6:52:56 pm'!
ApplicationModel subclass: #CalculatorInterface
instanceVariableNames: 'calculator value1 value2 result '
classVariableNames: ''
poolDictionaries: ''
category: 'UIApplications-New'!
!CalculatorInterface methodsFor: 'initialize'!
initialize
calculator := Calculator new! !
!CalculatorInterface methodsFor: 'aspects'!
result
"This method was generated by UIDefiner. Any edits made here
may be lost whenever methods are automatically defined. The
initialization provided below may have been preempted by an
initialize method."
^result isNil
ifTrue:
[result := 0 asValue]
ifFalse:
[result]!
value1
"This method was generated by UIDefiner. Any edits made here
may be lost whenever methods are automatically defined. The
initialization provided below may have been preempted by an
initialize method."
^value1 isNil
ifTrue:
[value1 := 0 asValue]
ifFalse:
[value1]!
value2
"This method was generated by UIDefiner. Any edits made here
may be lost whenever methods are automatically defined. The
initialization provided below may have been preempted by an
initialize method."
^value2 isNil
ifTrue:
[value2 := 0 asValue]
ifFalse:
[value2]! !
!CalculatorInterface methodsFor: 'actions'!
add
calculator operand1: value1 value.
calculator operand2: value2 value.
result value: calculator add!
clear
|accepted|
accepted := self openDialogInterface: #dialogSpec.
accepted
ifTrue: [ value1 value: 0.
value2 value: 0.
result value: 0]!
sub
calculator operand1: value1 value.
calculator operand2: value2 value.
result value: calculator sub! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
CalculatorInterface class
instanceVariableNames: ''!
!CalculatorInterface class methodsFor: 'interface specs'!
dialogSpec
"UIPainter new openOnClass: self andSelector: #dialogSpec"
<resource: #canvas>
^#(#FullSpec
#window:
#(#WindowSpec
#label: 'Dialog Window'
#bounds: #(#Rectangle 620 233 820 352 )
#flags: 8 )
#component:
#(#SpecCollection
#collection: #(
#(#ActionButtonSpec
#layout: #(#Rectangle 29 56 84 86 )
#model: #cancel
#label: 'No'
#defaultable: true )
#(#ActionButtonSpec
#layout: #(#Rectangle 115 56 170 86 )
#model: #accept
#label: 'Yes'
#defaultable: true )
#(#LabelSpec
#layout: #(#Point 12 22 )
#label: 'Do you really want to Clear?' ) ) ) )!
windowSpec
"UIPainter new openOnClass: self andSelector: #windowSpec"
<resource: #canvas>
^#(#FullSpec
#window:
#(#WindowSpec
#label: 'Money Calculator'
#bounds: #(#Rectangle 744 474 1050 788 )
#flags: 4
#menu: #menuBar )
#component:
#(#SpecCollection
#collection: #(
#(#InputFieldSpec
#layout: #(#Rectangle 59 29 241 64 )
#model: #value1
#alignment: #right
#type: #number
#formatString: '$#,##0.00;[Red]($#,##0.00)' )
#(#InputFieldSpec
#layout: #(#Rectangle 60 80 240 115 )
#model: #value2
#alignment: #right
#type: #number
#formatString: '$#,##0.00;[Red]($#,##0.00)' )
#(#InputFieldSpec
#layout: #(#Rectangle 59 168 244 201 )
#model: #result
#tabable: false
#menu: #menuBar
#alignment: #right
#isReadOnly: true
#type: #number
#formatString: '$#,##0.00;[Red]($#,##0.00)' )
#(#DividerSpec
#layout: #(#Rectangle 71 135 231 139 ) )
#(#ActionButtonSpec
#layout: #(#Rectangle 40 242 104 278 )
#model: #add
#label: '+'
#defaultable: true )
#(#ActionButtonSpec
#layout: #(#Rectangle 123 244 187 279 )
#model: #sub
#label: '-'
#defaultable: true )
#(#ActionButtonSpec
#layout: #(#Rectangle 204 245 267 280 )
#model: #clear
#label: 'Clear'
#defaultable: true ) ) ) )! !
!CalculatorInterface class methodsFor: 'resources'!
menuBar
"UIMenuEditor new openOnClass: self andSelector: #menuBar"
<resource: #menu>
^#(#Menu #(
#(#MenuItem
#label: 'File'
#submenu: #(#Menu #(
#(#MenuItem
#label: 'Exit' ) ) #(1 ) #(#closeRequest ) ) )
#(#MenuItem
#label: 'Action'
#submenu: #(#Menu #(
#(#MenuItem
#label: 'Add' )
#(#MenuItem
#label: 'Subtract' ) ) #(2 ) #(#add #sub ) ) ) ) #(2 ) #(nil nil ) ) decodeAsLiteralArray! !