FileDocCategorySizeDatePackage
SyntheticImage.javaAPI DocJava SE 5 API5378Fri Aug 26 14:58:00 BST 2005javax.swing.colorchooser

SyntheticImage

public 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.

version
1.24 12/19/03
author
James Gosling

Fields Summary
private SyntheticImageGenerator
root
protected int
width
protected int
height
static final ColorModel
cm
public static final int
pixMask
private Thread
runner
protected volatile boolean
aborted
Constructors Summary
protected SyntheticImage()

          
protected SyntheticImage(int w, int h)

 width = w; height = h; 
Methods Summary
public synchronized voidaddConsumer(java.awt.image.ImageConsumer ic)

        for (SyntheticImageGenerator ics = root; ics != null; ics = ics.next)
            if (ics.ic == ic) return;
        root = new SyntheticImageGenerator(ic, root, this);
    
protected voidcomputeRow(int y, int[] row)

        int p = 255-255*y/(height-1);
        p = (pixMask<<24)|(p<<16)|(p<<8)|p;
        for (int i = row.length; --i>=0; ) row[i] = p;
    
public synchronized booleanisConsumer(java.awt.image.ImageConsumer ic)

        for (SyntheticImageGenerator ics = root; ics != null; ics = ics.next)
            if (ics.ic == ic) return true;
        return false;
    
protected booleanisStatic()

 return true; 
public voidnextFrame(int param)

public synchronized voidremoveConsumer(java.awt.image.ImageConsumer ic)

        SyntheticImageGenerator prev = null;
        for (SyntheticImageGenerator ics = root; ics != null; ics = ics.next) {
            if (ics.ic == ic) {
                ics.useful = false;
                if (prev!=null) prev.next = ics.next;
                else root = ics.next;
                return;
            }
            prev = ics;
        }
    
public voidrequestTopDownLeftRightResend(java.awt.image.ImageConsumer ic)

public synchronized voidstartProduction(java.awt.image.ImageConsumer ic)

        addConsumer(ic);
        for (SyntheticImageGenerator ics = root; ics != null; ics = ics.next)
            if (ics.useful && !ics.isAlive())
                ics.start();