All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class Acme.MediaTracker

java.lang.Object
   |
   +----Acme.MediaTracker

public class MediaTracker
extends Object
Slightly enhanced MediaTracker.

All this does is add a second constructor to MediaTracker, taking a Toolkit instead of a Component. For use in cases where you don't happen to have a Component around - basically, non-GUI applications.

You may ask, well if it's a non-GUI context then why do you have a Toolkit? Well, the Image stuff is pretty inextricably bound up with Toolkits, so when I wanted to write non-GUI Image stuff I just made myself a StubToolkit. MediaTracker is the only dependency on Component, and it's not a very necessary dependency since it uses only one method from Component and that same method exists in Toolkit. Hence, make a MediaTracker that optionally takes a Toolkit instead of a Component.

Here's a diff of the changes:


 *** MediaTracker.orig        Sat Mar 23 11:41:07 1996
 --- MediaTracker.java        Sat Mar 23 13:01:31 1996
 ***************
 *** 125,131 ****
    * @author         Jim Graham
    */
   public class MediaTracker {
 !     Component target;
       MediaEntry head;
       /**
 --- 126,133 ----
    * @author         Jim Graham
    */
   public class MediaTracker {
 !     Component compTarget;
 !     Toolkit tkTarget;
       MediaEntry head;
       /**
 ***************
 *** 133,142 ****
        * @param comp the component on which the images will eventually be drawn
        */
       public MediaTracker(Component comp) {
 !         target = comp;
       }
       /**
        * Adds an image to the list of images being tracked.  The image
        * will eventually be rendered at its default (unscaled) size.
        * @param image the image to be tracked
 --- 135,153 ----
        * @param comp the component on which the images will eventually be drawn
        */
       public MediaTracker(Component comp) {
 !         compTarget = comp;
       }
       /**
 +      * Creates a Media tracker to track images for a given Toolikit.
 +      * @param tk the Toolkit in which the images will eventually be drawn
 +      */
 +     public MediaTracker(Toolkit tk) {
 +         compTarget = null;
 +         tkTarget = tk;
 +     }
 + 
 +     /**
        * Adds an image to the list of images being tracked.  The image
        * will eventually be rendered at its default (unscaled) size.
        * @param image the image to be tracked
 ***************
 *** 621,629 ****
       }
       void startLoad() {
 !         if (tracker.target.prepareImage(image, width, height, this)) {
 !             setStatus(COMPLETE);
 !         }
       }
       public boolean imageUpdate(Image img, int infoflags,
 --- 632,645 ----
       }
       void startLoad() {
 !         if ( tracker.compTarget != null )
 !             if (tracker.compTarget.prepareImage(image, width, height, this)) {
 !                 setStatus(COMPLETE);
 !             }
 !         else
 !             if (tracker.tkTarget.prepareImage(image, width, height, this)) {
 !                 setStatus(COMPLETE);
 !             }
       }
       public boolean imageUpdate(Image img, int infoflags,
 

See Also:
MediaTracker, Toolkit

Variable Index

 o ABORTED
Flag indicating the download of some media was aborted.
 o COMPLETE
Flag indicating the download of media completed successfully.
 o ERRORED
Flag indicating the download of some media encountered an error.
 o LOADING
Flag indicating some media is currently being loaded.

Constructor Index

 o MediaTracker(Component)
Creates a Media tracker to track images for a given Component.
 o MediaTracker(Toolkit)
Creates a Media tracker to track images for a given Toolikit.

Method Index

 o addImage(Image, int)
Adds an image to the list of images being tracked.
 o addImage(Image, int, int, int)
Adds a scaled image to the list of images being tracked.
 o checkAll()
Checks to see if all images have finished loading but does not start loading the images if they are not already loading.
 o checkAll(boolean)
Checks to see if all images have finished loading.
 o checkID(int)
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.
 o checkID(int, boolean)
Checks to see if all images tagged with the indicated ID have finished loading.
 o getErrorsAny()
Returns a list of all media that have encountered an error.
 o getErrorsID(int)
Returns a list of media with the specified ID that have encountered an error.
 o isErrorAny()
Checks the error status of all of the images.
 o isErrorID(int)
Checks the error status of all of the images with the specified ID.
 o statusAll(boolean)
Returns the boolean OR of the status of all of the media being tracked.
 o statusID(int, boolean)
Returns the boolean OR of the status of all of the media with a given ID.
 o waitForAll()
Starts loading all images.
 o waitForAll(long)
Starts loading all images.
 o waitForID(int)
Starts loading all images with the specified ID and waits until they have finished loading or receive an error.
 o waitForID(int, long)
Starts loading all images with the specified ID.

Variables

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

See Also:
statusAll, statusID
 o ABORTED
 public static final int ABORTED
Flag indicating the download of some media was aborted.

See Also:
statusAll, statusID
 o ERRORED
 public static final int ERRORED
Flag indicating the download of some media encountered an error.

See Also:
statusAll, statusID
 o COMPLETE
 public static final int COMPLETE
Flag indicating the download of media completed successfully.

See Also:
statusAll, statusID

Constructors

 o MediaTracker
 public MediaTracker(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
 o MediaTracker
 public MediaTracker(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

Methods

 o addImage
 public void addImage(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
 o addImage
 public synchronized void addImage(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
 o 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, checkID, isErrorAny, isErrorID
 o checkAll
 public synchronized 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, checkID, checkAll
 o isErrorAny
 public synchronized 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, getErrorsAny
 o getErrorsAny
 public synchronized 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
 o waitForAll
 public void waitForAll() throws 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: InterruptedException
Another thread has interrupted this thread.
See Also:
waitForID, waitForAll, isErrorAny, isErrorID
 o waitForAll
 public synchronized boolean waitForAll(long ms) throws 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: InterruptedException
Another thread has interrupted this thread.
See Also:
waitForID, waitForAll, isErrorAny, isErrorID
 o 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, LOADING, ABORTED, ERRORED, COMPLETE
 o 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, checkAll, isErrorAny, isErrorID
 o checkID
 public synchronized 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, checkAll, isErrorAny, isErrorID
 o isErrorID
 public synchronized 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
 o getErrorsID
 public synchronized 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, getErrorsAny
 o waitForID
 public void waitForID(int id) throws 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: InterruptedException
Another thread has interrupted this thread.
See Also:
waitForAll, waitForID, isErrorAny, isErrorID
 o waitForID
 public synchronized boolean waitForID(int id,
                                       long ms) throws 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: InterruptedException
Another thread has interrupted this thread.
See Also:
waitForAll, waitForID, isErrorAny, isErrorID
 o 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, LOADING, ABORTED, ERRORED, COMPLETE

All Packages  Class Hierarchy  This Package  Previous  Next  Index

ACME Java  ACME Labs