Acme
Class MediaTracker

java.lang.Object
  extended by Acme.MediaTracker

public class MediaTracker
extends java.lang.Object


Field Summary
static int ABORTED
          Flag indicating the download of some media was aborted.
static int COMPLETE
          Flag indicating the download of media completed successfully.
static int ERRORED
          Flag indicating the download of some media encountered an error.
static int LOADING
          Flag indicating some media is currently being loaded.
 
Constructor Summary
MediaTracker(java.awt.Component comp)
          Creates a Media tracker to track images for a given Component.
MediaTracker(java.awt.Toolkit tk)
          Creates a Media tracker to track images for a given Toolikit.
 
Method Summary
 void addImage(java.awt.Image image, int id)
          Adds an image to the list of images being tracked.
 void addImage(java.awt.Image image, int id, int w, int h)
          Adds a scaled image to the list of images being tracked.
 boolean checkAll()
          Checks to see if all images have finished loading but does not start loading the images if they are not already loading.
 boolean checkAll(boolean load)
          Checks to see if all images have finished loading.
 boolean checkID(int id)
          Checks to see if all images tagged with the indicated ID have finished loading, but does not start loading the images if they are not already loading.
 boolean checkID(int id, boolean load)
          Checks to see if all images tagged with the indicated ID have finished loading.
 java.lang.Object[] getErrorsAny()
          Returns a list of all media that have encountered an error.
 java.lang.Object[] getErrorsID(int id)
          Returns a list of media with the specified ID that have encountered an error.
 boolean isErrorAny()
          Checks the error status of all of the images.
 boolean isErrorID(int id)
          Checks the error status of all of the images with the specified ID.
 int statusAll(boolean load)
          Returns the boolean OR of the status of all of the media being tracked.
 int statusID(int id, boolean load)
          Returns the boolean OR of the status of all of the media with a given ID.
 void waitForAll()
          Starts loading all images.
 boolean waitForAll(long ms)
          Starts loading all images.
 void waitForID(int id)
          Starts loading all images with the specified ID and waits until they have finished loading or receive an error.
 boolean waitForID(int id, long ms)
          Starts loading all images with the specified ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOADING

public static final int LOADING
Flag indicating some media is currently being loaded.

See Also:
statusAll(boolean), statusID(int, boolean), Constant Field Values

ABORTED

public static final int ABORTED
Flag indicating the download of some media was aborted.

See Also:
statusAll(boolean), statusID(int, boolean), Constant Field Values

ERRORED

public static final int ERRORED
Flag indicating the download of some media encountered an error.

See Also:
statusAll(boolean), statusID(int, boolean), Constant Field Values

COMPLETE

public static final int COMPLETE
Flag indicating the download of media completed successfully.

See Also:
statusAll(boolean), statusID(int, boolean), Constant Field Values
Constructor Detail

MediaTracker

public MediaTracker(java.awt.Component comp)
Creates a Media tracker to track images for a given Component.

Parameters:
comp - the component on which the images will eventually be drawn

MediaTracker

public MediaTracker(java.awt.Toolkit tk)
Creates a Media tracker to track images for a given Toolikit. This is the only addition in the Acme version of MediaTracker.

Parameters:
tk - the Toolkit in which the images will eventually be drawn
Method Detail

addImage

public void addImage(java.awt.Image image,
                     int id)
Adds an image to the list of images being tracked. The image will eventually be rendered at its default (unscaled) size.

Parameters:
image - the image to be tracked
id - the identifier used to later track this image

addImage

public void addImage(java.awt.Image image,
                     int id,
                     int w,
                     int h)
Adds a scaled image to the list of images being tracked. The image will eventually be rendered at the indicated size.

Parameters:
image - the image to be tracked
id - the identifier used to later track this image
w - the width that the image will be rendered at
h - the height that the image will be rendered at

checkAll

public boolean checkAll()
Checks to see if all images have finished loading but does not start loading the images if they are not already loading. If there is an error while loading or scaling an image then that image is considered "complete." Use isErrorAny() or isErrorID() to check for errors.

Returns:
true if all images have finished loading, were aborted or encountered an error
See Also:
checkAll(boolean), checkID(int), isErrorAny(), isErrorID(int)

checkAll

public boolean checkAll(boolean load)
Checks to see if all images have finished loading. If load is true, starts loading any images that are not yet being loaded. If there is an error while loading or scaling an image then that image is considered "complete." Use isErrorAny() or isErrorID() to check for errors.

Parameters:
load - start loading the images if this parameter is true
Returns:
true if all images have finished loading, were aborted or encountered an error
See Also:
isErrorAny(), isErrorID(int), checkID(int, boolean), checkAll()

