au.com.zip.cs
Class ImageObserverThread

java.lang.Object
  extended by java.lang.Thread
      extended by au.com.zip.cs.ImageObserverThread
All Implemented Interfaces:
ImageObserver, Runnable

public class ImageObserverThread
extends Thread
implements ImageObserver

A Runnable object that will run until the desired Image properties have been seen.
TODO: maybe I want to use a Channel instead of polling.

Author:
Cameron Simpson <cs@zip.com.au> 30apr2003

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ImageObserverThread(Image im, int infoflags)
          Return a new Thread to monitor the supplied Image until the cited ImageObserver flags have been seen.
 
Method Summary
 boolean imageUpdate(Image im, int infoflags, int x, int y, int width, int height)
           
 void run()
           
 void setImage(Image im)
          Set the image to monitor and Thread.start() the Thread running.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ImageObserverThread

public ImageObserverThread(Image im,
                           int infoflags)
Return a new Thread to monitor the supplied Image until the cited ImageObserver flags have been seen. Usual use is:
// wait for the image height to be available
 Thread th = ImageObserverThread.waitFor(image,HEIGHT);
 th.join();
Alternatively, one may want to wait for a drawing operation to finish. In this case you don't supply the Image until the drawing has been dispatched because Graphics.drawImage(Image,int,int,ImageObserver) wants an ImageObserver to watch the updates, and we will supply this ImageObserverThread:
Graphics g = destImage.getGraphics(); // what to draw on
 ImageObserverThread th = ImageObserverThread.waitFor(null,ALLBITS);
 if (!g.drawImage(srcImage,0,0,th))
 { th.setImage(destImage); // start()s the Thread as side-effect
   th.join();
 }

Parameters:
im - the Image to monitor
infoflags - the bitwise OR of the desired flags
Method Detail

setImage

public final void setImage(Image im)
Set the image to monitor and Thread.start() the Thread running.

Parameters:
im - the Image to monitor

run

public final void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread

imageUpdate

public final boolean imageUpdate(Image im,
                                 int infoflags,
                                 int x,
                                 int y,
                                 int width,
                                 int height)
Specified by:
imageUpdate in interface ImageObserver