Category : Files from Magazines
Archive   : DDJ0790.ZIP
Filename : GOLDBERG.LST

 
Output of file : GOLDBERG.LST contained in archive : DDJ0790.ZIP
_INFORMATION MODELS, VIEWS, AND CONTROLLERS_
by Adele Goldberg




[LISTING ONE]


View subclass: #BarView
instanceVariableNames: 'maximumValue '
classVariableNames: ''
poolDictionaries: ''
category: 'Demo-Counter'!

!BarView methodsFor: 'accessing'!

barFrame
^self insetDisplayBox insetBy: (50 @ 10 corner: 10 @ 10)!
labelCount
^5!
maximumValue
^maximumValue!
maximumValue: anInteger
maximumValue _ anInteger!
positionFor: value
^self barFrame height * value / self maximumValue! !
!BarView methodsFor: 'displaying'!
clearBar
| height bar corner |

corner _ self barFrame bottomLeft.
height _ self positionFor: self model value + 1.
height _ height min: (self insetDisplayBox height-10).
bar _ corner - (0 @ height) extent: self barFrame width @ height.
Display white: bar.!
displayBar
| height bar corner |
corner _ self barFrame bottomLeft.
height _ self positionFor: self model value.
height _ height min: (self insetDisplayBox height-10).
bar _ corner - (0 @ height) extent: self barFrame width @ height.
Display black: bar.
Display fill: (bar insetBy: 2 @ 2)
mask: Form darkGray.!
displayView
self displayYLabels.
self displayBar!
displayYLabels
| count label increment |
count _ self labelCount.
increment _ self maximumValue / count.
label _ 0.
(count+1) timesRepeat:
[label printString displayAt: (self barFrame bottomLeft -
(35 @ ((self positionFor: label)+8))).
label _ label + increment]!
update: aParameter
self clearBar.
self displayBar.! !
!BarView methodsFor: 'controller access'!

defaultControllerClass
"Answer the class of a typically useful controller."

^CounterController! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

BarView class
instanceVariableNames: ''!

!BarView class methodsFor: 'instance creation'!

newWithHeight: aNumber
"Create a new BarView for displaying value between 0 and aNumber"
^super new maximumValue: aNumber!

open: aModel

"Open a view for a new counter."
"BarView open: Counter new."

| aBarView topView |

aBarView _ (BarView newWithHeight: 10) model: aModel.
aBarView borderWidth: 2.
aBarView insideColor: Form white.

topView _ StandardSystemView new label: 'Counter'.
topView minimumSize: 80@40.
topView addSubView: aBarView.

topView controller open!

open: aModel withHeight: anInteger
"Open a view for a new counter."

"BarView open: Counter new withHeight: 20."

| aBarView topView |

aBarView _ (BarView newWithHeight: anInteger) model: aModel.
aBarView borderWidth: 2.
aBarView insideColor: Form white.

topView _ StandardSystemView new label: 'Counter'.
topView minimumSize: 80@40.
topView addSubView: aBarView.

topView controller open! !

View subclass: #CounterView
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Demo-Counter'!

!CounterView methodsFor: 'displaying'!
displayView
"Display the value of the model."

| box pos |


"Position the text at the left side of the display area."
box _ self insetDisplayBox. "get the view's box"
pos _ box origin + (4 @ (box extent y / 3)).
"put the text 1/3 of the way down to the left"
"Concatenate the components of the output string and display them."
('val: ', self model value asInteger printString, ' ')
asDisplayText displayAt: pos.! !
!CounterView methodsFor: 'updating'!
update: aParameter
"Simply redisplay everything."
self display! !

!CounterView methodsFor: 'controller access'!
defaultControllerClass
"Answer the class of a typically useful controller."

^CounterController! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

CounterView class
instanceVariableNames: ''!

!CounterView class methodsFor: 'instance creation'!
open: aModel
"Open a view for a new counter."

"CounterView open: Counter new."

| aCounterView topView |

aCounterView _ CounterView new model: aModel.
aCounterView borderWidth: 2.
aCounterView insideColor: Form white.

topView _ StandardSystemView new label: 'Counter'.
topView minimumSize: 80@40.
topView addSubView: aCounterView.

topView controller open!

openWithGraphicalButtons: aModel
"Open a view for a new counter that has fixed graphical buttons for
incrementing and decrementing the value."
"CounterView openWithGraphicalButtons: Counter new"

| aCounterView topView switch aSwitchView |

aCounterView _ CounterView new model: aModel.
aCounterView insideColor: Form white.

