home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
LANGUAGE
/
SMALTALK
/
TEXTBOOK
/
AP19.ST
(
.txt
)
< prev
next >
Wrap
Text File
|
1997-04-22
|
13KB
|
486 lines
'Smalltalk Textbook Appendix 19'!
View subclass: #EngiCalendarView
instanceVariableNames: 'frames '
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Calendar'!
EngiCalendarView comment:
'
Engi 0.06 (19 March 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiCalendarView methodsFor: 'accessing'!
frames
^frames! !
!EngiCalendarView methodsFor: 'controller accessing'!
defaultControllerClass
^EngiCalendarController! !
!EngiCalendarView methodsFor: 'displaying'!
displayBox: aRectangle on: aGraphicsContext bool: aBoolean
| box gc |
box := aRectangle insetBy: (0 @ 0 corner: 1 @ 1).
gc := aGraphicsContext copy.
aBoolean = true
ifTrue: [gc paint: (ColorValue brightness: 0.25)]
ifFalse: [gc paint: (ColorValue brightness: 0.75)].
gc displayLineFrom: box bottomLeft to: box bottomRight.
gc displayLineFrom: box topRight to: box bottomRight.
aBoolean = true
ifTrue: [gc paint: (ColorValue brightness: 0.75)]
ifFalse: [gc paint: (ColorValue brightness: 0.25)].
gc displayLineFrom: box topLeft to: box topRight.
gc displayLineFrom: box topLeft to: box bottomLeft!
displayOn: aGraphicsContext
| width height today x y box para rect j i |
frames := OrderedCollection new.
width := self bounds width / 7.
height := self bounds height / 7.
today := Date today.
x := width * 1.
y := 0.
box := x @ y extent: width @ height.
para := self model yearIndex printString asComposedText.
rect := para bounds align: para bounds center with: box center.
para displayOn: aGraphicsContext at: rect origin rounded.
frames add: (box merge: rect) rounded -> #year.
x := width * 3.
y := 0.
box := x @ y extent: width @ height.
para := self model monthIndex printString asComposedText.
rect := para bounds align: para bounds center with: box center.
para displayOn: aGraphicsContext at: rect origin rounded.
frames add: (box merge: rect) rounded -> #month.
x := 0.
y := height * 1.
self model weekDayNames
do:
[:each |
box := x @ y extent: width @ height.
para := each asComposedText.
rect := para bounds align: para bounds center with: box center.
para displayOn: aGraphicsContext at: rect origin rounded.
x := x + width].
y := height * 2.
j := 1.
self model calendarMatrix
do:
[:week |
x := 0.
i := 1.
week
do:
[:each |
each isNil
ifFalse:
[box := x @ y extent: width @ height.
para := each printString asComposedText.
rect := para bounds align: para bounds center with: box center.
para displayOn: aGraphicsContext at: rect origin rounded.
((self model yearIndex = today year and: [self model monthIndex = today monthIndex])
and: [each = today dayOfMonth])
ifTrue: [self
displayBox: (box merge: rect)
on: aGraphicsContext
bool: true].
frames add: (box merge: rect) rounded -> (i @ j)].
x := x + width.
i := i + 1].
y := y + height.
j := j + 1]! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
EngiCalendarView class
instanceVariableNames: ''!
!EngiCalendarView class methodsFor: 'instance creation'!
openOn: calendarModel
| calendarView edgeDecorator openRectangle topWindow |
calendarView := self model: calendarModel.
edgeDecorator := LookPreferences edgeDecorator on: calendarView.
edgeDecorator noMenuBar.
edgeDecorator noVerticalScrollBar.
edgeDecorator noHorizontalScrollBar.
openRectangle := Point zero extent: 30 * 7 @ (20 * 7).
topWindow := ScheduledWindow
model: nil
label: 'Calendar'
minimumSize: openRectangle extent.
topWindow component: edgeDecorator.
topWindow open! !
ControllerWithMenu subclass: #EngiCalendarController
instanceVariableNames: 'today '
classVariableNames: 'CalendarMenu '
poolDictionaries: ''
category: 'Engi-Calendar'!
EngiCalendarController comment:
'
Engi 0.06 (19 March 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiCalendarController methodsFor: 'initialize-release'!
initialize
super initialize.
today := Date today! !
!EngiCalendarController methodsFor: 'control defaults'!
controlActivity
today = Date today
ifFalse:
[today := Date today.
self view clearInside.
self view displayOn: self view graphicsContext].
(self sensor redButtonPressed and: [self viewHasCursor])
ifTrue: [^self redButtonActivity].
(self sensor yellowButtonPressed and: [self viewHasCursor])
ifTrue: [^self yellowButtonActivity]!
redButtonActivity
| point pair box |
point := self sensor cursorPoint.
pair := self view frames detect: [:assoc | assoc key containsPoint: point]
ifNone: [nil].
pair isNil ifTrue: [^nil].
box := pair key.
self view
displayBox: box
on: self view graphicsContext
bool: false.
[self sensor anyButtonPressed and: [box containsPoint: self sensor cursorPoint]] whileTrue.
self view invalidateRectangle: box repairNow: true.
(box containsPoint: self sensor cursorPoint)
ifFalse: [^nil].
^pair!
yellowButtonActivity
| pair selection |
pair := self redButtonActivity.
pair isNil
ifTrue:
[CalendarMenu notNil
ifTrue:
[selection := CalendarMenu startUp.
selection ~= 0 ifTrue: [^self model perform: selection]].
^nil].
pair value = #year ifTrue: [^self model changeYear].
pair value = #month ifTrue: [^self model changeMonth].
^self model spawnDay: pair value! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
EngiCalendarController class
instanceVariableNames: ''!
!EngiCalendarController class methodsFor: 'class initialization'!
initialize
"EngiCalendarController initialize."
CalendarMenu := PopUpMenu
labelArray: #('new' 'open' 'save' )
lines: #(2 )
values: #(#newCalendar #openCalendar #saveCalendar )! !
Model subclass: #EngiCalendarModel
instanceVariableNames: 'monthIndex yearIndex calendarMatrix memoDictionary '
classVariableNames: 'MonthNames WeekDayNames '
poolDictionaries: ''
category: 'Engi-Calendar'!
EngiCalendarModel comment:
'
Engi 0.06 (19 March 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiCalendarModel methodsFor: 'accessing'!
calendarMatrix
^calendarMatrix!
memoDictionary
memoDictionary isNil ifTrue: [memoDictionary := Dictionary new].
^memoDictionary!
monthIndex
^monthIndex!
monthNames
^MonthNames!
weekDayNames
^WeekDayNames!
yearIndex
^yearIndex! !
!EngiCalendarModel methodsFor: 'copying'!
postCopy
| dictionary |
super postCopy.
dictionary := Dictionary new.
memoDictionary associationsDo: [:assoc | dictionary add: assoc key copy -> assoc value copy].
memoDictionary := dictionary! !
!EngiCalendarModel methodsFor: 'menu messages'!
changeMonth
| menu index |
menu := PopUpMenu labelArray: ((1 to: 12)
collect: [:each | each printString]).
menu selection: self monthIndex.
index := menu startUp.
index = 0 ifTrue: [^nil].
self month: index year: self yearIndex!
changeYear
| answer year |
answer := self yearIndex printString.
answer := EngiTextModel request: 'Please enter year.' default: answer.
(answer isNil or: [answer isEmpty])
ifTrue: [^nil].
year := Compiler evaluate: answer logged: false.
self month: self monthIndex year: year!
newCalendar
EngiCalendarView openOn: self class new!
openCalendar
| fileName fileStream binaryObjectStorage readBlockClosure className calendarModel |
fileName := EngiTextModel request: 'file name?'.
(fileName isNil or: [fileName isEmpty])
ifTrue: [^nil].
(self class errorSignal
handle:
[:exception |
Transcript cr; show: 'file not found'.
exception returnWith: nil]
do: [fileStream := fileName asFilename readStream]) isNil ifTrue: [^nil].
(self class errorSignal
handle:
[:exception |
Transcript cr; show: 'can not read boss'.
exception returnWith: nil]
do: [binaryObjectStorage := BinaryObjectStorage onOldNoScan: fileStream]) isNil ifTrue: [^nil].
readBlockClosure :=
[className := binaryObjectStorage next.
className = self class name ifTrue: [calendarModel := binaryObjectStorage next]].
Cursor read showWhile: [[readBlockClosure value]
valueNowOrOnUnwindDo: [binaryObjectStorage close]].
className = self class name ifFalse: [^nil].
EngiCalendarView openOn: calendarModel.
^calendarMod