TimeLogger defines 30 private instance methods. Though you can implement them in any order, begin with the methods that define the user interface.
Method createWindow
createWindow "Private - Creates the time logger." | b1 b2 b3 addB addB2 remB remB2 startB stopB label l2 tW tD | self createTopLevelShell. label := self createLabel. self createClientListBox: label. b1 := self createRowColumn: 'b1' top: clientListBox. addB := self createButton: b1 name: ' Add Client ' call: #addClient:clientData:callData: clientData: nil. remB := self createButton: b1 name: ' Remove Client ' call: #removeClient:clientData:callData: clientData: nil. l2 := self createLabel2: b1. self createServiceListBox: l2.
b2 := self createRowColumn: 'b2' top: serviceListBox. addB2 := self createButton: b2 name: ' Add Service Item ' call: #addItem:clientData:callData: clientData: nil. remB2 := self createButton: b2 name: ' Remove Item ' call: #removeItem:clientData:callData: clientData: nil. tW := self createRowColumnTW: b2. self createLabel3: tW. tD := self createTimeDisplay: tW. b3 := self createRowColumn: 'b3' top: tW. startB := self createButton: b3 name: ' Start Timer ' call: #startButtonMotion:clientData:callData: clientData: startB. stopB := self createButton: b3 name: ' Stop Timer / Show Interval' call: #stopButtonMotion:clientData:callData: clientData: stopB. self createFileButton: b3. busyCursor := shell display createFontCursor: XCWatch. self timeElapsedDisplay: tD.
Method createTopLevelShell
createTopLevelShell "Private - Creates a window and a form." shell := CwTopLevelShell createApplicationShell: 'shell' argBlock: nil. shell title: 'Time Logger'. form := shell createForm: 'form' argBlock: nil. form manageChild.
Method createShell
createShell "Private - Creates a shell." shell := CwTopLevelShell appCreateShell: self class name applicationClass: CwAppContext defaultApplicationClass display: CgDisplay default argBlock: nil.
Method createLabel
createLabel "Private - Creates a label." | label | label := form "The following line has several spaces before the end quote" createLabel: 'Client identification: ' argBlock: [: w | w marginHeight: 5; leftAttachment: XmATTACHFORM; topAttachment: XmATTACHFORM; rightAttachment: XmATTACHFORM]. label manageChild. ^label
Method createClientListBox:
createClientListBox: aWidget "Private - Creates a list box." clientListBox := form createScrolledList: 'clientListBox' argBlock: [:w | w items: self addClientsToList; visibleItemCount: 4; selectionPolicy: XmSINGLESELECT]. clientListBox parent topAttachment: XmATTACHWIDGET; topWidget: aWidget; leftAttachment: XmATTACHFORM; rightAttachment: XmATTACHFORM. clientListBox manageChild
Method createRowColumn:top:
createRowColumn: aName top: aWidget "Private - Creates a row column to hold widgets." | b | b := form createRowColumn: aName argBlock: [:w | w orientation: XmHORIZONTAL; topAttachment: XmATTACHWIDGET; topWidget: aWidget; leftAttachment: XmATTACHFORM; rightAttachment: XmATTACHFORM]. b manageChild. ^b
Method createButton:name:call:clientData:
createButton: anRC name: aName call: aSelector clientData: data "Private - Creates a push button." | b | b := anRC createPushButton: aName argBlock: nil. b addEventHandler: ButtonReleaseMask receiver: self selector: aSelector clientData: data. b manageChild. ^b
Method createLabel2:
createLabel2: anRC "Private - Creates a label." | l2 | l2 := form "The following line has several spaces before the end quote" createLabel: 'Services provided: ' argBlock: [:w | w marginHeight: 5; topAttachment: XmATTACHWIDGET; topWidget: anRC; leftAttachment: XmATTACHFORM; rightAttachment: XmATTACHFORM]. l2 manageChild. ^l2
Method createServiceListBox:
createServiceListBox: aWidget "Private - Creates a list box." serviceListBox := form createScrolledList: 'serviceListBox' argBlock: [:w | w items: self addItemsToList; visibleItemCount: 4; selectionPolicy: XmSINGLESELECT]. serviceListBox parent topAttachment: XmATTACHWIDGET; topWidget: aWidget; leftAttachment: XmATTACHFORM; rightAttachment: XmATTACHFORM. serviceListBox manageChild
Method createRowColumnTW:
createRowColumnTW: anRC "Private - Creates a row column to hold widgets." | tW | tW := form createRowColumn: 'timeWidgets' argBlock: [:w | w orientation: XmHORIZONTAL; topAttachment: XmATTACHWIDGET; topWidget: anRC]. tW manageChild. ^tW
Method createLabel3:
createLabel3: anRC "Private - Creates a label." | l3 | l3 := anRC createLabel: 'label' argBlock: [: w | w labelString: ' Time elapsed: '; marginHeight: 5]. l3 manageChild.
Method createTimeDisplay:
createTimeDisplay: anRC "Private - Creates a label." | tD | tD := anRC createText: 'timeDisplay' argBlock: [:w | w width: 190]. tD setString: 'Hours:Minutes:Seconds'. tD manageChild. ^tD
Method createFileButton:
createFileButton: anRC "Private - Creates a push button." | fileButton | fileButton := form createPushButton: ' Add Information to File ' argBlock: [:w | w marginTop: 4; marginBottom: 4; topAttachment: XmATTACHWIDGET; topWidget: anRC; leftAttachment: XmATTACHFORM; rightAttachment: XmATTACHFORM; bottomAttachment: XmATTACHFORM]. fileButton addEventHandler: ButtonReleaseMask receiver: self selector: #file:clientData:callData: clientData: nil. fileButton manageChild
Method realizeWindow
realizeWindow "Private - Realizes the receiver's widget hierarchy." shell realizeWidget.
Method addClient:clientData:callData:
addClient: aButton clientData: clientData callData: callData "Private - Displays a prompter for a new client ID; then adds the client ID to the list box." | prompter reply | prompter := CwTextPrompter new title: 'Prompter for Client Identification'; messageString: 'Add the client name or ID: '. reply := prompter prompt. reply notNil ifTrue: [clientListBox addItem: reply position: 1] ifFalse: [^self].
Method addItem:clientData:callData:
addItem: aButton clientData: clientData callData: callData "Private - Displays a prompter for a new service item; then adds the service item to the list box." | prompter reply | prompter := CwTextPrompter new title: 'Prompter for Service Item'; messageString: 'Add the service provided: '. reply := prompter prompt. reply notNil ifTrue: [serviceListBox addItem: reply position: 1] ifFalse: [^self].
Method file:clientData:callData:
file: aWidget clientData: clientData callData: callData "Private - Adds selected information and the elapsed time to the file." | output info stream | clientListBox itemCount > 0 ifTrue: [ (output := (CwFileSelectionPrompter new) title: 'Save As'; prompt) isNil ifTrue: [^self]] ifFalse: [^self]. self writeFileName: output. (output = nil) ifFalse: [ stream := CfsReadFileStream open: output. text := (stream upToEnd) trimBlanks. stream close].
info := CfsWriteFileStream open: output. text isNil ifTrue: [^self] ifFalse: [info nextPutAll: text]. info cr; nextPutAll: (clientListBox items first). info tab; tab; nextPutAll: (serviceListBox items first). info tab; tab; nextPutAll: ((elapsedTime printString) copyFrom: 2 to: 9). info close.
Method removeClient:clientData:callData:
removeClient: aButton clientData: clientData callData: callData "Private - Deletes the selected client ID from the list box." clientListBox selectedItemCount = 1 ifTrue: [clientListBox deleteItem: (clientListBox selectedItems first)] ifFalse: [^self]
Method removeItem:clientData:callData:
removeItem: aButton clientData: clientData callData: callData "Private - Deletes the selected service item from the list box." serviceListBox selectedItemCount = 1 ifTrue: [serviceListBox deleteItem: (serviceListBox selectedItems first)] ifFalse: [^self]
Method stopButtonMotion:clientData:callData:
stopButtonMotion: aButton clientData: aRowColumn callData: callData "Private - Ends timing. Subtracts the end-time from the start-time to determine the time elapsed." startTime isNil ifTrue: [ ^self ]. elapsedTime := self calculateTime: (Time fromSeconds: ((Time now asSeconds) - startTime asSeconds )). self timeElapsedDisplay setString: ' ', ((elapsedTime printString)"9 spaces between ' '" copyFrom: 2 to: 9).
Method addClientsToList
addClientsToList "Private - Answers a list of expressions to go into the list box." clientListBox := OrderedCollection new: self size. ^clientListBox
Method addItemsToList
addItemsToList "Private - Answers a list of services to go into the list box." serviceListBox := OrderedCollection new: self size. ^serviceListBox
Method readFileName:
readFileName: name "Private - Reads the contents of the specified file." | size file string result | file := CfsFileDescriptor open: name oflag: ORDONLY. file isCfsError ifTrue: [ ^(CwMessagePrompter new) iconType: XmICONERROR; messageString: file printString; prompt ].
(size := file size) >= self text maxLength ifTrue: [ file close. ^(CwMessagePrompter new) iconType: XmICONERROR; messageString: 'File size (',size printString,') is greater than Text widget maxLength (', self text maxLength printString,')' ; prompt ]. fileName := name. file close.
Method writeFileName:
writeFileName: name "Private - Writes the contents to the specified file." | file | file := CfsFileDescriptor open: name oflag: ORDWR | OCREAT | OAPPEND. file isCfsError ifTrue: [ ^(CwMessagePrompter new) iconType: XmICONERROR; messageString: file printString; prompt ]. fileName := name.