home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
LANGUAGE
/
SMALTALK
/
TEXTBOOK
/
AP04.ST
(
.txt
)
< prev
next >
Wrap
Text File
|
1997-04-22
|
8KB
|
314 lines
'Smalltalk Textbook Appendix 04'!
EngiVariable subclass: #EngiDisplayModel
instanceVariableNames: 'displayBounds displayOrigin windowLabel '
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Interface'!
EngiDisplayModel comment:
'
Engi 0.01 (10 January 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiDisplayModel methodsFor: 'accessing'!
value: anObject
self setValue: anObject.
self flushBounds.
self changed: #value! !
!EngiDisplayModel methodsFor: 'point accessing'!
convertToMyPoint: aPoint
^aPoint - displayOrigin! !
!EngiDisplayModel methodsFor: 'bounds accessing'!
bounds
displayBounds isNil ifTrue: [displayBounds := self computeBounds].
^displayBounds!
computeBounds
| bounds |
self canBeDisplayed
ifTrue: [bounds := self value bounds]
ifFalse: [bounds := self convertComposedText bounds].
(bounds origin x > 0 and: [bounds origin y > 0])
ifTrue:
[bounds := (Point zero corner: bounds corner)
expandedBy: self expandedRectangle.
displayOrigin := Point zero - bounds origin.
^Point zero extent: bounds extent].
(bounds origin x > 0 and: [bounds corner y < 0])
ifTrue:
[bounds := ((bounds topRight extent: Point zero)
merge: (Point zero extent: Point zero))
expandedBy: self expandedRectangle.
displayOrigin := Point zero - bounds origin.
^Point zero extent: bounds extent].
(bounds origin x < 0 and: [bounds corner y > 0])
ifTrue:
[bounds := ((bounds bottomLeft extent: Point zero)
merge: (Point zero extent: Point zero))
expandedBy: self expandedRectangle.
displayOrigin := Point zero - bounds origin.
^Point zero extent: bounds extent].
(bounds corner x < 0 and: [bounds corner y < 0])
ifTrue:
[bounds := (bounds origin corner: Point zero)
expandedBy: self expandedRectangle.
displayOrigin := Point zero - bounds origin.
^Point zero extent: bounds extent].
bounds := bounds expandedBy: self expandedRectangle.
displayOrigin := Point zero - bounds origin.
^Point zero extent: bounds extent!
expandedRectangle
^0 @ 0 corner: 0 @ 0!
flushBounds
displayBounds := nil.
(self value notNil and: [self value respondsTo: #flushBounds])
ifTrue: [self value flushBounds]! !
!EngiDisplayModel methodsFor: 'label accessing'!
windowLabel
windowLabel isNil ifTrue: [windowLabel := self defaultWindowLabel].
^windowLabel!
windowLabel: aStringOrNil
| topWindow |
windowLabel := aStringOrNil.
self dependedViews do: [:view | (view respondsTo: #topComponent)
ifTrue:
[topWindow := view topComponent.
(topWindow isKindOf: ScheduledWindow)
ifTrue: [topWindow label: windowLabel]]]! !
!EngiDisplayModel methodsFor: 'displaying'!
displayAxesOn: graphicsContext at: aPoint
| bounds displayContext |
bounds := self bounds.
displayContext := graphicsContext copy.
displayContext paint: ColorValue veryLightGray.
displayContext displayLineFrom: displayOrigin x @ 0 to: displayOrigin x @ bounds bottom.
displayContext displayLineFrom: 0 @ displayOrigin y to: bounds right @ displayOrigin y!
displayOn: graphicsContext
self displayOn: graphicsContext at: Point zero!
displayOn: graphicsContext at: aPoint
self displayAxesOn: graphicsContext at: aPoint.
self displayValueOn: graphicsContext at: aPoint!
displayValueOn: graphicsContext at: aPoint
self canBeDisplayed
ifTrue: [self value displayOn: graphicsContext at: aPoint + displayOrigin]
ifFalse: [self convertComposedText displayOn: graphicsContext at: aPoint + displayOrigin]! !
!EngiDisplayModel methodsFor: 'viewing'!
open
| displayView edgeDecorator topView |
displayView := self defaultViewClass model: self.
edgeDecorator := LookPreferences edgeDecorator on: displayView.
edgeDecorator noMenuBar.
edgeDecorator useVerticalScrollBar.
edgeDecorator useHorizontalScrollBar.
topView := EngiTopView
model: nil
label: self windowLabel
minimumSize: 100 @ 100.
topView add: edgeDecorator in: (topView frameFraction: (0 @ 0 corner: 1 @ 1)).
topView open! !
!EngiDisplayModel methodsFor: 'controlling'!
redButtonActivity: aController
| aPoint |
aPoint := self convertToMyPoint: aController sensor cursorPoint.
Transcript cr; show: aPoint printString!
yellowButtonActivity: aController
| aMenu aResult |
aMenu := EngiMenuMaker fromCollection: (Array with: 'inspect' -> [self value inspect]).
aResult := aMenu startUp.
aResult = 0 ifFalse: [aResult value]! !
!EngiDisplayModel methodsFor: 'updating'!
dependedViews
^self dependents select: [:view | view isKindOf: self defaultViewClass]!
dependentsDo: aBlock
self dependedViews do: [:view | aBlock value: view]! !
!EngiDisplayModel methodsFor: 'defaults'!
defaultViewClass
^EngiDisplayView!
defaultWindowLabel
^'Display'! !
!EngiDisplayModel methodsFor: 'private'!
canBeDisplayed
^((self value respondsTo: #displayOn:)
and: [self value respondsTo: #displayOn:at:])
and: [self value respondsTo: #bounds]!
convertComposedText
| aComposedText maxCompositionWidth compositionWidth |
aComposedText := self value printString asComposedText.
maxCompositionWidth := (Screen default bounds width / 2) asInteger.
compositionWidth := (aComposedText bounds width / 2) asInteger.
compositionWidth > maxCompositionWidth ifTrue: [aComposedText := ComposedText
withText: self value printString
style: TextAttributes default
compositionWidth: maxCompositionWidth].
^aComposedText! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
EngiDisplayModel class
instanceVariableNames: ''!
!EngiDisplayModel class methodsFor: 'instance creation'!
on: anObject
^super new value: anObject! !
!EngiDisplayModel class methodsFor: 'view creation'!
openOn: anObject
^self openOn: anObject label: nil!
openOn: anObject label: labelString
| displayModel |
displayModel := self on: anObject.
displayModel windowLabel: labelString.
displayModel open.
^displayModel! !
!EngiDisplayModel class methodsFor: 'examples'!
example1
"EngiDisplayModel example1."
"EngiDisplayModel openOn: Image fromUser label: 'Image'."
| displayObject displayModel |
displayObject := Image fromUser.
displayModel := EngiDisplayModel on: displayObject.
displayModel windowLabel: 'Image'.
displayModel open.
^displayModel!
example2
"EngiDisplayModel example2."
"EngiDisplayModel openOn: Time now label: 'Time'."
| displayObject displayModel |
displayObject := Time now.
displayModel := EngiDisplayModel on: displayObject.
displayModel windowLabel: 'Time'.
displayModel open.
^displayModel! !
AutoScrollingView subclass: #EngiDisplayView
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Interface'!
EngiDisplayView comment:
'
Engi 0.01 (10 January 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiDisplayView methodsFor: 'initialize-release'!
initialize
super initialize.
self scrollOffsetHolder: ScrollValueHolder new!
scrollOffsetHolder: aValueHolder
scrollOffset := aValueHolder.
scrollOffset grid: self scrollGrid! !
!EngiDisplayView methodsFor: 'controller accessing'!
defaultControllerClass
^EngiDisplayController! !
!EngiDisplayView methodsFor: 'bounds accessing'!
preferredBounds
(model notNil and: [model respondsTo: #bounds])
ifTrue: [^model bounds]
ifFalse: [^Point zero corner: Point zero]! !
!EngiDisplayView methodsFor: 'displaying'!
displayOn: graphicsContext
(model notNil and: [model respondsTo: #displayOn:])
ifTrue: [model displayOn: graphicsContext]! !
!EngiDisplayView methodsFor: 'scrolling'!
scrollGrid
^1 @ 1! !
!EngiDisplayView methodsFor: 'updating'!
update: aSymbol
self positionTo: Point zero.
self clearInside.
self displayOn: self graphicsContext! !
ControllerWithMenu subclass: #EngiDisplayController
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Interface'!
EngiDisplayController comment:
'
Engi 0.01 (10 January 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiDisplayController methodsFor: 'control defaults'!
redButtonActivity
(model notNil and: [model respondsTo: #redButtonActivity:])
ifTrue: [model redButtonActivity: self]!
yellowButtonActivity
(model notNil and: [model respondsT