ApplicationModel subclass: #Checkbookinterface instanceVariableNames: 'checkbook depositAmount balanceAmount checksList checkHolder ' classVariableNames: '' poolDictionaries: '' category: 'Examples-VWTutorial'! !Checkbookinterface methodsFor: 'initialize-release'! initialize "Create a new checkbook for the interface to manipulate." checkbook := Checkbook new! ! !Checkbookinterface methodsFor: 'aspects'! balanceAmount "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." ^balanceAmount isNil ifTrue: [balanceAmount := (AspectAdaptor subject: checkbook sendsUpdates: true) forAspect: #balance] ifFalse: [balanceAmount]! checkHolder "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." ^checkHolder isNil ifTrue: [checkHolder := nil asValue] ifFalse: [checkHolder]! checksList "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." ^checksList isNil ifTrue: [checksList := SelectionInList with: checkbook register] ifFalse: [checksList]! depositAmount "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." ^depositAmount isNil ifTrue: [depositAmount := 0 asValue] ifFalse: [depositAmount]! ! !Checkbookinterface methodsFor: 'actions'! cancelSelectedCheck self checksList selection isNil ifTrue: [^Dialog warn: 'select a check to cancel.' ]. checkbook cancelCheck: self checksList selection. self checksList list: checkbook register! makeDeposit self depositAmount value>0 ifFalse:[^Dialog warn: 'Enter a positive number']. checkbook deposit: self depositAmount value. self depositAmount value: 0! WriteNewCheck |userHasAccepted| self checkHolder value: checkbook makeNewCheck. userHasAccepted := self openDialogInterface: #dialogSpec. userHasAccepted ifTrue: [ checkbook recordCheck: self checkHolder value. self checksList list: checkbook register]! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! Checkbookinterface class instanceVariableNames: ''! !Checkbookinterface class methodsFor: 'interface specs'! dialogSpec "UIPainter new openOnClass: self andSelector: #dialogSpec" ^#(#FullSpec #window: #(#WindowSpec #label: 'Check' #bounds: #(#Rectangle 125 325 690 538 ) ) #component: #(#SpecCollection #collection: #( #(#InputFieldSpec #layout: #(#Rectangle 79 88 389 105 ) #flags: 0 #model: #'checkHolder payee' ) #(#LabelSpec #layout: #(#Point 19 75 ) #label: 'Pay to the' #style: #small ) #(#LabelSpec #layout: #(#Point 30 91 ) #label: 'order of' #style: #small ) #(#InputFieldSpec #layout: #(#Rectangle 157 160 257 181 ) #flags: 0 #model: #'checkHolder number' #isReadOnly: true #type: #number #formatString: '0' ) #(#LabelSpec #layout: #(#Point 68 162 ) #label: 'Check number:' ) #(#DividerSpec #layout: #(#Rectangle 84 109 394 113 ) ) #(#DividerSpec #layout: #(#Rectangle 393 85 493 108 ) #orientation: #vertical ) #(#InputFieldSpec #layout: #(#Rectangle 420 84 524 111 ) #model: #'checkHolder amount' #alignment: #right #type: #number #formatString: '$#,##0.00;[Red]($#,##0.00)' ) #(#ActionButtonSpec #layout: #(#Rectangle 462 164 521 196 ) #model: #accept #label: 'OK' #isDefault: true #defaultable: true ) #(#ActionButtonSpec #layout: #(#Rectangle 383 165 447 198 ) #model: #cancel #label: 'Cancel' #defaultable: true ) #(#InputFieldSpec #layout: #(#Rectangle 425 18 524 39 ) #flags: 0 #model: #'checkHolder date' #type: #date #formatString: 'm/d/yy' ) #(#DividerSpec #layout: #(#Rectangle 421 45 522 49 ) ) ) ) )! windowSpec "UIPainter new openOnClass: self andSelector: #windowSpec" ^#(#FullSpec #window: #(#WindowSpec #label: 'CheckBook' #bounds: #(#Rectangle 279 348 831 700 ) #flags: 4 #menu: #menuBar #colors: #(#LookPreferences #setForegroundColor: #(#ColorValue 805 805 6420 ) #setBackgroundColor: #(#ColorValue 1292 5165 5165 ) #setSelectionForegroundColor: #(#ColorValue #black ) #setSelectionBackgroundColor: #(#ColorValue 4915 4915 4915 ) #setBorderColor: #(#ColorValue #black ) ) #isEventDriven: true ) #component: #(#SpecCollection #collection: #( #(#LabelSpec #layout: #(#LayoutOrigin 0 0.378623 0 0.0679012 ) #colors: #(#LookPreferences #setForegroundColor: #(#ColorValue #red ) ) #label: 'Check Register' ) #(#SequenceViewSpec #layout: #(#LayoutFrame 0 0.148551 0 0.160494 0 0.833333 0 0.567901 ) #colors: #(#LookPreferences #setBackgroundColor: #(#ColorValue 7700 7700 7700 ) ) #model: #checksList #useModifierKeys: true #selectionType: #highlight ) #(#GroupBoxSpec #layout: #(#LayoutFrame 0 0.0235507 0 0.703704 0 0.532609 0 0.947531 ) #colors: #(#LookPreferences #setForegroundColor: #(#ColorValue 8191 1024 8191 ) #setBackgroundColor: #(#ColorValue 8191 1024 8191 ) ) ) #(#ActionButtonSpec #layout: #(#LayoutFrame 0 0.335145 0 0.814815 0 0.456522 0 0.910494 ) #colors: #(#LookPreferences #setBackgroundColor: #(#ColorValue #red ) ) #model: #makeDeposit #label: 'Deposit' #isDefault: true #defaultable: true ) #(#LabelSpec #layout: #(#LayoutOrigin 0 0.0815217 0 0.740741 ) #colors: #(#LookPreferences #setForegroundColor: #(#ColorValue #red ) ) #label: 'Amount of Deposit' ) #(#InputFieldSpec #layout: #(#LayoutFrame 0 0.311594 0 0.737654 0 0.472826 0 0.799383 ) #colors: #(#LookPreferences #setForegroundColor: #(#ColorValue 3321 416 416 ) #setBackgroundColor: #(#ColorValue #white ) ) #model: #depositAmount #alignment: #right #type: #number #formatString: '$#,##0.00;[Red]($#,##0.00)' ) #(#LabelSpec #layout: #(#LayoutOrigin 0 0.668478 0 0.703704 ) #colors: #(#LookPreferences #setForegroundColor: #(#ColorValue #red ) ) #label: 'Balance' ) #(#InputFieldSpec #layout: #(#LayoutFrame 0 0.764493 0 0.709877 0 0.945652 0 0.777778 ) #colors: #(#LookPreferences #setForegroundColor: #(#ColorValue 3321 416 416 ) #setBackgroundColor: #(#ColorValue #white ) ) #model: #balanceAmount #alignment: #right #isReadOnly: true #type: #number #formatString: '$#,##0.00;[Red]-$#,##0.00' ) ) ) )! ! !Checkbookinterface class methodsFor: 'resources'! menuBar "UIMenuEditor new openOnClass: self andSelector: #menuBar" ^#(#Menu #( #(#MenuItem #rawLabel: 'File' #submenu: #(#Menu #( #(#MenuItem #rawLabel: 'Close' #value: #closeRequest ) ) #(1 ) nil ) ) #(#MenuItem #rawLabel: 'Check' #submenu: #(#Menu #( #(#MenuItem #rawLabel: 'Write' #value: #WriteNewCheck ) #(#MenuItem #rawLabel: 'Cancel' #value: #cancelSelectedCheck ) ) #(2 ) nil ) ) ) #(2 ) nil ) decodeAsLiteralArray! ! Object subclass: #Check instanceVariableNames: 'number amount date payee ' classVariableNames: '' poolDictionaries: '' category: 'Examples-VWTutorial'! Check comment: 'The Check class is a container for the information that makes up a check. It has messages for accessing this information and for printing it on a stream. Instance Variables: numberSequence number of check in checkbook amountAmount of money for which the check is written dateDate on which the check is written payeeName of party receiving the check '! !Check methodsFor: 'accessing'! amount ^amount! amount: aValue amount := aValue! date ^date! date: aValue date := aValue! number ^number! number: aValue number := aValue! payee ^payee! payee: aValue payee := aValue! ! !Check methodsFor: 'printing'! printOn: aStream "Print a description of this check on the provided stream. Format of a sample description: #1, 4 August 1994: $40 to FRed " aStream nextPutAll: '#',number printString,',', date printString,': $',amount printString,' to ',payee displayString! ! Model subclass: #Checkbook instanceVariableNames: 'balance register nextCheckNumber ' classVariableNames: 'ClassVarName1 ClassVarName2 ' poolDictionaries: '' category: 'Examples-VWTutorial'! Checkbook comment: 'Instance fo the calss Checkbook contain a register of written checks and a balance; they also assign sequence numbers to the checks listed in the register `. The Checkbook class provides methods for creating and initializing new instances, accessing the information in them, and performing checkbook transactions such as making deposits and writing and cancelling checks. Instance Variables: balanceThe current baalance of the checking account. registerThe list of issued checks. nextChecknumberThe sequence number of the next check.'! !Checkbook methodsFor: 'Initialize-release'! initialize "set up the checkbook with an empty register and a balance of $0" register := OrderedCollection new. balance := 0. nextCheckNumber := 1! ! !Checkbook methodsFor: 'accessing'! balance ^balance! balance: anAmount "Set the balance to the specified amount, and notify dependents of the change." balance := anAmount. self changed: #balance! register ^register! ! !Checkbook methodsFor: 'transactions'! cancelCheck: aCheck "Remove the check from the register." self register remove: aCheck. "Update the balance." self balance: self balance + aCheck amount! deposit: anAmount "Deposit the specified amount and update the balance accordingly" self balance: self balance + anAmount! makeNewCheck "Create and initialize a new, blank check" |newCheck| newCheck := Check new. newCheck number: nextCheckNumber. newCheck date: Date today. newCheck amount: 0. newCheck payee: ' '. ^newCheck! recordCheck: aCheck "Add the check to the register." self register add: aCheck. "Update the balance to reflect the newly recorded check." self balance: self balance-aCheck amount. "Increment the sequence number." nextCheckNumber := nextCheckNumber+1! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! Checkbook class instanceVariableNames: ''! !Checkbook class methodsFor: 'instance creation'! new ^super new initialize! !