001: /*
002: * @(#)QtImage.java 1.12 03/01/16
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 sun.awt.qt;
029:
030: import java.awt.Component;
031: import java.awt.Color;
032: import java.awt.ImageCapabilities;
033: import java.awt.Toolkit;
034: import java.awt.GraphicsConfiguration;
035: import java.awt.image.BufferedImage;
036: import java.awt.image.ImageObserver;
037: import java.awt.image.ImageProducer;
038: import java.awt.image.VolatileImage;
039:
040: import java.awt.Graphics;
041: import java.awt.Graphics2D;
042:
043: class QtVolatileImage extends java.awt.image.VolatileImage implements
044: QtDrawableImage {
045: private QtImage qtimage;
046: //6258458
047: private static final Component IMAGE_COMPONENT = new java.awt.Canvas();
048:
049: //6258458
050:
051: QtVolatileImage(int width, int height, GraphicsConfiguration gc) {
052: // 6258458: Following the same pattern as BufferedImage by passing
053: // IMAGE_COMPONENT. This allows the Image.getGraphics() to return
054: // the graphics object for all images except for encoded images.
055: // (See QtImage.getGraphics() for details)
056: qtimage = new QtImage(IMAGE_COMPONENT, width, height,
057: (QtGraphicsConfiguration) gc);
058: //6258458
059: Graphics g = qtimage.getGraphics();
060:
061: g.clearRect(0, 0, width, height);
062: g.dispose();
063: }
064:
065: QtVolatileImage(Component c, int width, int height) {
066: // 6262150 : Overlooked this constructor when fixing 6258458
067: qtimage = new QtImage(c, width, height);
068: // 6262150
069: Graphics g = qtimage.getGraphics();
070: g.clearRect(0, 0, width, height);
071: g.dispose();
072: }
073:
074: public QtDrawableImage getQtImage() {
075: return qtimage;
076: }
077:
078: public int getHeight(ImageObserver observer) {
079: return qtimage.getHeight(observer);
080: }
081:
082: public java.lang.Object getProperty(java.lang.String name,
083: ImageObserver observer) {
084: return qtimage.getProperty(name, observer);
085: }
086:
087: public int getWidth(ImageObserver observer) {
088: return qtimage.getWidth(observer);
089: }
090:
091: public boolean contentsLost() {
092: return false;
093: }
094:
095: public Graphics2D createGraphics() {
096: return (Graphics2D) qtimage.getGraphics();
097: }
098:
099: public void flush() {
100: qtimage.flush();
101: }
102:
103: public ImageCapabilities getCapabilities() {
104: return new ImageCapabilities(false);
105: }
106:
107: public Graphics getGraphics() {
108: return qtimage.getGraphics();
109:
110: }
111:
112: public boolean isComplete() {
113: return qtimage.isComplete();
114: }
115:
116: public int getHeight() {
117: return qtimage.getHeight();
118: }
119:
120: public BufferedImage getSnapshot() {
121: //Returns a static snapshot image of this object.
122:
123: //6199364: Fixed by swapping the width and height
124: BufferedImage img = qtimage.gc.createCompatibleImage(qtimage
125: .getWidth(), qtimage.getHeight());
126: Graphics g = img.getGraphics();
127: g.drawImage(qtimage, 0, 0, null);
128: g.dispose(); // 6240468
129:
130: return img;
131: }
132:
133: public ImageProducer getSource() {
134: return getSnapshot().getSource(); // 6240468
135: }
136:
137: public int getWidth() {
138: return qtimage.getWidth();
139: }
140:
141: public int validate(GraphicsConfiguration gc) {
142: return 0;
143: }
144:
145: public boolean draw(QtGraphics g, int x, int y,
146: ImageObserver observer) {
147: return qtimage.draw(g, x, y, observer);
148: }
149:
150: public boolean draw(QtGraphics g, int x, int y, int width,
151: int height, ImageObserver observer) {
152: return qtimage.draw(g, x, y, width, height, observer);
153: }
154:
155: public boolean draw(QtGraphics g, int x, int y, Color bg,
156: ImageObserver observer) {
157: return qtimage.draw(g, x, y, bg, observer);
158: }
159:
160: public boolean draw(QtGraphics g, int x, int y, int width,
161: int height, Color bg, ImageObserver observer) {
162: return qtimage.draw(g, x, y, width, height, bg, observer);
163: }
164:
165: public boolean draw(QtGraphics g, int dx1, int dy1, int dx2,
166: int dy2, int sx1, int sy1, int sx2, int sy2,
167: ImageObserver observer) {
168: return qtimage.draw(g, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
169: observer);
170: }
171:
172: public boolean draw(QtGraphics g, int dx1, int dy1, int dx2,
173: int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor,
174: ImageObserver observer) {
175: return qtimage.draw(g, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
176: bgcolor, observer);
177: }
178: }
|