0N/A/*
2362N/A * Copyright (c) 1998, 2006, 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.print;
0N/A
0N/Aimport java.util.Map;
0N/A
0N/Aimport java.awt.BasicStroke;
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Composite;
0N/Aimport java.awt.Graphics;
0N/Aimport java.awt.Graphics2D;
0N/Aimport java.awt.Font;
0N/Aimport java.awt.FontMetrics;
0N/Aimport java.awt.font.FontRenderContext;
0N/Aimport java.awt.Graphics;
0N/Aimport java.awt.GraphicsConfiguration;
0N/Aimport java.awt.Image;
0N/Aimport java.awt.Paint;
0N/Aimport java.awt.Rectangle;
0N/Aimport java.awt.Shape;
0N/Aimport java.awt.Stroke;
0N/Aimport java.awt.RenderingHints;
0N/Aimport java.awt.RenderingHints.Key;
0N/A
0N/Aimport java.awt.font.GlyphVector;
0N/Aimport java.awt.font.TextLayout;
0N/A
0N/Aimport java.awt.geom.AffineTransform;
0N/Aimport java.awt.geom.Line2D;
0N/Aimport java.awt.geom.Point2D;
0N/Aimport java.awt.geom.Rectangle2D;
0N/Aimport java.awt.geom.RoundRectangle2D;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.BufferedImageOp;
0N/Aimport java.awt.image.ImageObserver;
0N/Aimport java.awt.image.RenderedImage;
0N/Aimport java.awt.image.renderable.RenderableImage;
0N/Aimport java.awt.print.PrinterGraphics;
0N/Aimport java.awt.print.PrinterJob;
0N/A
0N/Aimport java.text.AttributedCharacterIterator;
0N/A
0N/Aimport sun.java2d.Spans;
0N/A
0N/Apublic class PeekGraphics extends Graphics2D
0N/A implements PrinterGraphics,
0N/A ImageObserver,
0N/A Cloneable {
0N/A
0N/A /**
0N/A * Drawing methods will be forwarded to this object.
0N/A */
0N/A Graphics2D mGraphics;
0N/A
0N/A /**
0N/A * The PrinterJob controlling the current printing.
0N/A */
0N/A PrinterJob mPrinterJob;
0N/A
0N/A /**
0N/A * Keeps track of where drawing occurs on the page.
0N/A */
0N/A private Spans mDrawingArea = new Spans();
0N/A
0N/A /**
0N/A * Track information about the types of drawing
0N/A * performed by the printing application.
0N/A */
0N/A private PeekMetrics mPrintMetrics = new PeekMetrics();
0N/A
0N/A /**
0N/A * If true the application will only be drawing AWT style
0N/A * graphics, no Java2D graphics.
0N/A */
0N/A private boolean mAWTDrawingOnly = false;
0N/A
0N/A /**
0N/A * The new PeekGraphics2D will forward state changing
0N/A * calls to 'graphics'. 'printerJob' is stored away
0N/A * so that the printing application can get the PrinterJob
0N/A * if needed.
0N/A */
0N/A public PeekGraphics(Graphics2D graphics, PrinterJob printerJob) {
0N/A
0N/A mGraphics = graphics;
0N/A mPrinterJob = printerJob;
0N/A }
0N/A
0N/A /**
0N/A * Return the Graphics2D object that does the drawing
0N/A * for this instance.
0N/A */
0N/A public Graphics2D getDelegate() {
0N/A return mGraphics;
0N/A }
0N/A
0N/A /**
0N/A * Set the Graphics2D instance which will do the
0N/A * drawing.
0N/A */
0N/A public void setDelegate(Graphics2D graphics) {
0N/A mGraphics = graphics;
0N/A }
0N/A
0N/A public PrinterJob getPrinterJob() {
0N/A return mPrinterJob;
0N/A }
0N/A
0N/A /**
0N/A * The caller promises that only AWT graphics will be drawn.
0N/A * The print system can use this information to make general
0N/A * assumptions about the types of graphics to be drawn without
0N/A * requiring the application to draw the contents multiple
0N/A * times.
0N/A */
0N/A public void setAWTDrawingOnly() {
0N/A mAWTDrawingOnly = true;
0N/A }
0N/A
0N/A public boolean getAWTDrawingOnly() {
0N/A return mAWTDrawingOnly;
0N/A }
0N/A
0N/A /**
0N/A * Return a Spans instance describing the parts of the page in
0N/A * to which drawing occurred.
0N/A */
0N/A public Spans getDrawingArea() {
0N/A return mDrawingArea;
0N/A }
0N/A
0N/A /**
0N/A * Returns the device configuration associated with this Graphics2D.
0N/A */
0N/A public GraphicsConfiguration getDeviceConfiguration() {
0N/A return ((RasterPrinterJob)mPrinterJob).getPrinterGraphicsConfig();
0N/A }
0N/A
0N/A/* The Delegated Graphics Methods */
0N/A
0N/A /**
0N/A * Creates a new <code>Graphics</code> object that is
0N/A * a copy of this <code>Graphics</code> object.
0N/A * @return a new graphics context that is a copy of
0N/A * this graphics context.
0N/A * @since JDK1.0
0N/A */
0N/A public Graphics create() {
0N/A PeekGraphics newGraphics = null;
0N/A
0N/A try {
0N/A newGraphics = (PeekGraphics) clone();
0N/A newGraphics.mGraphics = (Graphics2D) mGraphics.create();
0N/A
0N/A /* This exception can not happen unless this
0N/A * class no longer implements the Cloneable
0N/A * interface.
0N/A */
0N/A } catch (CloneNotSupportedException e) {
0N/A // can never happen.
0N/A }
0N/A
0N/A return newGraphics;
0N/A }
0N/A
0N/A /**
0N/A * Translates the origin of the graphics context to the point
0N/A * (<i>x</i>,&nbsp;<i>y</i>) in the current coordinate system.
0N/A * Modifies this graphics context so that its new origin corresponds
0N/A * to the point (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's
0N/A * original coordinate system. All coordinates used in subsequent
0N/A * rendering operations on this graphics context will be relative
0N/A * to this new origin.
0N/A * @param x the <i>x</i> coordinate.
0N/A * @param y the <i>y</i> coordinate.
0N/A * @since JDK1.0
0N/A */
0N/A public void translate(int x, int y) {
0N/A mGraphics.translate(x, y);
0N/A }
0N/A
0N/A /**
0N/A * Concatenates the current transform of this Graphics2D with a
0N/A * translation transformation.
0N/A * This is equivalent to calling transform(T), where T is an
0N/A * AffineTransform represented by the following matrix:
0N/A * <pre>
0N/A * [ 1 0 tx ]
0N/A * [ 0 1 ty ]
0N/A * [ 0 0 1 ]
0N/A * </pre>
0N/A */
0N/A public void translate(double tx, double ty) {
0N/A mGraphics.translate(tx, ty);
0N/A }
0N/A
0N/A /**
0N/A * Concatenates the current transform of this Graphics2D with a
0N/A * rotation transformation.
0N/A * This is equivalent to calling transform(R), where R is an
0N/A * AffineTransform represented by the following matrix:
0N/A * <pre>
0N/A * [ cos(theta) -sin(theta) 0 ]
0N/A * [ sin(theta) cos(theta) 0 ]
0N/A * [ 0 0 1 ]
0N/A * </pre>
0N/A * Rotating with a positive angle theta rotates points on the positive
0N/A * x axis toward the positive y axis.
0N/A * @param theta The angle of rotation in radians.
0N/A */
0N/A public void rotate(double theta) {
0N/A mGraphics.rotate(theta);
0N/A }
0N/A
0N/A /**
0N/A * Concatenates the current transform of this Graphics2D with a
0N/A * translated rotation transformation.
0N/A * This is equivalent to the following sequence of calls:
0N/A * <pre>
0N/A * translate(x, y);
0N/A * rotate(theta);
0N/A * translate(-x, -y);
0N/A * </pre>
0N/A * Rotating with a positive angle theta rotates points on the positive
0N/A * x axis toward the positive y axis.
0N/A * @param theta The angle of rotation in radians.
0N/A * @param x The x coordinate of the origin of the rotation
0N/A * @param y The x coordinate of the origin of the rotation
0N/A */
0N/A public void rotate(double theta, double x, double y) {
0N/A mGraphics.rotate(theta, x, y);
0N/A }
0N/A
0N/A /**
0N/A * Concatenates the current transform of this Graphics2D with a
0N/A * scaling transformation.
0N/A * This is equivalent to calling transform(S), where S is an
0N/A * AffineTransform represented by the following matrix:
0N/A * <pre>
0N/A * [ sx 0 0 ]
0N/A * [ 0 sy 0 ]
0N/A * [ 0 0 1 ]
0N/A * </pre>
0N/A */
0N/A public void scale(double sx, double sy) {
0N/A mGraphics.scale(sx, sy);
0N/A }
0N/A
0N/A /**
0N/A * Concatenates the current transform of this Graphics2D with a
0N/A * shearing transformation.
0N/A * This is equivalent to calling transform(SH), where SH is an
0N/A * AffineTransform represented by the following matrix:
0N/A * <pre>
0N/A * [ 1 shx 0 ]
0N/A * [ shy 1 0 ]
0N/A * [ 0 0 1 ]
0N/A * </pre>
0N/A * @param shx The factor by which coordinates are shifted towards the
0N/A * positive X axis direction according to their Y coordinate
0N/A * @param shy The factor by which coordinates are shifted towards the
0N/A * positive Y axis direction according to their X coordinate
0N/A */
0N/A public void shear(double shx, double shy) {
0N/A mGraphics.shear(shx, shy);
0N/A }
0N/A
0N/A /**
0N/A * Gets this graphics context's current color.
0N/A * @return this graphics context's current color.
0N/A * @see java.awt.Color
0N/A * @see java.awt.Graphics#setColor
0N/A * @since JDK1.0
0N/A */
0N/A public Color getColor() {
0N/A return mGraphics.getColor();
0N/A }
0N/A
0N/A /**
0N/A * Sets this graphics context's current color to the specified
0N/A * color. All subsequent graphics operations using this graphics
0N/A * context use this specified color.
0N/A * @param c the new rendering color.
0N/A * @see java.awt.Color
0N/A * @see java.awt.Graphics#getColor
0N/A * @since JDK1.0
0N/A */
0N/A public void setColor(Color c) {
0N/A mGraphics.setColor(c);
0N/A }
0N/A
0N/A /**
0N/A * Sets the paint mode of this graphics context to overwrite the
0N/A * destination with this graphics context's current color.
0N/A * This sets the logical pixel operation function to the paint or
0N/A * overwrite mode. All subsequent rendering operations will
0N/A * overwrite the destination with the current color.
0N/A * @since JDK1.0
0N/A */
0N/A public void setPaintMode() {
0N/A mGraphics.setPaintMode();
0N/A }
0N/A
0N/A /**
0N/A * Sets the paint mode of this graphics context to alternate between
0N/A * this graphics context's current color and the new specified color.
0N/A * This specifies that logical pixel operations are performed in the
0N/A * XOR mode, which alternates pixels between the current color and
0N/A * a specified XOR color.
0N/A * <p>
0N/A * When drawing operations are performed, pixels which are the
0N/A * current color are changed to the specified color, and vice versa.
0N/A * <p>
0N/A * Pixels that are of colors other than those two colors are changed
0N/A * in an unpredictable but reversible manner; if the same figure is
0N/A * drawn twice, then all pixels are restored to their original values.
0N/A * @param c1 the XOR alternation color
0N/A * @since JDK1.0
0N/A */
0N/A public void setXORMode(Color c1) {
0N/A mGraphics.setXORMode(c1);
0N/A }
0N/A
0N/A /**
0N/A * Gets the current font.
0N/A * @return this graphics context's current font.
0N/A * @see java.awt.Font
0N/A * @see java.awt.Graphics#setFont
0N/A * @since JDK1.0
0N/A */
0N/A public Font getFont() {
0N/A return mGraphics.getFont();
0N/A }
0N/A
0N/A /**
0N/A * Sets this graphics context's font to the specified font.
0N/A * All subsequent text operations using this graphics context
0N/A * use this font.
0N/A * @param font the font.
0N/A * @see java.awt.Graphics#getFont
0N/A * @see java.awt.Graphics#drawChars(java.lang.String, int, int)
0N/A * @see java.awt.Graphics#drawString(byte[], int, int, int, int)
0N/A * @see java.awt.Graphics#drawBytes(char[], int, int, int, int)
0N/A * @since JDK1.0
0N/A */
0N/A public void setFont(Font font) {
0N/A mGraphics.setFont(font);
0N/A }
0N/A
0N/A /**
0N/A * Gets the font metrics for the specified font.
0N/A * @return the font metrics for the specified font.
0N/A * @param f the specified font
0N/A * @see java.awt.Graphics#getFont
0N/A * @see java.awt.FontMetrics
0N/A * @see java.awt.Graphics#getFontMetrics()
0N/A * @since JDK1.0
0N/A */
0N/A public FontMetrics getFontMetrics(Font f) {
0N/A return mGraphics.getFontMetrics(f);
0N/A }
0N/A
0N/A /**
0N/A * Get the rendering context of the font
0N/A * within this Graphics2D context.
0N/A */
0N/A public FontRenderContext getFontRenderContext() {
0N/A return mGraphics.getFontRenderContext();
0N/A }
0N/A
0N/A /**
0N/A * Returns the bounding rectangle of the current clipping area.
0N/A * The coordinates in the rectangle are relative to the coordinate
0N/A * system origin of this graphics context.
0N/A * @return the bounding rectangle of the current clipping area.
0N/A * @see java.awt.Graphics#getClip
0N/A * @see java.awt.Graphics#clipRect
0N/A * @see java.awt.Graphics#setClip(int, int, int, int)
0N/A * @see java.awt.Graphics#setClip(Shape)
0N/A * @since JDK1.1
0N/A */
0N/A public Rectangle getClipBounds() {
0N/A return mGraphics.getClipBounds();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Intersects the current clip with the specified rectangle.
0N/A * The resulting clipping area is the intersection of the current
0N/A * clipping area and the specified rectangle.
0N/A * This method can only be used to make the current clip smaller.
0N/A * To set the current clip larger, use any of the setClip methods.
0N/A * Rendering operations have no effect outside of the clipping area.
0N/A * @param x the x coordinate of the rectangle to intersect the clip with
0N/A * @param y the y coordinate of the rectangle to intersect the clip with
0N/A * @param width the width of the rectangle to intersect the clip with
0N/A * @param height the height of the rectangle to intersect the clip with
0N/A * @see #setClip(int, int, int, int)
0N/A * @see #setClip(Shape)
0N/A */
0N/A public void clipRect(int x, int y, int width, int height) {
0N/A mGraphics.clipRect(x, y, width, height);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the current clip to the rectangle specified by the given
0N/A * coordinates.
0N/A * Rendering operations have no effect outside of the clipping area.
0N/A * @param x the <i>x</i> coordinate of the new clip rectangle.
0N/A * @param y the <i>y</i> coordinate of the new clip rectangle.
0N/A * @param width the width of the new clip rectangle.
0N/A * @param height the height of the new clip rectangle.
0N/A * @see java.awt.Graphics#clipRect
0N/A * @see java.awt.Graphics#setClip(Shape)
0N/A * @since JDK1.1
0N/A */
0N/A public void setClip(int x, int y, int width, int height) {
0N/A mGraphics.setClip(x, y, width, height);
0N/A }
0N/A
0N/A /**
0N/A * Gets the current clipping area.
0N/A * @return a <code>Shape</code> object representing the
0N/A * current clipping area.
0N/A * @see java.awt.Graphics#getClipBounds
0N/A * @see java.awt.Graphics#clipRect
0N/A * @see java.awt.Graphics#setClip(int, int, int, int)
0N/A * @see java.awt.Graphics#setClip(Shape)
0N/A * @since JDK1.1
0N/A */
0N/A public Shape getClip() {
0N/A return mGraphics.getClip();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the current clipping area to an arbitrary clip shape.
0N/A * Not all objects which implement the <code>Shape</code>
0N/A * interface can be used to set the clip. The only
0N/A * <code>Shape</code> objects which are guaranteed to be
0N/A * supported are <code>Shape</code> objects which are
0N/A * obtained via the <code>getClip</code> method and via
0N/A * <code>Rectangle</code> objects.
0N/A * @see java.awt.Graphics#getClip()
0N/A * @see java.awt.Graphics#clipRect
0N/A * @see java.awt.Graphics#setClip(int, int, int, int)
0N/A * @since JDK1.1
0N/A */
0N/A public void setClip(Shape clip) {
0N/A mGraphics.setClip(clip);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Copies an area of the component by a distance specified by
0N/A * <code>dx</code> and <code>dy</code>. From the point specified
0N/A * by <code>x</code> and <code>y</code>, this method
0N/A * copies downwards and to the right. To copy an area of the
0N/A * component to the left or upwards, specify a negative value for
0N/A * <code>dx</code> or <code>dy</code>.
0N/A * If a portion of the source rectangle lies outside the bounds
0N/A * of the component, or is obscured by another window or component,
0N/A * <code>copyArea</code> will be unable to copy the associated
0N/A * pixels. The area that is omitted can be refreshed by calling
0N/A * the component's <code>paint</code> method.
0N/A * @param x the <i>x</i> coordinate of the source rectangle.
0N/A * @param y the <i>y</i> coordinate of the source rectangle.
0N/A * @param width the width of the source rectangle.
0N/A * @param height the height of the source rectangle.
0N/A * @param dx the horizontal distance to copy the pixels.
0N/A * @param dy the vertical distance to copy the pixels.
0N/A * @since JDK1.0
0N/A */
0N/A public void copyArea(int x, int y, int width, int height,
0N/A int dx, int dy) {
0N/A // This method is not supported for printing so we do nothing here.
0N/A }
0N/A
0N/A /**
0N/A * Draws a line, using the current color, between the points
0N/A * <code>(x1,&nbsp;y1)</code> and <code>(x2,&nbsp;y2)</code>
0N/A * in this graphics context's coordinate system.
0N/A * @param x1 the first point's <i>x</i> coordinate.
0N/A * @param y1 the first point's <i>y</i> coordinate.
0N/A * @param x2 the second point's <i>x</i> coordinate.
0N/A * @param y2 the second point's <i>y</i> coordinate.
0N/A * @since JDK1.0
0N/A */
0N/A public void drawLine(int x1, int y1, int x2, int y2) {
0N/A addStrokeShape(new Line2D.Float(x1, y1, x2, y2));
0N/A mPrintMetrics.draw(this);
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Fills the specified rectangle.
0N/A * The left and right edges of the rectangle are at
0N/A * <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>.
0N/A * The top and bottom edges are at
0N/A * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.
0N/A * The resulting rectangle covers an area
0N/A * <code>width</code> pixels wide by
0N/A * <code>height</code> pixels tall.
0N/A * The rectangle is filled using the graphics context's current color.
0N/A * @param x the <i>x</i> coordinate
0N/A * of the rectangle to be filled.
0N/A * @param y the <i>y</i> coordinate
0N/A * of the rectangle to be filled.
0N/A * @param width the width of the rectangle to be filled.
0N/A * @param height the height of the rectangle to be filled.
0N/A * @see java.awt.Graphics#fillRect
0N/A * @see java.awt.Graphics#clearRect
0N/A * @since JDK1.0
0N/A */
0N/A public void fillRect(int x, int y, int width, int height) {
0N/A
0N/A addDrawingRect(new Rectangle2D.Float(x, y, width, height));
0N/A mPrintMetrics.fill(this);
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Clears the specified rectangle by filling it with the background
0N/A * color of the current drawing surface. This operation does not
0N/A * use the current paint mode.
0N/A * <p>
0N/A * Beginning with Java&nbsp;1.1, the background color
0N/A * of offscreen images may be system dependent. Applications should
0N/A * use <code>setColor</code> followed by <code>fillRect</code> to
0N/A * ensure that an offscreen image is cleared to a specific color.
0N/A * @param x the <i>x</i> coordinate of the rectangle to clear.
0N/A * @param y the <i>y</i> coordinate of the rectangle to clear.
0N/A * @param width the width of the rectangle to clear.
0N/A * @param height the height of the rectangle to clear.
0N/A * @see java.awt.Graphics#fillRect(int, int, int, int)
0N/A * @see java.awt.Graphics#drawRect
0N/A * @see java.awt.Graphics#setColor(java.awt.Color)
0N/A * @see java.awt.Graphics#setPaintMode
0N/A * @see java.awt.Graphics#setXORMode(java.awt.Color)
0N/A * @since JDK1.0
0N/A */
0N/A public void clearRect(int x, int y, int width, int height) {
0N/A Rectangle2D.Float rect = new Rectangle2D.Float(x, y, width, height);
0N/A addDrawingRect(rect);
0N/A mPrintMetrics.clear(this);
0N/A }
0N/A
0N/A /**
0N/A * Draws an outlined round-cornered rectangle using this graphics
0N/A * context's current color. The left and right edges of the rectangle
0N/A * are at <code>x</code> and <code>x&nbsp;+&nbsp;width</code>,
0N/A * respectively. The top and bottom edges of the rectangle are at
0N/A * <code>y</code> and <code>y&nbsp;+&nbsp;height</code>.
0N/A * @param x the <i>x</i> coordinate of the rectangle to be drawn.
0N/A * @param y the <i>y</i> coordinate of the rectangle to be drawn.
0N/A * @param width the width of the rectangle to be drawn.
0N/A * @param height the height of the rectangle to be drawn.
0N/A * @param arcWidth the horizontal diameter of the arc
0N/A * at the four corners.
0N/A * @param arcHeight the vertical diameter of the arc
0N/A * at the four corners.
0N/A * @see java.awt.Graphics#fillRoundRect
0N/A * @since JDK1.0
0N/A */
0N/A public void drawRoundRect(int x, int y, int width, int height,
0N/A int arcWidth, int arcHeight) {
0N/A addStrokeShape(new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight));
0N/A mPrintMetrics.draw(this);
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Fills the specified rounded corner rectangle with the current color.
0N/A * The left and right edges of the rectangle
0N/A * are at <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>,
0N/A * respectively. The top and bottom edges of the rectangle are at
0N/A * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.
0N/A * @param x the <i>x</i> coordinate of the rectangle to be filled.
0N/A * @param y the <i>y</i> coordinate of the rectangle to be filled.
0N/A * @param width the width of the rectangle to be filled.
0N/A * @param height the height of the rectangle to be filled.
0N/A * @param arcWidth the horizontal diameter
0N/A * of the arc at the four corners.
0N/A * @param arcHeight the vertical diameter
0N/A * of the arc at the four corners.
0N/A * @see java.awt.Graphics#drawRoundRect
0N/A * @since JDK1.0
0N/A */
0N/A public void fillRoundRect(int x, int y, int width, int height,
0N/A int arcWidth, int arcHeight) {
0N/A Rectangle2D.Float rect = new Rectangle2D.Float(x, y,width, height);
0N/A addDrawingRect(rect);
0N/A mPrintMetrics.fill(this);
0N/A }
0N/A
0N/A /**
0N/A * Draws the outline of an oval.
0N/A * The result is a circle or ellipse that fits within the
0N/A * rectangle specified by the <code>x</code>, <code>y</code>,
0N/A * <code>width</code>, and <code>height</code> arguments.
0N/A * <p>
0N/A * The oval covers an area that is
0N/A * <code>width&nbsp;+&nbsp;1</code> pixels wide
0N/A * and <code>height&nbsp;+&nbsp;1</code> pixels tall.
0N/A * @param x the <i>x</i> coordinate of the upper left
0N/A * corner of the oval to be drawn.
0N/A * @param y the <i>y</i> coordinate of the upper left
0N/A * corner of the oval to be drawn.
0N/A * @param width the width of the oval to be drawn.
0N/A * @param height the height of the oval to be drawn.
0N/A * @see java.awt.Graphics#fillOval
0N/A * @since JDK1.0
0N/A */
0N/A public void drawOval(int x, int y, int width, int height) {
0N/A addStrokeShape(new Rectangle2D.Float(x, y, width, height));
0N/A mPrintMetrics.draw(this);
0N/A }
0N/A
0N/A /**
0N/A * Fills an oval bounded by the specified rectangle with the
0N/A * current color.
0N/A * @param x the <i>x</i> coordinate of the upper left corner
0N/A * of the oval to be filled.
0N/A * @param y the <i>y</i> coordinate of the upper left corner
0N/A * of the oval to be filled.
0N/A * @param width the width of the oval to be filled.
0N/A * @param height the height of the oval to be filled.
0N/A * @see java.awt.Graphics#drawOval
0N/A * @since JDK1.0
0N/A */
0N/A public void fillOval(int x, int y, int width, int height) {
0N/A Rectangle2D.Float rect = new Rectangle2D.Float(x, y, width, height);
0N/A addDrawingRect(rect);
0N/A mPrintMetrics.fill(this);
0N/A
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Draws the outline of a circular or elliptical arc
0N/A * covering the specified rectangle.
0N/A * <p>
0N/A * The resulting arc begins at <code>startAngle</code> and extends
0N/A * for <code>arcAngle</code> degrees, using the current color.
0N/A * Angles are interpreted such that 0&nbsp;degrees
0N/A * is at the 3&nbsp;o'clock position.
0N/A * A positive value indicates a counter-clockwise rotation
0N/A * while a negative value indicates a clockwise rotation.
0N/A * <p>
0N/A * The center of the arc is the center of the rectangle whose origin
0N/A * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
0N/A * <code>width</code> and <code>height</code> arguments.
0N/A * <p>
0N/A * The resulting arc covers an area
0N/A * <code>width&nbsp;+&nbsp;1</code> pixels wide
0N/A * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
0N/A * @param x the <i>x</i> coordinate of the
0N/A * upper-left corner of the arc to be drawn.
0N/A * @param y the <i>y</i> coordinate of the
0N/A * upper-left corner of the arc to be drawn.
0N/A * @param width the width of the arc to be drawn.
0N/A * @param height the height of the arc to be drawn.
0N/A * @param startAngle the beginning angle.
0N/A * @param arcAngle the angular extent of the arc,
0N/A * relative to the start angle.
0N/A * @see java.awt.Graphics#fillArc
0N/A * @since JDK1.0
0N/A */
0N/A public void drawArc(int x, int y, int width, int height,
0N/A int startAngle, int arcAngle) {
0N/A addStrokeShape(new Rectangle2D.Float(x, y, width, height));
0N/A mPrintMetrics.draw(this);
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Fills a circular or elliptical arc covering the specified rectangle.
0N/A * <p>
0N/A * The resulting arc begins at <code>startAngle</code> and extends
0N/A * for <code>arcAngle</code> degrees.
0N/A * Angles are interpreted such that 0&nbsp;degrees
0N/A * is at the 3&nbsp;o'clock position.
0N/A * A positive value indicates a counter-clockwise rotation
0N/A * while a negative value indicates a clockwise rotation.
0N/A * <p>
0N/A * The center of the arc is the center of the rectangle whose origin
0N/A * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
0N/A * <code>width</code> and <code>height</code> arguments.
0N/A * <p>
0N/A * The resulting arc covers an area
0N/A * <code>width&nbsp;+&nbsp;1</code> pixels wide
0N/A * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
0N/A * @param x the <i>x</i> coordinate of the
0N/A * upper-left corner of the arc to be filled.
0N/A * @param y the <i>y</i> coordinate of the
0N/A * upper-left corner of the arc to be filled.
0N/A * @param width the width of the arc to be filled.
0N/A * @param height the height of the arc to be filled.
0N/A * @param startAngle the beginning angle.
0N/A * @param arcAngle the angular extent of the arc,
0N/A * relative to the start angle.
0N/A * @see java.awt.Graphics#drawArc
0N/A * @since JDK1.0
0N/A */
0N/A public void fillArc(int x, int y, int width, int height,
0N/A int startAngle, int arcAngle) {
0N/A Rectangle2D.Float rect = new Rectangle2D.Float(x, y,width, height);
0N/A addDrawingRect(rect);
0N/A mPrintMetrics.fill(this);
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Draws a sequence of connected lines defined by
0N/A * arrays of <i>x</i> and <i>y</i> coordinates.
0N/A * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
0N/A * The figure is not closed if the first point
0N/A * differs from the last point.
0N/A * @param xPoints an array of <i>x</i> points
0N/A * @param yPoints an array of <i>y</i> points
0N/A * @param nPoints the total number of points
0N/A * @see java.awt.Graphics#drawPolygon(int[], int[], int)
0N/A * @since JDK1.1
0N/A */
0N/A public void drawPolyline(int xPoints[], int yPoints[],
0N/A int nPoints) {
0N/A if (nPoints > 0) {
0N/A int x = xPoints[0];
0N/A int y = yPoints[0];
0N/A
0N/A for (int i = 1; i < nPoints; i++) {
0N/A drawLine(x, y, xPoints[i], yPoints[i]);
0N/A x = xPoints[i];
0N/A y = yPoints[i];
0N/A }
0N/A }
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Draws a closed polygon defined by
0N/A * arrays of <i>x</i> and <i>y</i> coordinates.
0N/A * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
0N/A * <p>
0N/A * This method draws the polygon defined by <code>nPoint</code> line
0N/A * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
0N/A * line segments are line segments from
0N/A * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
0N/A * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
0N/A * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.
0N/A * The figure is automatically closed by drawing a line connecting
0N/A * the final point to the first point, if those points are different.
0N/A * @param xPoints a an array of <code>x</code> coordinates.
0N/A * @param yPoints a an array of <code>y</code> coordinates.
0N/A * @param nPoints a the total number of points.
0N/A * @see java.awt.Graphics#fillPolygon
0N/A * @see java.awt.Graphics#drawPolyline
0N/A * @since JDK1.0
0N/A */
0N/A public void drawPolygon(int xPoints[], int yPoints[],
0N/A int nPoints) {
0N/A if (nPoints > 0) {
0N/A drawPolyline(xPoints, yPoints, nPoints);
0N/A drawLine(xPoints[nPoints - 1], yPoints[nPoints - 1],
0N/A xPoints[0], yPoints[0]);
0N/A }
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Fills a closed polygon defined by
0N/A * arrays of <i>x</i> and <i>y</i> coordinates.
0N/A * <p>
0N/A * This method draws the polygon defined by <code>nPoint</code> line
0N/A * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
0N/A * line segments are line segments from
0N/A * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
0N/A * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
0N/A * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.
0N/A * The figure is automatically closed by drawing a line connecting
0N/A * the final point to the first point, if those points are different.
0N/A * <p>
0N/A * The area inside the polygon is defined using an
0N/A * even-odd fill rule, also known as the alternating rule.
0N/A * @param xPoints a an array of <code>x</code> coordinates.
0N/A * @param yPoints a an array of <code>y</code> coordinates.
0N/A * @param nPoints a the total number of points.
0N/A * @see java.awt.Graphics#drawPolygon(int[], int[], int)
0N/A * @since JDK1.0
0N/A */
0N/A public void fillPolygon(int xPoints[], int yPoints[],
0N/A int nPoints) {
0N/A if (nPoints > 0) {
0N/A int minX = xPoints[0];
0N/A int minY = yPoints[0];
0N/A int maxX = xPoints[0];
0N/A int maxY = yPoints[0];
0N/A
0N/A for (int i = 1; i < nPoints; i++) {
0N/A
0N/A if (xPoints[i] < minX) {
0N/A minX = xPoints[i];
0N/A } else if (xPoints[i] > maxX) {
0N/A maxX = xPoints[i];
0N/A }
0N/A
0N/A if (yPoints[i] < minY) {
0N/A minY = yPoints[i];
0N/A } else if (yPoints[i] > maxY) {
0N/A maxY = yPoints[i];
0N/A }
0N/A }
0N/A
0N/A addDrawingRect(minX, minY, maxX - minX, maxY - minY);
0N/A }
0N/A
0N/A mPrintMetrics.fill(this);
0N/A
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Draws the text given by the specified string, using this
0N/A * graphics context's current font and color. The baseline of the
0N/A * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
0N/A * graphics context's coordinate system.
0N/A * @param str the string to be drawn.
0N/A * @param x the <i>x</i> coordinate.
0N/A * @param y the <i>y</i> coordinate.
0N/A * @see java.awt.Graphics#drawBytes
0N/A * @see java.awt.Graphics#drawChars
0N/A * @since JDK1.0
0N/A */
0N/A public void drawString(String str, int x, int y) {
0N/A
0N/A drawString(str, (float)x, (float)y);
0N/A }
0N/A
0N/A /**
0N/A * Draws the text given by the specified iterator, using this
0N/A * graphics context's current color. The iterator has to specify a font
0N/A * for each character. The baseline of the
0N/A * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
0N/A * graphics context's coordinate system.
0N/A * The rendering attributes applied include the clip, transform,
0N/A * paint or color, and composite attributes.
0N/A * For characters in script systems such as Hebrew and Arabic,
0N/A * the glyphs may be draw from right to left, in which case the
0N/A * coordinate supplied is the the location of the leftmost character
0N/A * on the baseline.
0N/A * @param iterator the iterator whose text is to be drawn
0N/A * @param x,y the coordinates where the iterator's text should be drawn.
0N/A * @see #setPaint
0N/A * @see java.awt.Graphics#setColor
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #setClip
0N/A */
0N/A public void drawString(AttributedCharacterIterator iterator,
0N/A int x, int y) {
0N/A
0N/A drawString(iterator, (float)x, (float)y);
0N/A }
0N/A
0N/A /**
0N/A * Draws the text given by the specified iterator, using this
0N/A * graphics context's current color. The iterator has to specify a font
0N/A * for each character. The baseline of the
0N/A * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
0N/A * graphics context's coordinate system.
0N/A * The rendering attributes applied include the clip, transform,
0N/A * paint or color, and composite attributes.
0N/A * For characters in script systems such as Hebrew and Arabic,
0N/A * the glyphs may be draw from right to left, in which case the
0N/A * coordinate supplied is the the location of the leftmost character
0N/A * on the baseline.
0N/A * @param iterator the iterator whose text is to be drawn
0N/A * @param x,y the coordinates where the iterator's text should be drawn.
0N/A * @see #setPaint
0N/A * @see java.awt.Graphics#setColor
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #setClip
0N/A */
0N/A public void drawString(AttributedCharacterIterator iterator,
0N/A float x, float y) {
0N/A if (iterator == null) {
0N/A throw new
0N/A NullPointerException("AttributedCharacterIterator is null");
0N/A }
0N/A
0N/A TextLayout layout = new TextLayout(iterator, getFontRenderContext());
0N/A layout.draw(this, x, y);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Draws as much of the specified image as is currently available.
0N/A * The image is drawn with its top-left corner at
0N/A * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
0N/A * space. Transparent pixels in the image do not affect whatever
0N/A * pixels are already there.
0N/A * <p>
0N/A * This method returns immediately in all cases, even if the
0N/A * complete image has not yet been loaded, and it has not been dithered
0N/A * and converted for the current output device.
0N/A * <p>
0N/A * If the image has not yet been completely loaded, then
0N/A * <code>drawImage</code> returns <code>false</code>. As more of
0N/A * the image becomes available, the process that draws the image notifies
0N/A * the specified image observer.
0N/A * @param img the specified image to be drawn.
0N/A * @param x the <i>x</i> coordinate.
0N/A * @param y the <i>y</i> coordinate.
0N/A * @param observer object to be notified as more of
0N/A * the image is converted.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.0
0N/A */
0N/A public boolean drawImage(Image img, int x, int y,
0N/A ImageObserver observer) {
0N/A
0N/A if (img == null) {
0N/A return true;
0N/A }
0N/A
0N/A /* The ImageWaiter creation does not return until the
0N/A * image is loaded.
0N/A */
0N/A ImageWaiter dim = new ImageWaiter(img);
0N/A
0N/A addDrawingRect(x, y, dim.getWidth(), dim.getHeight());
0N/A mPrintMetrics.drawImage(this, img);
0N/A
0N/A return mGraphics.drawImage(img, x, y, observer);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Draws as much of the specified image as has already been scaled
0N/A * to fit inside the specified rectangle.
0N/A * <p>
0N/A * The image is drawn inside the specified rectangle of this
0N/A * graphics context's coordinate space, and is scaled if
0N/A * necessary. Transparent pixels do not affect whatever pixels
0N/A * are already there.
0N/A * <p>
0N/A * This method returns immediately in all cases, even if the
0N/A * entire image has not yet been scaled, dithered, and converted
0N/A * for the current output device.
0N/A * If the current output representation is not yet complete, then
0N/A * <code>drawImage</code> returns <code>false</code>. As more of
0N/A * the image becomes available, the process that draws the image notifies
0N/A * the image observer by calling its <code>imageUpdate</code> method.
0N/A * <p>
0N/A * A scaled version of an image will not necessarily be
0N/A * available immediately just because an unscaled version of the
0N/A * image has been constructed for this output device. Each size of
0N/A * the image may be cached separately and generated from the original
0N/A * data in a separate image production sequence.
0N/A * @param img the specified image to be drawn.
0N/A * @param x the <i>x</i> coordinate.
0N/A * @param y the <i>y</i> coordinate.
0N/A * @param width the width of the rectangle.
0N/A * @param height the height of the rectangle.
0N/A * @param observer object to be notified as more of
0N/A * the image is converted.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.0
0N/A */
0N/A public boolean drawImage(Image img, int x, int y,
0N/A int width, int height,
0N/A ImageObserver observer) {
0N/A
0N/A if (img == null) {
0N/A return true;
0N/A }
0N/A addDrawingRect(x, y, width, height);
0N/A mPrintMetrics.drawImage(this, img);
0N/A
0N/A return mGraphics.drawImage(img, x, y, width, height, observer);
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Draws as much of the specified image as is currently available.
0N/A * The image is drawn with its top-left corner at
0N/A * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
0N/A * space. Transparent pixels are drawn in the specified
0N/A * background color.
0N/A * <p>
0N/A * This operation is equivalent to filling a rectangle of the
0N/A * width and height of the specified image with the given color and then
0N/A * drawing the image on top of it, but possibly more efficient.
0N/A * <p>
0N/A * This method returns immediately in all cases, even if the
0N/A * complete image has not yet been loaded, and it has not been dithered
0N/A * and converted for the current output device.
0N/A * <p>
0N/A * If the image has not yet been completely loaded, then
0N/A * <code>drawImage</code> returns <code>false</code>. As more of
0N/A * the image becomes available, the process that draws the image notifies
0N/A * the specified image observer.
0N/A * @param img the specified image to be drawn.
0N/A * @param x the <i>x</i> coordinate.
0N/A * @param y the <i>y</i> coordinate.
0N/A * @param bgcolor the background color to paint under the
0N/A * non-opaque portions of the image.
0N/A * @param observer object to be notified as more of
0N/A * the image is converted.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.0
0N/A */
0N/A public boolean drawImage(Image img, int x, int y,
0N/A Color bgcolor,
0N/A ImageObserver observer) {
0N/A
0N/A if (img == null) {
0N/A return true;
0N/A }
0N/A
0N/A /* The ImageWaiter creation does not return until the
0N/A * image is loaded.
0N/A */
0N/A ImageWaiter dim = new ImageWaiter(img);
0N/A
0N/A addDrawingRect(x, y, dim.getWidth(), dim.getHeight());
0N/A mPrintMetrics.drawImage(this, img);
0N/A
0N/A return mGraphics.drawImage(img, x, y, bgcolor, observer);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Draws as much of the specified image as has already been scaled
0N/A * to fit inside the specified rectangle.
0N/A * <p>
0N/A * The image is drawn inside the specified rectangle of this
0N/A * graphics context's coordinate space, and is scaled if
0N/A * necessary. Transparent pixels are drawn in the specified
0N/A * background color.
0N/A * This operation is equivalent to filling a rectangle of the
0N/A * width and height of the specified image with the given color and then
0N/A * drawing the image on top of it, but possibly more efficient.
0N/A * <p>
0N/A * This method returns immediately in all cases, even if the
0N/A * entire image has not yet been scaled, dithered, and converted
0N/A * for the current output device.
0N/A * If the current output representation is not yet complete then
0N/A * <code>drawImage</code> returns <code>false</code>. As more of
0N/A * the image becomes available, the process that draws the image notifies
0N/A * the specified image observer.
0N/A * <p>
0N/A * A scaled version of an image will not necessarily be
0N/A * available immediately just because an unscaled version of the
0N/A * image has been constructed for this output device. Each size of
0N/A * the image may be cached separately and generated from the original
0N/A * data in a separate image production sequence.
0N/A * @param img the specified image to be drawn.
0N/A * @param x the <i>x</i> coordinate.
0N/A * @param y the <i>y</i> coordinate.
0N/A * @param width the width of the rectangle.
0N/A * @param height the height of the rectangle.
0N/A * @param bgcolor the background color to paint under the
0N/A * non-opaque portions of the image.
0N/A * @param observer object to be notified as more of
0N/A * the image is converted.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.0
0N/A */
0N/A public boolean drawImage(Image img, int x, int y,
0N/A int width, int height,
0N/A Color bgcolor,
0N/A ImageObserver observer) {
0N/A
0N/A if (img == null) {
0N/A return true;
0N/A }
0N/A
0N/A addDrawingRect(x, y, width, height);
0N/A mPrintMetrics.drawImage(this, img);
0N/A
0N/A return mGraphics.drawImage(img, x, y, width, height, bgcolor, observer);
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Draws as much of the specified area of the specified image as is
0N/A * currently available, scaling it on the fly to fit inside the
0N/A * specified area of the destination drawable surface. Transparent pixels
0N/A * do not affect whatever pixels are already there.
0N/A * <p>
0N/A * This method returns immediately in all cases, even if the
0N/A * image area to be drawn has not yet been scaled, dithered, and converted
0N/A * for the current output device.
0N/A * If the current output representation is not yet complete then
0N/A * <code>drawImage</code> returns <code>false</code>. As more of
0N/A * the image becomes available, the process that draws the image notifies
0N/A * the specified image observer.
0N/A * <p>
0N/A * This method always uses the unscaled version of the image
0N/A * to render the scaled rectangle and performs the required
0N/A * scaling on the fly. It does not use a cached, scaled version
0N/A * of the image for this operation. Scaling of the image from source
0N/A * to destination is performed such that the first coordinate
0N/A * of the source rectangle is mapped to the first coordinate of
0N/A * the destination rectangle, and the second source coordinate is
0N/A * mapped to the second destination coordinate. The subimage is
0N/A * scaled and flipped as needed to preserve those mappings.
0N/A * @param img the specified image to be drawn
0N/A * @param dx1 the <i>x</i> coordinate of the first corner of the
0N/A * destination rectangle.
0N/A * @param dy1 the <i>y</i> coordinate of the first corner of the
0N/A * destination rectangle.
0N/A * @param dx2 the <i>x</i> coordinate of the second corner of the
0N/A * destination rectangle.
0N/A * @param dy2 the <i>y</i> coordinate of the second corner of the
0N/A * destination rectangle.
0N/A * @param sx1 the <i>x</i> coordinate of the first corner of the
0N/A * source rectangle.
0N/A * @param sy1 the <i>y</i> coordinate of the first corner of the
0N/A * source rectangle.
0N/A * @param sx2 the <i>x</i> coordinate of the second corner of the
0N/A * source rectangle.
0N/A * @param sy2 the <i>y</i> coordinate of the second corner of the
0N/A * source rectangle.
0N/A * @param observer object to be notified as more of the image is
0N/A * scaled and converted.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.1
0N/A */
0N/A public boolean drawImage(Image img,
0N/A int dx1, int dy1, int dx2, int dy2,
0N/A int sx1, int sy1, int sx2, int sy2,
0N/A ImageObserver observer) {
0N/A
0N/A if (img == null) {
0N/A return true;
0N/A }
0N/A
0N/A int width = dx2 - dx1;
0N/A int height = dy2 - dy1;
0N/A
0N/A addDrawingRect(dx1, dy1, width, height);
0N/A mPrintMetrics.drawImage(this, img);
0N/A
0N/A return mGraphics.drawImage(img, dx1, dy1, dx2, dy2,
0N/A sx1, sy1, sx2, sy2, observer);
0N/A
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Draws as much of the specified area of the specified image as is
0N/A * currently available, scaling it on the fly to fit inside the
0N/A * specified area of the destination drawable surface.
0N/A * <p>
0N/A * Transparent pixels are drawn in the specified background color.
0N/A * This operation is equivalent to filling a rectangle of the
0N/A * width and height of the specified image with the given color and then
0N/A * drawing the image on top of it, but possibly more efficient.
0N/A * <p>
0N/A * This method returns immediately in all cases, even if the
0N/A * image area to be drawn has not yet been scaled, dithered, and converted
0N/A * for the current output device.
0N/A * If the current output representation is not yet complete then
0N/A * <code>drawImage</code> returns <code>false</code>. As more of
0N/A * the image becomes available, the process that draws the image notifies
0N/A * the specified image observer.
0N/A * <p>
0N/A * This method always uses the unscaled version of the image
0N/A * to render the scaled rectangle and performs the required
0N/A * scaling on the fly. It does not use a cached, scaled version
0N/A * of the image for this operation. Scaling of the image from source
0N/A * to destination is performed such that the first coordinate
0N/A * of the source rectangle is mapped to the first coordinate of
0N/A * the destination rectangle, and the second source coordinate is
0N/A * mapped to the second destination coordinate. The subimage is
0N/A * scaled and flipped as needed to preserve those mappings.
0N/A * @param img the specified image to be drawn
0N/A * @param dx1 the <i>x</i> coordinate of the first corner of the
0N/A * destination rectangle.
0N/A * @param dy1 the <i>y</i> coordinate of the first corner of the
0N/A * destination rectangle.
0N/A * @param dx2 the <i>x</i> coordinate of the second corner of the
0N/A * destination rectangle.
0N/A * @param dy2 the <i>y</i> coordinate of the second corner of the
0N/A * destination rectangle.
0N/A * @param sx1 the <i>x</i> coordinate of the first corner of the
0N/A * source rectangle.
0N/A * @param sy1 the <i>y</i> coordinate of the first corner of the
0N/A * source rectangle.
0N/A * @param sx2 the <i>x</i> coordinate of the second corner of the
0N/A * source rectangle.
0N/A * @param sy2 the <i>y</i> coordinate of the second corner of the
0N/A * source rectangle.
0N/A * @param bgcolor the background color to paint under the
0N/A * non-opaque portions of the image.
0N/A * @param observer object to be notified as more of the image is
0N/A * scaled and converted.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.1
0N/A */
0N/A public boolean drawImage(Image img,
0N/A int dx1, int dy1, int dx2, int dy2,
0N/A int sx1, int sy1, int sx2, int sy2,
0N/A Color bgcolor,
0N/A ImageObserver observer) {
0N/A
0N/A if (img == null) {
0N/A return true;
0N/A }
0N/A
0N/A int width = dx2 - dx1;
0N/A int height = dy2 - dy1;
0N/A
0N/A addDrawingRect(dx1, dy1, width, height);
0N/A mPrintMetrics.drawImage(this, img);
0N/A
0N/A return mGraphics.drawImage(img, dx1, dy1, dx2, dy2,
0N/A sx1, sy1, sx2, sy2, bgcolor, observer);
0N/A
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Draws an image, applying a transform from image space into user space
0N/A * before drawing.
0N/A * The transformation from user space into device space is done with
0N/A * the current transform in the Graphics2D.
0N/A * The given transformation is applied to the image before the
0N/A * transform attribute in the Graphics2D state is applied.
0N/A * The rendering attributes applied include the clip, transform,
0N/A * and composite attributes. Note that the result is
0N/A * undefined, if the given transform is noninvertible.
0N/A * @param img The image to be drawn.
0N/A * @param xform The transformation from image space into user space.
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #clip
0N/A * @see #setClip
0N/A */
0N/A public void drawRenderedImage(RenderedImage img,
0N/A AffineTransform xform) {
0N/A
0N/A if (img == null) {
0N/A return;
0N/A }
0N/A
0N/A mPrintMetrics.drawImage(this, img);
0N/A mDrawingArea.addInfinite();
0N/A }
0N/A
0N/A
0N/A public void drawRenderableImage(RenderableImage img,
0N/A AffineTransform xform) {
0N/A
0N/A if (img == null) {
0N/A return;
0N/A }
0N/A
0N/A mPrintMetrics.drawImage(this, img);
0N/A mDrawingArea.addInfinite();
0N/A }
0N/A
0N/A /**
0N/A * Disposes of this graphics context and releases
0N/A * any system resources that it is using.
0N/A * A <code>Graphics</code> object cannot be used after
0N/A * <code>dispose</code>has been called.
0N/A * <p>
0N/A * When a Java program runs, a large number of <code>Graphics</code>
0N/A * objects can be created within a short time frame.
0N/A * Although the finalization process of the garbage collector
0N/A * also disposes of the same system resources, it is preferable
0N/A * to manually free the associated resources by calling this
0N/A * method rather than to rely on a finalization process which
0N/A * may not run to completion for a long period of time.
0N/A * <p>
0N/A * Graphics objects which are provided as arguments to the
0N/A * <code>paint</code> and <code>update</code> methods
0N/A * of components are automatically released by the system when
0N/A * those methods return. For efficiency, programmers should
0N/A * call <code>dispose</code> when finished using
0N/A * a <code>Graphics</code> object only if it was created
0N/A * directly from a component or another <code>Graphics</code> object.
0N/A * @see java.awt.Graphics#finalize
0N/A * @see java.awt.Component#paint
0N/A * @see java.awt.Component#update
0N/A * @see java.awt.Component#getGraphics
0N/A * @see java.awt.Graphics#create
0N/A * @since JDK1.0
0N/A */
0N/A public void dispose() {
0N/A mGraphics.dispose();
0N/A }
0N/A
0N/A /**
0N/A * Empty finalizer as no clean up needed here.
0N/A */
0N/A public void finalize() {
0N/A }
0N/A
0N/A/* The Delegated Graphics2D Methods */
0N/A
0N/A /**
0N/A * Strokes the outline of a Shape using the settings of the current
0N/A * graphics state. The rendering attributes applied include the
0N/A * clip, transform, paint or color, composite and stroke attributes.
0N/A * @param s The shape to be drawn.
0N/A * @see #setStroke
0N/A * @see #setPaint
0N/A * @see java.awt.Graphics#setColor
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #clip
0N/A * @see #setClip
0N/A * @see #setComposite
0N/A */
0N/A public void draw(Shape s) {
0N/A addStrokeShape(s);
0N/A mPrintMetrics.draw(this);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Draws an image, applying a transform from image space into user space
0N/A * before drawing.
0N/A * The transformation from user space into device space is done with
0N/A * the current transform in the Graphics2D.
0N/A * The given transformation is applied to the image before the
0N/A * transform attribute in the Graphics2D state is applied.
0N/A * The rendering attributes applied include the clip, transform,
0N/A * and composite attributes. Note that the result is
0N/A * undefined, if the given transform is noninvertible.
0N/A * @param img The image to be drawn.
0N/A * @param xform The transformation from image space into user space.
0N/A * @param obs The image observer to be notified as more of the image
0N/A * is converted.
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #clip
0N/A * @see #setClip
0N/A */
0N/A public boolean drawImage(Image img,
0N/A AffineTransform xform,
0N/A ImageObserver obs) {
0N/A
0N/A if (img == null) {
0N/A return true;
0N/A }
0N/A
0N/A mDrawingArea.addInfinite();
0N/A mPrintMetrics.drawImage(this, img);
0N/A
0N/A return mGraphics.drawImage(img, xform, obs);
0N/A
0N/A
0N/A// if (mDrawingArea[0] != null) {
0N/A// Rectangle2D.Double bbox = new Rectangle2D.Double();
0N/A// Point2D leftTop = new Point2D.Double(0, 0);
0N/A// Point2D rightBottom = new Point2D.Double(getImageWidth(img),
0N/A// getImageHeight(img));
0N/A
0N/A// xform.transform(leftTop, leftTop);
0N/A// xform.transform(rightBottom, rightBottom);
0N/A
0N/A// bbox.setBoundsFromDiagonal(leftTop, rightBottom);
0N/A// addDrawingRect(bbox);
0N/A
0N/A// }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Draws a BufferedImage that is filtered with a BufferedImageOp.
0N/A * The rendering attributes applied include the clip, transform
0N/A * and composite attributes. This is equivalent to:
0N/A * <pre>
0N/A * img1 = op.filter(img, null);
0N/A * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
0N/A * </pre>
0N/A * @param op The filter to be applied to the image before drawing.
0N/A * @param img The BufferedImage to be drawn.
0N/A * @param x,y The location in user space where the image should be drawn.
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #clip
0N/A * @see #setClip
0N/A */
0N/A public void drawImage(BufferedImage img,
0N/A BufferedImageOp op,
0N/A int x,
0N/A int y) {
0N/A
0N/A if (img == null) {
0N/A return;
0N/A }
0N/A
0N/A mPrintMetrics.drawImage(this, (RenderedImage) img);
0N/A mDrawingArea.addInfinite();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Draws a string of text.
0N/A * The rendering attributes applied include the clip, transform,
0N/A * paint or color, font and composite attributes.
0N/A * @param s The string to be drawn.
0N/A * @param x,y The coordinates where the string should be drawn.
0N/A * @see #setPaint
0N/A * @see java.awt.Graphics#setColor
0N/A * @see java.awt.Graphics#setFont
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #clip
0N/A * @see #setClip
0N/A */
0N/A public void drawString(String str,
0N/A float x,
0N/A float y) {
0N/A
0N/A if (str.length() == 0) {
0N/A return;
0N/A }
0N/A /* Logical bounds close enough and is used for GlyphVector */
0N/A FontRenderContext frc = getFontRenderContext();
0N/A Rectangle2D bbox = getFont().getStringBounds(str, frc);
0N/A addDrawingRect(bbox, x, y);
0N/A mPrintMetrics.drawText(this);
0N/A }
0N/A
0N/A /**
0N/A * Draws a GlyphVector.
0N/A * The rendering attributes applied include the clip, transform,
0N/A * paint or color, and composite attributes. The GlyphVector specifies
0N/A * individual glyphs from a Font.
0N/A * @param g The GlyphVector to be drawn.
0N/A * @param x,y The coordinates where the glyphs should be drawn.
0N/A * @see #setPaint
0N/A * @see java.awt.Graphics#setColor
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #clip
0N/A * @see #setClip
0N/A */
0N/A public void drawGlyphVector(GlyphVector g,
0N/A float x,
0N/A float y) {
0N/A
0N/A Rectangle2D bbox = g.getLogicalBounds();
0N/A addDrawingRect(bbox, x, y);
0N/A mPrintMetrics.drawText(this);
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Fills the interior of a Shape using the settings of the current
0N/A * graphics state. The rendering attributes applied include the
0N/A * clip, transform, paint or color, and composite.
0N/A * @see #setPaint
0N/A * @see java.awt.Graphics#setColor
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #clip
0N/A * @see #setClip
0N/A */
0N/A public void fill(Shape s) {
0N/A addDrawingRect(s.getBounds());
0N/A mPrintMetrics.fill(this);
0N/A
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Checks to see if the outline of a Shape intersects the specified
0N/A * Rectangle in device space.
0N/A * The rendering attributes taken into account include the
0N/A * clip, transform, and stroke attributes.
0N/A * @param rect The area in device space to check for a hit.
0N/A * @param s The shape to check for a hit.
0N/A * @param onStroke Flag to choose between testing the stroked or
0N/A * the filled shape.
0N/A * @return True if there is a hit, false otherwise.
0N/A * @see #setStroke
0N/A * @see #fill
0N/A * @see #draw
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #clip
0N/A * @see #setClip
0N/A */
0N/A public boolean hit(Rectangle rect,
0N/A Shape s,
0N/A boolean onStroke) {
0N/A
0N/A return mGraphics.hit(rect, s, onStroke);
0N/A }
0N/A
0N/A /**
0N/A * Sets the Composite in the current graphics state. Composite is used
0N/A * in all drawing methods such as drawImage, drawString, draw,
0N/A * and fill. It specifies how new pixels are to be combined with
0N/A * the existing pixels on the graphics device in the rendering process.
0N/A * @param comp The Composite object to be used for drawing.
0N/A * @see java.awt.Graphics#setXORMode
0N/A * @see java.awt.Graphics#setPaintMode
0N/A * @see AlphaComposite
0N/A */
0N/A public void setComposite(Composite comp) {
0N/A mGraphics.setComposite(comp);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the Paint in the current graphics state.
0N/A * @param paint The Paint object to be used to generate color in
0N/A * the rendering process.
0N/A * @see java.awt.Graphics#setColor
0N/A * @see GradientPaint
0N/A * @see TexturePaint
0N/A */
0N/A public void setPaint(Paint paint) {
0N/A mGraphics.setPaint(paint);
0N/A }
0N/A
0N/A /**
0N/A * Sets the Stroke in the current graphics state.
0N/A * @param s The Stroke object to be used to stroke a Shape in
0N/A * the rendering process.
0N/A * @see BasicStroke
0N/A */
0N/A public void setStroke(Stroke s) {
0N/A mGraphics.setStroke(s);
0N/A }
0N/A
0N/A /**
0N/A * Sets the preferences for the rendering algorithms.
0N/A * Hint categories include controls for rendering quality and
0N/A * overall time/quality trade-off in the rendering process.
0N/A * @param hintCategory The category of hint to be set.
0N/A * @param hintValue The value indicating preferences for the specified
0N/A * hint category.
0N/A * @see RenderingHints
0N/A */
0N/A public void setRenderingHint(Key hintCategory, Object hintValue) {
0N/A mGraphics.setRenderingHint(hintCategory, hintValue);
0N/A }
0N/A
0N/A /**
0N/A * Returns the preferences for the rendering algorithms.
0N/A * @param hintCategory The category of hint to be set.
0N/A * @return The preferences for rendering algorithms.
0N/A * @see RenderingHings
0N/A */
0N/A public Object getRenderingHint(Key hintCategory) {
0N/A return mGraphics.getRenderingHint(hintCategory);
0N/A }
0N/A
0N/A /**
0N/A * Sets the preferences for the rendering algorithms.
0N/A * Hint categories include controls for rendering quality and
0N/A * overall time/quality trade-off in the rendering process.
0N/A * @param hints The rendering hints to be set
0N/A * @see RenderingHints
0N/A */
0N/A public void setRenderingHints(Map<?,?> hints) {
0N/A mGraphics.setRenderingHints(hints);
0N/A }
0N/A
0N/A /**
0N/A * Adds a number of preferences for the rendering algorithms.
0N/A * Hint categories include controls for rendering quality and
0N/A * overall time/quality trade-off in the rendering process.
0N/A * @param hints The rendering hints to be set
0N/A * @see RenderingHints
0N/A */
0N/A public void addRenderingHints(Map<?,?> hints) {
0N/A mGraphics.addRenderingHints(hints);
0N/A }
0N/A
0N/A /**
0N/A * Gets the preferences for the rendering algorithms.
0N/A * Hint categories include controls for rendering quality and
0N/A * overall time/quality trade-off in the rendering process.
0N/A * @see RenderingHints
0N/A */
0N/A public RenderingHints getRenderingHints() {
0N/A return mGraphics.getRenderingHints();
0N/A }
0N/A
0N/A /**
0N/A * Composes a Transform object with the transform in this
0N/A * Graphics2D according to the rule last-specified-first-applied.
0N/A * If the currrent transform is Cx, the result of composition
0N/A * with Tx is a new transform Cx'. Cx' becomes the current
0N/A * transform for this Graphics2D.
0N/A * Transforming a point p by the updated transform Cx' is
0N/A * equivalent to first transforming p by Tx and then transforming
0N/A * the result by the original transform Cx. In other words,
0N/A * Cx'(p) = Cx(Tx(p)).
0N/A * A copy of the Tx is made, if necessary, so further
0N/A * modifications to Tx do not affect rendering.
0N/A * @param Tx The Transform object to be composed with the current
0N/A * transform.
0N/A * @see #setTransform
0N/A * @see TransformChain
0N/A * @see AffineTransform
0N/A */
0N/A public void transform(AffineTransform Tx) {
0N/A mGraphics.transform(Tx);
0N/A }
0N/A
0N/A /**
0N/A * Sets the Transform in the current graphics state.
0N/A * @param Tx The Transform object to be used in the rendering process.
0N/A * @see #transform
0N/A * @see TransformChain
0N/A * @see AffineTransform
0N/A */
0N/A public void setTransform(AffineTransform Tx) {
0N/A mGraphics.setTransform(Tx);
0N/A }
0N/A
0N/A /**
0N/A * Returns the current Transform in the Graphics2D state.
0N/A * @see #transform
0N/A * @see #setTransform
0N/A */
0N/A public AffineTransform getTransform() {
0N/A return mGraphics.getTransform();
0N/A }
0N/A
0N/A /**
0N/A * Returns the current Paint in the Graphics2D state.
0N/A * @see #setPaint
0N/A * @see java.awt.Graphics#setColor
0N/A */
0N/A public Paint getPaint() {
0N/A return mGraphics.getPaint();
0N/A }
0N/A
0N/A /**
0N/A * Returns the current Composite in the Graphics2D state.
0N/A * @see #setComposite
0N/A */
0N/A public Composite getComposite() {
0N/A return mGraphics.getComposite();
0N/A }
0N/A
0N/A /**
0N/A * Sets the background color in this context used for clearing a region.
0N/A * When Graphics2D is constructed for a component, the backgroung color is
0N/A * inherited from the component. Setting the background color in the
0N/A * Graphics2D context only affects the subsequent clearRect() calls and
0N/A * not the background color of the component. To change the background
0N/A * of the component, use appropriate methods of the component.
0N/A * @param color The background color that should be used in
0N/A * subsequent calls to clearRect().
0N/A * @see getBackground
0N/A * @see Graphics.clearRect()
0N/A */
0N/A public void setBackground(Color color) {
0N/A mGraphics.setBackground(color);
0N/A }
0N/A
0N/A /**
0N/A * Returns the background color used for clearing a region.
0N/A * @see setBackground
0N/A */
0N/A public Color getBackground() {
0N/A return mGraphics.getBackground();
0N/A }
0N/A
0N/A /**
0N/A * Returns the current Stroke in the Graphics2D state.
0N/A * @see setStroke
0N/A */
0N/A public Stroke getStroke() {
0N/A return mGraphics.getStroke();
0N/A }
0N/A
0N/A /**
0N/A * Intersects the current clip with the interior of the specified Shape
0N/A * and sets the current clip to the resulting intersection.
0N/A * The indicated shape is transformed with the current transform in the
0N/A * Graphics2D state before being intersected with the current clip.
0N/A * This method is used to make the current clip smaller.
0N/A * To make the clip larger, use any setClip method.
0N/A * @param s The Shape to be intersected with the current clip.
0N/A */
0N/A public void clip(Shape s) {
0N/A mGraphics.clip(s);
0N/A }
0N/A
0N/A /**
0N/A * Return true if the Rectangle <code>rect</code>
0N/A * intersects the area into which the application
0N/A * has drawn.
0N/A */
0N/A public boolean hitsDrawingArea(Rectangle rect) {
0N/A
0N/A return mDrawingArea.intersects((float) rect.getMinY(),
0N/A (float) rect.getMaxY());
0N/A }
0N/A
0N/A /**
0N/A * Return the object holding the summary of the
0N/A * drawing done by the printing application.
0N/A */
0N/A public PeekMetrics getMetrics() {
0N/A return mPrintMetrics;
0N/A }
0N/A
0N/A /* Support Routines for Calculating the Drawing Area */
0N/A
0N/A /**
0N/A * Shift the rectangle 'rect' to the position ('x', 'y')
0N/A * and add the resulting rectangle to the area representing
0N/A * the part of the page which is drawn into.
0N/A */
0N/A private void addDrawingRect(Rectangle2D rect, float x, float y) {
0N/A
0N/A addDrawingRect((float) (rect.getX() + x),
0N/A (float) (rect.getY() + y),
0N/A (float) rect.getWidth(),
0N/A (float) rect.getHeight());
0N/A
0N/A }
0N/A
0N/A private void addDrawingRect(float x, float y, float width, float height) {
0N/A
0N/A Rectangle2D.Float bbox = new Rectangle2D.Float(x, y, width, height);
0N/A addDrawingRect(bbox);
0N/A }
0N/A
0N/A /**
0N/A * Add the rectangle 'rect' to the area representing
0N/A * the part of the page which is drawn into.
0N/A */
0N/A private void addDrawingRect(Rectangle2D rect) {
0N/A
0N/A /* For testing purposes the following line can be uncommented.
0N/A When uncommented it causes the entire page to be rasterized
0N/A thus eliminating errors caused by a faulty bounding box
0N/A calculation.
0N/A */
0N/A //mDrawingArea.addInfinite();
0N/A
0N/A
0N/A
0N/A AffineTransform matrix = getTransform();
0N/A
0N/A Shape transShape = matrix.createTransformedShape(rect);
0N/A
0N/A Rectangle2D transRect = transShape.getBounds2D();
0N/A
0N/A mDrawingArea.add((float) transRect.getMinY(),
0N/A (float) transRect.getMaxY());
0N/A
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Add the stroked shape to the area representing
0N/A * the part of the page which is drawn into.
0N/A */
0N/A private void addStrokeShape(Shape s) {
0N/A Shape transShape = getStroke().createStrokedShape(s);
0N/A addDrawingRect(transShape.getBounds2D());
0N/A }
0N/A
0N/A /* Image Observer */
0N/A
0N/A /**
0N/A * Notify this object when the height or width become available
0N/A * for an image.
0N/A */
0N/A public synchronized boolean imageUpdate(Image img, int infoFlags,
0N/A int x, int y,
0N/A int width, int height) {
0N/A
0N/A boolean gotInfo = false;
0N/A
0N/A if((infoFlags & (WIDTH | HEIGHT)) != 0) {
0N/A gotInfo = true;
0N/A notify();
0N/A }
0N/A
0N/A return gotInfo;
0N/A }
0N/A
0N/A private synchronized int getImageWidth(Image img) {
0N/A
0N/A /* Wait for the width the image to
0N/A * become available.
0N/A */
0N/A while (img.getWidth(this) == -1) {
0N/A try {
0N/A wait();
0N/A } catch (InterruptedException e) {
0N/A }
0N/A }
0N/A
0N/A
0N/A return img.getWidth(this);
0N/A }
0N/A
0N/A private synchronized int getImageHeight(Image img) {
0N/A
0N/A /* Wait for the height the image to
0N/A * become available.
0N/A */
0N/A while (img.getHeight(this) == -1) {
0N/A try {
0N/A wait();
0N/A } catch (InterruptedException e) {
0N/A }
0N/A }
0N/A
0N/A
0N/A return img.getHeight(this);
0N/A }
0N/A
0N/A /**
0N/A * This private class does not return from its constructor
0N/A * until 'img's width and height are available.
0N/A */
0N/A protected class ImageWaiter implements ImageObserver {
0N/A
0N/A private int mWidth;
0N/A private int mHeight;
0N/A private boolean badImage = false;
0N/A
0N/A ImageWaiter(Image img) {
0N/A waitForDimensions(img);
0N/A }
0N/A
0N/A public int getWidth() {
0N/A return mWidth;
0N/A }
0N/A
0N/A public int getHeight() {
0N/A return mHeight;
0N/A }
0N/A
0N/A synchronized private void waitForDimensions(Image img) {
0N/A mHeight = img.getHeight(this);
0N/A mWidth = img.getWidth(this);
0N/A while (!badImage && (mWidth < 0 || mHeight < 0)) {
0N/A try {
0N/A Thread.sleep(50);
0N/A } catch(InterruptedException e) {
0N/A // do nothing.
0N/A }
0N/A mHeight = img.getHeight(this);
0N/A mWidth = img.getWidth(this);
0N/A }
0N/A if (badImage) {
0N/A mHeight = 0;
0N/A mWidth = 0;
0N/A }
0N/A }
0N/A
0N/A synchronized public boolean imageUpdate(Image image, int flags,
0N/A int x, int y, int w, int h) {
0N/A
0N/A boolean dontCallMeAgain = (flags & (HEIGHT | ABORT | ERROR)) != 0;
0N/A badImage = (flags & (ABORT | ERROR)) != 0;
0N/A
0N/A return dontCallMeAgain;
0N/A }
0N/A
0N/A }
0N/A}