'From Squeak3.7 of ''4 September 2004'' [latest update: #5989] on 12 May 2008 at 11:24:55 pm'!

!Date class methodsFor: 'squeak protocol' stamp: 'jmv 5/12/2008 23:07'!
readFrom: aStream 
	"Read a Date from the stream in any of the forms:  
	
		<day> <monthName> <year>		(5 April 1982; 5-APR-82)  
	
		<monthName> <day> <year>		(April 5, 1982)  
	
		<monthNumber> <day> <year>		(4/5/82) 
			<day><monthName><year>			(5APR82)"
	| day month year |
	aStream peek isDigit
		ifTrue: [day := Integer readFrom: aStream].
	[aStream atEnd ifTrue: [^nil].
	aStream peek isAlphaNumeric]
		whileFalse: [aStream skip: 1].
	aStream peek isLetter
		ifTrue: ["number/name... or name..."
			month := WriteStream
						on: (String new: 10).
			[aStream peek isLetter]
				whileTrue: [month nextPut: aStream next].
			month := month contents.
			day isNil
				ifTrue: ["name/number..."
					[aStream peek isAlphaNumeric]
						whileFalse: [aStream skip: 1].
					day := Integer readFrom: aStream]]
		ifFalse: ["number/number..."
			day isNil ifTrue: [^nil].
			month := Month nameOfMonth: day.
			day := Integer readFrom: aStream].
	[aStream atEnd ifTrue: [^nil].
	aStream peek isAlphaNumeric]
		whileFalse: [aStream skip: 1].
	year := Integer readFrom: aStream.
	^ self
		year: year
		month: month
		day: day! !


!EntryFieldLW methodsFor: 'user actions' stamp: 'jmv 5/12/2008 23:19'!
characterEntered:  char
	| string h t newValue valid |
	string _ self value.
	self hasSelection
		ifTrue: [ 
			h _string copyFrom: 1 to: selection first -1. 
			t _ string copyFrom: selection last +1 to: string size. 
			h _ h , (Array with: char).
			newValue _ h , t.]
		ifFalse: [
			h _ string copyFrom: 1 to: cursorPosition-1.
			t _ string copyFrom: cursorPosition to: string size.
			newValue _ h , (Array with: char), t.].
	
	entryMask notNil
				ifTrue:[valid _ entryMask validate: newValue.  valid ifFalse:[ ^ Beeper beep]].
	self hasSelection 
		ifTrue:[cursorPosition _ selection first  +1 ]
		ifFalse:[	cursorPosition _ cursorPosition + 1].
	self clearSelection.
	self performActionWith: newValue 
	
	
	
	
	
	
	

	 
	
	! !

!EntryFieldLW methodsFor: 'user actions'!
moveCursorSelectionForth
	| end start string |
	string _ self value.
	start _ selection first.
	end _ selection last.
	selectionDirection == #right 
			ifTrue:[ end _ string  value size  min: end + 1]
			ifFalse:[	start _ string size + 1 min:  start + 1].
	selection  _ start to: end.
	cursorPosition _ string size + 1 min: cursorPosition + 1.
	self updateView
! !

!EntryFieldLW methodsFor: 'drawing' stamp: 'jmv 5/12/2008 23:23'!
drawOn: aCanvas
	| string leftX w cColor borderWidth  stringBounds font xOffset xExtent selectionBounds orig ext cursorBounds str |
	borderWidth _ self borderWidth.
	aCanvas frameAndFillRectangle: bounds fillColor: self backgroundColor borderWidth: borderWidth borderColor: self borderColor.

	self isValid ifFalse:[aCanvas fillRectangle: bounds  color: (Color red alpha:0.4)].
 
	string _ self value.
	stringBounds _ self stringPosition extent: bounds extent - (2* borderWidth). 
	hideValue ifTrue:[ str _ string collect:[:char| $*]] ifFalse:[ str_ string].
	aCanvas drawString: str in: stringBounds font: self font color: color.

	self hasSelection
		ifTrue:[ 
			font _ self font.
			xOffset _ 0.
			(1 to: selection first - 1) do:[:i| xOffset _  xOffset + (font widthOf: (string at:i))].
			xExtent _ 0.
			 selection do:[:i|  xExtent _ xExtent + (font widthOf: (string at:i))]. 
			selectionBounds _  (stringBounds origin +(xOffset@0) ) extent: (xExtent@ stringBounds extent y).
			aCanvas fillRectangle: selectionBounds color: (Color green lighter alpha:0.5)]. 
	
	
	xOffset _ 0. 
	font _ self font.
	(string notNil and:[string notEmpty ])
		ifTrue:[	
				cursorPosition _ cursorPosition min: string size+1.
				(0 to: cursorPosition -2 ) do:[:i|  xOffset _ xOffset + (font widthOf: (string at:i+1))]].	
	orig _ self stringPosition + (xOffset@0).
	ext _  2@ stringBounds extent y.
	cursorBounds _ orig extent: ext.
	leftX _ cursorBounds origin x + (cursorBounds extent x / 2).
	w := 4.
	cColor :=  self cursorColor.
	1 to: w
		do: 
			[:i | 
				aCanvas fillRectangle: ((leftX - w + i - 1) @ (cursorBounds origin y + i - 1) 
								extent: ((w - i) * 2 + 3) @ 1)
						color: cColor.
					aCanvas fillRectangle: ((leftX - w + i - 1) @ (cursorBounds origin y + cursorBounds extent y - i) 
								extent: ((w - i) * 2 + 3) @ 1)
						color: cColor].
			aCanvas fillRectangle: cursorBounds color: cColor
	
			
	! !


!SliderLW methodsFor: 'private' stamp: 'jmv 5/12/2008 23:10'!
cursorForm: extent
	| w h |
	w _ extent x asInteger.
	h _ extent y asInteger.
	(cursorForm isNil or: [(cursorForm height = h) not]) ifTrue: [
		cursorForm _ (Form fromFileNamed: 'cursor.jpeg') scaledToSize: w@h ].
	^cursorForm! !