topView _ StandardSystemView new label: 'Counter'.
topView minimumSize: 120 @ 80.
topView maximumSize: 400 @ 300.
"add main view"
topView addSubView: aCounterView
in: (0.4 @ 0 extent: 0.6 @ 1)
borderWidth: (0 @ 2 extent: 2 @ 1).

switch _ Button newOff. "add increment button"
switch onAction: [aCounterView model increment].
aSwitchView _ SwitchView new model: switch.
aSwitchView label: ('+' asDisplayText form magnifyBy: 2@2).
aSwitchView insideColor: Form lightGray.
topView addSubView: aSwitchView
in: (0 @ 0 extent: 0.4 @ 0.5)
borderWidth: (2 @ 2 extent: 0 @ 0).

switch _ Button newOff. "add decrement button"
switch onAction: [aCounterView model decrement].
aSwitchView _ SwitchView new model: switch.
aSwitchView label: ('-' asDisplayText form magnifyBy: 2@2).
aSwitchView insideColor: Form lightGray.
topView addSubView: aSwitchView
in: (0 @ 0.5 extent: 0.4 @ 0.5)
borderWidth: (2 @ 1 extent: 0 @ 2).
topView controller open!

openWithTextButtons: aModel
"Open a view for a new counter that has fixed text buttons for
incrementing and decrementing the value."
"CounterView openWithTextButtons: Counter new"

| aCounterView topView switch aSwitchView |

aCounterView _ CounterView new model: aModel.
aCounterView insideColor: Form white.

topView _ StandardSystemView new label: 'Counter'.
topView minimumSize: 160 @ 60.
topView addSubView: aCounterView
in: (0 @ 0 extent: 1 @ 0.6)
borderWidth: 2.
switch _ Button newOff. "increment button"
switch onAction: [aCounterView model increment].
aSwitchView _ SwitchView new model: switch.
aSwitchView label: (Text string: 'increment' emphasis:
2) asDisplayText.
aSwitchView insideColor: Form white.
topView addSubView: aSwitchView
in: (0 @ 0.6 extent: 0.5 @ 0.4)
borderWidth: (2 @ 0 extent: 0 @ 2).
switch _ Button newOff. "decrement button"
switch onAction: [aCounterView model decrement].
aSwitchView _ SwitchView new model: switch.
aSwitchView label: (Text string: 'decrement' emphasis:
2) asDisplayText.
aSwitchView insideColor: Form white.
topView addSubView: aSwitchView
in: (0.5 @ 0.6 extent: 0.5 @ 0.4)
borderWidth: (0 @ 0 extent: 2 @ 2).
topView controller open! !

MouseMenuController subclass: #CounterController
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Demo-Counter'!

!CounterController methodsFor: 'initialize-release'!
initialize
"Initialize a pop-up menu of commands for changing the value
of the model. "
super initialize.
self yellowButtonMenu: (PopUpMenu labelList: #((Increment Decrement ) ))
yellowButtonMessages: #(increment decrement )! !

!CounterController methodsFor: 'control defaults'!
isControlActive
"Take control when the blue button is not pressed."
^super isControlActive & sensor blueButtonPressed not! !

!CounterController methodsFor: 'menu messages'!
decrement
"Subtract 1 from the value of the counter."
self model decrement!
increment
"Add 1 to the value of the counter."
self model increment! !
Model subclass: #Counter
instanceVariableNames: 'value '
classVariableNames: ''
poolDictionaries: ''
category: 'Demo-Counter'!

!Counter methodsFor: 'initialize-release'!
initialize
"Set the initial value to 0."
self value: 0! !

!Counter methodsFor: 'accessing'!
getValue
"Return the current value of 'value'"
^value!

setValue: aNumber
"Set the value of 'value' to be aNumber"
value := aNumber!

value
"Answer the current value of the receiver."
^value!

value: aNumber
"Set the counter to aNumber."
value _ aNumber.
self changed! !

!Counter methodsFor: 'operations'!
decrement
"Subtract 1 from the value of the counter."
self value: self value - 1!

increment
"Add 1 to the value of the counter."
self value: self value + 1!

printOn: aStream
aStream nextPutAll: 'a CounterHolder with value ', self value printString! !

!Counter methodsFor: 'printing'! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

Counter class
instanceVariableNames: ''!

!Counter class methodsFor: 'instance creation'!
new
"Answer an initialized instance of the receiver."
^super new initialize! !





  3 Responses to “Category : Files from Magazines
Archive   : DDJ0790.ZIP
Filename : GOLDBERG.LST

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/