home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / awt / image / OffScreenImageSource.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  2.4 KB  |  88 lines

  1. /*
  2.  * @(#)OffScreenImageSource.java    1.9 96/03/30 Jim Graham
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.awt.image;
  21.  
  22. import java.util.Hashtable;
  23. import java.awt.Component;
  24. import java.awt.image.ImageConsumer;
  25. import java.awt.image.ImageProducer;
  26. import java.awt.image.ColorModel;
  27.  
  28. public class OffScreenImageSource implements ImageProducer {
  29.     Component target;
  30.     int width;
  31.     int height;
  32.     ImageRepresentation baseIR;
  33.  
  34.     public OffScreenImageSource(Component c, int w, int h) {
  35.     target = c;
  36.     width = w;
  37.     height = h;
  38.     }
  39.  
  40.     void setImageRep(ImageRepresentation ir) {
  41.     baseIR = ir;
  42.     }
  43.  
  44.     public ImageRepresentation getImageRep() {
  45.     return baseIR;
  46.     }
  47.  
  48.     // We can only have one consumer since we immediately return the data...
  49.     private ImageConsumer theConsumer;
  50.  
  51.     public synchronized void addConsumer(ImageConsumer ic) {
  52.     theConsumer = ic;
  53.     produce();
  54.     }
  55.  
  56.     public synchronized boolean isConsumer(ImageConsumer ic) {
  57.     return (ic == theConsumer);
  58.     }
  59.  
  60.     public synchronized void removeConsumer(ImageConsumer ic) {
  61.     if (theConsumer == ic) {
  62.         theConsumer = null;
  63.     }
  64.     }
  65.  
  66.     public void startProduction(ImageConsumer ic) {
  67.     addConsumer(ic);
  68.     }
  69.  
  70.     public void requestTopDownLeftRightResend(ImageConsumer ic) {
  71.     }
  72.  
  73.     private native void sendPixels();
  74.  
  75.     private void produce() {
  76.     if (theConsumer != null) {
  77.         theConsumer.setDimensions(width, height);
  78.     }
  79.     if (theConsumer != null) {
  80.         theConsumer.setProperties(new Hashtable());
  81.     }
  82.     sendPixels();
  83.     if (theConsumer != null) {
  84.         theConsumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
  85.     }
  86.     }
  87. }
  88.