001: /*
002: * @(#)MWOffscreenImage.java 1.20 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package java.awt;
029:
030: import java.util.Vector;
031: import java.awt.image.ImageProducer;
032: import java.awt.image.ImageObserver;
033: import java.awt.image.ImageConsumer;
034: import java.awt.image.ColorModel;
035:
036: /** @version 1.16, 08/19/02 */
037:
038: /** An offscreen image created by Component.createImage(int width, int height). As it is not
039: possible to create a graphics from an image produced
040: through the image producer/consumer model this class exists to allow us to get the graphics
041: for an offscreen image. */
042:
043: class MWOffscreenImage extends MWImage implements ImageProducer {
044: Color foreground, background;
045: Font font;
046: private int originX, originY;
047: // We can only have one consumer since we immediately return the data...
048: private ImageConsumer theConsumer;
049: // 4679080 - create instance of props as in JPEG and GIF image architecture
050: private java.util.Hashtable props = new java.util.Hashtable();
051:
052: MWOffscreenImage(Component component, int width, int height,
053: MWGraphicsConfiguration gc) {
054: super (width, height, gc);
055: if (component != null) {
056: foreground = component.getForeground();
057: background = component.getBackground();
058: font = component.getFont();
059: }
060: // 4679080 - setProperties as n JEPG and GIF architecture.
061: setProperties(props);
062: /* Clear image to background color. */
063:
064: Graphics g = getGraphics();
065: g.clearRect(0, 0, width, height);
066: g.dispose();
067: }
068:
069: public void flush() {
070: };
071:
072: public Graphics getGraphics() {
073: return new MWGraphics(this );
074: }
075:
076: public ImageProducer getSource() {
077: return this ;
078: }
079:
080: public synchronized void addConsumer(ImageConsumer ic) {
081: theConsumer = ic;
082: startProduction(ic);
083: }
084:
085: public synchronized boolean isConsumer(ImageConsumer ic) {
086: return (ic == theConsumer);
087: }
088:
089: public synchronized void removeConsumer(ImageConsumer ic) {
090: if (theConsumer == ic)
091: theConsumer = null;
092: }
093:
094: public void requestTopDownLeftRightResend(ImageConsumer ic) {
095: }
096:
097: public void startProduction(ImageConsumer ic) {
098: if (ic == null)
099: return;
100: int[] rgbArray;
101: ColorModel cm = ColorModel.getRGBdefault();
102: ic.setDimensions(width, height);
103: ic.setColorModel(cm);
104: rgbArray = getRGB(originX, originY, width, height, null, 0,
105: width);
106: ic.setPixels(0, 0, width, height, cm, rgbArray, 0, width);
107: ic.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
108: }
109: }
|