0N/A/*
2362N/A * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.awt.image;
0N/A
0N/Aimport java.awt.Component;
0N/Aimport java.awt.Color;
0N/Aimport java.awt.SystemColor;
0N/Aimport java.awt.Font;
0N/Aimport java.awt.Graphics;
0N/Aimport java.awt.Graphics2D;
0N/Aimport java.awt.GraphicsEnvironment;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.ImageProducer;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.image.WritableRaster;
0N/Aimport sun.java2d.SunGraphics2D;
0N/Aimport sun.java2d.SurfaceData;
0N/A
0N/A/**
0N/A * This is a special variant of BufferedImage that keeps a reference to
0N/A * a Component. The Component's foreground and background colors and
0N/A * default font are used as the defaults for this image.
0N/A */
0N/Apublic class OffScreenImage extends BufferedImage {
0N/A
0N/A protected Component c;
0N/A private OffScreenImageSource osis;
0N/A private Font defaultFont;
0N/A
0N/A /**
0N/A * Constructs an OffScreenImage given a color model and tile,
0N/A * for offscreen rendering to be used with a given component.
0N/A * The component is used to obtain the foreground color, background
0N/A * color and font.
0N/A */
0N/A public OffScreenImage(Component c, ColorModel cm, WritableRaster raster,
0N/A boolean isRasterPremultiplied)
0N/A {
0N/A super(cm, raster, isRasterPremultiplied, null);
0N/A this.c = c;
0N/A initSurface(raster.getWidth(), raster.getHeight());
0N/A }
0N/A
0N/A public Graphics getGraphics() {
0N/A return createGraphics();
0N/A }
0N/A
0N/A public Graphics2D createGraphics() {
0N/A if (c == null) {
0N/A GraphicsEnvironment env =
0N/A GraphicsEnvironment.getLocalGraphicsEnvironment();
0N/A return env.createGraphics(this);
0N/A }
0N/A
0N/A Color bg = c.getBackground();
0N/A if (bg == null) {
0N/A bg = SystemColor.window;
0N/A }
0N/A
0N/A Color fg = c.getForeground();
0N/A if (fg == null) {
0N/A fg = SystemColor.windowText;
0N/A }
0N/A
0N/A Font font = c.getFont();
0N/A if (font == null) {
0N/A if (defaultFont == null) {
0N/A defaultFont = new Font("Dialog", Font.PLAIN, 12);
0N/A }
0N/A font = defaultFont;
0N/A }
0N/A
0N/A return new SunGraphics2D(SurfaceData.getPrimarySurfaceData(this),
0N/A fg, bg, font);
0N/A }
0N/A
0N/A private void initSurface(int width, int height) {
0N/A Graphics2D g2 = createGraphics();
0N/A try {
0N/A g2.clearRect(0, 0, width, height);
0N/A } finally {
0N/A g2.dispose();
0N/A }
0N/A }
0N/A
0N/A public ImageProducer getSource() {
0N/A if (osis == null) {
0N/A osis = new OffScreenImageSource(this);
0N/A }
0N/A return osis;
0N/A }
0N/A}