001: /*
002: * @(#)QtOffscreenImage.java 1.12 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: package java.awt;
028:
029: import java.util.Vector;
030:
031: import java.awt.image.ImageProducer;
032: import java.awt.image.ImageObserver;
033: import java.awt.image.ImageConsumer;
034:
035: import java.awt.image.ColorModel;
036:
037: /**
038: @version 1.15, 05/27/02 */
039:
040: /** An offscreen image created by Component.createImage(int width, int height). As it is not
041: possible to create a graphics from an image produced
042: through the image producer/consumer model this class exists to allow us to get the graphics
043: for an offscreen image. */
044:
045: class QtOffscreenImage extends QtImage implements ImageProducer {
046: Color foreground, background;
047: Font font;
048: private int originX, originY;
049:
050: // We can only have one consumer since we immediately return the data...
051: private ImageConsumer theConsumer;
052:
053: // 4679080 - create instance of props as in JPEG and GIF image architecture
054: private java.util.Hashtable props = new java.util.Hashtable();
055:
056: QtOffscreenImage(Component component, int width, int height,
057: QtGraphicsConfiguration gc) {
058: super (width, height, gc);
059:
060: if (component != null) {
061: foreground = component.getForeground();
062: background = component.getBackground();
063: font = component.getFont();
064: }
065:
066: // 4679080 - setProperties as n JEPG and GIF architecture.
067: setProperties(props);
068:
069: /* Clear image to background color. */
070:
071: Graphics g = getGraphics();
072:
073: g.clearRect(0, 0, width, height);
074: g.dispose();
075:
076: }
077:
078: public void flush() {
079: };
080:
081: public Graphics getGraphics() {
082: return new QtGraphics(this );
083: }
084:
085: public ImageProducer getSource() {
086: return this ;
087: }
088:
089: public synchronized void addConsumer(ImageConsumer ic) {
090: theConsumer = ic;
091: startProduction(ic);
092: }
093:
094: public synchronized boolean isConsumer(ImageConsumer ic) {
095: return (ic == theConsumer);
096: }
097:
098: public synchronized void removeConsumer(ImageConsumer ic) {
099: if (theConsumer == ic)
100: theConsumer = null;
101: }
102:
103: public void requestTopDownLeftRightResend(ImageConsumer ic) {
104: }
105:
106: public void startProduction(ImageConsumer ic) {
107:
108: if (ic == null)
109: return;
110:
111: int[] rgbArray;
112: ColorModel cm = ColorModel.getRGBdefault();
113:
114: ic.setDimensions(width, height);
115: ic.setColorModel(cm);
116:
117: rgbArray = getRGB(originX, originY, width, height, null, 0,
118: width);
119:
120: ic.setPixels(0, 0, width, height, cm, rgbArray, 0, width);
121:
122: ic.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
123: }
124:
125: }
|