'From Squeak3.7 of ''4 September 2004'' [latest update: #5989] on 24 May 2008 at 8:22:28 am'!
!classDefinition: #IndeterminatePogressBarLW category: #'LightWidgets-Kernel'!
LightWidget subclass: #IndeterminatePogressBarLW
	instanceVariableNames: 'xOffset stepping'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'LightWidgets-Kernel'!

!IndeterminatePogressBarLW commentStamp: '<historical>' prior: 0!
An  indeterminate progress bar  is used in situations where the extent of the task is unknown or the progress of the task can not be determined in a way that could be expressed as a percentage. This bar uses motion or some other indicator to show that progress is taking place, rather than using the size of the filled portion to show the total amount of progress!

!classDefinition: #ProgressBarLW category: #'LightWidgets-Kernel'!
LightWidget subclass: #ProgressBarLW
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'LightWidgets-Kernel'!

!ProgressBarLW commentStamp: '<historical>' prior: 0!
A progress bar is a component in a graphical user interface used to convey the progress of a task, such as a download or file transfer. The progress  is accompanied by a textual representation of the progress in a percent format. 

The target (model) of the widget keeps track of the progress of the task, the view simply updates itself accordingly. Going from 0% to 100%.

Take a look at ProgressPaneLW>>openExample!

!classDefinition: #ProgressPaneLW category: #'LightWidgets-Examples'!
CompositeLW subclass: #ProgressPaneLW
	instanceVariableNames: 'progressBar start indeterminateProgressBar'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'LightWidgets-Examples'!
!classDefinition: #ProgressStatus category: #'LightWidgets-Examples'!
Object subclass: #ProgressStatus
	instanceVariableNames: 'maxValue percentage'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'LightWidgets-Examples'!

!IndeterminatePogressBarLW methodsFor: 'accessing' stamp: 'F Olivero 5/22/2008 22:06'!
backgroundColor
	^Color white! !

!IndeterminatePogressBarLW methodsFor: 'accessing' stamp: 'F Olivero 5/22/2008 22:06'!
borderColor
	^ Color gray ! !

!IndeterminatePogressBarLW methodsFor: 'accessing' stamp: 'F Olivero 5/22/2008 22:07'!
borderWidth 
	^ 4.0! !

!IndeterminatePogressBarLW methodsFor: 'accessing' stamp: 'F Olivero 5/22/2008 22:07'!
fillColor
	^ Color green! !

!IndeterminatePogressBarLW methodsFor: 'accessing' stamp: 'F Olivero 5/22/2008 23:27'!
fillStyle
	| fc |
	fc _ self fillColor.
	^ GradientFillStyle ramp: {0.0 -> fc twiceLighter. 0.1 -> fc . 0.3 -> fc darker. 0.5 -> fc twiceDarker. 0.7-> fc  darker.  0.9 -> fc . 1 -> fc twiceLighter}.! !

!IndeterminatePogressBarLW methodsFor: 'juanREVISA' stamp: 'F Olivero 5/22/2008 23:52'!
shouldStep
	^ target notNil and:[ aspect notNil] and:[self targetAspect]
! !

!IndeterminatePogressBarLW methodsFor: 'juanREVISA'!
startStepping
	"JUAN: dado que light widget todavia no tiene stepping... FO"
	stepping _ [ [true] whileTrue:[(Delay forMilliseconds:1) wait. self step]]  forkAt: Processor activePriority! !

!IndeterminatePogressBarLW methodsFor: 'juanREVISA'!
step
	| plus |
	self shouldStep
		ifTrue:[
			plus _ xOffset + 1.
			(plus < bounds extent x)
				ifTrue:[ xOffset _ xOffset + (bounds extent x /100)]
				ifFalse:[xOffset _ 0.0]]
			ifFalse:[xOffset _ 0.0].
	self updateView! !

!IndeterminatePogressBarLW methodsFor: 'juanREVISA'!
stopStepping
	"JUAN: dado que light widget todavia no tiene stepping...FO"
	stepping  terminate.
	stepping _ nil.
	xOffset _ 0.0.
	self updateView! !

!IndeterminatePogressBarLW methodsFor: 'initialization' stamp: 'F Olivero 5/22/2008 22:53'!
initialize
	super initialize.
	bounds _ 10@10 extent: 200@30.
	xOffset _ self borderWidth! !

!IndeterminatePogressBarLW methodsFor: 'drawing' stamp: 'F Olivero 5/22/2008 23:23'!
drawOn: aCanvas
	| bw bc pos fillBounds fill |
	bw _ self borderWidth.
	bc _ self borderColor.
		
	aCanvas fillRectangle: bounds color: self backgroundColor.

	pos _ bounds origin  + (xOffset@0).
	fillBounds _ pos  extent:  (bounds extent  x/ 4)@(bounds extent y).
	fill _ self fillStyle.
	fill origin:  fillBounds origin.
	fill direction:  fillBounds extent x@ 0.
	fill radial: false.
	aCanvas fillRectangle: fillBounds fillStyle:  fill.
			
	aCanvas frameRectangle: bounds width: bw color: bc
	
	
! !

