net.sf.fmj.ejmf.toolkit.media
Class BasicCachingControl

java.lang.Object
  extended by net.sf.fmj.ejmf.toolkit.media.BasicCachingControl
All Implemented Interfaces:
CachingControl, Control

public class BasicCachingControl
extends java.lang.Object
implements CachingControl

This class provides a CachingControl for the AbstractController class. It provides a progress bar to monitor the media download. Its control Component is simply a button that stops the media download. Whenever there is a change in this BasicCachingControl, a CachingControlEvent is posted automatically. From the book: Essential JMF, Gordon, Talley (ISBN 0130801046). Used with permission.

Author:
Steve Talley & Rob Gordon
See Also:
AbstractController

Field Summary
 
Fields inherited from interface javax.media.CachingControl
LENGTH_UNKNOWN
 
Constructor Summary
BasicCachingControl(AbstractController c, long length)
          Constructs a BasicCachingControl for the given AbstractController.
 
Method Summary
 void addToProgress(long toAdd)
          Adds an amount of bytes to the media already downloaded.
 void blockWhilePaused()
          Blocks the current thread until the download is not paused.
 long getContentLength()
          Get the total number of bytes in the media being downloaded.
 long getContentProgress()
          Get the total number of bytes of media data that have been downloaded so far.
 java.awt.Component getControlComponent()
          Get a Component that provides additional download control.
 java.awt.Component getProgressBarComponent()
          Get a Component for displaying the download progress.
 boolean isDownloading()
          Check whether or not media is being downloaded.
 boolean isPaused()
          Tells whether the media download is paused or not.
 void reset(long length)
          Resets this BasicCachingControl.
 void setContentLength(long length)
          Set the length of the media without reinitializing the progress bar.
 void setContentProgress(long progress)
          Set the current progress of the media download.
 void setDone()
          Indicates that the media is fully downloaded.
 void setDownLoading(boolean isDownloading)
          Sets whether the AbstractController is downloading or not.
protected  void setPaused(boolean isPaused)
          Sets whether the AbstractController is paused or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicCachingControl

public BasicCachingControl(AbstractController c,
                           long length)
Constructs a BasicCachingControl for the given AbstractController. Uses the length arg to initialize the progress bar.

Parameters:
c - The AbstractController from which CachingControlEvents are posted whenever the status of this BasicCachingControl changes.
length - The length of the media to be downloaded.
Method Detail

setPaused

protected void setPaused(boolean isPaused)
Sets whether the AbstractController is paused or not.

Parameters:
isPaused - boolean indicating whether the media is paused.

isPaused

public boolean isPaused()
Tells whether the media download is paused or not.


blockWhilePaused

public void blockWhilePaused()
Blocks the current thread until the download is not paused.


setDownLoading

public void setDownLoading(boolean isDownloading)
Sets whether the AbstractController is downloading or not. Other methods in the BasicCachingControl call this method automatically.

Parameters:
isDownloading - boolean indicating whether the media is downloading.

reset

public void reset(long length)
Resets this BasicCachingControl. Sets the media length, reinitializes the progress bar, and posts a CachingControlEvent.

Parameters:
length - The length of the media.

setContentLength

public void setContentLength(long length)
Set the length of the media without reinitializing the progress bar.

Parameters:
length - The length of the media.

setContentProgress

public void setContentProgress(long progress)
Set the current progress of the media download.

Parameters:
progress - Number of bytes that have been downloaded.

addToProgress

public void addToProgress(long toAdd)
Adds an amount of bytes to the media already downloaded.

Parameters:
toAdd - Number of bytes that have been downloaded since the last time this method or setContentProgress have been called.

setDone

public void setDone()
Indicates that the media is fully downloaded.


isDownloading

public boolean isDownloading()
Check whether or not media is being downloaded.

Specified by:
isDownloading in interface CachingControl

getContentLength

public long getContentLength()
Get the total number of bytes in the media being downloaded. Returns LENGTH_UNKNOWN if this information is not available.

Specified by:
getContentLength in interface CachingControl
Returns:
The media length in bytes, or LENGTH_UNKNOWN.

getContentProgress

public long getContentProgress()
Get the total number of bytes of media data that have been downloaded so far.

Specified by:
getContentProgress in interface CachingControl
Returns:
The number of bytes downloaded.

getProgressBarComponent

public java.awt.Component getProgressBarComponent()
Get a Component for displaying the download progress.

Specified by:
getProgressBarComponent in interface CachingControl
Returns:
Progress bar GUI Component.

getControlComponent

public java.awt.Component getControlComponent()
Get a Component that provides additional download control. Returns null if only a progress bar is provided.

Specified by:
getControlComponent in interface CachingControl
Specified by:
getControlComponent in interface Control
Returns:
Download control GUI Component.