home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-27 | 2.4 KB | 88 lines |
- /*
- * @(#)OffScreenImageSource.java 1.9 96/03/30 Jim Graham
- *
- * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for NON-COMMERCIAL purposes and without
- * fee is hereby granted provided that this copyright notice
- * appears in all copies. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
-
- package sun.awt.image;
-
- import java.util.Hashtable;
- import java.awt.Component;
- import java.awt.image.ImageConsumer;
- import java.awt.image.ImageProducer;
- import java.awt.image.ColorModel;
-
- public class OffScreenImageSource implements ImageProducer {
- Component target;
- int width;
- int height;
- ImageRepresentation baseIR;
-
- public OffScreenImageSource(Component c, int w, int h) {
- target = c;
- width = w;
- height = h;
- }
-
- void setImageRep(ImageRepresentation ir) {
- baseIR = ir;
- }
-
- public ImageRepresentation getImageRep() {
- return baseIR;
- }
-
- // We can only have one consumer since we immediately return the data...
- private ImageConsumer theConsumer;
-
- public synchronized void addConsumer(ImageConsumer ic) {
- theConsumer = ic;
- produce();
- }
-
- public synchronized boolean isConsumer(ImageConsumer ic) {
- return (ic == theConsumer);
- }
-
- public synchronized void removeConsumer(ImageConsumer ic) {
- if (theConsumer == ic) {
- theConsumer = null;
- }
- }
-
- public void startProduction(ImageConsumer ic) {
- addConsumer(ic);
- }
-
- public void requestTopDownLeftRightResend(ImageConsumer ic) {
- }
-
- private native void sendPixels();
-
- private void produce() {
- if (theConsumer != null) {
- theConsumer.setDimensions(width, height);
- }
- if (theConsumer != null) {
- theConsumer.setProperties(new Hashtable());
- }
- sendPixels();
- if (theConsumer != null) {
- theConsumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
- }
- }
- }
-