0001: /*
0002: * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved.
0003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004: *
0005: * This code is free software; you can redistribute it and/or modify it
0006: * under the terms of the GNU General Public License version 2 only, as
0007: * published by the Free Software Foundation. Sun designates this
0008: * particular file as subject to the "Classpath" exception as provided
0009: * by Sun in the LICENSE file that accompanied this code.
0010: *
0011: * This code is distributed in the hope that it will be useful, but WITHOUT
0012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0014: * version 2 for more details (a copy is included in the LICENSE file that
0015: * accompanied this code).
0016: *
0017: * You should have received a copy of the GNU General Public License version
0018: * 2 along with this work; if not, write to the Free Software Foundation,
0019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020: *
0021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022: * CA 95054 USA or visit www.sun.com if you need additional information or
0023: * have any questions.
0024: */
0025: package java.awt;
0026:
0027: import java.io.*;
0028: import java.lang.*;
0029: import java.util.*;
0030: import java.awt.image.ImageObserver;
0031: import java.text.AttributedCharacterIterator;
0032:
0033: /**
0034: * The <code>Graphics</code> class is the abstract base class for
0035: * all graphics contexts that allow an application to draw onto
0036: * components that are realized on various devices, as well as
0037: * onto off-screen images.
0038: * <p>
0039: * A <code>Graphics</code> object encapsulates state information needed
0040: * for the basic rendering operations that Java supports. This
0041: * state information includes the following properties:
0042: * <p>
0043: * <ul>
0044: * <li>The <code>Component</code> object on which to draw.
0045: * <li>A translation origin for rendering and clipping coordinates.
0046: * <li>The current clip.
0047: * <li>The current color.
0048: * <li>The current font.
0049: * <li>The current logical pixel operation function (XOR or Paint).
0050: * <li>The current XOR alternation color
0051: * (see {@link Graphics#setXORMode}).
0052: * </ul>
0053: * <p>
0054: * Coordinates are infinitely thin and lie between the pixels of the
0055: * output device.
0056: * Operations that draw the outline of a figure operate by traversing
0057: * an infinitely thin path between pixels with a pixel-sized pen that hangs
0058: * down and to the right of the anchor point on the path.
0059: * Operations that fill a figure operate by filling the interior
0060: * of that infinitely thin path.
0061: * Operations that render horizontal text render the ascending
0062: * portion of character glyphs entirely above the baseline coordinate.
0063: * <p>
0064: * The graphics pen hangs down and to the right from the path it traverses.
0065: * This has the following implications:
0066: * <p><ul>
0067: * <li>If you draw a figure that covers a given rectangle, that
0068: * figure occupies one extra row of pixels on the right and bottom edges
0069: * as compared to filling a figure that is bounded by that same rectangle.
0070: * <li>If you draw a horizontal line along the same <i>y</i> coordinate as
0071: * the baseline of a line of text, that line is drawn entirely below
0072: * the text, except for any descenders.
0073: * </ul><p>
0074: * All coordinates that appear as arguments to the methods of this
0075: * <code>Graphics</code> object are considered relative to the
0076: * translation origin of this <code>Graphics</code> object prior to
0077: * the invocation of the method.
0078: * <p>
0079: * All rendering operations modify only pixels which lie within the
0080: * area bounded by the current clip, which is specified by a {@link Shape}
0081: * in user space and is controlled by the program using the
0082: * <code>Graphics</code> object. This <i>user clip</i>
0083: * is transformed into device space and combined with the
0084: * <i>device clip</i>, which is defined by the visibility of windows and
0085: * device extents. The combination of the user clip and device clip
0086: * defines the <i>composite clip</i>, which determines the final clipping
0087: * region. The user clip cannot be modified by the rendering
0088: * system to reflect the resulting composite clip. The user clip can only
0089: * be changed through the <code>setClip</code> or <code>clipRect</code>
0090: * methods.
0091: * All drawing or writing is done in the current color,
0092: * using the current paint mode, and in the current font.
0093: *
0094: * @version 1.80, 05/05/07
0095: * @author Sami Shaio
0096: * @author Arthur van Hoff
0097: * @see java.awt.Component
0098: * @see java.awt.Graphics#clipRect(int, int, int, int)
0099: * @see java.awt.Graphics#setColor(java.awt.Color)
0100: * @see java.awt.Graphics#setPaintMode()
0101: * @see java.awt.Graphics#setXORMode(java.awt.Color)
0102: * @see java.awt.Graphics#setFont(java.awt.Font)
0103: * @since JDK1.0
0104: */
0105: public abstract class Graphics {
0106:
0107: /**
0108: * Constructs a new <code>Graphics</code> object.
0109: * This constructor is the default contructor for a graphics
0110: * context.
0111: * <p>
0112: * Since <code>Graphics</code> is an abstract class, applications
0113: * cannot call this constructor directly. Graphics contexts are
0114: * obtained from other graphics contexts or are created by calling
0115: * <code>getGraphics</code> on a component.
0116: * @see java.awt.Graphics#create()
0117: * @see java.awt.Component#getGraphics
0118: */
0119: protected Graphics() {
0120: }
0121:
0122: /**
0123: * Creates a new <code>Graphics</code> object that is
0124: * a copy of this <code>Graphics</code> object.
0125: * @return a new graphics context that is a copy of
0126: * this graphics context.
0127: */
0128: public abstract Graphics create();
0129:
0130: /**
0131: * Creates a new <code>Graphics</code> object based on this
0132: * <code>Graphics</code> object, but with a new translation and clip area.
0133: * The new <code>Graphics</code> object has its origin
0134: * translated to the specified point (<i>x</i>, <i>y</i>).
0135: * Its clip area is determined by the intersection of the original
0136: * clip area with the specified rectangle. The arguments are all
0137: * interpreted in the coordinate system of the original
0138: * <code>Graphics</code> object. The new graphics context is
0139: * identical to the original, except in two respects:
0140: * <p>
0141: * <ul>
0142: * <li>
0143: * The new graphics context is translated by (<i>x</i>, <i>y</i>).
0144: * That is to say, the point (<code>0</code>, <code>0</code>) in the
0145: * new graphics context is the same as (<i>x</i>, <i>y</i>) in
0146: * the original graphics context.
0147: * <li>
0148: * The new graphics context has an additional clipping rectangle, in
0149: * addition to whatever (translated) clipping rectangle it inherited
0150: * from the original graphics context. The origin of the new clipping
0151: * rectangle is at (<code>0</code>, <code>0</code>), and its size
0152: * is specified by the <code>width</code> and <code>height</code>
0153: * arguments.
0154: * </ul>
0155: * <p>
0156: * @param x the <i>x</i> coordinate.
0157: * @param y the <i>y</i> coordinate.
0158: * @param width the width of the clipping rectangle.
0159: * @param height the height of the clipping rectangle.
0160: * @return a new graphics context.
0161: * @see java.awt.Graphics#translate
0162: * @see java.awt.Graphics#clipRect
0163: */
0164: public Graphics create(int x, int y, int width, int height) {
0165: Graphics g = create();
0166: if (g == null)
0167: return null;
0168: g.translate(x, y);
0169: g.clipRect(0, 0, width, height);
0170: return g;
0171: }
0172:
0173: /**
0174: * Translates the origin of the graphics context to the point
0175: * (<i>x</i>, <i>y</i>) in the current coordinate system.
0176: * Modifies this graphics context so that its new origin corresponds
0177: * to the point (<i>x</i>, <i>y</i>) in this graphics context's
0178: * original coordinate system. All coordinates used in subsequent
0179: * rendering operations on this graphics context will be relative
0180: * to this new origin.
0181: * @param x the <i>x</i> coordinate.
0182: * @param y the <i>y</i> coordinate.
0183: */
0184: public abstract void translate(int x, int y);
0185:
0186: /**
0187: * Gets this graphics context's current color.
0188: * @return this graphics context's current color.
0189: * @see java.awt.Color
0190: * @see java.awt.Graphics#setColor(Color)
0191: */
0192: public abstract Color getColor();
0193:
0194: /**
0195: * Sets this graphics context's current color to the specified
0196: * color. All subsequent graphics operations using this graphics
0197: * context use this specified color.
0198: * @param c the new rendering color.
0199: * @see java.awt.Color
0200: * @see java.awt.Graphics#getColor
0201: */
0202: public abstract void setColor(Color c);
0203:
0204: /**
0205: * Sets the paint mode of this graphics context to overwrite the
0206: * destination with this graphics context's current color.
0207: * This sets the logical pixel operation function to the paint or
0208: * overwrite mode. All subsequent rendering operations will
0209: * overwrite the destination with the current color.
0210: */
0211: public abstract void setPaintMode();
0212:
0213: /**
0214: * Sets the paint mode of this graphics context to alternate between
0215: * this graphics context's current color and the new specified color.
0216: * This specifies that logical pixel operations are performed in the
0217: * XOR mode, which alternates pixels between the current color and
0218: * a specified XOR color.
0219: * <p>
0220: * When drawing operations are performed, pixels which are the
0221: * current color are changed to the specified color, and vice versa.
0222: * <p>
0223: * Pixels that are of colors other than those two colors are changed
0224: * in an unpredictable but reversible manner; if the same figure is
0225: * drawn twice, then all pixels are restored to their original values.
0226: * @param c1 the XOR alternation color
0227: */
0228: public abstract void setXORMode(Color c1);
0229:
0230: /**
0231: * Gets the current font.
0232: * @return this graphics context's current font.
0233: * @see java.awt.Font
0234: * @see java.awt.Graphics#setFont(Font)
0235: */
0236: public abstract Font getFont();
0237:
0238: /**
0239: * Sets this graphics context's font to the specified font.
0240: * All subsequent text operations using this graphics context
0241: * use this font. A null argument is silently ignored.
0242: * @param font the font.
0243: * @see java.awt.Graphics#getFont
0244: * @see java.awt.Graphics#drawString(java.lang.String, int, int)
0245: * @see java.awt.Graphics#drawBytes(byte[], int, int, int, int)
0246: * @see java.awt.Graphics#drawChars(char[], int, int, int, int)
0247: */
0248: public abstract void setFont(Font font);
0249:
0250: /**
0251: * Gets the font metrics of the current font.
0252: * @return the font metrics of this graphics
0253: * context's current font.
0254: * @see java.awt.Graphics#getFont
0255: * @see java.awt.FontMetrics
0256: * @see java.awt.Graphics#getFontMetrics(Font)
0257: */
0258: public FontMetrics getFontMetrics() {
0259: return getFontMetrics(getFont());
0260: }
0261:
0262: /**
0263: * Gets the font metrics for the specified font.
0264: * @return the font metrics for the specified font.
0265: * @param f the specified font
0266: * @see java.awt.Graphics#getFont
0267: * @see java.awt.FontMetrics
0268: * @see java.awt.Graphics#getFontMetrics()
0269: */
0270: public abstract FontMetrics getFontMetrics(Font f);
0271:
0272: /**
0273: * Returns the bounding rectangle of the current clipping area.
0274: * This method refers to the user clip, which is independent of the
0275: * clipping associated with device bounds and window visibility.
0276: * If no clip has previously been set, or if the clip has been
0277: * cleared using <code>setClip(null)</code>, this method returns
0278: * <code>null</code>.
0279: * The coordinates in the rectangle are relative to the coordinate
0280: * system origin of this graphics context.
0281: * @return the bounding rectangle of the current clipping area,
0282: * or <code>null</code> if no clip is set.
0283: * @see java.awt.Graphics#getClip
0284: * @see java.awt.Graphics#clipRect
0285: * @see java.awt.Graphics#setClip(int, int, int, int)
0286: * @see java.awt.Graphics#setClip(Shape)
0287: * @since JDK1.1
0288: */
0289: public abstract Rectangle getClipBounds();
0290:
0291: /**
0292: * Intersects the current clip with the specified rectangle.
0293: * The resulting clipping area is the intersection of the current
0294: * clipping area and the specified rectangle. If there is no
0295: * current clipping area, either because the clip has never been
0296: * set, or the clip has been cleared using <code>setClip(null)</code>,
0297: * the specified rectangle becomes the new clip.
0298: * This method sets the user clip, which is independent of the
0299: * clipping associated with device bounds and window visibility.
0300: * This method can only be used to make the current clip smaller.
0301: * To set the current clip larger, use any of the setClip methods.
0302: * Rendering operations have no effect outside of the clipping area.
0303: * @param x the x coordinate of the rectangle to intersect the clip with
0304: * @param y the y coordinate of the rectangle to intersect the clip with
0305: * @param width the width of the rectangle to intersect the clip with
0306: * @param height the height of the rectangle to intersect the clip with
0307: * @see #setClip(int, int, int, int)
0308: * @see #setClip(Shape)
0309: */
0310: public abstract void clipRect(int x, int y, int width, int height);
0311:
0312: /**
0313: * Sets the current clip to the rectangle specified by the given
0314: * coordinates. This method sets the user clip, which is
0315: * independent of the clipping associated with device bounds
0316: * and window visibility.
0317: * Rendering operations have no effect outside of the clipping area.
0318: * @param x the <i>x</i> coordinate of the new clip rectangle.
0319: * @param y the <i>y</i> coordinate of the new clip rectangle.
0320: * @param width the width of the new clip rectangle.
0321: * @param height the height of the new clip rectangle.
0322: * @see java.awt.Graphics#clipRect
0323: * @see java.awt.Graphics#setClip(Shape)
0324: * @see java.awt.Graphics#getClip
0325: * @since JDK1.1
0326: */
0327: public abstract void setClip(int x, int y, int width, int height);
0328:
0329: /**
0330: * Gets the current clipping area.
0331: * This method returns the user clip, which is independent of the
0332: * clipping associated with device bounds and window visibility.
0333: * If no clip has previously been set, or if the clip has been
0334: * cleared using <code>setClip(null)</code>, this method returns
0335: * <code>null</code>.
0336: * @return a <code>Shape</code> object representing the
0337: * current clipping area, or <code>null</code> if
0338: * no clip is set.
0339: * @see java.awt.Graphics#getClipBounds
0340: * @see java.awt.Graphics#clipRect
0341: * @see java.awt.Graphics#setClip(int, int, int, int)
0342: * @see java.awt.Graphics#setClip(Shape)
0343: * @since JDK1.1
0344: */
0345: public abstract Shape getClip();
0346:
0347: /**
0348: * Sets the current clipping area to an arbitrary clip shape.
0349: * Not all objects that implement the <code>Shape</code>
0350: * interface can be used to set the clip. The only
0351: * <code>Shape</code> objects that are guaranteed to be
0352: * supported are <code>Shape</code> objects that are
0353: * obtained via the <code>getClip</code> method and via
0354: * <code>Rectangle</code> objects. This method sets the
0355: * user clip, which is independent of the clipping associated
0356: * with device bounds and window visibility.
0357: * @param clip the <code>Shape</code> to use to set the clip
0358: * @see java.awt.Graphics#getClip()
0359: * @see java.awt.Graphics#clipRect
0360: * @see java.awt.Graphics#setClip(int, int, int, int)
0361: * @since JDK1.1
0362: */
0363: public abstract void setClip(Shape clip);
0364:
0365: /**
0366: * Copies an area of the component by a distance specified by
0367: * <code>dx</code> and <code>dy</code>. From the point specified
0368: * by <code>x</code> and <code>y</code>, this method
0369: * copies downwards and to the right. To copy an area of the
0370: * component to the left or upwards, specify a negative value for
0371: * <code>dx</code> or <code>dy</code>.
0372: * If a portion of the source rectangle lies outside the bounds
0373: * of the component, or is obscured by another window or component,
0374: * <code>copyArea</code> will be unable to copy the associated
0375: * pixels. The area that is omitted can be refreshed by calling
0376: * the component's <code>paint</code> method.
0377: * @param x the <i>x</i> coordinate of the source rectangle.
0378: * @param y the <i>y</i> coordinate of the source rectangle.
0379: * @param width the width of the source rectangle.
0380: * @param height the height of the source rectangle.
0381: * @param dx the horizontal distance to copy the pixels.
0382: * @param dy the vertical distance to copy the pixels.
0383: */
0384: public abstract void copyArea(int x, int y, int width, int height,
0385: int dx, int dy);
0386:
0387: /**
0388: * Draws a line, using the current color, between the points
0389: * <code>(x1, y1)</code> and <code>(x2, y2)</code>
0390: * in this graphics context's coordinate system.
0391: * @param x1 the first point's <i>x</i> coordinate.
0392: * @param y1 the first point's <i>y</i> coordinate.
0393: * @param x2 the second point's <i>x</i> coordinate.
0394: * @param y2 the second point's <i>y</i> coordinate.
0395: */
0396: public abstract void drawLine(int x1, int y1, int x2, int y2);
0397:
0398: /**
0399: * Fills the specified rectangle.
0400: * The left and right edges of the rectangle are at
0401: * <code>x</code> and <code>x + width - 1</code>.
0402: * The top and bottom edges are at
0403: * <code>y</code> and <code>y + height - 1</code>.
0404: * The resulting rectangle covers an area
0405: * <code>width</code> pixels wide by
0406: * <code>height</code> pixels tall.
0407: * The rectangle is filled using the graphics context's current color.
0408: * @param x the <i>x</i> coordinate
0409: * of the rectangle to be filled.
0410: * @param y the <i>y</i> coordinate
0411: * of the rectangle to be filled.
0412: * @param width the width of the rectangle to be filled.
0413: * @param height the height of the rectangle to be filled.
0414: * @see java.awt.Graphics#clearRect
0415: * @see java.awt.Graphics#drawRect
0416: */
0417: public abstract void fillRect(int x, int y, int width, int height);
0418:
0419: /**
0420: * Draws the outline of the specified rectangle.
0421: * The left and right edges of the rectangle are at
0422: * <code>x</code> and <code>x + width</code>.
0423: * The top and bottom edges are at
0424: * <code>y</code> and <code>y + height</code>.
0425: * The rectangle is drawn using the graphics context's current color.
0426: * @param x the <i>x</i> coordinate
0427: * of the rectangle to be drawn.
0428: * @param y the <i>y</i> coordinate
0429: * of the rectangle to be drawn.
0430: * @param width the width of the rectangle to be drawn.
0431: * @param height the height of the rectangle to be drawn.
0432: * @see java.awt.Graphics#fillRect
0433: * @see java.awt.Graphics#clearRect
0434: */
0435: public void drawRect(int x, int y, int width, int height) {
0436: if ((width < 0) || (height < 0)) {
0437: return;
0438: }
0439:
0440: if (height == 0 || width == 0) {
0441: drawLine(x, y, x + width, y + height);
0442: } else {
0443: drawLine(x, y, x + width - 1, y);
0444: drawLine(x + width, y, x + width, y + height - 1);
0445: drawLine(x + width, y + height, x + 1, y + height);
0446: drawLine(x, y + height, x, y + 1);
0447: }
0448: }
0449:
0450: /**
0451: * Clears the specified rectangle by filling it with the background
0452: * color of the current drawing surface. This operation does not
0453: * use the current paint mode.
0454: * <p>
0455: * Beginning with Java 1.1, the background color
0456: * of offscreen images may be system dependent. Applications should
0457: * use <code>setColor</code> followed by <code>fillRect</code> to
0458: * ensure that an offscreen image is cleared to a specific color.
0459: * @param x the <i>x</i> coordinate of the rectangle to clear.
0460: * @param y the <i>y</i> coordinate of the rectangle to clear.
0461: * @param width the width of the rectangle to clear.
0462: * @param height the height of the rectangle to clear.
0463: * @see java.awt.Graphics#fillRect(int, int, int, int)
0464: * @see java.awt.Graphics#drawRect
0465: * @see java.awt.Graphics#setColor(java.awt.Color)
0466: * @see java.awt.Graphics#setPaintMode
0467: * @see java.awt.Graphics#setXORMode(java.awt.Color)
0468: */
0469: public abstract void clearRect(int x, int y, int width, int height);
0470:
0471: /**
0472: * Draws an outlined round-cornered rectangle using this graphics
0473: * context's current color. The left and right edges of the rectangle
0474: * are at <code>x</code> and <code>x + width</code>,
0475: * respectively. The top and bottom edges of the rectangle are at
0476: * <code>y</code> and <code>y + height</code>.
0477: * @param x the <i>x</i> coordinate of the rectangle to be drawn.
0478: * @param y the <i>y</i> coordinate of the rectangle to be drawn.
0479: * @param width the width of the rectangle to be drawn.
0480: * @param height the height of the rectangle to be drawn.
0481: * @param arcWidth the horizontal diameter of the arc
0482: * at the four corners.
0483: * @param arcHeight the vertical diameter of the arc
0484: * at the four corners.
0485: * @see java.awt.Graphics#fillRoundRect
0486: */
0487: public abstract void drawRoundRect(int x, int y, int width,
0488: int height, int arcWidth, int arcHeight);
0489:
0490: /**
0491: * Fills the specified rounded corner rectangle with the current color.
0492: * The left and right edges of the rectangle
0493: * are at <code>x</code> and <code>x + width - 1</code>,
0494: * respectively. The top and bottom edges of the rectangle are at
0495: * <code>y</code> and <code>y + height - 1</code>.
0496: * @param x the <i>x</i> coordinate of the rectangle to be filled.
0497: * @param y the <i>y</i> coordinate of the rectangle to be filled.
0498: * @param width the width of the rectangle to be filled.
0499: * @param height the height of the rectangle to be filled.
0500: * @param arcWidth the horizontal diameter
0501: * of the arc at the four corners.
0502: * @param arcHeight the vertical diameter
0503: * of the arc at the four corners.
0504: * @see java.awt.Graphics#drawRoundRect
0505: */
0506: public abstract void fillRoundRect(int x, int y, int width,
0507: int height, int arcWidth, int arcHeight);
0508:
0509: /**
0510: * Draws a 3-D highlighted outline of the specified rectangle.
0511: * The edges of the rectangle are highlighted so that they
0512: * appear to be beveled and lit from the upper left corner.
0513: * <p>
0514: * The colors used for the highlighting effect are determined
0515: * based on the current color.
0516: * The resulting rectangle covers an area that is
0517: * <code>width + 1</code> pixels wide
0518: * by <code>height + 1</code> pixels tall.
0519: * @param x the <i>x</i> coordinate of the rectangle to be drawn.
0520: * @param y the <i>y</i> coordinate of the rectangle to be drawn.
0521: * @param width the width of the rectangle to be drawn.
0522: * @param height the height of the rectangle to be drawn.
0523: * @param raised a boolean that determines whether the rectangle
0524: * appears to be raised above the surface
0525: * or sunk into the surface.
0526: * @see java.awt.Graphics#fill3DRect
0527: */
0528: public void draw3DRect(int x, int y, int width, int height,
0529: boolean raised) {
0530: Color c = getColor();
0531: Color brighter = c.brighter();
0532: Color darker = c.darker();
0533:
0534: setColor(raised ? brighter : darker);
0535: drawLine(x, y, x, y + height);
0536: drawLine(x + 1, y, x + width - 1, y);
0537: setColor(raised ? darker : brighter);
0538: drawLine(x + 1, y + height, x + width, y + height);
0539: drawLine(x + width, y, x + width, y + height - 1);
0540: setColor(c);
0541: }
0542:
0543: /**
0544: * Paints a 3-D highlighted rectangle filled with the current color.
0545: * The edges of the rectangle will be highlighted so that it appears
0546: * as if the edges were beveled and lit from the upper left corner.
0547: * The colors used for the highlighting effect will be determined from
0548: * the current color.
0549: * @param x the <i>x</i> coordinate of the rectangle to be filled.
0550: * @param y the <i>y</i> coordinate of the rectangle to be filled.
0551: * @param width the width of the rectangle to be filled.
0552: * @param height the height of the rectangle to be filled.
0553: * @param raised a boolean value that determines whether the
0554: * rectangle appears to be raised above the surface
0555: * or etched into the surface.
0556: * @see java.awt.Graphics#draw3DRect
0557: */
0558: public void fill3DRect(int x, int y, int width, int height,
0559: boolean raised) {
0560: Color c = getColor();
0561: Color brighter = c.brighter();
0562: Color darker = c.darker();
0563:
0564: if (!raised) {
0565: setColor(darker);
0566: }
0567: fillRect(x + 1, y + 1, width - 2, height - 2);
0568: setColor(raised ? brighter : darker);
0569: drawLine(x, y, x, y + height - 1);
0570: drawLine(x + 1, y, x + width - 2, y);
0571: setColor(raised ? darker : brighter);
0572: drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
0573: drawLine(x + width - 1, y, x + width - 1, y + height - 2);
0574: setColor(c);
0575: }
0576:
0577: /**
0578: * Draws the outline of an oval.
0579: * The result is a circle or ellipse that fits within the
0580: * rectangle specified by the <code>x</code>, <code>y</code>,
0581: * <code>width</code>, and <code>height</code> arguments.
0582: * <p>
0583: * The oval covers an area that is
0584: * <code>width + 1</code> pixels wide
0585: * and <code>height + 1</code> pixels tall.
0586: * @param x the <i>x</i> coordinate of the upper left
0587: * corner of the oval to be drawn.
0588: * @param y the <i>y</i> coordinate of the upper left
0589: * corner of the oval to be drawn.
0590: * @param width the width of the oval to be drawn.
0591: * @param height the height of the oval to be drawn.
0592: * @see java.awt.Graphics#fillOval
0593: */
0594: public abstract void drawOval(int x, int y, int width, int height);
0595:
0596: /**
0597: * Fills an oval bounded by the specified rectangle with the
0598: * current color.
0599: * @param x the <i>x</i> coordinate of the upper left corner
0600: * of the oval to be filled.
0601: * @param y the <i>y</i> coordinate of the upper left corner
0602: * of the oval to be filled.
0603: * @param width the width of the oval to be filled.
0604: * @param height the height of the oval to be filled.
0605: * @see java.awt.Graphics#drawOval
0606: */
0607: public abstract void fillOval(int x, int y, int width, int height);
0608:
0609: /**
0610: * Draws the outline of a circular or elliptical arc
0611: * covering the specified rectangle.
0612: * <p>
0613: * The resulting arc begins at <code>startAngle</code> and extends
0614: * for <code>arcAngle</code> degrees, using the current color.
0615: * Angles are interpreted such that 0 degrees
0616: * is at the 3 o'clock position.
0617: * A positive value indicates a counter-clockwise rotation
0618: * while a negative value indicates a clockwise rotation.
0619: * <p>
0620: * The center of the arc is the center of the rectangle whose origin
0621: * is (<i>x</i>, <i>y</i>) and whose size is specified by the
0622: * <code>width</code> and <code>height</code> arguments.
0623: * <p>
0624: * The resulting arc covers an area
0625: * <code>width + 1</code> pixels wide
0626: * by <code>height + 1</code> pixels tall.
0627: * <p>
0628: * The angles are specified relative to the non-square extents of
0629: * the bounding rectangle such that 45 degrees always falls on the
0630: * line from the center of the ellipse to the upper right corner of
0631: * the bounding rectangle. As a result, if the bounding rectangle is
0632: * noticeably longer in one axis than the other, the angles to the
0633: * start and end of the arc segment will be skewed farther along the
0634: * longer axis of the bounds.
0635: * @param x the <i>x</i> coordinate of the
0636: * upper-left corner of the arc to be drawn.
0637: * @param y the <i>y</i> coordinate of the
0638: * upper-left corner of the arc to be drawn.
0639: * @param width the width of the arc to be drawn.
0640: * @param height the height of the arc to be drawn.
0641: * @param startAngle the beginning angle.
0642: * @param arcAngle the angular extent of the arc,
0643: * relative to the start angle.
0644: * @see java.awt.Graphics#fillArc
0645: */
0646: public abstract void drawArc(int x, int y, int width, int height,
0647: int startAngle, int arcAngle);
0648:
0649: /**
0650: * Fills a circular or elliptical arc covering the specified rectangle.
0651: * <p>
0652: * The resulting arc begins at <code>startAngle</code> and extends
0653: * for <code>arcAngle</code> degrees.
0654: * Angles are interpreted such that 0 degrees
0655: * is at the 3 o'clock position.
0656: * A positive value indicates a counter-clockwise rotation
0657: * while a negative value indicates a clockwise rotation.
0658: * <p>
0659: * The center of the arc is the center of the rectangle whose origin
0660: * is (<i>x</i>, <i>y</i>) and whose size is specified by the
0661: * <code>width</code> and <code>height</code> arguments.
0662: * <p>
0663: * The resulting arc covers an area
0664: * <code>width + 1</code> pixels wide
0665: * by <code>height + 1</code> pixels tall.
0666: * <p>
0667: * The angles are specified relative to the non-square extents of
0668: * the bounding rectangle such that 45 degrees always falls on the
0669: * line from the center of the ellipse to the upper right corner of
0670: * the bounding rectangle. As a result, if the bounding rectangle is
0671: * noticeably longer in one axis than the other, the angles to the
0672: * start and end of the arc segment will be skewed farther along the
0673: * longer axis of the bounds.
0674: * @param x the <i>x</i> coordinate of the
0675: * upper-left corner of the arc to be filled.
0676: * @param y the <i>y</i> coordinate of the
0677: * upper-left corner of the arc to be filled.
0678: * @param width the width of the arc to be filled.
0679: * @param height the height of the arc to be filled.
0680: * @param startAngle the beginning angle.
0681: * @param arcAngle the angular extent of the arc,
0682: * relative to the start angle.
0683: * @see java.awt.Graphics#drawArc
0684: */
0685: public abstract void fillArc(int x, int y, int width, int height,
0686: int startAngle, int arcAngle);
0687:
0688: /**
0689: * Draws a sequence of connected lines defined by
0690: * arrays of <i>x</i> and <i>y</i> coordinates.
0691: * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
0692: * The figure is not closed if the first point
0693: * differs from the last point.
0694: * @param xPoints an array of <i>x</i> points
0695: * @param yPoints an array of <i>y</i> points
0696: * @param nPoints the total number of points
0697: * @see java.awt.Graphics#drawPolygon(int[], int[], int)
0698: * @since JDK1.1
0699: */
0700: public abstract void drawPolyline(int xPoints[], int yPoints[],
0701: int nPoints);
0702:
0703: /**
0704: * Draws a closed polygon defined by
0705: * arrays of <i>x</i> and <i>y</i> coordinates.
0706: * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
0707: * <p>
0708: * This method draws the polygon defined by <code>nPoint</code> line
0709: * segments, where the first <code>nPoint - 1</code>
0710: * line segments are line segments from
0711: * <code>(xPoints[i - 1], yPoints[i - 1])</code>
0712: * to <code>(xPoints[i], yPoints[i])</code>, for
0713: * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
0714: * The figure is automatically closed by drawing a line connecting
0715: * the final point to the first point, if those points are different.
0716: * @param xPoints a an array of <code>x</code> coordinates.
0717: * @param yPoints a an array of <code>y</code> coordinates.
0718: * @param nPoints a the total number of points.
0719: * @see java.awt.Graphics#fillPolygon
0720: * @see java.awt.Graphics#drawPolyline
0721: */
0722: public abstract void drawPolygon(int xPoints[], int yPoints[],
0723: int nPoints);
0724:
0725: /**
0726: * Draws the outline of a polygon defined by the specified
0727: * <code>Polygon</code> object.
0728: * @param p the polygon to draw.
0729: * @see java.awt.Graphics#fillPolygon
0730: * @see java.awt.Graphics#drawPolyline
0731: */
0732: public void drawPolygon(Polygon p) {
0733: drawPolygon(p.xpoints, p.ypoints, p.npoints);
0734: }
0735:
0736: /**
0737: * Fills a closed polygon defined by
0738: * arrays of <i>x</i> and <i>y</i> coordinates.
0739: * <p>
0740: * This method draws the polygon defined by <code>nPoint</code> line
0741: * segments, where the first <code>nPoint - 1</code>
0742: * line segments are line segments from
0743: * <code>(xPoints[i - 1], yPoints[i - 1])</code>
0744: * to <code>(xPoints[i], yPoints[i])</code>, for
0745: * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
0746: * The figure is automatically closed by drawing a line connecting
0747: * the final point to the first point, if those points are different.
0748: * <p>
0749: * The area inside the polygon is defined using an
0750: * even-odd fill rule, also known as the alternating rule.
0751: * @param xPoints a an array of <code>x</code> coordinates.
0752: * @param yPoints a an array of <code>y</code> coordinates.
0753: * @param nPoints a the total number of points.
0754: * @see java.awt.Graphics#drawPolygon(int[], int[], int)
0755: */
0756: public abstract void fillPolygon(int xPoints[], int yPoints[],
0757: int nPoints);
0758:
0759: /**
0760: * Fills the polygon defined by the specified Polygon object with
0761: * the graphics context's current color.
0762: * <p>
0763: * The area inside the polygon is defined using an
0764: * even-odd fill rule, also known as the alternating rule.
0765: * @param p the polygon to fill.
0766: * @see java.awt.Graphics#drawPolygon(int[], int[], int)
0767: */
0768: public void fillPolygon(Polygon p) {
0769: fillPolygon(p.xpoints, p.ypoints, p.npoints);
0770: }
0771:
0772: /**
0773: * Draws the text given by the specified string, using this
0774: * graphics context's current font and color. The baseline of the
0775: * leftmost character is at position (<i>x</i>, <i>y</i>) in this
0776: * graphics context's coordinate system.
0777: * @param str the string to be drawn.
0778: * @param x the <i>x</i> coordinate.
0779: * @param y the <i>y</i> coordinate.
0780: * @throws NullPointerException if <code>str</code> is <code>null</code>.
0781: * @see java.awt.Graphics#drawBytes
0782: * @see java.awt.Graphics#drawChars
0783: */
0784: public abstract void drawString(String str, int x, int y);
0785:
0786: /**
0787: * Renders the text of the specified iterator applying its attributes
0788: * in accordance with the specification of the
0789: * {@link java.awt.font.TextAttribute TextAttribute} class.
0790: * <p>
0791: * The baseline of the leftmost character is at position
0792: * (<i>x</i>, <i>y</i>) in this graphics context's coordinate system.
0793: * @param iterator the iterator whose text is to be drawn
0794: * @param x the <i>x</i> coordinate.
0795: * @param y the <i>y</i> coordinate.
0796: * @throws NullPointerException if <code>iterator</code> is
0797: * <code>null</code>.
0798: * @see java.awt.Graphics#drawBytes
0799: * @see java.awt.Graphics#drawChars
0800: */
0801: public abstract void drawString(
0802: AttributedCharacterIterator iterator, int x, int y);
0803:
0804: /**
0805: * Draws the text given by the specified character array, using this
0806: * graphics context's current font and color. The baseline of the
0807: * first character is at position (<i>x</i>, <i>y</i>) in this
0808: * graphics context's coordinate system.
0809: * @param data the array of characters to be drawn
0810: * @param offset the start offset in the data
0811: * @param length the number of characters to be drawn
0812: * @param x the <i>x</i> coordinate of the baseline of the text
0813: * @param y the <i>y</i> coordinate of the baseline of the text
0814: * @throws NullPointerException if <code>data</code> is <code>null</code>.
0815: * @throws IndexOutOfBoundsException if <code>offset</code> or
0816: * <code>length</code>is less than zero, or
0817: * <code>offset+length</code> is greater than the length of the
0818: * <code>data</code> array.
0819: * @see java.awt.Graphics#drawBytes
0820: * @see java.awt.Graphics#drawString
0821: */
0822: public void drawChars(char data[], int offset, int length, int x,
0823: int y) {
0824: drawString(new String(data, offset, length), x, y);
0825: }
0826:
0827: /**
0828: * Draws the text given by the specified byte array, using this
0829: * graphics context's current font and color. The baseline of the
0830: * first character is at position (<i>x</i>, <i>y</i>) in this
0831: * graphics context's coordinate system.
0832: * <p>
0833: * Use of this method is not recommended as each byte is interpreted
0834: * as a Unicode code point in the range 0 to 255, and so can only be
0835: * used to draw Latin characters in that range.
0836: * @param data the data to be drawn
0837: * @param offset the start offset in the data
0838: * @param length the number of bytes that are drawn
0839: * @param x the <i>x</i> coordinate of the baseline of the text
0840: * @param y the <i>y</i> coordinate of the baseline of the text
0841: * @throws NullPointerException if <code>data</code> is <code>null</code>.
0842: * @throws IndexOutOfBoundsException if <code>offset</code> or
0843: * <code>length</code>is less than zero, or <code>offset+length</code>
0844: * is greater than the length of the <code>data</code> array.
0845: * @see java.awt.Graphics#drawChars
0846: * @see java.awt.Graphics#drawString
0847: */
0848: public void drawBytes(byte data[], int offset, int length, int x,
0849: int y) {
0850: drawString(new String(data, 0, offset, length), x, y);
0851: }
0852:
0853: /**
0854: * Draws as much of the specified image as is currently available.
0855: * The image is drawn with its top-left corner at
0856: * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
0857: * space. Transparent pixels in the image do not affect whatever
0858: * pixels are already there.
0859: * <p>
0860: * This method returns immediately in all cases, even if the
0861: * complete image has not yet been loaded, and it has not been dithered
0862: * and converted for the current output device.
0863: * <p>
0864: * If the image has completely loaded and its pixels are
0865: * no longer being changed, then
0866: * <code>drawImage</code> returns <code>true</code>.
0867: * Otherwise, <code>drawImage</code> returns <code>false</code>
0868: * and as more of
0869: * the image becomes available
0870: * or it is time to draw another frame of animation,
0871: * the process that loads the image notifies
0872: * the specified image observer.
0873: * @param img the specified image to be drawn. This method does
0874: * nothing if <code>img</code> is null.
0875: * @param x the <i>x</i> coordinate.
0876: * @param y the <i>y</i> coordinate.
0877: * @param observer object to be notified as more of
0878: * the image is converted.
0879: * @return <code>false</code> if the image pixels are still changing;
0880: * <code>true</code> otherwise.
0881: * @see java.awt.Image
0882: * @see java.awt.image.ImageObserver
0883: * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0884: */
0885: public abstract boolean drawImage(Image img, int x, int y,
0886: ImageObserver observer);
0887:
0888: /**
0889: * Draws as much of the specified image as has already been scaled
0890: * to fit inside the specified rectangle.
0891: * <p>
0892: * The image is drawn inside the specified rectangle of this
0893: * graphics context's coordinate space, and is scaled if
0894: * necessary. Transparent pixels do not affect whatever pixels
0895: * are already there.
0896: * <p>
0897: * This method returns immediately in all cases, even if the
0898: * entire image has not yet been scaled, dithered, and converted
0899: * for the current output device.
0900: * If the current output representation is not yet complete, then
0901: * <code>drawImage</code> returns <code>false</code>. As more of
0902: * the image becomes available, the process that loads the image notifies
0903: * the image observer by calling its <code>imageUpdate</code> method.
0904: * <p>
0905: * A scaled version of an image will not necessarily be
0906: * available immediately just because an unscaled version of the
0907: * image has been constructed for this output device. Each size of
0908: * the image may be cached separately and generated from the original
0909: * data in a separate image production sequence.
0910: * @param img the specified image to be drawn. This method does
0911: * nothing if <code>img</code> is null.
0912: * @param x the <i>x</i> coordinate.
0913: * @param y the <i>y</i> coordinate.
0914: * @param width the width of the rectangle.
0915: * @param height the height of the rectangle.
0916: * @param observer object to be notified as more of
0917: * the image is converted.
0918: * @return <code>false</code> if the image pixels are still changing;
0919: * <code>true</code> otherwise.
0920: * @see java.awt.Image
0921: * @see java.awt.image.ImageObserver
0922: * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0923: */
0924: public abstract boolean drawImage(Image img, int x, int y,
0925: int width, int height, ImageObserver observer);
0926:
0927: /**
0928: * Draws as much of the specified image as is currently available.
0929: * The image is drawn with its top-left corner at
0930: * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
0931: * space. Transparent pixels are drawn in the specified
0932: * background color.
0933: * <p>
0934: * This operation is equivalent to filling a rectangle of the
0935: * width and height of the specified image with the given color and then
0936: * drawing the image on top of it, but possibly more efficient.
0937: * <p>
0938: * This method returns immediately in all cases, even if the
0939: * complete image has not yet been loaded, and it has not been dithered
0940: * and converted for the current output device.
0941: * <p>
0942: * If the image has completely loaded and its pixels are
0943: * no longer being changed, then
0944: * <code>drawImage</code> returns <code>true</code>.
0945: * Otherwise, <code>drawImage</code> returns <code>false</code>
0946: * and as more of
0947: * the image becomes available
0948: * or it is time to draw another frame of animation,
0949: * the process that loads the image notifies
0950: * the specified image observer.
0951: * @param img the specified image to be drawn. This method does
0952: * nothing if <code>img</code> is null.
0953: * @param x the <i>x</i> coordinate.
0954: * @param y the <i>y</i> coordinate.
0955: * @param bgcolor the background color to paint under the
0956: * non-opaque portions of the image.
0957: * @param observer object to be notified as more of
0958: * the image is converted.
0959: * @return <code>false</code> if the image pixels are still changing;
0960: * <code>true</code> otherwise.
0961: * @see java.awt.Image
0962: * @see java.awt.image.ImageObserver
0963: * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0964: */
0965: public abstract boolean drawImage(Image img, int x, int y,
0966: Color bgcolor, ImageObserver observer);
0967:
0968: /**
0969: * Draws as much of the specified image as has already been scaled
0970: * to fit inside the specified rectangle.
0971: * <p>
0972: * The image is drawn inside the specified rectangle of this
0973: * graphics context's coordinate space, and is scaled if
0974: * necessary. Transparent pixels are drawn in the specified
0975: * background color.
0976: * This operation is equivalent to filling a rectangle of the
0977: * width and height of the specified image with the given color and then
0978: * drawing the image on top of it, but possibly more efficient.
0979: * <p>
0980: * This method returns immediately in all cases, even if the
0981: * entire image has not yet been scaled, dithered, and converted
0982: * for the current output device.
0983: * If the current output representation is not yet complete then
0984: * <code>drawImage</code> returns <code>false</code>. As more of
0985: * the image becomes available, the process that loads the image notifies
0986: * the specified image observer.
0987: * <p>
0988: * A scaled version of an image will not necessarily be
0989: * available immediately just because an unscaled version of the
0990: * image has been constructed for this output device. Each size of
0991: * the image may be cached separately and generated from the original
0992: * data in a separate image production sequence.
0993: * @param img the specified image to be drawn. This method does
0994: * nothing if <code>img</code> is null.
0995: * @param x the <i>x</i> coordinate.
0996: * @param y the <i>y</i> coordinate.
0997: * @param width the width of the rectangle.
0998: * @param height the height of the rectangle.
0999: * @param bgcolor the background color to paint under the
1000: * non-opaque portions of the image.
1001: * @param observer object to be notified as more of
1002: * the image is converted.
1003: * @return <code>false</code> if the image pixels are still changing;
1004: * <code>true</code> otherwise.
1005: * @see java.awt.Image
1006: * @see java.awt.image.ImageObserver
1007: * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
1008: */
1009: public abstract boolean drawImage(Image img, int x, int y,
1010: int width, int height, Color bgcolor, ImageObserver observer);
1011:
1012: /**
1013: * Draws as much of the specified area of the specified image as is
1014: * currently available, scaling it on the fly to fit inside the
1015: * specified area of the destination drawable surface. Transparent pixels
1016: * do not affect whatever pixels are already there.
1017: * <p>
1018: * This method returns immediately in all cases, even if the
1019: * image area to be drawn has not yet been scaled, dithered, and converted
1020: * for the current output device.
1021: * If the current output representation is not yet complete then
1022: * <code>drawImage</code> returns <code>false</code>. As more of
1023: * the image becomes available, the process that loads the image notifies
1024: * the specified image observer.
1025: * <p>
1026: * This method always uses the unscaled version of the image
1027: * to render the scaled rectangle and performs the required
1028: * scaling on the fly. It does not use a cached, scaled version
1029: * of the image for this operation. Scaling of the image from source
1030: * to destination is performed such that the first coordinate
1031: * of the source rectangle is mapped to the first coordinate of
1032: * the destination rectangle, and the second source coordinate is
1033: * mapped to the second destination coordinate. The subimage is
1034: * scaled and flipped as needed to preserve those mappings.
1035: * @param img the specified image to be drawn. This method does
1036: * nothing if <code>img</code> is null.
1037: * @param dx1 the <i>x</i> coordinate of the first corner of the
1038: * destination rectangle.
1039: * @param dy1 the <i>y</i> coordinate of the first corner of the
1040: * destination rectangle.
1041: * @param dx2 the <i>x</i> coordinate of the second corner of the
1042: * destination rectangle.
1043: * @param dy2 the <i>y</i> coordinate of the second corner of the
1044: * destination rectangle.
1045: * @param sx1 the <i>x</i> coordinate of the first corner of the
1046: * source rectangle.
1047: * @param sy1 the <i>y</i> coordinate of the first corner of the
1048: * source rectangle.
1049: * @param sx2 the <i>x</i> coordinate of the second corner of the
1050: * source rectangle.
1051: * @param sy2 the <i>y</i> coordinate of the second corner of the
1052: * source rectangle.
1053: * @param observer object to be notified as more of the image is
1054: * scaled and converted.
1055: * @return <code>false</code> if the image pixels are still changing;
1056: * <code>true</code> otherwise.
1057: * @see java.awt.Image
1058: * @see java.awt.image.ImageObserver
1059: * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
1060: * @since JDK1.1
1061: */
1062: public abstract boolean drawImage(Image img, int dx1, int dy1,
1063: int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
1064: ImageObserver observer);
1065:
1066: /**
1067: * Draws as much of the specified area of the specified image as is
1068: * currently available, scaling it on the fly to fit inside the
1069: * specified area of the destination drawable surface.
1070: * <p>
1071: * Transparent pixels are drawn in the specified background color.
1072: * This operation is equivalent to filling a rectangle of the
1073: * width and height of the specified image with the given color and then
1074: * drawing the image on top of it, but possibly more efficient.
1075: * <p>
1076: * This method returns immediately in all cases, even if the
1077: * image area to be drawn has not yet been scaled, dithered, and converted
1078: * for the current output device.
1079: * If the current output representation is not yet complete then
1080: * <code>drawImage</code> returns <code>false</code>. As more of
1081: * the image becomes available, the process that loads the image notifies
1082: * the specified image observer.
1083: * <p>
1084: * This method always uses the unscaled version of the image
1085: * to render the scaled rectangle and performs the required
1086: * scaling on the fly. It does not use a cached, scaled version
1087: * of the image for this operation. Scaling of the image from source
1088: * to destination is performed such that the first coordinate
1089: * of the source rectangle is mapped to the first coordinate of
1090: * the destination rectangle, and the second source coordinate is
1091: * mapped to the second destination coordinate. The subimage is
1092: * scaled and flipped as needed to preserve those mappings.
1093: * @param img the specified image to be drawn. This method does
1094: * nothing if <code>img</code> is null.
1095: * @param dx1 the <i>x</i> coordinate of the first corner of the
1096: * destination rectangle.
1097: * @param dy1 the <i>y</i> coordinate of the first corner of the
1098: * destination rectangle.
1099: * @param dx2 the <i>x</i> coordinate of the second corner of the
1100: * destination rectangle.
1101: * @param dy2 the <i>y</i> coordinate of the second corner of the
1102: * destination rectangle.
1103: * @param sx1 the <i>x</i> coordinate of the first corner of the
1104: * source rectangle.
1105: * @param sy1 the <i>y</i> coordinate of the first corner of the
1106: * source rectangle.
1107: * @param sx2 the <i>x</i> coordinate of the second corner of the
1108: * source rectangle.
1109: * @param sy2 the <i>y</i> coordinate of the second corner of the
1110: * source rectangle.
1111: * @param bgcolor the background color to paint under the
1112: * non-opaque portions of the image.
1113: * @param observer object to be notified as more of the image is
1114: * scaled and converted.
1115: * @return <code>false</code> if the image pixels are still changing;
1116: * <code>true</code> otherwise.
1117: * @see java.awt.Image
1118: * @see java.awt.image.ImageObserver
1119: * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
1120: * @since JDK1.1
1121: */
1122: public abstract boolean drawImage(Image img, int dx1, int dy1,
1123: int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
1124: Color bgcolor, ImageObserver observer);
1125:
1126: /**
1127: * Disposes of this graphics context and releases
1128: * any system resources that it is using.
1129: * A <code>Graphics</code> object cannot be used after
1130: * <code>dispose</code>has been called.
1131: * <p>
1132: * When a Java program runs, a large number of <code>Graphics</code>
1133: * objects can be created within a short time frame.
1134: * Although the finalization process of the garbage collector
1135: * also disposes of the same system resources, it is preferable
1136: * to manually free the associated resources by calling this
1137: * method rather than to rely on a finalization process which
1138: * may not run to completion for a long period of time.
1139: * <p>
1140: * Graphics objects which are provided as arguments to the
1141: * <code>paint</code> and <code>update</code> methods
1142: * of components are automatically released by the system when
1143: * those methods return. For efficiency, programmers should
1144: * call <code>dispose</code> when finished using
1145: * a <code>Graphics</code> object only if it was created
1146: * directly from a component or another <code>Graphics</code> object.
1147: * @see java.awt.Graphics#finalize
1148: * @see java.awt.Component#paint
1149: * @see java.awt.Component#update
1150: * @see java.awt.Component#getGraphics
1151: * @see java.awt.Graphics#create
1152: */
1153: public abstract void dispose();
1154:
1155: /**
1156: * Disposes of this graphics context once it is no longer referenced.
1157: * @see #dispose
1158: */
1159: public void finalize() {
1160: dispose();
1161: }
1162:
1163: /**
1164: * Returns a <code>String</code> object representing this
1165: * <code>Graphics</code> object's value.
1166: * @return a string representation of this graphics context.
1167: */
1168: public String toString() {
1169: return getClass().getName() + "[font=" + getFont() + ",color="
1170: + getColor() + "]";
1171: }
1172:
1173: /**
1174: * Returns the bounding rectangle of the current clipping area.
1175: * @return the bounding rectangle of the current clipping area
1176: * or <code>null</code> if no clip is set.
1177: * @deprecated As of JDK version 1.1,
1178: * replaced by <code>getClipBounds()</code>.
1179: */
1180: @Deprecated
1181: public Rectangle getClipRect() {
1182: return getClipBounds();
1183: }
1184:
1185: /**
1186: * Returns true if the specified rectangular area might intersect
1187: * the current clipping area.
1188: * The coordinates of the specified rectangular area are in the
1189: * user coordinate space and are relative to the coordinate
1190: * system origin of this graphics context.
1191: * This method may use an algorithm that calculates a result quickly
1192: * but which sometimes might return true even if the specified
1193: * rectangular area does not intersect the clipping area.
1194: * The specific algorithm employed may thus trade off accuracy for
1195: * speed, but it will never return false unless it can guarantee
1196: * that the specified rectangular area does not intersect the
1197: * current clipping area.
1198: * The clipping area used by this method can represent the
1199: * intersection of the user clip as specified through the clip
1200: * methods of this graphics context as well as the clipping
1201: * associated with the device or image bounds and window visibility.
1202: *
1203: * @param x the x coordinate of the rectangle to test against the clip
1204: * @param y the y coordinate of the rectangle to test against the clip
1205: * @param width the width of the rectangle to test against the clip
1206: * @param height the height of the rectangle to test against the clip
1207: * @return <code>true</code> if the specified rectangle intersects
1208: * the bounds of the current clip; <code>false</code>
1209: * otherwise.
1210: */
1211: public boolean hitClip(int x, int y, int width, int height) {
1212: // Note, this implementation is not very efficient.
1213: // Subclasses should override this method and calculate
1214: // the results more directly.
1215: Rectangle clipRect = getClipBounds();
1216: if (clipRect == null) {
1217: return true;
1218: }
1219: return clipRect.intersects(x, y, width, height);
1220: }
1221:
1222: /**
1223: * Returns the bounding rectangle of the current clipping area.
1224: * The coordinates in the rectangle are relative to the coordinate
1225: * system origin of this graphics context. This method differs
1226: * from {@link #getClipBounds() getClipBounds} in that an existing
1227: * rectangle is used instead of allocating a new one.
1228: * This method refers to the user clip, which is independent of the
1229: * clipping associated with device bounds and window visibility.
1230: * If no clip has previously been set, or if the clip has been
1231: * cleared using <code>setClip(null)</code>, this method returns the
1232: * specified <code>Rectangle</code>.
1233: * @param r the rectangle where the current clipping area is
1234: * copied to. Any current values in this rectangle are
1235: * overwritten.
1236: * @return the bounding rectangle of the current clipping area.
1237: */
1238: public Rectangle getClipBounds(Rectangle r) {
1239: // Note, this implementation is not very efficient.
1240: // Subclasses should override this method and avoid
1241: // the allocation overhead of getClipBounds().
1242: Rectangle clipRect = getClipBounds();
1243: if (clipRect != null) {
1244: r.x = clipRect.x;
1245: r.y = clipRect.y;
1246: r.width = clipRect.width;
1247: r.height = clipRect.height;
1248: } else if (r == null) {
1249: throw new NullPointerException("null rectangle parameter");
1250: }
1251: return r;
1252: }
1253: }
|