isErrorAny

public boolean isErrorAny()
Checks the error status of all of the images.

Returns:
true if any of the images had an error during loading
See Also:
isErrorID(int), getErrorsAny()

getErrorsAny

public java.lang.Object[] getErrorsAny()
Returns a list of all media that have encountered an error.

Returns:
an array of media objects or null if there are no errors
See Also:
isErrorAny(), getErrorsID(int)

waitForAll

public void waitForAll()
                throws java.lang.InterruptedException
Starts loading all images. Waits until they have finished loading, are aborted, or it receives an error. If there is an error while loading or scaling an image then that image is considered "complete." Use isErrorAny() or statusAll() to check for errors.

Throws:
java.lang.InterruptedException - Another thread has interrupted this thread.
See Also:
waitForID(int), waitForAll(long), isErrorAny(), isErrorID(int)

waitForAll

public boolean waitForAll(long ms)
                   throws java.lang.InterruptedException
Starts loading all images. Waits until they have finished loading, are aborted, it receives an error, or until the specified timeout has elapsed. If there is an error while loading or scaling an image then that image is considered "complete." Use isErrorAny() or statusAll() to check for errors.

Parameters:
ms - the length of time to wait for the loading to complete
Returns:
true if all images were successfully loaded
Throws:
java.lang.InterruptedException - Another thread has interrupted this thread.
See Also:
waitForID(int), waitForAll(), isErrorAny(), isErrorID(int)

statusAll

public int statusAll(boolean load)
Returns the boolean OR of the status of all of the media being tracked.

Parameters:
load - specifies whether to start the media loading
See Also:
statusID(int, boolean), LOADING, ABORTED, ERRORED, COMPLETE

checkID

public boolean checkID(int id)
Checks to see if all images tagged with the indicated ID have finished loading, but does not start loading the images if they are not already loading. If there is an error while loading or scaling an image then that image is considered "complete." Use isErrorAny() or isErrorID() to check for errors.

Parameters:
id - the identifier used to determine which images to check
Returns:
true if all tagged images have finished loading, were aborted, or an error occurred.
See Also:
checkID(int, boolean), checkAll(), isErrorAny(), isErrorID(int)

checkID

public boolean checkID(int id,
                       boolean load)
Checks to see if all images tagged with the indicated ID have finished loading. If load is true, starts loading any images with that ID that are not yet being loaded. If there is an error while loading or scaling an image then that image is considered "complete." Use isErrorAny() or isErrorID() to check for errors.

Parameters:
id - the identifier used to determine which images to check
load - start loading the images if this parameter is true
Returns:
true if all tagged images have finished loading, were aborted, or an error occurred
See Also:
checkID(int), checkAll(), isErrorAny(), isErrorID(int)

isErrorID

public boolean isErrorID(int id)
Checks the error status of all of the images with the specified ID.

Parameters:
id - the identifier used to determine which images to check
Returns:
true if any of the tagged images had an error during loading
See Also:
isErrorAny(), getErrorsID(int)

getErrorsID

public java.lang.Object[] getErrorsID(int id)
Returns a list of media with the specified ID that have encountered an error.

Parameters:
id - the identifier used to determine which images to return
Returns:
an array of media objects or null if there are no errors
See Also:
isErrorID(int), getErrorsAny()

waitForID

public void waitForID(int id)
               throws java.lang.InterruptedException
Starts loading all images with the specified ID and waits until they have finished loading or receive an error. If there is an error while loading or scaling an image then that image is considered "complete." Use statusID() or isErrorID() to check for errors.

Parameters:
id - the identifier used to determine which images to wait for
Throws:
java.lang.InterruptedException - Another thread has interrupted this thread.
See Also:
waitForAll(), waitForID(int, long), isErrorAny(), isErrorID(int)

waitForID

public boolean waitForID(int id,
                         long ms)
                  throws java.lang.InterruptedException
Starts loading all images with the specified ID. Waits until they have finished loading, an error occurs, or the specified timeout has elapsed. If there is an error while loading or scaling an image then that image is considered "complete." Use statusID or isErrorID to check for errors.

Parameters:
id - the identifier used to determine which images to wait for
ms - the length of time to wait for the loading to complete
Throws:
java.lang.InterruptedException - Another thread has interrupted this thread.
See Also:
waitForAll(), waitForID(int), isErrorAny(), isErrorID(int)

statusID

public int statusID(int id,
                    boolean load)
Returns the boolean OR of the status of all of the media with a given ID.

Parameters:
id - the identifier used to determine which images to check
load - specifies whether to start the media loading
See Also:
statusAll(boolean), LOADING, ABORTED, ERRORED, COMPLETE