!IndeterminatePogressBarLW methodsFor: 'updating'!
updateView
	super updateView.
	"JUAN: dado que todavia LightWidget no soporta stepping...FO"
	(self shouldStep and:[ stepping isNil]) ifTrue:[ self startStepping].
	(self shouldStep not and:[stepping notNil]) ifTrue:[ self stopStepping].! !


!ProgressBarLW methodsFor: 'initialization'!
initialize
	super initialize.
	bounds _ 10@10 extent: 200@30.
! !

!ProgressBarLW methodsFor: 'drawing'!
drawOn: aCanvas
	| fillBounds pp progressExtent bw xOffset str bc font pos |
	bw _ self borderWidth.
	bc _ self borderColor.
	font _ self defaultFont.
	
	aCanvas fillRectangle: bounds color: self backgroundColor.
	
	fillBounds _ bounds .
	pp _ self progressPercentage .
	progressExtent _ pp  * (bounds extent x/100).	
	fillBounds _bounds origin extent: ( progressExtent@bounds extent y).
	aCanvas fillRectangle:  fillBounds  color: self fillColor.
	
	str _ pp asString , '%'.
	pp  < 50 ifTrue:[xOffset _ progressExtent +  bw ]
		     	ifFalse:[xOffset _  progressExtent - (font widthOfString: str)].
	pos _  bounds origin + (xOffset@bw).
	aCanvas drawString: str at: pos font: font color: bc.
	
	aCanvas frameRectangle: bounds width: bw color: bc
	
! !

!ProgressBarLW methodsFor: 'private'!
progressPercentage
	(target notNil and: [aspect notNil])
		ifTrue:[^self targetAspect]
		ifFalse:[ ^0].! !

!ProgressBarLW methodsFor: 'accessing' stamp: 'F Olivero 5/22/2008 17:53'!
backgroundColor
	^Color white! !

!ProgressBarLW methodsFor: 'accessing' stamp: 'F Olivero 5/22/2008 17:54'!
borderColor
	^ Color gray ! !

!ProgressBarLW methodsFor: 'accessing' stamp: 'F Olivero 5/22/2008 17:54'!
borderWidth 
	^ 4.0! !

!ProgressBarLW methodsFor: 'accessing'!
fillColor
	^ Color green! !


!ProgressPaneLW methodsFor: 'events handlers'!
isOperationInProgress
	^ target notNil and:[target percentage > 0]! !

!ProgressPaneLW methodsFor: 'events handlers'!
startOperation
		[(1 to:100) do:[:i| target step.  (Delay forMilliseconds: i*5) wait]. target reset.] fork.! !

!ProgressPaneLW methodsFor: 'updating'!
updateIndeterminateProgressBar
	indeterminateProgressBar target: self! !

!ProgressPaneLW methodsFor: 'updating'!
updateProgressBar
	progressBar target: target.
	self isOperationInProgress ifTrue:[ActiveHand navigationFocus:  progressBar]
! !

!ProgressPaneLW methodsFor: 'updating'!
updateStart
	start
		visible:  target percentage = 0;
		target: self.
	
	 target percentage = 0 ifTrue:[ActiveHand navigationFocus: start]! !

!ProgressPaneLW methodsFor: 'updating'!
updateView
	self
		updateStart;
		updateProgressBar;
		updateIndeterminateProgressBar! !

!ProgressPaneLW methodsFor: 'initialization'!
initialize
	super initialize.
	bounds _ 10@10 extent: 250@150.
	
	progressBar _ ProgressBarLW new.
	progressBar
		bounds:(20@60 extent: 200@30);
		aspect:#percentage.
	self addMorphBack: progressBar.
	
	indeterminateProgressBar _ IndeterminatePogressBarLW new.
	indeterminateProgressBar
		bounds:(20@100 extent: 200@30);
		target: self aspect:#isOperationInProgress.
	self addMorphBack: indeterminateProgressBar.
	
	
	
	start _ ButtonLW new.
	start
		bounds: (20@10 extent: 180@30);
		action:#startOperation;
		label:'Start operation'.
	self addMorphBack: start.
	
	
	ActiveHand navigationFocus: start
	
	
	 ! !


!ProgressPaneLW class methodsFor: 'instance creation'!
openExample
	| model view |
	model _ ProgressStatus new.
	view _ self new.
	view beMainViewOn: model.
	^ view openInWorld
! !


!ProgressStatus methodsFor: 'accessing' stamp: 'F Olivero 5/22/2008 18:48'!
percentage
	^ percentage! !

!ProgressStatus methodsFor: 'events processing' stamp: 'F Olivero 5/22/2008 18:53'!
reset
	percentage _ 0.
	self triggerEvent:#selfChanged! !

!ProgressStatus methodsFor: 'events processing'!
step
	percentage _ percentage+ 1.
	self triggerEvent:#selfChanged! !

!ProgressStatus methodsFor: 'initialization' stamp: 'F Olivero 5/22/2008 18:34'!
initialize
	super initialize.
	percentage _ 0! !


!SliderLW methodsFor: 'initialization'!
initialize
	super initialize.
	bounds _ 10@10 extent: 200@50.
	showAxis _ true
! !

