Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

java.awt
Class MediaTracker  view MediaTracker download MediaTracker.java

java.lang.Object
  extended byjava.awt.MediaTracker
All Implemented Interfaces:
java.io.Serializable

public class MediaTracker
extends java.lang.Object
implements java.io.Serializable

This class is used for keeping track of the status of various media objects. Media objects are tracked by assigning them an ID. It is possible to assign the same ID to mutliple objects, effectivly grouping them together. In this case the status flags (statusID(int, boolean) 55 ) and error flag (@link #isErrorID} and getErrorsID(int) 55 ) are ORed together. This means that you cannot say exactly which media object has which status, at most you can say that there are certain media objects with some certain status. At the moment only images are supported by this class.


Nested Class Summary
(package private)  class MediaTracker.MediaEntry
          This represents a media object that is tracked by a MediaTracker.
 
Field Summary
static int ABORTED
          Indicates that the loading operation has been aborted.
static int COMPLETE
          Indicates that the media has been successfully and completely loaded.
static int ERRORED
          Indicates that an error has occured during loading of the media.
(package private)  MediaTracker.MediaEntry head
          The head of the linked list of tracked media objects.
static int LOADING
          Indicates that the media is still loading.
(package private) static long serialVersionUID
          Our serialVersionUID for serialization.
(package private)  Component target
          The component on which the media is eventually been drawn.
 
Constructor Summary
MediaTracker(Component c)
          Constructs a new MediaTracker for the component c.
 
Method Summary
 void addImage(Image image, int id)
          Adds an image to the tracker with the specified ID.
 void addImage(Image image, int id, int width, int height)
          Adds an image to the tracker with the specified ID.
 boolean checkAll()
          Checks if all media objects have finished loading, i.e.
 boolean checkAll(boolean load)
          Checks if all media objects have finished loading, i.e.
 boolean checkID(int id)
          Checks if the media objects with ID have completed loading.
 boolean checkID(int id, boolean load)
          Checks if the media objects with ID have completed loading.
 java.lang.Object[] getErrorsAny()
          Returns all media objects that have encountered errors during loading.
 java.lang.Object[] getErrorsID(int id)
          Returns all media objects with the specified ID that have encountered an error.
 boolean isErrorAny()
          Checks if any of the registered media objects has encountered an error during loading.
 boolean isErrorID(int id)
          Returns true if any of the media objects with ID have encountered errors during loading, false otherwise.
 void removeImage(Image image)
          Removes an image from this MediaTracker.
 void removeImage(Image image, int id)
          Removes an image with the specified ID from this MediaTracker.
 void removeImage(Image image, int id, int width, int height)
          Removes an image with the specified ID and scale from this MediaTracker.
 int statusAll(boolean load)
          Returns the status flags of all registered media objects ORed together.
 int statusID(int id, boolean load)
          Returns the status flags of the media objects with the specified ID ORed together.
 void waitForAll()
          Waits for all media objects to finish loading, either by completing successfully or by aborting or encountering an error.
 boolean waitForAll(long ms)
          Waits for all media objects to finish loading, either by completing successfully or by aborting or encountering an error.
 void waitForID(int id)
          Waits for all media objects with the specified ID to finish loading, either by completing successfully or by aborting or encountering an error.
 boolean waitForID(int id, long ms)
          Waits for all media objects with the specified ID to finish loading, either by completing successfully or by aborting or encountering an error.
 
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
Indicates that the media is still loading.

See Also:
Constant Field Values

ABORTED

public static final int ABORTED
Indicates that the loading operation has been aborted.

See Also:
Constant Field Values

ERRORED

public static final int ERRORED
Indicates that an error has occured during loading of the media.

See Also:
Constant Field Values

COMPLETE

public static final int COMPLETE
Indicates that the media has been successfully and completely loaded.

See Also:
Constant Field Values

target

Component target
The component on which the media is eventually been drawn.


head

MediaTracker.MediaEntry head
The head of the linked list of tracked media objects.


serialVersionUID

static final long serialVersionUID
Our serialVersionUID for serialization.

See Also:
Constant Field Values
Constructor Detail

MediaTracker

public MediaTracker(Component c)
Constructs a new MediaTracker for the component c. The component should be the component that uses the media (i.e. draws it).

Method Detail

addImage

public void addImage(Image image,
                     int id)
Adds an image to the tracker with the specified ID.


addImage

public void addImage(Image image,
                     int id,
                     int width,
                     int height)
Adds an image to the tracker with the specified ID. The image is expected to be rendered with the specified width and height.


checkAll

public boolean checkAll()
Checks if all media objects have finished loading, i.e. are COMPLETE 55 , ABORTED 55 or ERRORED 55 . If the media objects are not already loading, a call to this method does not start loading. This is equivalent to a call to checkAll(false).


checkAll

public boolean checkAll(boolean load)
Checks if all media objects have finished loading, i.e. are COMPLETE 55 , ABORTED 55 or ERRORED 55 . If the media objects are not already loading, and load is true then a call to this method starts loading the media objects.


isErrorAny

public boolean isErrorAny()
Checks if any of the registered media objects has encountered an error during loading.


getErrorsAny

public java.lang.Object[] getErrorsAny()
Returns all media objects that have encountered errors during loading.


waitForAll

public void waitForAll()
                throws java.lang.InterruptedException
Waits for all media objects to finish loading, either by completing successfully or by aborting or encountering an error.


waitForAll

public boolean waitForAll(long ms)
                   throws java.lang.InterruptedException
Waits for all media objects to finish loading, either by completing successfully or by aborting or encountering an error. This method waits at most ms milliseconds. If the media objects have not completed loading within this timeframe, this method returns false, otherwise true.


statusAll

public int statusAll(boolean load)
Returns the status flags of all registered media objects ORed together. If load is true then media objects that are not already loading will be started to load.


checkID

public boolean checkID(int id)
Checks if the media objects with ID have completed loading.


checkID

public boolean checkID(int id,
                       boolean load)
Checks if the media objects with ID have completed loading. If load is true then media objects that are not already loading will be started to load.


isErrorID

public boolean isErrorID(int id)
Returns true if any of the media objects with ID have encountered errors during loading, false otherwise.


getErrorsID

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


waitForID

public void waitForID(int id)
               throws java.lang.InterruptedException
Waits for all media objects with the specified ID to finish loading, either by completing successfully or by aborting or encountering an error.


waitForID

public boolean waitForID(int id,
                         long ms)
                  throws java.lang.InterruptedException
Waits for all media objects with the specified ID to finish loading, either by completing successfully or by aborting or encountering an error. This method waits at most ms milliseconds. If the media objects have not completed loading within this timeframe, this method returns false, otherwise true.


statusID

public int statusID(int id,
                    boolean load)
Returns the status flags of the media objects with the specified ID ORed together. If load is true then media objects that are not already loading will be started to load.


removeImage

public void removeImage(Image image)
Removes an image from this MediaTracker.


removeImage

public void removeImage(Image image,
                        int id)
Removes an image with the specified ID from this MediaTracker.


removeImage

public void removeImage(Image image,
                        int id,
                        int width,
                        int height)
Removes an image with the specified ID and scale from this MediaTracker.