0001: /*
0002: * Copyright 1996-2005 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:
0026: package java.awt;
0027:
0028: import java.awt.RenderingHints.Key;
0029: import java.awt.geom.AffineTransform;
0030: import java.awt.image.ImageObserver;
0031: import java.awt.image.BufferedImageOp;
0032: import java.awt.image.BufferedImage;
0033: import java.awt.image.RenderedImage;
0034: import java.awt.image.renderable.RenderableImage;
0035: import java.awt.font.GlyphVector;
0036: import java.awt.font.FontRenderContext;
0037: import java.awt.font.TextAttribute;
0038: import java.text.AttributedCharacterIterator;
0039: import java.util.Map;
0040:
0041: /**
0042: * This <code>Graphics2D</code> class extends the
0043: * {@link Graphics} class to provide more sophisticated
0044: * control over geometry, coordinate transformations, color management,
0045: * and text layout. This is the fundamental class for rendering
0046: * 2-dimensional shapes, text and images on the Java(tm) platform.
0047: * <p>
0048: * <h2>Coordinate Spaces</h2>
0049: * All coordinates passed to a <code>Graphics2D</code> object are specified
0050: * in a device-independent coordinate system called User Space, which is
0051: * used by applications. The <code>Graphics2D</code> object contains
0052: * an {@link AffineTransform} object as part of its rendering state
0053: * that defines how to convert coordinates from user space to
0054: * device-dependent coordinates in Device Space.
0055: * <p>
0056: * Coordinates in device space usually refer to individual device pixels
0057: * and are aligned on the infinitely thin gaps between these pixels.
0058: * Some <code>Graphics2D</code> objects can be used to capture rendering
0059: * operations for storage into a graphics metafile for playback on a
0060: * concrete device of unknown physical resolution at a later time. Since
0061: * the resolution might not be known when the rendering operations are
0062: * captured, the <code>Graphics2D</code> <code>Transform</code> is set up
0063: * to transform user coordinates to a virtual device space that
0064: * approximates the expected resolution of the target device. Further
0065: * transformations might need to be applied at playback time if the
0066: * estimate is incorrect.
0067: * <p>
0068: * Some of the operations performed by the rendering attribute objects
0069: * occur in the device space, but all <code>Graphics2D</code> methods take
0070: * user space coordinates.
0071: * <p>
0072: * Every <code>Graphics2D</code> object is associated with a target that
0073: * defines where rendering takes place. A
0074: * {@link GraphicsConfiguration} object defines the characteristics
0075: * of the rendering target, such as pixel format and resolution.
0076: * The same rendering target is used throughout the life of a
0077: * <code>Graphics2D</code> object.
0078: * <p>
0079: * When creating a <code>Graphics2D</code> object, the
0080: * <code>GraphicsConfiguration</code>
0081: * specifies the <a name="#deftransform">default transform</a> for
0082: * the target of the <code>Graphics2D</code> (a
0083: * {@link Component} or {@link Image}). This default transform maps the
0084: * user space coordinate system to screen and printer device coordinates
0085: * such that the origin maps to the upper left hand corner of the
0086: * target region of the device with increasing X coordinates extending
0087: * to the right and increasing Y coordinates extending downward.
0088: * The scaling of the default transform is set to identity for those devices
0089: * that are close to 72 dpi, such as screen devices.
0090: * The scaling of the default transform is set to approximately 72 user
0091: * space coordinates per square inch for high resolution devices, such as
0092: * printers. For image buffers, the default transform is the
0093: * <code>Identity</code> transform.
0094: *
0095: * <h2>Rendering Process</h2>
0096: * The Rendering Process can be broken down into four phases that are
0097: * controlled by the <code>Graphics2D</code> rendering attributes.
0098: * The renderer can optimize many of these steps, either by caching the
0099: * results for future calls, by collapsing multiple virtual steps into
0100: * a single operation, or by recognizing various attributes as common
0101: * simple cases that can be eliminated by modifying other parts of the
0102: * operation.
0103: * <p>
0104: * The steps in the rendering process are:
0105: * <ol>
0106: * <li>
0107: * Determine what to render.
0108: * <li>
0109: * Constrain the rendering operation to the current <code>Clip</code>.
0110: * The <code>Clip</code> is specified by a {@link Shape} in user
0111: * space and is controlled by the program using the various clip
0112: * manipulation methods of <code>Graphics</code> and
0113: * <code>Graphics2D</code>. This <i>user clip</i>
0114: * is transformed into device space by the current
0115: * <code>Transform</code> and combined with the
0116: * <i>device clip</i>, which is defined by the visibility of windows and
0117: * device extents. The combination of the user clip and device clip
0118: * defines the <i>composite clip</i>, which determines the final clipping
0119: * region. The user clip is not modified by the rendering
0120: * system to reflect the resulting composite clip.
0121: * <li>
0122: * Determine what colors to render.
0123: * <li>
0124: * Apply the colors to the destination drawing surface using the current
0125: * {@link Composite} attribute in the <code>Graphics2D</code> context.
0126: * </ol>
0127: * <br>
0128: * The three types of rendering operations, along with details of each
0129: * of their particular rendering processes are:
0130: * <ol>
0131: * <li>
0132: * <b><a name="rendershape"><code>Shape</code> operations</a></b>
0133: * <ol>
0134: * <li>
0135: * If the operation is a <code>draw(Shape)</code> operation, then
0136: * the {@link Stroke#createStrokedShape(Shape) createStrokedShape}
0137: * method on the current {@link Stroke} attribute in the
0138: * <code>Graphics2D</code> context is used to construct a new
0139: * <code>Shape</code> object that contains the outline of the specified
0140: * <code>Shape</code>.
0141: * <li>
0142: * The <code>Shape</code> is transformed from user space to device space
0143: * using the current <code>Transform</code>
0144: * in the <code>Graphics2D</code> context.
0145: * <li>
0146: * The outline of the <code>Shape</code> is extracted using the
0147: * {@link Shape#getPathIterator(AffineTransform) getPathIterator} method of
0148: * <code>Shape</code>, which returns a
0149: * {@link java.awt.geom.PathIterator PathIterator}
0150: * object that iterates along the boundary of the <code>Shape</code>.
0151: * <li>
0152: * If the <code>Graphics2D</code> object cannot handle the curved segments
0153: * that the <code>PathIterator</code> object returns then it can call the
0154: * alternate
0155: * {@link Shape#getPathIterator(AffineTransform, double) getPathIterator}
0156: * method of <code>Shape</code>, which flattens the <code>Shape</code>.
0157: * <li>
0158: * The current {@link Paint} in the <code>Graphics2D</code> context
0159: * is queried for a {@link PaintContext}, which specifies the
0160: * colors to render in device space.
0161: * </ol>
0162: * <li>
0163: * <b><a name=rendertext>Text operations</a></b>
0164: * <ol>
0165: * <li>
0166: * The following steps are used to determine the set of glyphs required
0167: * to render the indicated <code>String</code>:
0168: * <ol>
0169: * <li>
0170: * If the argument is a <code>String</code>, then the current
0171: * <code>Font</code> in the <code>Graphics2D</code> context is asked to
0172: * convert the Unicode characters in the <code>String</code> into a set of
0173: * glyphs for presentation with whatever basic layout and shaping
0174: * algorithms the font implements.
0175: * <li>
0176: * If the argument is an
0177: * {@link AttributedCharacterIterator},
0178: * the iterator is asked to convert itself to a
0179: * {@link java.awt.font.TextLayout TextLayout}
0180: * using its embedded font attributes. The <code>TextLayout</code>
0181: * implements more sophisticated glyph layout algorithms that
0182: * perform Unicode bi-directional layout adjustments automatically
0183: * for multiple fonts of differing writing directions.
0184: * <li>
0185: * If the argument is a
0186: * {@link GlyphVector}, then the
0187: * <code>GlyphVector</code> object already contains the appropriate
0188: * font-specific glyph codes with explicit coordinates for the position of
0189: * each glyph.
0190: * </ol>
0191: * <li>
0192: * The current <code>Font</code> is queried to obtain outlines for the
0193: * indicated glyphs. These outlines are treated as shapes in user space
0194: * relative to the position of each glyph that was determined in step 1.
0195: * <li>
0196: * The character outlines are filled as indicated above
0197: * under <a href="#rendershape"><code>Shape</code> operations</a>.
0198: * <li>
0199: * The current <code>Paint</code> is queried for a
0200: * <code>PaintContext</code>, which specifies
0201: * the colors to render in device space.
0202: * </ol>
0203: * <li>
0204: * <b><a name= renderingimage><code>Image</code> Operations</a></b>
0205: * <ol>
0206: * <li>
0207: * The region of interest is defined by the bounding box of the source
0208: * <code>Image</code>.
0209: * This bounding box is specified in Image Space, which is the
0210: * <code>Image</code> object's local coordinate system.
0211: * <li>
0212: * If an <code>AffineTransform</code> is passed to
0213: * {@link #drawImage(java.awt.Image, java.awt.geom.AffineTransform, java.awt.image.ImageObserver) drawImage(Image, AffineTransform, ImageObserver)},
0214: * the <code>AffineTransform</code> is used to transform the bounding
0215: * box from image space to user space. If no <code>AffineTransform</code>
0216: * is supplied, the bounding box is treated as if it is already in user space.
0217: * <li>
0218: * The bounding box of the source <code>Image</code> is transformed from user
0219: * space into device space using the current <code>Transform</code>.
0220: * Note that the result of transforming the bounding box does not
0221: * necessarily result in a rectangular region in device space.
0222: * <li>
0223: * The <code>Image</code> object determines what colors to render,
0224: * sampled according to the source to destination
0225: * coordinate mapping specified by the current <code>Transform</code> and the
0226: * optional image transform.
0227: * </ol>
0228: * </ol>
0229: *
0230: * <h2>Default Rendering Attributes</h2>
0231: * The default values for the <code>Graphics2D</code> rendering attributes are:
0232: * <dl compact>
0233: * <dt><i><code>Paint</code></i>
0234: * <dd>The color of the <code>Component</code>.
0235: * <dt><i><code>Font</code></i>
0236: * <dd>The <code>Font</code> of the <code>Component</code>.
0237: * <dt><i><code>Stroke</code></i>
0238: * <dd>A square pen with a linewidth of 1, no dashing, miter segment joins
0239: * and square end caps.
0240: * <dt><i><code>Transform</code></i>
0241: * <dd>The
0242: * {@link GraphicsConfiguration#getDefaultTransform() getDefaultTransform}
0243: * for the <code>GraphicsConfiguration</code> of the <code>Component</code>.
0244: * <dt><i><code>Composite</code></i>
0245: * <dd>The {@link AlphaComposite#SRC_OVER} rule.
0246: * <dt><i><code>Clip</code></i>
0247: * <dd>No rendering <code>Clip</code>, the output is clipped to the
0248: * <code>Component</code>.
0249: * </dl>
0250: *
0251: * <h2>Rendering Compatibility Issues</h2>
0252: * The JDK(tm) 1.1 rendering model is based on a pixelization model
0253: * that specifies that coordinates
0254: * are infinitely thin, lying between the pixels. Drawing operations are
0255: * performed using a one-pixel wide pen that fills the
0256: * pixel below and to the right of the anchor point on the path.
0257: * The JDK 1.1 rendering model is consistent with the
0258: * capabilities of most of the existing class of platform
0259: * renderers that need to resolve integer coordinates to a
0260: * discrete pen that must fall completely on a specified number of pixels.
0261: * <p>
0262: * The Java 2D(tm) (Java(tm) 2 platform) API supports antialiasing renderers.
0263: * A pen with a width of one pixel does not need to fall
0264: * completely on pixel N as opposed to pixel N+1. The pen can fall
0265: * partially on both pixels. It is not necessary to choose a bias
0266: * direction for a wide pen since the blending that occurs along the
0267: * pen traversal edges makes the sub-pixel position of the pen
0268: * visible to the user. On the other hand, when antialiasing is
0269: * turned off by setting the
0270: * {@link RenderingHints#KEY_ANTIALIASING KEY_ANTIALIASING} hint key
0271: * to the
0272: * {@link RenderingHints#VALUE_ANTIALIAS_OFF VALUE_ANTIALIAS_OFF}
0273: * hint value, the renderer might need
0274: * to apply a bias to determine which pixel to modify when the pen
0275: * is straddling a pixel boundary, such as when it is drawn
0276: * along an integer coordinate in device space. While the capabilities
0277: * of an antialiasing renderer make it no longer necessary for the
0278: * rendering model to specify a bias for the pen, it is desirable for the
0279: * antialiasing and non-antialiasing renderers to perform similarly for
0280: * the common cases of drawing one-pixel wide horizontal and vertical
0281: * lines on the screen. To ensure that turning on antialiasing by
0282: * setting the
0283: * {@link RenderingHints#KEY_ANTIALIASING KEY_ANTIALIASING} hint
0284: * key to
0285: * {@link RenderingHints#VALUE_ANTIALIAS_ON VALUE_ANTIALIAS_ON}
0286: * does not cause such lines to suddenly become twice as wide and half
0287: * as opaque, it is desirable to have the model specify a path for such
0288: * lines so that they completely cover a particular set of pixels to help
0289: * increase their crispness.
0290: * <p>
0291: * Java 2D API maintains compatibility with JDK 1.1 rendering
0292: * behavior, such that legacy operations and existing renderer
0293: * behavior is unchanged under Java 2D API. Legacy
0294: * methods that map onto general <code>draw</code> and
0295: * <code>fill</code> methods are defined, which clearly indicates
0296: * how <code>Graphics2D</code> extends <code>Graphics</code> based
0297: * on settings of <code>Stroke</code> and <code>Transform</code>
0298: * attributes and rendering hints. The definition
0299: * performs identically under default attribute settings.
0300: * For example, the default <code>Stroke</code> is a
0301: * <code>BasicStroke</code> with a width of 1 and no dashing and the
0302: * default Transform for screen drawing is an Identity transform.
0303: * <p>
0304: * The following two rules provide predictable rendering behavior whether
0305: * aliasing or antialiasing is being used.
0306: * <ul>
0307: * <li> Device coordinates are defined to be between device pixels which
0308: * avoids any inconsistent results between aliased and antaliased
0309: * rendering. If coordinates were defined to be at a pixel's center, some
0310: * of the pixels covered by a shape, such as a rectangle, would only be
0311: * half covered.
0312: * With aliased rendering, the half covered pixels would either be
0313: * rendered inside the shape or outside the shape. With anti-aliased
0314: * rendering, the pixels on the entire edge of the shape would be half
0315: * covered. On the other hand, since coordinates are defined to be
0316: * between pixels, a shape like a rectangle would have no half covered
0317: * pixels, whether or not it is rendered using antialiasing.
0318: * <li> Lines and paths stroked using the <code>BasicStroke</code>
0319: * object may be "normalized" to provide consistent rendering of the
0320: * outlines when positioned at various points on the drawable and
0321: * whether drawn with aliased or antialiased rendering. This
0322: * normalization process is controlled by the
0323: * {@link RenderingHints#KEY_STROKE_CONTROL KEY_STROKE_CONTROL} hint.
0324: * The exact normalization algorithm is not specified, but the goals
0325: * of this normalization are to ensure that lines are rendered with
0326: * consistent visual appearance regardless of how they fall on the
0327: * pixel grid and to promote more solid horizontal and vertical
0328: * lines in antialiased mode so that they resemble their non-antialiased
0329: * counterparts more closely. A typical normalization step might
0330: * promote antialiased line endpoints to pixel centers to reduce the
0331: * amount of blending or adjust the subpixel positioning of
0332: * non-antialiased lines so that the floating point line widths
0333: * round to even or odd pixel counts with equal likelihood. This
0334: * process can move endpoints by up to half a pixel (usually towards
0335: * positive infinity along both axes) to promote these consistent
0336: * results.
0337: * </ul>
0338: * <p>
0339: * The following definitions of general legacy methods
0340: * perform identically to previously specified behavior under default
0341: * attribute settings:
0342: * <ul>
0343: * <li>
0344: * For <code>fill</code> operations, including <code>fillRect</code>,
0345: * <code>fillRoundRect</code>, <code>fillOval</code>,
0346: * <code>fillArc</code>, <code>fillPolygon</code>, and
0347: * <code>clearRect</code>, {@link #fill(Shape) fill} can now be called
0348: * with the desired <code>Shape</code>. For example, when filling a
0349: * rectangle:
0350: * <pre>
0351: * fill(new Rectangle(x, y, w, h));
0352: * </pre>
0353: * is called.
0354: * <p>
0355: * <li>
0356: * Similarly, for draw operations, including <code>drawLine</code>,
0357: * <code>drawRect</code>, <code>drawRoundRect</code>,
0358: * <code>drawOval</code>, <code>drawArc</code>, <code>drawPolyline</code>,
0359: * and <code>drawPolygon</code>, {@link #draw(Shape) draw} can now be
0360: * called with the desired <code>Shape</code>. For example, when drawing a
0361: * rectangle:
0362: * <pre>
0363: * draw(new Rectangle(x, y, w, h));
0364: * </pre>
0365: * is called.
0366: * <p>
0367: * <li>
0368: * The <code>draw3DRect</code> and <code>fill3DRect</code> methods were
0369: * implemented in terms of the <code>drawLine</code> and
0370: * <code>fillRect</code> methods in the <code>Graphics</code> class which
0371: * would predicate their behavior upon the current <code>Stroke</code>
0372: * and <code>Paint</code> objects in a <code>Graphics2D</code> context.
0373: * This class overrides those implementations with versions that use
0374: * the current <code>Color</code> exclusively, overriding the current
0375: * <code>Paint</code> and which uses <code>fillRect</code> to describe
0376: * the exact same behavior as the preexisting methods regardless of the
0377: * setting of the current <code>Stroke</code>.
0378: * </ul>
0379: * The <code>Graphics</code> class defines only the <code>setColor</code>
0380: * method to control the color to be painted. Since the Java 2D API extends
0381: * the <code>Color</code> object to implement the new <code>Paint</code>
0382: * interface, the existing
0383: * <code>setColor</code> method is now a convenience method for setting the
0384: * current <code>Paint</code> attribute to a <code>Color</code> object.
0385: * <code>setColor(c)</code> is equivalent to <code>setPaint(c)</code>.
0386: * <p>
0387: * The <code>Graphics</code> class defines two methods for controlling
0388: * how colors are applied to the destination.
0389: * <ol>
0390: * <li>
0391: * The <code>setPaintMode</code> method is implemented as a convenience
0392: * method to set the default <code>Composite</code>, equivalent to
0393: * <code>setComposite(new AlphaComposite.SrcOver)</code>.
0394: * <li>
0395: * The <code>setXORMode(Color xorcolor)</code> method is implemented
0396: * as a convenience method to set a special <code>Composite</code> object that
0397: * ignores the <code>Alpha</code> components of source colors and sets the
0398: * destination color to the value:
0399: * <pre>
0400: * dstpixel = (PixelOf(srccolor) ^ PixelOf(xorcolor) ^ dstpixel);
0401: * </pre>
0402: * </ol>
0403: *
0404: * @version 1.90, 05/05/07
0405: * @author Jim Graham
0406: * @see java.awt.RenderingHints
0407: */
0408: public abstract class Graphics2D extends Graphics {
0409:
0410: /**
0411: * Constructs a new <code>Graphics2D</code> object. Since
0412: * <code>Graphics2D</code> is an abstract class, and since it must be
0413: * customized by subclasses for different output devices,
0414: * <code>Graphics2D</code> objects cannot be created directly.
0415: * Instead, <code>Graphics2D</code> objects must be obtained from another
0416: * <code>Graphics2D</code> object, created by a
0417: * <code>Component</code>, or obtained from images such as
0418: * {@link BufferedImage} objects.
0419: * @see java.awt.Component#getGraphics
0420: * @see java.awt.Graphics#create
0421: */
0422: protected Graphics2D() {
0423: }
0424:
0425: /**
0426: * Draws a 3-D highlighted outline of the specified rectangle.
0427: * The edges of the rectangle are highlighted so that they
0428: * appear to be beveled and lit from the upper left corner.
0429: * <p>
0430: * The colors used for the highlighting effect are determined
0431: * based on the current color.
0432: * The resulting rectangle covers an area that is
0433: * <code>width + 1</code> pixels wide
0434: * by <code>height + 1</code> pixels tall. This method
0435: * uses the current <code>Color</code> exclusively and ignores
0436: * the current <code>Paint</code>.
0437: * @param x the x coordinate of the rectangle to be drawn.
0438: * @param y the y coordinate of the rectangle to be drawn.
0439: * @param width the width of the rectangle to be drawn.
0440: * @param height the height of the rectangle to be drawn.
0441: * @param raised a boolean that determines whether the rectangle
0442: * appears to be raised above the surface
0443: * or sunk into the surface.
0444: * @see java.awt.Graphics#fill3DRect
0445: */
0446: public void draw3DRect(int x, int y, int width, int height,
0447: boolean raised) {
0448: Paint p = getPaint();
0449: Color c = getColor();
0450: Color brighter = c.brighter();
0451: Color darker = c.darker();
0452:
0453: setColor(raised ? brighter : darker);
0454: //drawLine(x, y, x, y + height);
0455: fillRect(x, y, 1, height + 1);
0456: //drawLine(x + 1, y, x + width - 1, y);
0457: fillRect(x + 1, y, width - 1, 1);
0458: setColor(raised ? darker : brighter);
0459: //drawLine(x + 1, y + height, x + width, y + height);
0460: fillRect(x + 1, y + height, width, 1);
0461: //drawLine(x + width, y, x + width, y + height - 1);
0462: fillRect(x + width, y, 1, height);
0463: setPaint(p);
0464: }
0465:
0466: /**
0467: * Paints a 3-D highlighted rectangle filled with the current color.
0468: * The edges of the rectangle are highlighted so that it appears
0469: * as if the edges were beveled and lit from the upper left corner.
0470: * The colors used for the highlighting effect and for filling are
0471: * determined from the current <code>Color</code>. This method uses
0472: * the current <code>Color</code> exclusively and ignores the current
0473: * <code>Paint</code>.
0474: * @param x the x coordinate of the rectangle to be filled.
0475: * @param y the y coordinate of the rectangle to be filled.
0476: * @param width the width of the rectangle to be filled.
0477: * @param height the height of the rectangle to be filled.
0478: * @param raised a boolean value that determines whether the
0479: * rectangle appears to be raised above the surface
0480: * or etched into the surface.
0481: * @see java.awt.Graphics#draw3DRect
0482: */
0483: public void fill3DRect(int x, int y, int width, int height,
0484: boolean raised) {
0485: Paint p = getPaint();
0486: Color c = getColor();
0487: Color brighter = c.brighter();
0488: Color darker = c.darker();
0489:
0490: if (!raised) {
0491: setColor(darker);
0492: } else if (p != c) {
0493: setColor(c);
0494: }
0495: fillRect(x + 1, y + 1, width - 2, height - 2);
0496: setColor(raised ? brighter : darker);
0497: //drawLine(x, y, x, y + height - 1);
0498: fillRect(x, y, 1, height);
0499: //drawLine(x + 1, y, x + width - 2, y);
0500: fillRect(x + 1, y, width - 2, 1);
0501: setColor(raised ? darker : brighter);
0502: //drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
0503: fillRect(x + 1, y + height - 1, width - 1, 1);
0504: //drawLine(x + width - 1, y, x + width - 1, y + height - 2);
0505: fillRect(x + width - 1, y, 1, height - 1);
0506: setPaint(p);
0507: }
0508:
0509: /**
0510: * Strokes the outline of a <code>Shape</code> using the settings of the
0511: * current <code>Graphics2D</code> context. The rendering attributes
0512: * applied include the <code>Clip</code>, <code>Transform</code>,
0513: * <code>Paint</code>, <code>Composite</code> and
0514: * <code>Stroke</code> attributes.
0515: * @param s the <code>Shape</code> to be rendered
0516: * @see #setStroke
0517: * @see #setPaint
0518: * @see java.awt.Graphics#setColor
0519: * @see #transform
0520: * @see #setTransform
0521: * @see #clip
0522: * @see #setClip
0523: * @see #setComposite
0524: */
0525: public abstract void draw(Shape s);
0526:
0527: /**
0528: * Renders an image, applying a transform from image space into user space
0529: * before drawing.
0530: * The transformation from user space into device space is done with
0531: * the current <code>Transform</code> in the <code>Graphics2D</code>.
0532: * The specified transformation is applied to the image before the
0533: * transform attribute in the <code>Graphics2D</code> context is applied.
0534: * The rendering attributes applied include the <code>Clip</code>,
0535: * <code>Transform</code>, and <code>Composite</code> attributes.
0536: * Note that no rendering is done if the specified transform is
0537: * noninvertible.
0538: * @param img the specified image to be rendered.
0539: * This method does nothing if <code>img</code> is null.
0540: * @param xform the transformation from image space into user space
0541: * @param obs the {@link ImageObserver}
0542: * to be notified as more of the <code>Image</code>
0543: * is converted
0544: * @return <code>true</code> if the <code>Image</code> is
0545: * fully loaded and completely rendered, or if it's null;
0546: * <code>false</code> if the <code>Image</code> is still being loaded.
0547: * @see #transform
0548: * @see #setTransform
0549: * @see #setComposite
0550: * @see #clip
0551: * @see #setClip
0552: */
0553: public abstract boolean drawImage(Image img, AffineTransform xform,
0554: ImageObserver obs);
0555:
0556: /**
0557: * Renders a <code>BufferedImage</code> that is
0558: * filtered with a
0559: * {@link BufferedImageOp}.
0560: * The rendering attributes applied include the <code>Clip</code>,
0561: * <code>Transform</code>
0562: * and <code>Composite</code> attributes. This is equivalent to:
0563: * <pre>
0564: * img1 = op.filter(img, null);
0565: * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
0566: * </pre>
0567: * @param op the filter to be applied to the image before rendering
0568: * @param img the specified <code>BufferedImage</code> to be rendered.
0569: * This method does nothing if <code>img</code> is null.
0570: * @param x the x coordinate of the location in user space where
0571: * the upper left corner of the image is rendered
0572: * @param y the y coordinate of the location in user space where
0573: * the upper left corner of the image is rendered
0574: *
0575: * @see #transform
0576: * @see #setTransform
0577: * @see #setComposite
0578: * @see #clip
0579: * @see #setClip
0580: */
0581: public abstract void drawImage(BufferedImage img,
0582: BufferedImageOp op, int x, int y);
0583:
0584: /**
0585: * Renders a {@link RenderedImage},
0586: * applying a transform from image
0587: * space into user space before drawing.
0588: * The transformation from user space into device space is done with
0589: * the current <code>Transform</code> in the <code>Graphics2D</code>.
0590: * The specified transformation is applied to the image before the
0591: * transform attribute in the <code>Graphics2D</code> context is applied.
0592: * The rendering attributes applied include the <code>Clip</code>,
0593: * <code>Transform</code>, and <code>Composite</code> attributes. Note
0594: * that no rendering is done if the specified transform is
0595: * noninvertible.
0596: * @param img the image to be rendered. This method does
0597: * nothing if <code>img</code> is null.
0598: * @param xform the transformation from image space into user space
0599: * @see #transform
0600: * @see #setTransform
0601: * @see #setComposite
0602: * @see #clip
0603: * @see #setClip
0604: */
0605: public abstract void drawRenderedImage(RenderedImage img,
0606: AffineTransform xform);
0607:
0608: /**
0609: * Renders a
0610: * {@link RenderableImage},
0611: * applying a transform from image space into user space before drawing.
0612: * The transformation from user space into device space is done with
0613: * the current <code>Transform</code> in the <code>Graphics2D</code>.
0614: * The specified transformation is applied to the image before the
0615: * transform attribute in the <code>Graphics2D</code> context is applied.
0616: * The rendering attributes applied include the <code>Clip</code>,
0617: * <code>Transform</code>, and <code>Composite</code> attributes. Note
0618: * that no rendering is done if the specified transform is
0619: * noninvertible.
0620: *<p>
0621: * Rendering hints set on the <code>Graphics2D</code> object might
0622: * be used in rendering the <code>RenderableImage</code>.
0623: * If explicit control is required over specific hints recognized by a
0624: * specific <code>RenderableImage</code>, or if knowledge of which hints
0625: * are used is required, then a <code>RenderedImage</code> should be
0626: * obtained directly from the <code>RenderableImage</code>
0627: * and rendered using
0628: *{@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}.
0629: * @param img the image to be rendered. This method does
0630: * nothing if <code>img</code> is null.
0631: * @param xform the transformation from image space into user space
0632: * @see #transform
0633: * @see #setTransform
0634: * @see #setComposite
0635: * @see #clip
0636: * @see #setClip
0637: * @see #drawRenderedImage
0638: */
0639: public abstract void drawRenderableImage(RenderableImage img,
0640: AffineTransform xform);
0641:
0642: /**
0643: * Renders the text of the specified <code>String</code>, using the
0644: * current text attribute state in the <code>Graphics2D</code> context.
0645: * The baseline of the
0646: * first character is at position (<i>x</i>, <i>y</i>) in
0647: * the User Space.
0648: * The rendering attributes applied include the <code>Clip</code>,
0649: * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
0650: * <code>Composite</code> attributes. For characters in script
0651: * systems such as Hebrew and Arabic, the glyphs can be rendered from
0652: * right to left, in which case the coordinate supplied is the
0653: * location of the leftmost character on the baseline.
0654: * @param str the string to be rendered
0655: * @param x the x coordinate of the location where the
0656: * <code>String</code> should be rendered
0657: * @param y the y coordinate of the location where the
0658: * <code>String</code> should be rendered
0659: * @throws NullPointerException if <code>str</code> is
0660: * <code>null</code>
0661: * @see java.awt.Graphics#drawBytes
0662: * @see java.awt.Graphics#drawChars
0663: * @since JDK1.0
0664: */
0665: public abstract void drawString(String str, int x, int y);
0666:
0667: /**
0668: * Renders the text specified by the specified <code>String</code>,
0669: * using the current text attribute state in the <code>Graphics2D</code> context.
0670: * The baseline of the first character is at position
0671: * (<i>x</i>, <i>y</i>) in the User Space.
0672: * The rendering attributes applied include the <code>Clip</code>,
0673: * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
0674: * <code>Composite</code> attributes. For characters in script systems
0675: * such as Hebrew and Arabic, the glyphs can be rendered from right to
0676: * left, in which case the coordinate supplied is the location of the
0677: * leftmost character on the baseline.
0678: * @param str the <code>String</code> to be rendered
0679: * @param x the x coordinate of the location where the
0680: * <code>String</code> should be rendered
0681: * @param y the y coordinate of the location where the
0682: * <code>String</code> should be rendered
0683: * @throws NullPointerException if <code>str</code> is
0684: * <code>null</code>
0685: * @see #setPaint
0686: * @see java.awt.Graphics#setColor
0687: * @see java.awt.Graphics#setFont
0688: * @see #setTransform
0689: * @see #setComposite
0690: * @see #setClip
0691: */
0692: public abstract void drawString(String str, float x, float y);
0693:
0694: /**
0695: * Renders the text of the specified iterator applying its attributes
0696: * in accordance with the specification of the {@link TextAttribute} class.
0697: * <p>
0698: * The baseline of the first character is at position
0699: * (<i>x</i>, <i>y</i>) in User Space.
0700: * For characters in script systems such as Hebrew and Arabic,
0701: * the glyphs can be rendered from right to left, in which case the
0702: * coordinate supplied is the location of the leftmost character
0703: * on the baseline.
0704: * @param iterator the iterator whose text is to be rendered
0705: * @param x the x coordinate where the iterator's text is to be
0706: * rendered
0707: * @param y the y coordinate where the iterator's text is to be
0708: * rendered
0709: * @throws NullPointerException if <code>iterator</code> is
0710: * <code>null</code>
0711: * @see #setPaint
0712: * @see java.awt.Graphics#setColor
0713: * @see #setTransform
0714: * @see #setComposite
0715: * @see #setClip
0716: */
0717: public abstract void drawString(
0718: AttributedCharacterIterator iterator, int x, int y);
0719:
0720: /**
0721: * Renders the text of the specified iterator applying its attributes
0722: * in accordance with the specification of the {@link TextAttribute} class.
0723: * <p>
0724: * The baseline of the first character is at position
0725: * (<i>x</i>, <i>y</i>) in User Space.
0726: * For characters in script systems such as Hebrew and Arabic,
0727: * the glyphs can be rendered from right to left, in which case the
0728: * coordinate supplied is the location of the leftmost character
0729: * on the baseline.
0730: * @param iterator the iterator whose text is to be rendered
0731: * @param x the x coordinate where the iterator's text is to be
0732: * rendered
0733: * @param y the y coordinate where the iterator's text is to be
0734: * rendered
0735: * @throws NullPointerException if <code>iterator</code> is
0736: * <code>null</code>
0737: * @see #setPaint
0738: * @see java.awt.Graphics#setColor
0739: * @see #setTransform
0740: * @see #setComposite
0741: * @see #setClip
0742: */
0743: public abstract void drawString(
0744: AttributedCharacterIterator iterator, float x, float y);
0745:
0746: /**
0747: * Renders the text of the specified
0748: * {@link GlyphVector} using
0749: * the <code>Graphics2D</code> context's rendering attributes.
0750: * The rendering attributes applied include the <code>Clip</code>,
0751: * <code>Transform</code>, <code>Paint</code>, and
0752: * <code>Composite</code> attributes. The <code>GlyphVector</code>
0753: * specifies individual glyphs from a {@link Font}.
0754: * The <code>GlyphVector</code> can also contain the glyph positions.
0755: * This is the fastest way to render a set of characters to the
0756: * screen.
0757: * @param g the <code>GlyphVector</code> to be rendered
0758: * @param x the x position in User Space where the glyphs should
0759: * be rendered
0760: * @param y the y position in User Space where the glyphs should
0761: * be rendered
0762: * @throws NullPointerException if <code>g</code> is <code>null</code>.
0763: *
0764: * @see java.awt.Font#createGlyphVector
0765: * @see java.awt.font.GlyphVector
0766: * @see #setPaint
0767: * @see java.awt.Graphics#setColor
0768: * @see #setTransform
0769: * @see #setComposite
0770: * @see #setClip
0771: */
0772: public abstract void drawGlyphVector(GlyphVector g, float x, float y);
0773:
0774: /**
0775: * Fills the interior of a <code>Shape</code> using the settings of the
0776: * <code>Graphics2D</code> context. The rendering attributes applied
0777: * include the <code>Clip</code>, <code>Transform</code>,
0778: * <code>Paint</code>, and <code>Composite</code>.
0779: * @param s the <code>Shape</code> to be filled
0780: * @see #setPaint
0781: * @see java.awt.Graphics#setColor
0782: * @see #transform
0783: * @see #setTransform
0784: * @see #setComposite
0785: * @see #clip
0786: * @see #setClip
0787: */
0788: public abstract void fill(Shape s);
0789:
0790: /**
0791: * Checks whether or not the specified <code>Shape</code> intersects
0792: * the specified {@link Rectangle}, which is in device
0793: * space. If <code>onStroke</code> is false, this method checks
0794: * whether or not the interior of the specified <code>Shape</code>
0795: * intersects the specified <code>Rectangle</code>. If
0796: * <code>onStroke</code> is <code>true</code>, this method checks
0797: * whether or not the <code>Stroke</code> of the specified
0798: * <code>Shape</code> outline intersects the specified
0799: * <code>Rectangle</code>.
0800: * The rendering attributes taken into account include the
0801: * <code>Clip</code>, <code>Transform</code>, and <code>Stroke</code>
0802: * attributes.
0803: * @param rect the area in device space to check for a hit
0804: * @param s the <code>Shape</code> to check for a hit
0805: * @param onStroke flag used to choose between testing the
0806: * stroked or the filled shape. If the flag is <code>true</code>, the
0807: * <code>Stroke</code> oultine is tested. If the flag is
0808: * <code>false</code>, the filled <code>Shape</code> is tested.
0809: * @return <code>true</code> if there is a hit; <code>false</code>
0810: * otherwise.
0811: * @see #setStroke
0812: * @see #fill
0813: * @see #draw
0814: * @see #transform
0815: * @see #setTransform
0816: * @see #clip
0817: * @see #setClip
0818: */
0819: public abstract boolean hit(Rectangle rect, Shape s,
0820: boolean onStroke);
0821:
0822: /**
0823: * Returns the device configuration associated with this
0824: * <code>Graphics2D</code>.
0825: * @return the device configuration of this <code>Graphics2D</code>.
0826: */
0827: public abstract GraphicsConfiguration getDeviceConfiguration();
0828:
0829: /**
0830: * Sets the <code>Composite</code> for the <code>Graphics2D</code> context.
0831: * The <code>Composite</code> is used in all drawing methods such as
0832: * <code>drawImage</code>, <code>drawString</code>, <code>draw</code>,
0833: * and <code>fill</code>. It specifies how new pixels are to be combined
0834: * with the existing pixels on the graphics device during the rendering
0835: * process.
0836: * <p>If this <code>Graphics2D</code> context is drawing to a
0837: * <code>Component</code> on the display screen and the
0838: * <code>Composite</code> is a custom object rather than an
0839: * instance of the <code>AlphaComposite</code> class, and if
0840: * there is a security manager, its <code>checkPermission</code>
0841: * method is called with an <code>AWTPermission("readDisplayPixels")</code>
0842: * permission.
0843: * @throws SecurityException
0844: * if a custom <code>Composite</code> object is being
0845: * used to render to the screen and a security manager
0846: * is set and its <code>checkPermission</code> method
0847: * does not allow the operation.
0848: * @param comp the <code>Composite</code> object to be used for rendering
0849: * @see java.awt.Graphics#setXORMode
0850: * @see java.awt.Graphics#setPaintMode
0851: * @see #getComposite
0852: * @see AlphaComposite
0853: * @see SecurityManager#checkPermission
0854: * @see java.awt.AWTPermission
0855: */
0856: public abstract void setComposite(Composite comp);
0857:
0858: /**
0859: * Sets the <code>Paint</code> attribute for the
0860: * <code>Graphics2D</code> context. Calling this method
0861: * with a <code>null</code> <code>Paint</code> object does
0862: * not have any effect on the current <code>Paint</code> attribute
0863: * of this <code>Graphics2D</code>.
0864: * @param paint the <code>Paint</code> object to be used to generate
0865: * color during the rendering process, or <code>null</code>
0866: * @see java.awt.Graphics#setColor
0867: * @see #getPaint
0868: * @see GradientPaint
0869: * @see TexturePaint
0870: */
0871: public abstract void setPaint(Paint paint);
0872:
0873: /**
0874: * Sets the <code>Stroke</code> for the <code>Graphics2D</code> context.
0875: * @param s the <code>Stroke</code> object to be used to stroke a
0876: * <code>Shape</code> during the rendering process
0877: * @see BasicStroke
0878: * @see #getStroke
0879: */
0880: public abstract void setStroke(Stroke s);
0881:
0882: /**
0883: * Sets the value of a single preference for the rendering algorithms.
0884: * Hint categories include controls for rendering quality and overall
0885: * time/quality trade-off in the rendering process. Refer to the
0886: * <code>RenderingHints</code> class for definitions of some common
0887: * keys and values.
0888: * @param hintKey the key of the hint to be set.
0889: * @param hintValue the value indicating preferences for the specified
0890: * hint category.
0891: * @see #getRenderingHint(RenderingHints.Key)
0892: * @see RenderingHints
0893: */
0894: public abstract void setRenderingHint(Key hintKey, Object hintValue);
0895:
0896: /**
0897: * Returns the value of a single preference for the rendering algorithms.
0898: * Hint categories include controls for rendering quality and overall
0899: * time/quality trade-off in the rendering process. Refer to the
0900: * <code>RenderingHints</code> class for definitions of some common
0901: * keys and values.
0902: * @param hintKey the key corresponding to the hint to get.
0903: * @return an object representing the value for the specified hint key.
0904: * Some of the keys and their associated values are defined in the
0905: * <code>RenderingHints</code> class.
0906: * @see RenderingHints
0907: * @see #setRenderingHint(RenderingHints.Key, Object)
0908: */
0909: public abstract Object getRenderingHint(Key hintKey);
0910:
0911: /**
0912: * Replaces the values of all preferences for the rendering
0913: * algorithms with the specified <code>hints</code>.
0914: * The existing values for all rendering hints are discarded and
0915: * the new set of known hints and values are initialized from the
0916: * specified {@link Map} object.
0917: * Hint categories include controls for rendering quality and
0918: * overall time/quality trade-off in the rendering process.
0919: * Refer to the <code>RenderingHints</code> class for definitions of
0920: * some common keys and values.
0921: * @param hints the rendering hints to be set
0922: * @see #getRenderingHints
0923: * @see RenderingHints
0924: */
0925: public abstract void setRenderingHints(Map<?, ?> hints);
0926:
0927: /**
0928: * Sets the values of an arbitrary number of preferences for the
0929: * rendering algorithms.
0930: * Only values for the rendering hints that are present in the
0931: * specified <code>Map</code> object are modified.
0932: * All other preferences not present in the specified
0933: * object are left unmodified.
0934: * Hint categories include controls for rendering quality and
0935: * overall time/quality trade-off in the rendering process.
0936: * Refer to the <code>RenderingHints</code> class for definitions of
0937: * some common keys and values.
0938: * @param hints the rendering hints to be set
0939: * @see RenderingHints
0940: */
0941: public abstract void addRenderingHints(Map<?, ?> hints);
0942:
0943: /**
0944: * Gets the preferences for the rendering algorithms. Hint categories
0945: * include controls for rendering quality and overall time/quality
0946: * trade-off in the rendering process.
0947: * Returns all of the hint key/value pairs that were ever specified in
0948: * one operation. Refer to the
0949: * <code>RenderingHints</code> class for definitions of some common
0950: * keys and values.
0951: * @return a reference to an instance of <code>RenderingHints</code>
0952: * that contains the current preferences.
0953: * @see RenderingHints
0954: * @see #setRenderingHints(Map)
0955: */
0956: public abstract RenderingHints getRenderingHints();
0957:
0958: /**
0959: * Translates the origin of the <code>Graphics2D</code> context to the
0960: * point (<i>x</i>, <i>y</i>) in the current coordinate system.
0961: * Modifies the <code>Graphics2D</code> context so that its new origin
0962: * corresponds to the point (<i>x</i>, <i>y</i>) in the
0963: * <code>Graphics2D</code> context's former coordinate system. All
0964: * coordinates used in subsequent rendering operations on this graphics
0965: * context are relative to this new origin.
0966: * @param x the specified x coordinate
0967: * @param y the specified y coordinate
0968: * @since JDK1.0
0969: */
0970: public abstract void translate(int x, int y);
0971:
0972: /**
0973: * Concatenates the current
0974: * <code>Graphics2D</code> <code>Transform</code>
0975: * with a translation transform.
0976: * Subsequent rendering is translated by the specified
0977: * distance relative to the previous position.
0978: * This is equivalent to calling transform(T), where T is an
0979: * <code>AffineTransform</code> represented by the following matrix:
0980: * <pre>
0981: * [ 1 0 tx ]
0982: * [ 0 1 ty ]
0983: * [ 0 0 1 ]
0984: * </pre>
0985: * @param tx the distance to translate along the x-axis
0986: * @param ty the distance to translate along the y-axis
0987: */
0988: public abstract void translate(double tx, double ty);
0989:
0990: /**
0991: * Concatenates the current <code>Graphics2D</code>
0992: * <code>Transform</code> with a rotation transform.
0993: * Subsequent rendering is rotated by the specified radians relative
0994: * to the previous origin.
0995: * This is equivalent to calling <code>transform(R)</code>, where R is an
0996: * <code>AffineTransform</code> represented by the following matrix:
0997: * <pre>
0998: * [ cos(theta) -sin(theta) 0 ]
0999: * [ sin(theta) cos(theta) 0 ]
1000: * [ 0 0 1 ]
1001: * </pre>
1002: * Rotating with a positive angle theta rotates points on the positive
1003: * x axis toward the positive y axis.
1004: * @param theta the angle of rotation in radians
1005: */
1006: public abstract void rotate(double theta);
1007:
1008: /**
1009: * Concatenates the current <code>Graphics2D</code>
1010: * <code>Transform</code> with a translated rotation
1011: * transform. Subsequent rendering is transformed by a transform
1012: * which is constructed by translating to the specified location,
1013: * rotating by the specified radians, and translating back by the same
1014: * amount as the original translation. This is equivalent to the
1015: * following sequence of calls:
1016: * <pre>
1017: * translate(x, y);
1018: * rotate(theta);
1019: * translate(-x, -y);
1020: * </pre>
1021: * Rotating with a positive angle theta rotates points on the positive
1022: * x axis toward the positive y axis.
1023: * @param theta the angle of rotation in radians
1024: * @param x the x coordinate of the origin of the rotation
1025: * @param y the y coordinate of the origin of the rotation
1026: */
1027: public abstract void rotate(double theta, double x, double y);
1028:
1029: /**
1030: * Concatenates the current <code>Graphics2D</code>
1031: * <code>Transform</code> with a scaling transformation
1032: * Subsequent rendering is resized according to the specified scaling
1033: * factors relative to the previous scaling.
1034: * This is equivalent to calling <code>transform(S)</code>, where S is an
1035: * <code>AffineTransform</code> represented by the following matrix:
1036: * <pre>
1037: * [ sx 0 0 ]
1038: * [ 0 sy 0 ]
1039: * [ 0 0 1 ]
1040: * </pre>
1041: * @param sx the amount by which X coordinates in subsequent
1042: * rendering operations are multiplied relative to previous
1043: * rendering operations.
1044: * @param sy the amount by which Y coordinates in subsequent
1045: * rendering operations are multiplied relative to previous
1046: * rendering operations.
1047: */
1048: public abstract void scale(double sx, double sy);
1049:
1050: /**
1051: * Concatenates the current <code>Graphics2D</code>
1052: * <code>Transform</code> with a shearing transform.
1053: * Subsequent renderings are sheared by the specified
1054: * multiplier relative to the previous position.
1055: * This is equivalent to calling <code>transform(SH)</code>, where SH
1056: * is an <code>AffineTransform</code> represented by the following
1057: * matrix:
1058: * <pre>
1059: * [ 1 shx 0 ]
1060: * [ shy 1 0 ]
1061: * [ 0 0 1 ]
1062: * </pre>
1063: * @param shx the multiplier by which coordinates are shifted in
1064: * the positive X axis direction as a function of their Y coordinate
1065: * @param shy the multiplier by which coordinates are shifted in
1066: * the positive Y axis direction as a function of their X coordinate
1067: */
1068: public abstract void shear(double shx, double shy);
1069:
1070: /**
1071: * Composes an <code>AffineTransform</code> object with the
1072: * <code>Transform</code> in this <code>Graphics2D</code> according
1073: * to the rule last-specified-first-applied. If the current
1074: * <code>Transform</code> is Cx, the result of composition
1075: * with Tx is a new <code>Transform</code> Cx'. Cx' becomes the
1076: * current <code>Transform</code> for this <code>Graphics2D</code>.
1077: * Transforming a point p by the updated <code>Transform</code> Cx' is
1078: * equivalent to first transforming p by Tx and then transforming
1079: * the result by the original <code>Transform</code> Cx. In other
1080: * words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary,
1081: * so further modifications to Tx do not affect rendering.
1082: * @param Tx the <code>AffineTransform</code> object to be composed with
1083: * the current <code>Transform</code>
1084: * @see #setTransform
1085: * @see AffineTransform
1086: */
1087: public abstract void transform(AffineTransform Tx);
1088:
1089: /**
1090: * Overwrites the Transform in the <code>Graphics2D</code> context.
1091: * WARNING: This method should <b>never</b> be used to apply a new
1092: * coordinate transform on top of an existing transform because the
1093: * <code>Graphics2D</code> might already have a transform that is
1094: * needed for other purposes, such as rendering Swing
1095: * components or applying a scaling transformation to adjust for the
1096: * resolution of a printer.
1097: * <p>To add a coordinate transform, use the
1098: * <code>transform</code>, <code>rotate</code>, <code>scale</code>,
1099: * or <code>shear</code> methods. The <code>setTransform</code>
1100: * method is intended only for restoring the original
1101: * <code>Graphics2D</code> transform after rendering, as shown in this
1102: * example:
1103: * <pre><blockquote>
1104: * // Get the current transform
1105: * AffineTransform saveAT = g2.getTransform();
1106: * // Perform transformation
1107: * g2d.transform(...);
1108: * // Render
1109: * g2d.draw(...);
1110: * // Restore original transform
1111: * g2d.setTransform(saveAT);
1112: * </blockquote></pre>
1113: *
1114: * @param Tx the <code>AffineTransform</code> that was retrieved
1115: * from the <code>getTransform</code> method
1116: * @see #transform
1117: * @see #getTransform
1118: * @see AffineTransform
1119: */
1120: public abstract void setTransform(AffineTransform Tx);
1121:
1122: /**
1123: * Returns a copy of the current <code>Transform</code> in the
1124: * <code>Graphics2D</code> context.
1125: * @return the current <code>AffineTransform</code> in the
1126: * <code>Graphics2D</code> context.
1127: * @see #transform
1128: * @see #setTransform
1129: */
1130: public abstract AffineTransform getTransform();
1131:
1132: /**
1133: * Returns the current <code>Paint</code> of the
1134: * <code>Graphics2D</code> context.
1135: * @return the current <code>Graphics2D</code> <code>Paint</code>,
1136: * which defines a color or pattern.
1137: * @see #setPaint
1138: * @see java.awt.Graphics#setColor
1139: */
1140: public abstract Paint getPaint();
1141:
1142: /**
1143: * Returns the current <code>Composite</code> in the
1144: * <code>Graphics2D</code> context.
1145: * @return the current <code>Graphics2D</code> <code>Composite</code>,
1146: * which defines a compositing style.
1147: * @see #setComposite
1148: */
1149: public abstract Composite getComposite();
1150:
1151: /**
1152: * Sets the background color for the <code>Graphics2D</code> context.
1153: * The background color is used for clearing a region.
1154: * When a <code>Graphics2D</code> is constructed for a
1155: * <code>Component</code>, the background color is
1156: * inherited from the <code>Component</code>. Setting the background color
1157: * in the <code>Graphics2D</code> context only affects the subsequent
1158: * <code>clearRect</code> calls and not the background color of the
1159: * <code>Component</code>. To change the background
1160: * of the <code>Component</code>, use appropriate methods of
1161: * the <code>Component</code>.
1162: * @param color the background color that isused in
1163: * subsequent calls to <code>clearRect</code>
1164: * @see #getBackground
1165: * @see java.awt.Graphics#clearRect
1166: */
1167: public abstract void setBackground(Color color);
1168:
1169: /**
1170: * Returns the background color used for clearing a region.
1171: * @return the current <code>Graphics2D</code> <code>Color</code>,
1172: * which defines the background color.
1173: * @see #setBackground
1174: */
1175: public abstract Color getBackground();
1176:
1177: /**
1178: * Returns the current <code>Stroke</code> in the
1179: * <code>Graphics2D</code> context.
1180: * @return the current <code>Graphics2D</code> <code>Stroke</code>,
1181: * which defines the line style.
1182: * @see #setStroke
1183: */
1184: public abstract Stroke getStroke();
1185:
1186: /**
1187: * Intersects the current <code>Clip</code> with the interior of the
1188: * specified <code>Shape</code> and sets the <code>Clip</code> to the
1189: * resulting intersection. The specified <code>Shape</code> is
1190: * transformed with the current <code>Graphics2D</code>
1191: * <code>Transform</code> before being intersected with the current
1192: * <code>Clip</code>. This method is used to make the current
1193: * <code>Clip</code> smaller.
1194: * To make the <code>Clip</code> larger, use <code>setClip</code>.
1195: * The <i>user clip</i> modified by this method is independent of the
1196: * clipping associated with device bounds and visibility. If no clip has
1197: * previously been set, or if the clip has been cleared using
1198: * {@link Graphics#setClip(Shape) setClip} with a <code>null</code>
1199: * argument, the specified <code>Shape</code> becomes the new
1200: * user clip.
1201: * @param s the <code>Shape</code> to be intersected with the current
1202: * <code>Clip</code>. If <code>s</code> is <code>null</code>,
1203: * this method clears the current <code>Clip</code>.
1204: */
1205: public abstract void clip(Shape s);
1206:
1207: /**
1208: * Get the rendering context of the <code>Font</code> within this
1209: * <code>Graphics2D</code> context.
1210: * The {@link FontRenderContext}
1211: * encapsulates application hints such as anti-aliasing and
1212: * fractional metrics, as well as target device specific information
1213: * such as dots-per-inch. This information should be provided by the
1214: * application when using objects that perform typographical
1215: * formatting, such as <code>Font</code> and
1216: * <code>TextLayout</code>. This information should also be provided
1217: * by applications that perform their own layout and need accurate
1218: * measurements of various characteristics of glyphs such as advance
1219: * and line height when various rendering hints have been applied to
1220: * the text rendering.
1221: *
1222: * @return a reference to an instance of FontRenderContext.
1223: * @see java.awt.font.FontRenderContext
1224: * @see java.awt.Font#createGlyphVector
1225: * @see java.awt.font.TextLayout
1226: * @since 1.2
1227: */
1228:
1229: public abstract FontRenderContext getFontRenderContext();
1230:
1231: }
|