Home » openjdk-7 » java » awt » [javadoc | source]

    1   /*
    2    * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Oracle designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Oracle in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   22    * or visit www.oracle.com if you need additional information or have any
   23    * questions.
   24    */
   25   
   26   package java.awt;
   27   
   28   import java.awt.RenderingHints.Key;
   29   import java.awt.geom.AffineTransform;
   30   import java.awt.image.ImageObserver;
   31   import java.awt.image.BufferedImageOp;
   32   import java.awt.image.BufferedImage;
   33   import java.awt.image.RenderedImage;
   34   import java.awt.image.renderable.RenderableImage;
   35   import java.awt.font.GlyphVector;
   36   import java.awt.font.FontRenderContext;
   37   import java.awt.font.TextAttribute;
   38   import java.text.AttributedCharacterIterator;
   39   import java.util.Map;
   40   
   41   /**
   42    * This <code>Graphics2D</code> class extends the
   43    * {@link Graphics} class to provide more sophisticated
   44    * control over geometry, coordinate transformations, color management,
   45    * and text layout.  This is the fundamental class for rendering
   46    * 2-dimensional shapes, text and images on the  Java(tm) platform.
   47    * <p>
   48    * <h2>Coordinate Spaces</h2>
   49    * All coordinates passed to a <code>Graphics2D</code> object are specified
   50    * in a device-independent coordinate system called User Space, which is
   51    * used by applications.  The <code>Graphics2D</code> object contains
   52    * an {@link AffineTransform} object as part of its rendering state
   53    * that defines how to convert coordinates from user space to
   54    * device-dependent coordinates in Device Space.
   55    * <p>
   56    * Coordinates in device space usually refer to individual device pixels
   57    * and are aligned on the infinitely thin gaps between these pixels.
   58    * Some <code>Graphics2D</code> objects can be used to capture rendering
   59    * operations for storage into a graphics metafile for playback on a
   60    * concrete device of unknown physical resolution at a later time.  Since
   61    * the resolution might not be known when the rendering operations are
   62    * captured, the <code>Graphics2D</code> <code>Transform</code> is set up
   63    * to transform user coordinates to a virtual device space that
   64    * approximates the expected resolution of the target device. Further
   65    * transformations might need to be applied at playback time if the
   66    * estimate is incorrect.
   67    * <p>
   68    * Some of the operations performed by the rendering attribute objects
   69    * occur in the device space, but all <code>Graphics2D</code> methods take
   70    * user space coordinates.
   71    * <p>
   72    * Every <code>Graphics2D</code> object is associated with a target that
   73    * defines where rendering takes place. A
   74    * {@link GraphicsConfiguration} object defines the characteristics
   75    * of the rendering target, such as pixel format and resolution.
   76    * The same rendering target is used throughout the life of a
   77    * <code>Graphics2D</code> object.
   78    * <p>
   79    * When creating a <code>Graphics2D</code> object,  the
   80    * <code>GraphicsConfiguration</code>
   81    * specifies the <a name="#deftransform">default transform</a> for
   82    * the target of the <code>Graphics2D</code> (a
   83    * {@link Component} or {@link Image}).  This default transform maps the
   84    * user space coordinate system to screen and printer device coordinates
   85    * such that the origin maps to the upper left hand corner of the
   86    * target region of the device with increasing X coordinates extending
   87    * to the right and increasing Y coordinates extending downward.
   88    * The scaling of the default transform is set to identity for those devices
   89    * that are close to 72 dpi, such as screen devices.
   90    * The scaling of the default transform is set to approximately 72 user
   91    * space coordinates per square inch for high resolution devices, such as
   92    * printers.  For image buffers, the default transform is the
   93    * <code>Identity</code> transform.
   94    *
   95    * <h2>Rendering Process</h2>
   96    * The Rendering Process can be broken down into four phases that are
   97    * controlled by the <code>Graphics2D</code> rendering attributes.
   98    * The renderer can optimize many of these steps, either by caching the
   99    * results for future calls, by collapsing multiple virtual steps into
  100    * a single operation, or by recognizing various attributes as common
  101    * simple cases that can be eliminated by modifying other parts of the
  102    * operation.
  103    * <p>
  104    * The steps in the rendering process are:
  105    * <ol>
  106    * <li>
  107    * Determine what to render.
  108    * <li>
  109    * Constrain the rendering operation to the current <code>Clip</code>.
  110    * The <code>Clip</code> is specified by a {@link Shape} in user
  111    * space and is controlled by the program using the various clip
  112    * manipulation methods of <code>Graphics</code> and
  113    * <code>Graphics2D</code>.  This <i>user clip</i>
  114    * is transformed into device space by the current
  115    * <code>Transform</code> and combined with the
  116    * <i>device clip</i>, which is defined by the visibility of windows and
  117    * device extents.  The combination of the user clip and device clip
  118    * defines the <i>composite clip</i>, which determines the final clipping
  119    * region.  The user clip is not modified by the rendering
  120    * system to reflect the resulting composite clip.
  121    * <li>
  122    * Determine what colors to render.
  123    * <li>
  124    * Apply the colors to the destination drawing surface using the current
  125    * {@link Composite} attribute in the <code>Graphics2D</code> context.
  126    * </ol>
  127    * <br>
  128    * The three types of rendering operations, along with details of each
  129    * of their particular rendering processes are:
  130    * <ol>
  131    * <li>
  132    * <b><a name="rendershape"><code>Shape</code> operations</a></b>
  133    * <ol>
  134    * <li>
  135    * If the operation is a <code>draw(Shape)</code> operation, then
  136    * the  {@link Stroke#createStrokedShape(Shape) createStrokedShape}
  137    * method on the current {@link Stroke} attribute in the
  138    * <code>Graphics2D</code> context is used to construct a new
  139    * <code>Shape</code> object that contains the outline of the specified
  140    * <code>Shape</code>.
  141    * <li>
  142    * The <code>Shape</code> is transformed from user space to device space
  143    * using the current <code>Transform</code>
  144    * in the <code>Graphics2D</code> context.
  145    * <li>
  146    * The outline of the <code>Shape</code> is extracted using the
  147    * {@link Shape#getPathIterator(AffineTransform) getPathIterator} method of
  148    * <code>Shape</code>, which returns a
  149    * {@link java.awt.geom.PathIterator PathIterator}
  150    * object that iterates along the boundary of the <code>Shape</code>.
  151    * <li>
  152    * If the <code>Graphics2D</code> object cannot handle the curved segments
  153    * that the <code>PathIterator</code> object returns then it can call the
  154    * alternate
  155    * {@link Shape#getPathIterator(AffineTransform, double) getPathIterator}
  156    * method of <code>Shape</code>, which flattens the <code>Shape</code>.
  157    * <li>
  158    * The current {@link Paint} in the <code>Graphics2D</code> context
  159    * is queried for a {@link PaintContext}, which specifies the
  160    * colors to render in device space.
  161    * </ol>
  162    * <li>
  163    * <b><a name=rendertext>Text operations</a></b>
  164    * <ol>
  165    * <li>
  166    * The following steps are used to determine the set of glyphs required
  167    * to render the indicated <code>String</code>:
  168    * <ol>
  169    * <li>
  170    * If the argument is a <code>String</code>, then the current
  171    * <code>Font</code> in the <code>Graphics2D</code> context is asked to
  172    * convert the Unicode characters in the <code>String</code> into a set of
  173    * glyphs for presentation with whatever basic layout and shaping
  174    * algorithms the font implements.
  175    * <li>
  176    * If the argument is an
  177    * {@link AttributedCharacterIterator},
  178    * the iterator is asked to convert itself to a
  179    * {@link java.awt.font.TextLayout TextLayout}
  180    * using its embedded font attributes. The <code>TextLayout</code>
  181    * implements more sophisticated glyph layout algorithms that
  182    * perform Unicode bi-directional layout adjustments automatically
  183    * for multiple fonts of differing writing directions.
  184     * <li>
  185    * If the argument is a
  186    * {@link GlyphVector}, then the
  187    * <code>GlyphVector</code> object already contains the appropriate
  188    * font-specific glyph codes with explicit coordinates for the position of
  189    * each glyph.
  190    * </ol>
  191    * <li>
  192    * The current <code>Font</code> is queried to obtain outlines for the
  193    * indicated glyphs.  These outlines are treated as shapes in user space
  194    * relative to the position of each glyph that was determined in step 1.
  195    * <li>
  196    * The character outlines are filled as indicated above
  197    * under <a href="#rendershape"><code>Shape</code> operations</a>.
  198    * <li>
  199    * The current <code>Paint</code> is queried for a
  200    * <code>PaintContext</code>, which specifies
  201    * the colors to render in device space.
  202    * </ol>
  203    * <li>
  204    * <b><a name= renderingimage><code>Image</code> Operations</a></b>
  205    * <ol>
  206    * <li>
  207    * The region of interest is defined by the bounding box of the source
  208    * <code>Image</code>.
  209    * This bounding box is specified in Image Space, which is the
  210    * <code>Image</code> object's local coordinate system.
  211    * <li>
  212    * If an <code>AffineTransform</code> is passed to
  213    * {@link #drawImage(java.awt.Image, java.awt.geom.AffineTransform, java.awt.image.ImageObserver) drawImage(Image, AffineTransform, ImageObserver)},
  214    * the <code>AffineTransform</code> is used to transform the bounding
  215    * box from image space to user space. If no <code>AffineTransform</code>
  216    * is supplied, the bounding box is treated as if it is already in user space.
  217    * <li>
  218    * The bounding box of the source <code>Image</code> is transformed from user
  219    * space into device space using the current <code>Transform</code>.
  220    * Note that the result of transforming the bounding box does not
  221    * necessarily result in a rectangular region in device space.
  222    * <li>
  223    * The <code>Image</code> object determines what colors to render,
  224    * sampled according to the source to destination
  225    * coordinate mapping specified by the current <code>Transform</code> and the
  226    * optional image transform.
  227    * </ol>
  228    * </ol>
  229    *
  230    * <h2>Default Rendering Attributes</h2>
  231    * The default values for the <code>Graphics2D</code> rendering attributes are:
  232    * <dl compact>
  233    * <dt><i><code>Paint</code></i>
  234    * <dd>The color of the <code>Component</code>.
  235    * <dt><i><code>Font</code></i>
  236    * <dd>The <code>Font</code> of the <code>Component</code>.
  237    * <dt><i><code>Stroke</code></i>
  238    * <dd>A square pen with a linewidth of 1, no dashing, miter segment joins
  239    * and square end caps.
  240    * <dt><i><code>Transform</code></i>
  241    * <dd>The
  242    * {@link GraphicsConfiguration#getDefaultTransform() getDefaultTransform}
  243    * for the <code>GraphicsConfiguration</code> of the <code>Component</code>.
  244    * <dt><i><code>Composite</code></i>
  245    * <dd>The {@link AlphaComposite#SRC_OVER} rule.
  246    * <dt><i><code>Clip</code></i>
  247    * <dd>No rendering <code>Clip</code>, the output is clipped to the
  248    * <code>Component</code>.
  249    * </dl>
  250    *
  251    * <h2>Rendering Compatibility Issues</h2>
  252    * The JDK(tm) 1.1 rendering model is based on a pixelization model
  253    * that specifies that coordinates
  254    * are infinitely thin, lying between the pixels.  Drawing operations are
  255    * performed using a one-pixel wide pen that fills the
  256    * pixel below and to the right of the anchor point on the path.
  257    * The JDK 1.1 rendering model is consistent with the
  258    * capabilities of most of the existing class of platform
  259    * renderers that need  to resolve integer coordinates to a
  260    * discrete pen that must fall completely on a specified number of pixels.
  261    * <p>
  262    * The Java 2D(tm) (Java(tm) 2 platform) API supports antialiasing renderers.
  263    * A pen with a width of one pixel does not need to fall
  264    * completely on pixel N as opposed to pixel N+1.  The pen can fall
  265    * partially on both pixels. It is not necessary to choose a bias
  266    * direction for a wide pen since the blending that occurs along the
  267    * pen traversal edges makes the sub-pixel position of the pen
  268    * visible to the user.  On the other hand, when antialiasing is
  269    * turned off by setting the
  270    * {@link RenderingHints#KEY_ANTIALIASING KEY_ANTIALIASING} hint key
  271    * to the
  272    * {@link RenderingHints#VALUE_ANTIALIAS_OFF VALUE_ANTIALIAS_OFF}
  273    * hint value, the renderer might need
  274    * to apply a bias to determine which pixel to modify when the pen
  275    * is straddling a pixel boundary, such as when it is drawn
  276    * along an integer coordinate in device space.  While the capabilities
  277    * of an antialiasing renderer make it no longer necessary for the
  278    * rendering model to specify a bias for the pen, it is desirable for the
  279    * antialiasing and non-antialiasing renderers to perform similarly for
  280    * the common cases of drawing one-pixel wide horizontal and vertical
  281    * lines on the screen.  To ensure that turning on antialiasing by
  282    * setting the
  283    * {@link RenderingHints#KEY_ANTIALIASING KEY_ANTIALIASING} hint
  284    * key to
  285    * {@link RenderingHints#VALUE_ANTIALIAS_ON VALUE_ANTIALIAS_ON}
  286    * does not cause such lines to suddenly become twice as wide and half
  287    * as opaque, it is desirable to have the model specify a path for such
  288    * lines so that they completely cover a particular set of pixels to help
  289    * increase their crispness.
  290    * <p>
  291    * Java 2D API maintains compatibility with JDK 1.1 rendering
  292    * behavior, such that legacy operations and existing renderer
  293    * behavior is unchanged under Java 2D API.  Legacy
  294    * methods that map onto general <code>draw</code> and
  295    * <code>fill</code> methods are defined, which clearly indicates
  296    * how <code>Graphics2D</code> extends <code>Graphics</code> based
  297    * on settings of <code>Stroke</code> and <code>Transform</code>
  298    * attributes and rendering hints.  The definition
  299    * performs identically under default attribute settings.
  300    * For example, the default <code>Stroke</code> is a
  301    * <code>BasicStroke</code> with a width of 1 and no dashing and the
  302    * default Transform for screen drawing is an Identity transform.
  303    * <p>
  304    * The following two rules provide predictable rendering behavior whether
  305    * aliasing or antialiasing is being used.
  306    * <ul>
  307    * <li> Device coordinates are defined to be between device pixels which
  308    * avoids any inconsistent results between aliased and antaliased
  309    * rendering.  If coordinates were defined to be at a pixel's center, some
  310    * of the pixels covered by a shape, such as a rectangle, would only be
  311    * half covered.
  312    * With aliased rendering, the half covered pixels would either be
  313    * rendered inside the shape or outside the shape.  With anti-aliased
  314    * rendering, the pixels on the entire edge of the shape would be half
  315    * covered.  On the other hand, since coordinates are defined to be
  316    * between pixels, a shape like a rectangle would have no half covered
  317    * pixels, whether or not it is rendered using antialiasing.
  318    * <li> Lines and paths stroked using the <code>BasicStroke</code>
  319    * object may be "normalized" to provide consistent rendering of the
  320    * outlines when positioned at various points on the drawable and
  321    * whether drawn with aliased or antialiased rendering.  This
  322    * normalization process is controlled by the
  323    * {@link RenderingHints#KEY_STROKE_CONTROL KEY_STROKE_CONTROL} hint.
  324    * The exact normalization algorithm is not specified, but the goals
  325    * of this normalization are to ensure that lines are rendered with
  326    * consistent visual appearance regardless of how they fall on the
  327    * pixel grid and to promote more solid horizontal and vertical
  328    * lines in antialiased mode so that they resemble their non-antialiased
  329    * counterparts more closely.  A typical normalization step might
  330    * promote antialiased line endpoints to pixel centers to reduce the
  331    * amount of blending or adjust the subpixel positioning of
  332    * non-antialiased lines so that the floating point line widths
  333    * round to even or odd pixel counts with equal likelihood.  This
  334    * process can move endpoints by up to half a pixel (usually towards
  335    * positive infinity along both axes) to promote these consistent
  336    * results.
  337    * </ul>
  338    * <p>
  339    * The following definitions of general legacy methods
  340    * perform identically to previously specified behavior under default
  341    * attribute settings:
  342    * <ul>
  343    * <li>
  344    * For <code>fill</code> operations, including <code>fillRect</code>,
  345    * <code>fillRoundRect</code>, <code>fillOval</code>,
  346    * <code>fillArc</code>, <code>fillPolygon</code>, and
  347    * <code>clearRect</code>, {@link #fill(Shape) fill} can now be called
  348    * with the desired <code>Shape</code>.  For example, when filling a
  349    * rectangle:
  350    * <pre>
  351    * fill(new Rectangle(x, y, w, h));
  352    * </pre>
  353    * is called.
  354    * <p>
  355    * <li>
  356    * Similarly, for draw operations, including <code>drawLine</code>,
  357    * <code>drawRect</code>, <code>drawRoundRect</code>,
  358    * <code>drawOval</code>, <code>drawArc</code>, <code>drawPolyline</code>,
  359    * and <code>drawPolygon</code>, {@link #draw(Shape) draw} can now be
  360    * called with the desired <code>Shape</code>.  For example, when drawing a
  361    * rectangle:
  362    * <pre>
  363    * draw(new Rectangle(x, y, w, h));
  364    * </pre>
  365    * is called.
  366    * <p>
  367    * <li>
  368    * The <code>draw3DRect</code> and <code>fill3DRect</code> methods were
  369    * implemented in terms of the <code>drawLine</code> and
  370    * <code>fillRect</code> methods in the <code>Graphics</code> class which
  371    * would predicate their behavior upon the current <code>Stroke</code>
  372    * and <code>Paint</code> objects in a <code>Graphics2D</code> context.
  373    * This class overrides those implementations with versions that use
  374    * the current <code>Color</code> exclusively, overriding the current
  375    * <code>Paint</code> and which uses <code>fillRect</code> to describe
  376    * the exact same behavior as the preexisting methods regardless of the
  377    * setting of the current <code>Stroke</code>.
  378    * </ul>
  379    * The <code>Graphics</code> class defines only the <code>setColor</code>
  380    * method to control the color to be painted.  Since the Java 2D API extends
  381    * the <code>Color</code> object to implement the new <code>Paint</code>
  382    * interface, the existing
  383    * <code>setColor</code> method is now a convenience method for setting the
  384    * current <code>Paint</code> attribute to a <code>Color</code> object.
  385    * <code>setColor(c)</code> is equivalent to <code>setPaint(c)</code>.
  386    * <p>
  387    * The <code>Graphics</code> class defines two methods for controlling
  388    * how colors are applied to the destination.
  389    * <ol>
  390    * <li>
  391    * The <code>setPaintMode</code> method is implemented as a convenience
  392    * method to set the default <code>Composite</code>, equivalent to
  393    * <code>setComposite(new AlphaComposite.SrcOver)</code>.
  394    * <li>
  395    * The <code>setXORMode(Color xorcolor)</code> method is implemented
  396    * as a convenience method to set a special <code>Composite</code> object that
  397    * ignores the <code>Alpha</code> components of source colors and sets the
  398    * destination color to the value:
  399    * <pre>
  400    * dstpixel = (PixelOf(srccolor) ^ PixelOf(xorcolor) ^ dstpixel);
  401    * </pre>
  402    * </ol>
  403    *
  404    * @author Jim Graham
  405    * @see java.awt.RenderingHints
  406    */
  407   public abstract class Graphics2D extends Graphics {
  408   
  409       /**
  410        * Constructs a new <code>Graphics2D</code> object.  Since
  411        * <code>Graphics2D</code> is an abstract class, and since it must be
  412        * customized by subclasses for different output devices,
  413        * <code>Graphics2D</code> objects cannot be created directly.
  414        * Instead, <code>Graphics2D</code> objects must be obtained from another
  415        * <code>Graphics2D</code> object, created by a
  416        * <code>Component</code>, or obtained from images such as
  417        * {@link BufferedImage} objects.
  418        * @see java.awt.Component#getGraphics
  419        * @see java.awt.Graphics#create
  420        */
  421       protected Graphics2D() {
  422       }
  423   
  424       /**
  425        * Draws a 3-D highlighted outline of the specified rectangle.
  426        * The edges of the rectangle are highlighted so that they
  427        * appear to be beveled and lit from the upper left corner.
  428        * <p>
  429        * The colors used for the highlighting effect are determined
  430        * based on the current color.
  431        * The resulting rectangle covers an area that is
  432        * <code>width&nbsp;+&nbsp;1</code> pixels wide
  433        * by <code>height&nbsp;+&nbsp;1</code> pixels tall.  This method
  434        * uses the current <code>Color</code> exclusively and ignores
  435        * the current <code>Paint</code>.
  436        * @param x the x coordinate of the rectangle to be drawn.
  437        * @param y the y coordinate of the rectangle to be drawn.
  438        * @param width the width of the rectangle to be drawn.
  439        * @param height the height of the rectangle to be drawn.
  440        * @param raised a boolean that determines whether the rectangle
  441        *                      appears to be raised above the surface
  442        *                      or sunk into the surface.
  443        * @see         java.awt.Graphics#fill3DRect
  444        */
  445       public void draw3DRect(int x, int y, int width, int height,
  446                              boolean raised) {
  447           Paint p = getPaint();
  448           Color c = getColor();
  449           Color brighter = c.brighter();
  450           Color darker = c.darker();
  451   
  452           setColor(raised ? brighter : darker);
  453           //drawLine(x, y, x, y + height);
  454           fillRect(x, y, 1, height + 1);
  455           //drawLine(x + 1, y, x + width - 1, y);
  456           fillRect(x + 1, y, width - 1, 1);
  457           setColor(raised ? darker : brighter);
  458           //drawLine(x + 1, y + height, x + width, y + height);
  459           fillRect(x + 1, y + height, width, 1);
  460           //drawLine(x + width, y, x + width, y + height - 1);
  461           fillRect(x + width, y, 1, height);
  462           setPaint(p);
  463       }
  464   
  465       /**
  466        * Paints a 3-D highlighted rectangle filled with the current color.
  467        * The edges of the rectangle are highlighted so that it appears
  468        * as if the edges were beveled and lit from the upper left corner.
  469        * The colors used for the highlighting effect and for filling are
  470        * determined from the current <code>Color</code>.  This method uses
  471        * the current <code>Color</code> exclusively and ignores the current
  472        * <code>Paint</code>.
  473        * @param x the x coordinate of the rectangle to be filled.
  474        * @param y the y coordinate of the rectangle to be filled.
  475        * @param       width the width of the rectangle to be filled.
  476        * @param       height the height of the rectangle to be filled.
  477        * @param       raised a boolean value that determines whether the
  478        *                      rectangle appears to be raised above the surface
  479        *                      or etched into the surface.
  480        * @see         java.awt.Graphics#draw3DRect
  481        */
  482       public void fill3DRect(int x, int y, int width, int height,
  483                              boolean raised) {
  484           Paint p = getPaint();
  485           Color c = getColor();
  486           Color brighter = c.brighter();
  487           Color darker = c.darker();
  488   
  489           if (!raised) {
  490               setColor(darker);
  491           } else if (p != c) {
  492               setColor(c);
  493           }
  494           fillRect(x+1, y+1, width-2, height-2);
  495           setColor(raised ? brighter : darker);
  496           //drawLine(x, y, x, y + height - 1);
  497           fillRect(x, y, 1, height);
  498           //drawLine(x + 1, y, x + width - 2, y);
  499           fillRect(x + 1, y, width - 2, 1);
  500           setColor(raised ? darker : brighter);
  501           //drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
  502           fillRect(x + 1, y + height - 1, width - 1, 1);
  503           //drawLine(x + width - 1, y, x + width - 1, y + height - 2);
  504           fillRect(x + width - 1, y, 1, height - 1);
  505           setPaint(p);
  506       }
  507   
  508       /**
  509        * Strokes the outline of a <code>Shape</code> using the settings of the
  510        * current <code>Graphics2D</code> context.  The rendering attributes
  511        * applied include the <code>Clip</code>, <code>Transform</code>,
  512        * <code>Paint</code>, <code>Composite</code> and
  513        * <code>Stroke</code> attributes.
  514        * @param s the <code>Shape</code> to be rendered
  515        * @see #setStroke
  516        * @see #setPaint
  517        * @see java.awt.Graphics#setColor
  518        * @see #transform
  519        * @see #setTransform
  520        * @see #clip
  521        * @see #setClip
  522        * @see #setComposite
  523        */
  524       public abstract void draw(Shape s);
  525   
  526       /**
  527        * Renders an image, applying a transform from image space into user space
  528        * before drawing.
  529        * The transformation from user space into device space is done with
  530        * the current <code>Transform</code> in the <code>Graphics2D</code>.
  531        * The specified transformation is applied to the image before the
  532        * transform attribute in the <code>Graphics2D</code> context is applied.
  533        * The rendering attributes applied include the <code>Clip</code>,
  534        * <code>Transform</code>, and <code>Composite</code> attributes.
  535        * Note that no rendering is done if the specified transform is
  536        * noninvertible.
  537        * @param img the specified image to be rendered.
  538        *            This method does nothing if <code>img</code> is null.
  539        * @param xform the transformation from image space into user space
  540        * @param obs the {@link ImageObserver}
  541        * to be notified as more of the <code>Image</code>
  542        * is converted
  543        * @return <code>true</code> if the <code>Image</code> is
  544        * fully loaded and completely rendered, or if it's null;
  545        * <code>false</code> if the <code>Image</code> is still being loaded.
  546        * @see #transform
  547        * @see #setTransform
  548        * @see #setComposite
  549        * @see #clip
  550        * @see #setClip
  551        */
  552       public abstract boolean drawImage(Image img,
  553                                         AffineTransform xform,
  554                                         ImageObserver obs);
  555   
  556       /**
  557        * Renders a <code>BufferedImage</code> that is
  558        * filtered with a
  559        * {@link BufferedImageOp}.
  560        * The rendering attributes applied include the <code>Clip</code>,
  561        * <code>Transform</code>
  562        * and <code>Composite</code> attributes.  This is equivalent to:
  563        * <pre>
  564        * img1 = op.filter(img, null);
  565        * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
  566        * </pre>
  567        * @param op the filter to be applied to the image before rendering
  568        * @param img the specified <code>BufferedImage</code> to be rendered.
  569        *            This method does nothing if <code>img</code> is null.
  570        * @param x the x coordinate of the location in user space where
  571        * the upper left corner of the image is rendered
  572        * @param y the y coordinate of the location in user space where
  573        * the upper left corner of the image is rendered
  574        *
  575        * @see #transform
  576        * @see #setTransform
  577        * @see #setComposite
  578        * @see #clip
  579        * @see #setClip
  580        */
  581       public abstract void drawImage(BufferedImage img,
  582                                      BufferedImageOp op,
  583                                      int x,
  584                                      int y);
  585   
  586       /**
  587        * Renders a {@link RenderedImage},
  588        * applying a transform from image
  589        * space into user space before drawing.
  590        * The transformation from user space into device space is done with
  591        * the current <code>Transform</code> in the <code>Graphics2D</code>.
  592        * The specified transformation is applied to the image before the
  593        * transform attribute in the <code>Graphics2D</code> context is applied.
  594        * The rendering attributes applied include the <code>Clip</code>,
  595        * <code>Transform</code>, and <code>Composite</code> attributes. Note
  596        * that no rendering is done if the specified transform is
  597        * noninvertible.
  598        * @param img the image to be rendered. This method does
  599        *            nothing if <code>img</code> is null.
  600        * @param xform the transformation from image space into user space
  601        * @see #transform
  602        * @see #setTransform
  603        * @see #setComposite
  604        * @see #clip
  605        * @see #setClip
  606        */
  607       public abstract void drawRenderedImage(RenderedImage img,
  608                                              AffineTransform xform);
  609   
  610       /**
  611        * Renders a
  612        * {@link RenderableImage},
  613        * applying a transform from image space into user space before drawing.
  614        * The transformation from user space into device space is done with
  615        * the current <code>Transform</code> in the <code>Graphics2D</code>.
  616        * The specified transformation is applied to the image before the
  617        * transform attribute in the <code>Graphics2D</code> context is applied.
  618        * The rendering attributes applied include the <code>Clip</code>,
  619        * <code>Transform</code>, and <code>Composite</code> attributes. Note
  620        * that no rendering is done if the specified transform is
  621        * noninvertible.
  622        *<p>
  623        * Rendering hints set on the <code>Graphics2D</code> object might
  624        * be used in rendering the <code>RenderableImage</code>.
  625        * If explicit control is required over specific hints recognized by a
  626        * specific <code>RenderableImage</code>, or if knowledge of which hints
  627        * are used is required, then a <code>RenderedImage</code> should be
  628        * obtained directly from the <code>RenderableImage</code>
  629        * and rendered using
  630        *{@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}.
  631        * @param img the image to be rendered. This method does
  632        *            nothing if <code>img</code> is null.
  633        * @param xform the transformation from image space into user space
  634        * @see #transform
  635        * @see #setTransform
  636        * @see #setComposite
  637        * @see #clip
  638        * @see #setClip
  639        * @see #drawRenderedImage
  640        */
  641       public abstract void drawRenderableImage(RenderableImage img,
  642                                                AffineTransform xform);
  643   
  644       /**
  645        * Renders the text of the specified <code>String</code>, using the
  646        * current text attribute state in the <code>Graphics2D</code> context.
  647        * The baseline of the
  648        * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in
  649        * the User Space.
  650        * The rendering attributes applied include the <code>Clip</code>,
  651        * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
  652        * <code>Composite</code> attributes.  For characters in script
  653        * systems such as Hebrew and Arabic, the glyphs can be rendered from
  654        * right to left, in which case the coordinate supplied is the
  655        * location of the leftmost character on the baseline.
  656        * @param str the string to be rendered
  657        * @param x the x coordinate of the location where the
  658        * <code>String</code> should be rendered
  659        * @param y the y coordinate of the location where the
  660        * <code>String</code> should be rendered
  661        * @throws NullPointerException if <code>str</code> is
  662        *         <code>null</code>
  663        * @see         java.awt.Graphics#drawBytes
  664        * @see         java.awt.Graphics#drawChars
  665        * @since       JDK1.0
  666        */
  667       public abstract void drawString(String str, int x, int y);
  668   
  669       /**
  670        * Renders the text specified by the specified <code>String</code>,
  671        * using the current text attribute state in the <code>Graphics2D</code> context.
  672        * The baseline of the first character is at position
  673        * (<i>x</i>,&nbsp;<i>y</i>) in the User Space.
  674        * The rendering attributes applied include the <code>Clip</code>,
  675        * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
  676        * <code>Composite</code> attributes. For characters in script systems
  677        * such as Hebrew and Arabic, the glyphs can be rendered from right to
  678        * left, in which case the coordinate supplied is the location of the
  679        * leftmost character on the baseline.
  680        * @param str the <code>String</code> to be rendered
  681        * @param x the x coordinate of the location where the
  682        * <code>String</code> should be rendered
  683        * @param y the y coordinate of the location where the
  684        * <code>String</code> should be rendered
  685        * @throws NullPointerException if <code>str</code> is
  686        *         <code>null</code>
  687        * @see #setPaint
  688        * @see java.awt.Graphics#setColor
  689        * @see java.awt.Graphics#setFont
  690        * @see #setTransform
  691        * @see #setComposite
  692        * @see #setClip
  693        */
  694       public abstract void drawString(String str, float x, float y);
  695   
  696       /**
  697        * Renders the text of the specified iterator applying its attributes
  698        * in accordance with the specification of the {@link TextAttribute} class.
  699        * <p>
  700        * The baseline of the first character is at position
  701        * (<i>x</i>,&nbsp;<i>y</i>) in User Space.
  702        * For characters in script systems such as Hebrew and Arabic,
  703        * the glyphs can be rendered from right to left, in which case the
  704        * coordinate supplied is the location of the leftmost character
  705        * on the baseline.
  706        * @param iterator the iterator whose text is to be rendered
  707        * @param x the x coordinate where the iterator's text is to be
  708        * rendered
  709        * @param y the y coordinate where the iterator's text is to be
  710        * rendered
  711        * @throws NullPointerException if <code>iterator</code> is
  712        *         <code>null</code>
  713        * @see #setPaint
  714        * @see java.awt.Graphics#setColor
  715        * @see #setTransform
  716        * @see #setComposite
  717        * @see #setClip
  718        */
  719       public abstract void drawString(AttributedCharacterIterator iterator,
  720                                       int x, int y);
  721   
  722       /**
  723        * Renders the text of the specified iterator applying its attributes
  724        * in accordance with the specification of the {@link TextAttribute} class.
  725        * <p>
  726        * The baseline of the first character is at position
  727        * (<i>x</i>,&nbsp;<i>y</i>) in User Space.
  728        * For characters in script systems such as Hebrew and Arabic,
  729        * the glyphs can be rendered from right to left, in which case the
  730        * coordinate supplied is the location of the leftmost character
  731        * on the baseline.
  732        * @param iterator the iterator whose text is to be rendered
  733        * @param x the x coordinate where the iterator's text is to be
  734        * rendered
  735        * @param y the y coordinate where the iterator's text is to be
  736        * rendered
  737        * @throws NullPointerException if <code>iterator</code> is
  738        *         <code>null</code>
  739        * @see #setPaint
  740        * @see java.awt.Graphics#setColor
  741        * @see #setTransform
  742        * @see #setComposite
  743        * @see #setClip
  744        */
  745       public abstract void drawString(AttributedCharacterIterator iterator,
  746                                       float x, float y);
  747   
  748       /**
  749        * Renders the text of the specified
  750        * {@link GlyphVector} using
  751        * the <code>Graphics2D</code> context's rendering attributes.
  752        * The rendering attributes applied include the <code>Clip</code>,
  753        * <code>Transform</code>, <code>Paint</code>, and
  754        * <code>Composite</code> attributes.  The <code>GlyphVector</code>
  755        * specifies individual glyphs from a {@link Font}.
  756        * The <code>GlyphVector</code> can also contain the glyph positions.
  757        * This is the fastest way to render a set of characters to the
  758        * screen.
  759        * @param g the <code>GlyphVector</code> to be rendered
  760        * @param x the x position in User Space where the glyphs should
  761        * be rendered
  762        * @param y the y position in User Space where the glyphs should
  763        * be rendered
  764        * @throws NullPointerException if <code>g</code> is <code>null</code>.
  765        *
  766        * @see java.awt.Font#createGlyphVector
  767        * @see java.awt.font.GlyphVector
  768        * @see #setPaint
  769        * @see java.awt.Graphics#setColor
  770        * @see #setTransform
  771        * @see #setComposite
  772        * @see #setClip
  773        */
  774       public abstract void drawGlyphVector(GlyphVector g, float x, float y);
  775   
  776       /**
  777        * Fills the interior of a <code>Shape</code> using the settings of the
  778        * <code>Graphics2D</code> context. The rendering attributes applied
  779        * include the <code>Clip</code>, <code>Transform</code>,
  780        * <code>Paint</code>, and <code>Composite</code>.
  781        * @param s the <code>Shape</code> to be filled
  782        * @see #setPaint
  783        * @see java.awt.Graphics#setColor
  784        * @see #transform
  785        * @see #setTransform
  786        * @see #setComposite
  787        * @see #clip
  788        * @see #setClip
  789        */
  790       public abstract void fill(Shape s);
  791   
  792       /**
  793        * Checks whether or not the specified <code>Shape</code> intersects
  794        * the specified {@link Rectangle}, which is in device
  795        * space. If <code>onStroke</code> is false, this method checks
  796        * whether or not the interior of the specified <code>Shape</code>
  797        * intersects the specified <code>Rectangle</code>.  If
  798        * <code>onStroke</code> is <code>true</code>, this method checks
  799        * whether or not the <code>Stroke</code> of the specified
  800        * <code>Shape</code> outline intersects the specified
  801        * <code>Rectangle</code>.
  802        * The rendering attributes taken into account include the
  803        * <code>Clip</code>, <code>Transform</code>, and <code>Stroke</code>
  804        * attributes.
  805        * @param rect the area in device space to check for a hit
  806        * @param s the <code>Shape</code> to check for a hit
  807        * @param onStroke flag used to choose between testing the
  808        * stroked or the filled shape.  If the flag is <code>true</code>, the
  809        * <code>Stroke</code> oultine is tested.  If the flag is
  810        * <code>false</code>, the filled <code>Shape</code> is tested.
  811        * @return <code>true</code> if there is a hit; <code>false</code>
  812        * otherwise.
  813        * @see #setStroke
  814        * @see #fill
  815        * @see #draw
  816        * @see #transform
  817        * @see #setTransform
  818        * @see #clip
  819        * @see #setClip
  820        */
  821       public abstract boolean hit(Rectangle rect,
  822                                   Shape s,
  823                                   boolean onStroke);
  824   
  825       /**
  826        * Returns the device configuration associated with this
  827        * <code>Graphics2D</code>.
  828        * @return the device configuration of this <code>Graphics2D</code>.
  829        */
  830       public abstract GraphicsConfiguration getDeviceConfiguration();
  831   
  832       /**
  833        * Sets the <code>Composite</code> for the <code>Graphics2D</code> context.
  834        * The <code>Composite</code> is used in all drawing methods such as
  835        * <code>drawImage</code>, <code>drawString</code>, <code>draw</code>,
  836        * and <code>fill</code>.  It specifies how new pixels are to be combined
  837        * with the existing pixels on the graphics device during the rendering
  838        * process.
  839        * <p>If this <code>Graphics2D</code> context is drawing to a
  840        * <code>Component</code> on the display screen and the
  841        * <code>Composite</code> is a custom object rather than an
  842        * instance of the <code>AlphaComposite</code> class, and if
  843        * there is a security manager, its <code>checkPermission</code>
  844        * method is called with an <code>AWTPermission("readDisplayPixels")</code>
  845        * permission.
  846        * @throws SecurityException
  847        *         if a custom <code>Composite</code> object is being
  848        *         used to render to the screen and a security manager
  849        *         is set and its <code>checkPermission</code> method
  850        *         does not allow the operation.
  851        * @param comp the <code>Composite</code> object to be used for rendering
  852        * @see java.awt.Graphics#setXORMode
  853        * @see java.awt.Graphics#setPaintMode
  854        * @see #getComposite
  855        * @see AlphaComposite
  856        * @see SecurityManager#checkPermission
  857        * @see java.awt.AWTPermission
  858        */
  859       public abstract void setComposite(Composite comp);
  860   
  861       /**
  862        * Sets the <code>Paint</code> attribute for the
  863        * <code>Graphics2D</code> context.  Calling this method
  864        * with a <code>null</code> <code>Paint</code> object does
  865        * not have any effect on the current <code>Paint</code> attribute
  866        * of this <code>Graphics2D</code>.
  867        * @param paint the <code>Paint</code> object to be used to generate
  868        * color during the rendering process, or <code>null</code>
  869        * @see java.awt.Graphics#setColor
  870        * @see #getPaint
  871        * @see GradientPaint
  872        * @see TexturePaint
  873        */
  874       public abstract void setPaint( Paint paint );
  875   
  876       /**
  877        * Sets the <code>Stroke</code> for the <code>Graphics2D</code> context.
  878        * @param s the <code>Stroke</code> object to be used to stroke a
  879        * <code>Shape</code> during the rendering process
  880        * @see BasicStroke
  881        * @see #getStroke
  882        */
  883       public abstract void setStroke(Stroke s);
  884   
  885       /**
  886        * Sets the value of a single preference for the rendering algorithms.
  887        * Hint categories include controls for rendering quality and overall
  888        * time/quality trade-off in the rendering process.  Refer to the
  889        * <code>RenderingHints</code> class for definitions of some common
  890        * keys and values.
  891        * @param hintKey the key of the hint to be set.
  892        * @param hintValue the value indicating preferences for the specified
  893        * hint category.
  894        * @see #getRenderingHint(RenderingHints.Key)
  895        * @see RenderingHints
  896        */
  897       public abstract void setRenderingHint(Key hintKey, Object hintValue);
  898   
  899       /**
  900        * Returns the value of a single preference for the rendering algorithms.
  901        * Hint categories include controls for rendering quality and overall
  902        * time/quality trade-off in the rendering process.  Refer to the
  903        * <code>RenderingHints</code> class for definitions of some common
  904        * keys and values.
  905        * @param hintKey the key corresponding to the hint to get.
  906        * @return an object representing the value for the specified hint key.
  907        * Some of the keys and their associated values are defined in the
  908        * <code>RenderingHints</code> class.
  909        * @see RenderingHints
  910        * @see #setRenderingHint(RenderingHints.Key, Object)
  911        */
  912       public abstract Object getRenderingHint(Key hintKey);
  913   
  914       /**
  915        * Replaces the values of all preferences for the rendering
  916        * algorithms with the specified <code>hints</code>.
  917        * The existing values for all rendering hints are discarded and
  918        * the new set of known hints and values are initialized from the
  919        * specified {@link Map} object.
  920        * Hint categories include controls for rendering quality and
  921        * overall time/quality trade-off in the rendering process.
  922        * Refer to the <code>RenderingHints</code> class for definitions of
  923        * some common keys and values.
  924        * @param hints the rendering hints to be set
  925        * @see #getRenderingHints
  926        * @see RenderingHints
  927        */
  928       public abstract void setRenderingHints(Map<?,?> hints);
  929   
  930       /**
  931        * Sets the values of an arbitrary number of preferences for the
  932        * rendering algorithms.
  933        * Only values for the rendering hints that are present in the
  934        * specified <code>Map</code> object are modified.
  935        * All other preferences not present in the specified
  936        * object are left unmodified.
  937        * Hint categories include controls for rendering quality and
  938        * overall time/quality trade-off in the rendering process.
  939        * Refer to the <code>RenderingHints</code> class for definitions of
  940        * some common keys and values.
  941        * @param hints the rendering hints to be set
  942        * @see RenderingHints
  943        */
  944       public abstract void addRenderingHints(Map<?,?> hints);
  945   
  946       /**
  947        * Gets the preferences for the rendering algorithms.  Hint categories
  948        * include controls for rendering quality and overall time/quality
  949        * trade-off in the rendering process.
  950        * Returns all of the hint key/value pairs that were ever specified in
  951        * one operation.  Refer to the
  952        * <code>RenderingHints</code> class for definitions of some common
  953        * keys and values.
  954        * @return a reference to an instance of <code>RenderingHints</code>
  955        * that contains the current preferences.
  956        * @see RenderingHints
  957        * @see #setRenderingHints(Map)
  958        */
  959       public abstract RenderingHints getRenderingHints();
  960   
  961       /**
  962        * Translates the origin of the <code>Graphics2D</code> context to the
  963        * point (<i>x</i>,&nbsp;<i>y</i>) in the current coordinate system.
  964        * Modifies the <code>Graphics2D</code> context so that its new origin
  965        * corresponds to the point (<i>x</i>,&nbsp;<i>y</i>) in the
  966        * <code>Graphics2D</code> context's former coordinate system.  All
  967        * coordinates used in subsequent rendering operations on this graphics
  968        * context are relative to this new origin.
  969        * @param  x the specified x coordinate
  970        * @param  y the specified y coordinate
  971        * @since   JDK1.0
  972        */
  973       public abstract void translate(int x, int y);
  974   
  975       /**
  976        * Concatenates the current
  977        * <code>Graphics2D</code> <code>Transform</code>
  978        * with a translation transform.
  979        * Subsequent rendering is translated by the specified
  980        * distance relative to the previous position.
  981        * This is equivalent to calling transform(T), where T is an
  982        * <code>AffineTransform</code> represented by the following matrix:
  983        * <pre>
  984        *          [   1    0    tx  ]
  985        *          [   0    1    ty  ]
  986        *          [   0    0    1   ]
  987        * </pre>
  988        * @param tx the distance to translate along the x-axis
  989        * @param ty the distance to translate along the y-axis
  990        */
  991       public abstract void translate(double tx, double ty);
  992   
  993       /**
  994        * Concatenates the current <code>Graphics2D</code>
  995        * <code>Transform</code> with a rotation transform.
  996        * Subsequent rendering is rotated by the specified radians relative
  997        * to the previous origin.
  998        * This is equivalent to calling <code>transform(R)</code>, where R is an
  999        * <code>AffineTransform</code> represented by the following matrix:
 1000        * <pre>
 1001        *          [   cos(theta)    -sin(theta)    0   ]
 1002        *          [   sin(theta)     cos(theta)    0   ]
 1003        *          [       0              0         1   ]
 1004        * </pre>
 1005        * Rotating with a positive angle theta rotates points on the positive
 1006        * x axis toward the positive y axis.
 1007        * @param theta the angle of rotation in radians
 1008        */
 1009       public abstract void rotate(double theta);
 1010   
 1011       /**
 1012        * Concatenates the current <code>Graphics2D</code>
 1013        * <code>Transform</code> with a translated rotation
 1014        * transform.  Subsequent rendering is transformed by a transform
 1015        * which is constructed by translating to the specified location,
 1016        * rotating by the specified radians, and translating back by the same
 1017        * amount as the original translation.  This is equivalent to the
 1018        * following sequence of calls:
 1019        * <pre>
 1020        *          translate(x, y);
 1021        *          rotate(theta);
 1022        *          translate(-x, -y);
 1023        * </pre>
 1024        * Rotating with a positive angle theta rotates points on the positive
 1025        * x axis toward the positive y axis.
 1026        * @param theta the angle of rotation in radians
 1027        * @param x the x coordinate of the origin of the rotation
 1028        * @param y the y coordinate of the origin of the rotation
 1029        */
 1030       public abstract void rotate(double theta, double x, double y);
 1031   
 1032       /**
 1033        * Concatenates the current <code>Graphics2D</code>
 1034        * <code>Transform</code> with a scaling transformation
 1035        * Subsequent rendering is resized according to the specified scaling
 1036        * factors relative to the previous scaling.
 1037        * This is equivalent to calling <code>transform(S)</code>, where S is an
 1038        * <code>AffineTransform</code> represented by the following matrix:
 1039        * <pre>
 1040        *          [   sx   0    0   ]
 1041        *          [   0    sy   0   ]
 1042        *          [   0    0    1   ]
 1043        * </pre>
 1044        * @param sx the amount by which X coordinates in subsequent
 1045        * rendering operations are multiplied relative to previous
 1046        * rendering operations.
 1047        * @param sy the amount by which Y coordinates in subsequent
 1048        * rendering operations are multiplied relative to previous
 1049        * rendering operations.
 1050        */
 1051       public abstract void scale(double sx, double sy);
 1052   
 1053       /**
 1054        * Concatenates the current <code>Graphics2D</code>
 1055        * <code>Transform</code> with a shearing transform.
 1056        * Subsequent renderings are sheared by the specified
 1057        * multiplier relative to the previous position.
 1058        * This is equivalent to calling <code>transform(SH)</code>, where SH
 1059        * is an <code>AffineTransform</code> represented by the following
 1060        * matrix:
 1061        * <pre>
 1062        *          [   1   shx   0   ]
 1063        *          [  shy   1    0   ]
 1064        *          [   0    0    1   ]
 1065        * </pre>
 1066        * @param shx the multiplier by which coordinates are shifted in
 1067        * the positive X axis direction as a function of their Y coordinate
 1068        * @param shy the multiplier by which coordinates are shifted in
 1069        * the positive Y axis direction as a function of their X coordinate
 1070        */
 1071       public abstract void shear(double shx, double shy);
 1072   
 1073       /**
 1074        * Composes an <code>AffineTransform</code> object with the
 1075        * <code>Transform</code> in this <code>Graphics2D</code> according
 1076        * to the rule last-specified-first-applied.  If the current
 1077        * <code>Transform</code> is Cx, the result of composition
 1078        * with Tx is a new <code>Transform</code> Cx'.  Cx' becomes the
 1079        * current <code>Transform</code> for this <code>Graphics2D</code>.
 1080        * Transforming a point p by the updated <code>Transform</code> Cx' is
 1081        * equivalent to first transforming p by Tx and then transforming
 1082        * the result by the original <code>Transform</code> Cx.  In other
 1083        * words, Cx'(p) = Cx(Tx(p)).  A copy of the Tx is made, if necessary,
 1084        * so further modifications to Tx do not affect rendering.
 1085        * @param Tx the <code>AffineTransform</code> object to be composed with
 1086        * the current <code>Transform</code>
 1087        * @see #setTransform
 1088        * @see AffineTransform
 1089        */
 1090       public abstract void transform(AffineTransform Tx);
 1091   
 1092       /**
 1093        * Overwrites the Transform in the <code>Graphics2D</code> context.
 1094        * WARNING: This method should <b>never</b> be used to apply a new
 1095        * coordinate transform on top of an existing transform because the
 1096        * <code>Graphics2D</code> might already have a transform that is
 1097        * needed for other purposes, such as rendering Swing
 1098        * components or applying a scaling transformation to adjust for the
 1099        * resolution of a printer.
 1100        * <p>To add a coordinate transform, use the
 1101        * <code>transform</code>, <code>rotate</code>, <code>scale</code>,
 1102        * or <code>shear</code> methods.  The <code>setTransform</code>
 1103        * method is intended only for restoring the original
 1104        * <code>Graphics2D</code> transform after rendering, as shown in this
 1105        * example:
 1106        * <pre><blockquote>
 1107        * // Get the current transform
 1108        * AffineTransform saveAT = g2.getTransform();
 1109        * // Perform transformation
 1110        * g2d.transform(...);
 1111        * // Render
 1112        * g2d.draw(...);
 1113        * // Restore original transform
 1114        * g2d.setTransform(saveAT);
 1115        * </blockquote></pre>
 1116        *
 1117        * @param Tx the <code>AffineTransform</code> that was retrieved
 1118        *           from the <code>getTransform</code> method
 1119        * @see #transform
 1120        * @see #getTransform
 1121        * @see AffineTransform
 1122        */
 1123       public abstract void setTransform(AffineTransform Tx);
 1124   
 1125       /**
 1126        * Returns a copy of the current <code>Transform</code> in the
 1127        * <code>Graphics2D</code> context.
 1128        * @return the current <code>AffineTransform</code> in the
 1129        *             <code>Graphics2D</code> context.
 1130        * @see #transform
 1131        * @see #setTransform
 1132        */
 1133       public abstract AffineTransform getTransform();
 1134   
 1135       /**
 1136        * Returns the current <code>Paint</code> of the
 1137        * <code>Graphics2D</code> context.
 1138        * @return the current <code>Graphics2D</code> <code>Paint</code>,
 1139        * which defines a color or pattern.
 1140        * @see #setPaint
 1141        * @see java.awt.Graphics#setColor
 1142        */
 1143       public abstract Paint getPaint();
 1144   
 1145       /**
 1146        * Returns the current <code>Composite</code> in the
 1147        * <code>Graphics2D</code> context.
 1148        * @return the current <code>Graphics2D</code> <code>Composite</code>,
 1149        *              which defines a compositing style.
 1150        * @see #setComposite
 1151        */
 1152       public abstract Composite getComposite();
 1153   
 1154       /**
 1155        * Sets the background color for the <code>Graphics2D</code> context.
 1156        * The background color is used for clearing a region.
 1157        * When a <code>Graphics2D</code> is constructed for a
 1158        * <code>Component</code>, the background color is
 1159        * inherited from the <code>Component</code>. Setting the background color
 1160        * in the <code>Graphics2D</code> context only affects the subsequent
 1161        * <code>clearRect</code> calls and not the background color of the
 1162        * <code>Component</code>.  To change the background
 1163        * of the <code>Component</code>, use appropriate methods of
 1164        * the <code>Component</code>.
 1165        * @param color the background color that isused in
 1166        * subsequent calls to <code>clearRect</code>
 1167        * @see #getBackground
 1168        * @see java.awt.Graphics#clearRect
 1169        */
 1170       public abstract void setBackground(Color color);
 1171   
 1172       /**
 1173        * Returns the background color used for clearing a region.
 1174        * @return the current <code>Graphics2D</code> <code>Color</code>,
 1175        * which defines the background color.
 1176        * @see #setBackground
 1177        */
 1178       public abstract Color getBackground();
 1179   
 1180       /**
 1181        * Returns the current <code>Stroke</code> in the
 1182        * <code>Graphics2D</code> context.
 1183        * @return the current <code>Graphics2D</code> <code>Stroke</code>,
 1184        *                 which defines the line style.
 1185        * @see #setStroke
 1186        */
 1187       public abstract Stroke getStroke();
 1188   
 1189       /**
 1190        * Intersects the current <code>Clip</code> with the interior of the
 1191        * specified <code>Shape</code> and sets the <code>Clip</code> to the
 1192        * resulting intersection.  The specified <code>Shape</code> is
 1193        * transformed with the current <code>Graphics2D</code>
 1194        * <code>Transform</code> before being intersected with the current
 1195        * <code>Clip</code>.  This method is used to make the current
 1196        * <code>Clip</code> smaller.
 1197        * To make the <code>Clip</code> larger, use <code>setClip</code>.
 1198        * The <i>user clip</i> modified by this method is independent of the
 1199        * clipping associated with device bounds and visibility.  If no clip has
 1200        * previously been set, or if the clip has been cleared using
 1201        * {@link Graphics#setClip(Shape) setClip} with a <code>null</code>
 1202        * argument, the specified <code>Shape</code> becomes the new
 1203        * user clip.
 1204        * @param s the <code>Shape</code> to be intersected with the current
 1205        *          <code>Clip</code>.  If <code>s</code> is <code>null</code>,
 1206        *          this method clears the current <code>Clip</code>.
 1207        */
 1208        public abstract void clip(Shape s);
 1209   
 1210        /**
 1211        * Get the rendering context of the <code>Font</code> within this
 1212        * <code>Graphics2D</code> context.
 1213        * The {@link FontRenderContext}
 1214        * encapsulates application hints such as anti-aliasing and
 1215        * fractional metrics, as well as target device specific information
 1216        * such as dots-per-inch.  This information should be provided by the
 1217        * application when using objects that perform typographical
 1218        * formatting, such as <code>Font</code> and
 1219        * <code>TextLayout</code>.  This information should also be provided
 1220        * by applications that perform their own layout and need accurate
 1221        * measurements of various characteristics of glyphs such as advance
 1222        * and line height when various rendering hints have been applied to
 1223        * the text rendering.
 1224        *
 1225        * @return a reference to an instance of FontRenderContext.
 1226        * @see java.awt.font.FontRenderContext
 1227        * @see java.awt.Font#createGlyphVector
 1228        * @see java.awt.font.TextLayout
 1229        * @since     1.2
 1230        */
 1231   
 1232       public abstract FontRenderContext getFontRenderContext();
 1233   
 1234   }

Home » openjdk-7 » java » awt » [javadoc | source]