home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / sun / awt / image / OffScreenImageSource.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  1.8 KB  |  67 lines

  1. package sun.awt.image;
  2.  
  3. import java.awt.image.ImageConsumer;
  4. import java.awt.image.ImageProducer;
  5. import java.util.Hashtable;
  6.  
  7. public class OffScreenImageSource implements ImageProducer {
  8.    int width;
  9.    int height;
  10.    ImageRepresentation baseIR;
  11.    private ImageConsumer theConsumer;
  12.  
  13.    public OffScreenImageSource(int w, int h) {
  14.       this.width = w;
  15.       this.height = h;
  16.    }
  17.  
  18.    void setImageRep(ImageRepresentation ir) {
  19.       this.baseIR = ir;
  20.    }
  21.  
  22.    public ImageRepresentation getImageRep() {
  23.       return this.baseIR;
  24.    }
  25.  
  26.    public synchronized void addConsumer(ImageConsumer ic) {
  27.       this.theConsumer = ic;
  28.       this.produce();
  29.    }
  30.  
  31.    public synchronized boolean isConsumer(ImageConsumer ic) {
  32.       return ic == this.theConsumer;
  33.    }
  34.  
  35.    public synchronized void removeConsumer(ImageConsumer ic) {
  36.       if (this.theConsumer == ic) {
  37.          this.theConsumer = null;
  38.       }
  39.  
  40.    }
  41.  
  42.    public void startProduction(ImageConsumer ic) {
  43.       this.addConsumer(ic);
  44.    }
  45.  
  46.    public void requestTopDownLeftRightResend(ImageConsumer ic) {
  47.    }
  48.  
  49.    private native void sendPixels();
  50.  
  51.    private void produce() {
  52.       if (this.theConsumer != null) {
  53.          this.theConsumer.setDimensions(this.width, this.height);
  54.       }
  55.  
  56.       if (this.theConsumer != null) {
  57.          this.theConsumer.setProperties(new Hashtable());
  58.       }
  59.  
  60.       this.sendPixels();
  61.       if (this.theConsumer != null) {
  62.          this.theConsumer.imageComplete(2);
  63.       }
  64.  
  65.    }
  66. }
  67.