javax.swing.colorchooser
Class SyntheticImage

java.lang.Object
  extended byjavax.swing.colorchooser.SyntheticImage
All Implemented Interfaces:
ImageProducer
Direct Known Subclasses:
DefaultHSBChooserPanel.HSBImage

abstract class SyntheticImage
extends Object
implements ImageProducer

A helper class to make computing synthetic images a little easier. All you need to do is define a subclass that overrides computeRow to compute a row of the image. It is passed the y coordinate of the row and an array into which to put the pixels in standard ARGB format.

Normal usage looks something like this:

 Image i = createImage(new SyntheticImage(200, 100) {
       protected void computeRow(int y, int[] row) {
   	for(int i = width; --i>=0; ) {
   	    int grey = i*255/(width-1);
   	    row[i] = (255<<24)|(grey<<16)|(grey<<8)|grey;
   	}
       }
   }
  
This creates a image 200 pixels wide and 100 pixels high that is a horizontal grey ramp, going from black on the left to white on the right.

If the image is to be a movie, override isStatic to return false, y cycling back to 0 is computeRow's signal that the next frame has started. It is acceptable (expected?) for computeRow(0,r) to pause until the appropriate time to start the next frame.

Author:
James Gosling

Field Summary
protected  boolean aborted
           
(package private) static ColorModel cm
           
protected  int height
           
static int pixMask
           
private  SyntheticImageGenerator root
           
private  Thread runner
           
protected  int width
           
 
Constructor Summary
protected SyntheticImage()
           
protected SyntheticImage(int w, int h)
           
 
Method Summary
 void addConsumer(ImageConsumer ic)
          Registers an ImageConsumer with the ImageProducer for access to the image data during a later reconstruction of the Image.
protected  void computeRow(int y, int[] row)
           
 boolean isConsumer(ImageConsumer ic)
          Determines if a specified ImageConsumer object is currently registered with this ImageProducer as one of its consumers.
protected  boolean isStatic()
           
 void nextFrame(int param)
           
 void removeConsumer(ImageConsumer ic)
          Removes the specified ImageConsumer object from the list of consumers currently registered to receive image data.
 void requestTopDownLeftRightResend(ImageConsumer ic)
          Requests, on behalf of the ImageConsumer, that the ImageProducer attempt to resend the image data one more time in TOPDOWNLEFTRIGHT order so that higher quality conversion algorithms which depend on receiving pixels in order can be used to produce a better output version of the image.
 void startProduction(ImageConsumer ic)
          Registers the specified ImageConsumer object as a consumer and starts an immediate reconstruction of the image data which will then be delivered to this consumer and any other consumer which might have already been registered with the producer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

private SyntheticImageGenerator root

width

protected int width

height

protected int height

cm

static final ColorModel cm

pixMask

public static final int pixMask
See Also:
Constant Field Values

runner

private Thread runner

aborted

protected volatile boolean aborted
Constructor Detail

SyntheticImage

protected SyntheticImage()

SyntheticImage

protected SyntheticImage(int w,
                         int h)
Method Detail

computeRow

protected void computeRow(int y,
                          int[] row)

addConsumer

public void addConsumer(ImageConsumer ic)
Description copied from interface: ImageProducer
Registers an ImageConsumer with the ImageProducer for access to the image data during a later reconstruction of the Image. The ImageProducer may, at its discretion, start delivering the image data to the consumer using the ImageConsumer interface immediately, or when the next available image reconstruction is triggered by a call to the startProduction method.

Specified by:
addConsumer in interface ImageProducer
Parameters:
ic - the specified ImageConsumer
See Also:
ImageProducer.startProduction(java.awt.image.ImageConsumer)

isConsumer

public boolean isConsumer(ImageConsumer ic)
Description copied from interface: ImageProducer
Determines if a specified ImageConsumer object is currently registered with this ImageProducer as one of its consumers.

Specified by:
isConsumer in interface ImageProducer
Parameters:
ic - the specified ImageConsumer
Returns:
true if the specified ImageConsumer is registered with this ImageProducer; false otherwise.

removeConsumer

public void removeConsumer(ImageConsumer ic)
Description copied from interface: ImageProducer
Removes the specified ImageConsumer object from the list of consumers currently registered to receive image data. It is not considered an error to remove a consumer that is not currently registered. The ImageProducer should stop sending data to this consumer as soon as is feasible.

Specified by:
removeConsumer in interface ImageProducer
Parameters:
ic - the specified ImageConsumer

startProduction

public void startProduction(ImageConsumer ic)
Description copied from interface: ImageProducer
Registers the specified ImageConsumer object as a consumer and starts an immediate reconstruction of the image data which will then be delivered to this consumer and any other consumer which might have already been registered with the producer. This method differs from the addConsumer method in that a reproduction of the image data should be triggered as soon as possible.

Specified by:
startProduction in interface ImageProducer
Parameters:
ic - the specified ImageConsumer
See Also:
ImageProducer.addConsumer(java.awt.image.ImageConsumer)

isStatic

protected boolean isStatic()

nextFrame

public void nextFrame(int param)

requestTopDownLeftRightResend

public void requestTopDownLeftRightResend(ImageConsumer ic)
Description copied from interface: ImageProducer
Requests, on behalf of the ImageConsumer, that the ImageProducer attempt to resend the image data one more time in TOPDOWNLEFTRIGHT order so that higher quality conversion algorithms which depend on receiving pixels in order can be used to produce a better output version of the image. The ImageProducer is free to ignore this call if it cannot resend the data in that order. If the data can be resent, the ImageProducer should respond by executing the following minimum set of ImageConsumer method calls:
	ic.setHints(TOPDOWNLEFTRIGHT | < otherhints >);
	ic.setPixels(...);	// As many times as needed
	ic.imageComplete();
 

Specified by:
requestTopDownLeftRightResend in interface ImageProducer
Parameters:
ic - the specified ImageConsumer
See Also:
ImageConsumer.setHints(int)