home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / Graphics2D.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  32.4 KB  |  843 lines

  1. /*
  2.  * @(#)Graphics2D.java    1.35 98/03/18
  3.  *
  4.  * Copyright 1996-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt;
  16.  
  17. import java.awt.geom.AffineTransform;
  18. import java.awt.image.ImageObserver;
  19. import java.awt.image.BufferedImageOp;
  20. import java.awt.image.BufferedImage;
  21. import java.awt.image.RenderedImage;
  22. import java.util.Hashtable;
  23. import java.awt.image.renderable.RenderableImage;
  24. import java.awt.font.StyledString;
  25. import java.awt.font.GlyphSet;
  26. import java.awt.font.TextLayout;
  27. import java.util.Vector;
  28.  
  29. /**
  30.  * This is the fundamental class for 2D rendering in Java.  This
  31.  * class extends the original java.awt.Graphics class to provide
  32.  * more sophisticated control over geometry, coordinate
  33.  * transformation, color management, and text layout.
  34.  * 
  35.  * <h2>Coordinate Spaces</h2>
  36.  * All coordinates that are given to a Graphics2D object are treated
  37.  * as being in a virtual coordinate system which is called the User
  38.  * Coordinate Space, or User Space.  The Graphics2D object contains
  39.  * an AffineTransform object as part of its rendering state that defines
  40.  * how to convert coordinates from this user space to coordinates
  41.  * in the Device Coordinate Space, or Device Space.
  42.  * <p>
  43.  * Coordinates in device space usually refer to individual device pixels
  44.  * and are aligned in the infinitely thin gaps between these pixels.
  45.  * Some Graphics2D objects may be used to capture rendering operations
  46.  * for storage into a graphics metafile for playback on a concrete
  47.  * device of unknown physical resolution at a later time.  Since the
  48.  * resolution may not be known when the rendering operations are
  49.  * captured, the Transform will be set up to transform user coordinates
  50.  * to a virtual device space that typically approximates the expected
  51.  * resolution of the target device, though further transformation may
  52.  * need to be applied at playback time if the estimate is incorrect.
  53.  * <p>
  54.  * Some of the operations performed by the rendering attribute objects
  55.  * may operate in the device space, but all methods that are defined
  56.  * on the Graphics2D object work with user space coordinates.
  57.  * <p>
  58.  * The <a name="#deftransform">default transform</a> when a Graphics2D
  59.  * object is created will be specified by the GraphicsConfiguration for
  60.  * the target of the Graphics2D (a Component or Image).
  61.  * This default transform will map the user space coordinate system
  62.  * to screen and printer device coordinates such that the origin
  63.  * maps to the upper left hand corner of the
  64.  * target region of the device with increasing X coordinates extending
  65.  * to the right and increasing Y coordinates extending downward.
  66.  * The scaling of the default transform for screen devices will be set
  67.  * to identity for screen devices.
  68.  * The scaling of the default transform for printers and other high
  69.  * resolution devices will be set to approximate 72 user space coordinates
  70.  * per device inch.
  71.  * For image buffers, the default transform will be the Identity transform.
  72.  *
  73.  * <h2>Rendering Outline</h2>
  74.  * Rendering in the Java 2D API can be described by a 4-step conceptual process
  75.  * controlled by the various rendering attributes in the Graphics2D object.
  76.  * The renderer may optimize many of these steps, either by caching the
  77.  * results for future calls, by collapsing multiple virtual steps into
  78.  * a single operation, or by recognizing various attributes as common
  79.  * simple cases that can be eliminated by modifying other parts of the
  80.  * operation.
  81.  * <p>
  82.  * As a behavioral reference, the steps can be described in the following
  83.  * way:
  84.  * <ol>
  85.  * <li>
  86.  * Determine where to render.  This step can be further broken down
  87.  * according to the type of rendering operation as follows:
  88.  * <br>
  89.  * <b><a name="#rendershape">Shape operations</a></b>
  90.  * <ol>
  91.  * <li>
  92.  * If the operation is a draw(Shape) operation, then the shape is converted
  93.  * into a shape to fill using the
  94.  * <a href=java.awt.Stroke.html#createStrokedShape>createStrokedShape()</a>
  95.  * method on the current <a href=java.awt.Stroke.html>Stroke</a>.
  96.  * <li>
  97.  * The shape is transformed from user space to device space using the
  98.  * current <a href=java.awt.geom.AffineTransform.html>Transform</a>.
  99.  * <li>
  100.  * The outline of the Shape is extracted using a
  101.  * <a href=java.awt.geom.PathIterator.html>PathIterator</a> using the
  102.  * <a href=java.awt.Shape.html#getPathIterator>Shape.getPathIterator()</a>
  103.  * method.
  104.  * <li>
  105.  * If the Graphics2D object is not able to handle the curved segments
  106.  * that a PathIterator object can return, then it may call the alternat
  107.  * getPathIterator() method which flattens the shape.
  108.  * </ol>
  109.  * <b><a name=#rendertext>Text operations</a></b>
  110.  * <ol>
  111.  * <li>
  112.  * The set of glyphs required to render the indicated string
  113.  * are determined as follows:
  114.  * <ul>
  115.  * <li>
  116.  * If the argument is a String, then the current
  117.  * <a href=java.awt.Font.html>Font</a> is asked to convert the
  118.  * Unicode characters in the String into a GlyphSet with whatever
  119.  * basic layout algorithm the font implements.
  120.  * <li>
  121.  * If the argument is a
  122.  * <a href=java.awt.font.StyledString.html>StyledString</a>,
  123.  * the StyledString is asked to convert itself to a GlyphSet
  124.  * according to its embedded font attributes.  The StyledString
  125.  * may implement more sophisticated glyph layout algorithms that
  126.  * perform Unicode bi-directional layout adjustments automatically
  127.  * for multiple fonts of differing writing directions.
  128.  * <li>
  129.  * If the argument is a
  130.  * <a href=java.awt.font.GlyphSet.html>GlyphSet</a>, then the GlyphSet
  131.  * object already contains the appropriate font-specific glyph codes
  132.  * with explicit coordinates for the position of each glyph.
  133.  * </ul>
  134.  * <li>
  135.  * The current Font is queried to obtain outlines for the indicated
  136.  * glyphs.  These outlines are treated as shapes in user space relative
  137.  * to the position of each glyph that was determined in step 1.
  138.  * <li>
  139.  * The outline of the characters are filled as indicated above
  140.  * under <a href="#rendershape">Shape operations</a>
  141.  * </ol>
  142.  * <b><a name=#renderimg>Image operations</a></b>
  143.  * <ol>
  144.  * <li>
  145.  * The bounding box of the source image defines the region of interest
  146.  * in a coordinate system local to the Image object, called Image Space.
  147.  * <li>
  148.  * If an optional transform is supplied to the
  149.  * <a href="#drawImage(java.awt.Image, java.awt.geom.AffineTransform, java.awt.image.ImageObserver)">drawImage()</a>
  150.  * method call, then this transform is used to transform the bounding
  151.  * box from image space to user space, otherwise the bounding box is
  152.  * treated as if it already was in user space.
  153.  * <li>
  154.  * The bounding box of the source image is then transformed from user
  155.  * space into device space using the current transform of the Graphics2D.
  156.  * Note that the result of transforming the bounding box will not
  157.  * necessarily result in a rectangular region in device space and
  158.  * for some custom transforms may not even result in a quadrilateral
  159.  * region.
  160.  * </ol>
  161.  * <li>
  162.  * Constrain the rendering operation to the current Clip.  The clip
  163.  * was originally specified by a shape in user space and was converted
  164.  * into device space by the Transform in effect at the time it was
  165.  * modified.
  166.  * <li>
  167.  * Determine what colors to render as the renderer scan converts the
  168.  * associated shape in device space.
  169.  * <ul>
  170.  * <li>
  171.  * For image operations, the colors are determined from the Image
  172.  * object itself sampled according to the source to destination
  173.  * coordinate mapping specified by the current transform and the
  174.  * optional image transform.
  175.  * <li>
  176.  * For all other operations, the current
  177.  * <a href=java.awt.Paint.html>Paint</a> or
  178.  * <a href=java.awt.Color.html>Color</a> object is queried for a
  179.  * <a href=java.awt.PaintContext.html>PaintContext</a> which specifies
  180.  * what colors are to be rendered in device space.
  181.  * </ul>
  182.  * <li>
  183.  * Apply the colors to the destination drawing surface using the current
  184.  * <a href=java.awt.Composite.html>Composite</a> object.
  185.  * </ol>
  186.  *
  187.  * <h2>Default values</h2>
  188.  * The default values for the various rendering attributes are:
  189.  * <dl compact>
  190.  * <dt><i>Color</i>
  191.  * <dd>The color of the Component.
  192.  * <dt><i>Font</i>
  193.  * <dd>The font of the Component.
  194.  * <dt><i>Stroke</i>
  195.  * <dd>A square pen with a linewidth of 1, no dashing, miter segment joins
  196.  * and non-projecting end caps.
  197.  * <dt><i>Transform</i>
  198.  * <dd>The <a href="java.awt.GraphicsConfiguration#getDefaultTransform">default</a> for the
  199.  * GraphicsConfiguration of the Component.
  200.  * <dt><i>Composite</i>
  201.  * <dd>The Porter-Duff
  202.  * <a href=java.awt.AlphaComposite.html#SRC_OVER>Source Over
  203.  * Destination</a> rule.
  204.  * <dt><i>Clip</i>
  205.  * <dd>No rendering clip, output is clipped to the Component
  206.  * </dl>
  207.  *
  208.  * <h2>Rendering compatibility issue</h2>
  209.  * The rendering model presented by the pre-Java 2D API Graphics class
  210.  * was based on a pixelization model that specified that coordinates
  211.  * were infinitely thin, lying between the pixels, and that drawing
  212.  * operations were performed by dragging a one-pixel square Pen along
  213.  * the path hanging down and to the right of the anchor point on the
  214.  * path.
  215.  * <p>
  216.  * The behavior of these operations given the model presented here is
  217.  * unclear if the current Stroke specifies a wide pen, or if there
  218.  * is a non-identity Transform being applied.
  219.  * <p>
  220.  * That rendering model was consistent with the capabilities of most
  221.  * of the existing class of platform renderers that needed to resolve
  222.  * integer coordinates to a discrete pen that must fall completely on
  223.  * a given number of pixels.  Since the Java 2D API is capable of driving an
  224.  * antialiasing renderer it no longer makes sense to choose a bias
  225.  * direction for a wide pen since sub-pixel positioning of the pen
  226.  * can be made visible to the user via the blending that occurs along
  227.  * the edges of the traversal of the pen.  It is thus, no longer true
  228.  * that a 1-pixel wide pen must choose to fall on pixel N as opposed
  229.  * to pixel N+1; it can now fall partially on both pixels.
  230.  * <p>
  231.  * When antialiasing is turned off with the ANTIALIAS_OFF hint, the
  232.  * underlying renderer may still need to apply a bias in order to
  233.  * resolve the conflict of which pixel to modify when the pen is
  234.  * exactly straddling a pixel boundary (such as when it is drawn
  235.  * along an integer coordinate in device space).  But when
  236.  * antialiasing is enabled, no biasing of the pen needs to occur
  237.  * and so no bias should be explicitly specified by the rendering
  238.  * model.
  239.  * <p>
  240.  * Thus, there remains the problem of how to define the operation of
  241.  * the legacy rendering operations inherited from the Graphics class
  242.  * to be compatible with existing rendering behavior and to be
  243.  * predictable and unsurprising under all possible settings of the
  244.  * latest rendering attributes.
  245.  * <p>
  246.  * To provide predictability we will define operations for all of the
  247.  * legacy methods that map onto the more general draw(Shape) and fill(Shape)
  248.  * methods.  Such a specification will thus be clear how it extends
  249.  * based on various settings of Stroke and Transform attributes,
  250.  * and rendering hints.
  251.  * <p>
  252.  * To provide compatibility with previous rendering behavior it is
  253.  * important to specify a definition that performs identically under
  254.  * the default attribute settings.  In particular, the default Stroke
  255.  * is a <a href=java.awt.BasicStroke.html>BasicStroke</a>
  256.  * with a width of 1 and no dashing, and the default
  257.  * Transform for screen drawing is an Identity transform.  Unfortunately,
  258.  * the default antialiasing rendering hint is ANTIALIAS_DEFAULT which
  259.  * may be enabled on some implementations and not on others.  This
  260.  * means that the definition of these operations needs to be invariant
  261.  * under antialiasing.
  262.  * <p>
  263.  * We now define the following generalizations of the various legacy
  264.  * methods which can be shown to be identical to the previously
  265.  * specified behavior under the default attributes:
  266.  * <ul>
  267.  * <li>
  268.  * For fill operations, which include fillRect, fillRoundRect, fillOval,
  269.  * fillArc, fillPolygon, and clearRect, we could create a GeneralPath, gp,
  270.  * that traverses the same integer coordinates and call:
  271.  * <pre>
  272.  * fill(gp);
  273.  * </pre>
  274.  * <li>
  275.  * For draw operations, which include drawLine, drawRect, drawRoundRect,
  276.  * drawOval, drawArc, drawPolyline, and drawPolygon, we could create a
  277.  * GeneralPath, gp, that traverses the same integer coordinates and call:
  278.  * <pre>
  279.  * AffineTransform at = new AffineTransform(1f,0f,0f,1f,0.5f,0.5f);
  280.  * draw(at.createTransformedShape(bp));
  281.  * </pre>
  282.  * <li>
  283.  * The draw3DRect and fill3DRect methods were implemented in terms
  284.  * of the drawLine and fillRect methods and their behavior is thus
  285.  * extended as well.
  286.  * </ul>
  287.  * The existing Graphics class defined only the single setColor
  288.  * method to control the color to be painted.  Since the Java 2D API extends
  289.  * the Color object to implement the new Paint interface, the existing
  290.  * setColor method is now a convenience method for setting the current
  291.  * Paint to a Color object.  <tt>setColor(c)</tt> is thus equivalent to
  292.  * <tt>setPaint(c)</tt>.
  293.  * <p>
  294.  * The existing Graphics class defined two methods for controlling
  295.  * how colors were applied to the destination.
  296.  * The setPaintMode() method will now be implemented as a convenience
  297.  * method to set the default Composite, equivalent to
  298.  * <tt>setComposite(new AlphaComposite(SRC_OVER))</tt>.
  299.  * The setXORMode(Color xorcolor) method will now be implemented
  300.  * as a convenience method to set a special Composite object which
  301.  * ignores the Alpha components of source colors and sets the
  302.  * destination color to the value:
  303.  * <pre>
  304.  * dstpixel = (PixelOf(srccolor) ^ PixelOf(xorcolor) ^ dstpixel);
  305.  * </pre>
  306.  * 
  307.  * @version 10-Feb-97
  308.  * @author Jim Graham
  309.  */
  310. public abstract class Graphics2D extends Graphics {
  311.  
  312.     /**
  313.      * Antialiasing hint category.
  314.      */
  315.     public static final int ANTIALIASING    = 0;
  316.  
  317.     /**
  318.      * Rendering is done with antialiasing.
  319.      */
  320.     public static final int ANTIALIAS_ON    = 1;
  321.  
  322.     /**
  323.      * Rendering is done without antialiasing.
  324.      */
  325.     public static final int ANTIALIAS_OFF    = 2;
  326.  
  327.     /**
  328.      * Rendering is done with the platform default antialiasing mode.
  329.      */
  330.     public static final int ANTIALIAS_DEFAULT    = 3;
  331.  
  332.     /**
  333.      * Rendering hint category.
  334.      */
  335.     public static final int RENDERING        = 1;
  336.  
  337.     /**
  338.      * Appropriate rendering algorithms are chosen with a preference
  339.      * for output speed.
  340.      */
  341.     public static final int RENDER_SPEED    = 4;
  342.  
  343.     /**
  344.      * Appropriate rendering algorithms are chosen with a preference
  345.      * for output quality.
  346.      */
  347.     public static final int RENDER_QUALITY    = 5;
  348.  
  349.     /**
  350.      * The platform default algorithms are chosen for rendering.
  351.      */
  352.     public static final int RENDER_DEFAULT    = 6;
  353.  
  354.     /**
  355.      * Text antialiasing hint category.  The values for this category
  356.      * ANTIALIAS_ON, ANTIALIAS_OFF, ANTIALIAS_DEFAULT.
  357.      */
  358.     public static final int TEXT_ANTIALIASING   = 2;
  359.     
  360.     /**
  361.      * Constructs a new Graphics2D object.  Since Graphics2D is an abstract
  362.      * class, and since it must be customized by subclasses for different
  363.      * output devices, Graphics2D objects cannot be created directly.
  364.      * Instead, Graphics2D objects must be obtained from another Graphics2D
  365.      * object or created by a Component.
  366.      * @see java.awt.Component#getGraphics
  367.      * @see java.awt.Graphics#create
  368.      */
  369.     protected Graphics2D() {
  370.     }
  371.  
  372.     /**
  373.      * Strokes the outline of a Shape using the settings of the current
  374.      * graphics state.  The rendering attributes applied include the
  375.      * clip, transform, paint or color, composite and stroke attributes.
  376.      * @param s The shape to be drawn.
  377.      * @see #setStroke
  378.      * @see #setPaint
  379.      * @see java.awt.Graphics#setColor
  380.      * @see #transform
  381.      * @see #setTransform
  382.      * @see #clip
  383.      * @see #setClip
  384.      * @see #setComposite
  385.      */
  386.     public abstract void draw(Shape s);
  387.  
  388.     /**
  389.      * Draws an image, applying a transform from image space into user space
  390.      * before drawing.
  391.      * The transformation from user space into device space is done with
  392.      * the current transform in the Graphics2D.
  393.      * The given transformation is applied to the image before the
  394.      * transform attribute in the Graphics2D state is applied.
  395.      * The rendering attributes applied include the clip, transform,
  396.      * and composite attributes. Note that the result is
  397.      * undefined, if the given transform is noninvertible.
  398.      * @param img The image to be drawn.
  399.      * @param xform The transformation from image space into user space.
  400.      * @param obs The image observer to be notified as more of the image
  401.      * is converted.
  402.      * @see #transform
  403.      * @see #setTransform
  404.      * @see #setComposite
  405.      * @see #clip
  406.      * @see #setClip
  407.      */
  408.     public abstract void drawImage(Image img,
  409.                    AffineTransform xform,
  410.                    ImageObserver obs);
  411.  
  412.     /**
  413.      * Draws a BufferedImage that is filtered with a BufferedImageOp.
  414.      * The rendering attributes applied include the clip, transform
  415.      * and composite attributes.  This is equivalent to:
  416.      * <pre>
  417.      * img1 = op.filter(img, null);
  418.      * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
  419.      * </pre>
  420.      * @param op The filter to be applied to the image before drawing.
  421.      * @param img The BufferedImage to be drawn.
  422.      * @param x,y The location in user space where the image should be drawn.
  423.      * @see #transform
  424.      * @see #setTransform
  425.      * @see #setComposite
  426.      * @see #clip
  427.      * @see #setClip
  428.      */
  429.     public abstract void drawImage(BufferedImage img,
  430.                    BufferedImageOp op,
  431.                    int x,
  432.                    int y);
  433.  
  434.     /**
  435.      * Draws an image, applying a transform from image space into user space
  436.      * before drawing.
  437.      * The transformation from user space into device space is done with
  438.      * the current transform in the Graphics2D.
  439.      * The given transformation is applied to the image before the
  440.      * transform attribute in the Graphics2D state is applied.
  441.      * The rendering attributes applied include the clip, transform,
  442.      * and composite attributes. Note that the result is
  443.      * undefined, if the given transform is noninvertible.
  444.      * @param img The image to be drawn.
  445.      * @param xform The transformation from image space into user space.
  446.      * @see #transform
  447.      * @see #setTransform
  448.      * @see #setComposite
  449.      * @see #clip
  450.      * @see #setClip
  451.      */
  452.     public abstract void drawRenderedImage(RenderedImage img,
  453.                                            AffineTransform xform);
  454.  
  455.     public abstract void drawRenderableImage(RenderableImage img,
  456.                                              AffineTransform xfrom,
  457.                                              Hashtable renderHints,
  458.                                              Hashtable renderHintsObserved);
  459.  
  460.     /** 
  461.      * Draws the text given by the specified string, using this 
  462.      * graphics context's current font and color. The baseline of the 
  463.      * first character is at position (<i>x</i>, <i>y</i>) in this 
  464.      * graphics context's coordinate system. 
  465.      * @param       str      the string to be drawn.
  466.      * @param       x        the <i>x</i> coordinate.
  467.      * @param       y        the <i>y</i> coordinate.
  468.      * @see         java.awt.Graphics#drawBytes
  469.      * @see         java.awt.Graphics#drawChars
  470.      * @since       JDK1.0
  471.      */
  472.     public abstract void drawString(String str, int x, int y);
  473.  
  474.     /**
  475.      * Draws a string of text.
  476.      * The rendering attributes applied include the clip, transform,
  477.      * paint or color, font and composite attributes.
  478.      * @param s The string to be drawn.
  479.      * @param x,y The coordinates where the string should be drawn.
  480.      * @see #setPaint
  481.      * @see java.awt.Graphics#setColor
  482.      * @see java.awt.Graphics#setFont
  483.      * @see #transform
  484.      * @see #setTransform
  485.      * @see #setComposite
  486.      * @see #clip
  487.      * @see #setClip
  488.      */
  489.     public abstract void drawString(String s,
  490.                     float x,
  491.                     float y);
  492.  
  493.     /**
  494.      * Draws a StyledString.
  495.      * The rendering attributes applied include the clip, transform,
  496.      * paint or color, and composite attributes.  A Font is associated
  497.      * with each character in the StyledString.
  498.      * @param s The StyledString to be drawn.
  499.      * @param x,y The coordinates where the StyledString should be drawn.
  500.      * @see #setPaint
  501.      * @see java.awt.Graphics#setColor
  502.      * @see #transform
  503.      * @see #setTransform
  504.      * @see #setComposite
  505.      * @see #clip
  506.      * @see #setClip
  507.      * @see Font
  508.      */
  509.     public abstract void drawString(StyledString s,
  510.                     float x,
  511.                     float y);
  512.  
  513.     /**
  514.      * Draws a GlyphSet.
  515.      * The rendering attributes applied include the clip, transform,
  516.      * paint or color, and composite attributes.  The glyphSet specifies
  517.      * individual glyphs from a Font.
  518.      * @param g The GlyphSet to be drawn.
  519.      * @param x,y The coordinates where the glyphs should be drawn.
  520.      * @see #setPaint
  521.      * @see java.awt.Graphics#setColor
  522.      * @see #transform
  523.      * @see #setTransform
  524.      * @see #setComposite
  525.      * @see #clip
  526.      * @see #setClip
  527.      */
  528.     public abstract void drawString(GlyphSet g,
  529.                     float x,
  530.                     float y);
  531.  
  532.     public abstract void drawString(TextLayout text, float x, float y);
  533.     /**
  534.      * Fills the interior of a Shape using the settings of the current
  535.      * graphics state. The rendering attributes applied include the
  536.      * clip, transform, paint or color, and composite.
  537.      * @see #setPaint
  538.      * @see java.awt.Graphics#setColor
  539.      * @see #transform
  540.      * @see #setTransform
  541.      * @see #setComposite
  542.      * @see #clip
  543.      * @see #setClip
  544.      */
  545.     public abstract void fill(Shape s);
  546.  
  547.     /**
  548.      * Checks to see if the outline of a Shape intersects the specified
  549.      * Rectangle in device space.
  550.      * The rendering attributes taken into account include the
  551.      * clip, transform, and stroke attributes.
  552.      * @param rect The area in device space to check for a hit.
  553.      * @param s The shape to check for a hit.
  554.      * @param onStroke Flag to choose between testing the stroked or
  555.      * the filled shape.
  556.      * @return True if there is a hit, false otherwise.
  557.      * @see #setStroke
  558.      * @see #fill
  559.      * @see #draw
  560.      * @see #transform
  561.      * @see #setTransform
  562.      * @see #clip
  563.      * @see #setClip
  564.      */
  565.     public abstract boolean hit(Rectangle rect,
  566.                 Shape s,
  567.                 boolean onStroke);
  568.  
  569.     /**
  570.      * Checks to see if the StyledString intersects the specified Rectangle
  571.      * in device space.
  572.      * The rendering attributes taken into account include the clip
  573.      * and transform.
  574.      * @param rect The area in device space to check for a hit.
  575.      * @param s The StyledString to check for a hit.
  576.      * @param x,y The coordinates where the StyledString should be
  577.      * hit tested.
  578.      * @return True if there is a hit, false otherwise.
  579.      * @see #drawString(StyledString, float, float)
  580.      * @see #transform
  581.      * @see #setTransform
  582.      * @see #clip
  583.      * @see #setClip
  584.      */
  585.     public abstract boolean hitString(Rectangle rect,
  586.                       StyledString s,
  587.                                       float x,
  588.                                       float y);
  589.  
  590.     /**
  591.      * Returns the device configuration associated with this Graphics2D.
  592.      */
  593.     public abstract GraphicsConfiguration getDeviceConfiguration();
  594.  
  595.     /**
  596.      * Sets the Composite in the current graphics state. Composite is used
  597.      * in all drawing methods such as drawImage, drawString, draw,
  598.      * and fill.  It specifies how new pixels are to be combined with
  599.      * the existing pixels on the graphics device in the rendering process.
  600.      * @param comp The Composite object to be used for drawing.
  601.      * @see java.awt.Graphics#setXORMode
  602.      * @see java.awt.Graphics#setPaintMode
  603.      * @see AlphaComposite
  604.      */
  605.     public abstract void setComposite(Composite comp);
  606.  
  607.     /**
  608.      * Sets the Paint in the current graphics state.
  609.      * @param paint The Paint object to be used to generate color in
  610.      * the rendering process.
  611.      * @see java.awt.Graphics#setColor
  612.      * @see GradientPaint
  613.      * @see TexturePaint
  614.      */
  615.     public abstract void setPaint( Paint paint );
  616.  
  617.     /**
  618.      * Sets the Stroke in the current graphics state.
  619.      * @param s The Stroke object to be used to stroke a Shape in
  620.      * the rendering process.
  621.      * @see BasicStroke
  622.      */
  623.     public abstract void setStroke(Stroke s);
  624.  
  625.     /**
  626.      * Sets the preferences for the rendering algorithms.
  627.      * Hint categories include controls for rendering quality and
  628.      * overall time/quality trade-off in the rendering process.
  629.      * @param hintCategory The category of hint to be set. Possible values
  630.      * are ANTIALIASING and RENDERING.
  631.      * @param hintValue The value indicating preferences for the specified
  632.      * hint category. Possible values for the ANTIALIASING category are
  633.      * ANTIALIAS_ON, ANTIALIAS_OFF, ANTIALIAS_DEFAULT. Possible values for
  634.      * the RENDERING hint are RENDER_SPEED, RENDER_QUALITY, RENDER_DEFAULT.
  635.      * @see #ANTIALIASING
  636.      * @see #RENDERING
  637.      * @see #ANTIALIAS_ON
  638.      * @see #ANTIALIAS_OFF
  639.      * @see #ANTIALIAS_DEFAULT
  640.      * @see #RENDER_SPEED
  641.      * @see #RENDER_QUALITY
  642.      * @see #RENDER_DEFAULT
  643.      */
  644.     public abstract void setRenderingHints(int hintCategory, int hintValue);
  645.  
  646.     /**
  647.      * Returns the preferences for the rendering algorithms.
  648.      * @param hintCategory The category of hint to be set. Possible values
  649.      * are ANTIALIASING and RENDERING.
  650.      * @return The preferences for rendering algorithms. Possible values for
  651.      * the ANTIALIASING category are ANTIALIAS_ON, ANTIALIAS_OFF,
  652.      * ANTIALIAS_DEFAULT.  Possible values for the RENDERING hint are
  653.      * RENDER_SPEED, RENDER_QUALITY, RENDER_DEFAULT.
  654.      * @see #ANTIALIASING
  655.      * @see #RENDERING
  656.      * @see #ANTIALIAS_ON
  657.      * @see #ANTIALIAS_OFF
  658.      * @see #ANTIALIAS_DEFAULT
  659.      * @see #RENDER_SPEED
  660.      * @see #RENDER_QUALITY
  661.      * @see #RENDER_DEFAULT
  662.      */
  663.     public abstract int getRenderingHints(int hintCategory);
  664.  
  665.     /**
  666.      * Translates the origin of the graphics context to the point
  667.      * (<i>x</i>, <i>y</i>) in the current coordinate system. 
  668.      * Modifies this graphics context so that its new origin corresponds 
  669.      * to the point (<i>x</i>, <i>y</i>) in this graphics context's 
  670.      * original coordinate system.  All coordinates used in subsequent 
  671.      * rendering operations on this graphics context will be relative 
  672.      * to this new origin.
  673.      * @param  x   the <i>x</i> coordinate.
  674.      * @param  y   the <i>y</i> coordinate.
  675.      * @since   JDK1.0
  676.      */
  677.     public abstract void translate(int x, int y);
  678.  
  679.     /**
  680.      * Concatenates the current transform of this Graphics2D with a
  681.      * translation transformation.
  682.      * This is equivalent to calling transform(T), where T is an
  683.      * AffineTransform represented by the following matrix:
  684.      * <pre>
  685.      *        [   1    0    tx  ]
  686.      *        [   0    1    ty  ]
  687.      *        [   0    0    1   ]
  688.      * </pre>
  689.      */
  690.     public abstract void translate(double tx, double ty);
  691.  
  692.     /**
  693.      * Concatenates the current transform of this Graphics2D with a
  694.      * rotation transformation.
  695.      * This is equivalent to calling transform(R), where R is an
  696.      * AffineTransform represented by the following matrix:
  697.      * <pre>
  698.      *        [   cos(theta)    -sin(theta)    0   ]
  699.      *        [   sin(theta)     cos(theta)    0   ]
  700.      *        [       0              0         1   ]
  701.      * </pre>
  702.      * Rotating with a positive angle theta rotates points on the positive
  703.      * x axis toward the positive y axis.
  704.      * @param theta The angle of rotation in radians.
  705.      */
  706.     public abstract void rotate(double theta);
  707.  
  708.     /**
  709.      * Concatenates the current transform of this Graphics2D with a
  710.      * translated rotation transformation.
  711.      * This is equivalent to the following sequence of calls:
  712.      * <pre>
  713.      *        translate(x, y);
  714.      *        rotate(theta);
  715.      *        translate(-x, -y);
  716.      * </pre>
  717.      * Rotating with a positive angle theta rotates points on the positive
  718.      * x axis toward the positive y axis.
  719.      * @param theta The angle of rotation in radians.
  720.      * @param x The x coordinate of the origin of the rotation
  721.      * @param y The x coordinate of the origin of the rotation
  722.      */
  723.     public abstract void rotate(double theta, double x, double y);
  724.  
  725.     /**
  726.      * Concatenates the current transform of this Graphics2D with a
  727.      * scaling transformation.
  728.      * This is equivalent to calling transform(S), where S is an
  729.      * AffineTransform represented by the following matrix:
  730.      * <pre>
  731.      *        [   sx   0    0   ]
  732.      *        [   0    sy   0   ]
  733.      *        [   0    0    1   ]
  734.      * </pre>
  735.      */
  736.     public abstract void scale(double sx, double sy);
  737.  
  738.     /**
  739.      * Concatenates the current transform of this Graphics2D with a
  740.      * shearing transformation.
  741.      * This is equivalent to calling transform(SH), where SH is an
  742.      * AffineTransform represented by the following matrix:
  743.      * <pre>
  744.      *        [   1   shx   0   ]
  745.      *        [  shy   1    0   ]
  746.      *        [   0    0    1   ]
  747.      * </pre>
  748.      * @param shx The factor by which coordinates are shifted towards the
  749.      * positive X axis direction according to their Y coordinate
  750.      * @param shy The factor by which coordinates are shifted towards the
  751.      * positive Y axis direction according to their X coordinate
  752.      */
  753.     public abstract void shear(double shx, double shy);
  754.  
  755.     /**
  756.      * Composes an AffineTransform object with the transform in this
  757.      * Graphics2D according to the rule last-specified-first-applied.
  758.      * If the currrent transform is Cx, the result of composition
  759.      * with Tx is a new transform Cx'.  Cx' becomes the current
  760.      * transform for this Graphics2D.
  761.      * Transforming a point p by the updated transform Cx' is
  762.      * equivalent to first transforming p by Tx and then transforming
  763.      * the result by the original transform Cx.  In other words,
  764.      * Cx'(p) = Cx(Tx(p)).
  765.      * A copy of the Tx is made, if necessary, so further
  766.      * modifications to Tx do not affect rendering.
  767.      * @param Tx The AffineTransform object to be composed with the current
  768.      * transform.
  769.      * @see #setTransform
  770.      * @see TransformChain
  771.      * @see AffineTransform
  772.      */
  773.     public abstract void transform(AffineTransform Tx);
  774.  
  775.     /**
  776.      * Sets the transform in the current graphics state.
  777.      * @param Tx The AffineTransform object to be used in the
  778.      * rendering process.
  779.      * @see #transform
  780.      * @see TransformChain
  781.      * @see AffineTransform
  782.      */
  783.     public abstract void setTransform(AffineTransform Tx);
  784.  
  785.     /**
  786.      * Returns the current transform in the Graphics2D state.
  787.      * @see #transform
  788.      * @see #setTransform
  789.      */
  790.     public abstract AffineTransform getTransform();
  791.  
  792.     /**
  793.      * Returns the current Paint in the Graphics2D state.
  794.      * @see #setPaint
  795.      * @see java.awt.Graphics#setColor
  796.      */
  797.     public abstract Paint getPaint();
  798.  
  799.     /**
  800.      * Returns the current Composite in the Graphics2D state.
  801.      * @see #setComposite
  802.      */
  803.     public abstract Composite getComposite();
  804.  
  805.     /**
  806.      * Sets the background color in this context used for clearing a region.
  807.      * When Graphics2D is constructed for a component, the backgroung color is
  808.      * inherited from the component. Setting the background color in the
  809.      * Graphics2D context only affects the subsequent clearRect() calls and
  810.      * not the background color of the component. To change the background
  811.      * of the component, use appropriate methods of the component.
  812.      * @param color The background color that should be used in
  813.      * subsequent calls to clearRect().
  814.      * @see getBackground
  815.      * @see Graphics.clearRect()
  816.      */
  817.     public abstract void setBackground(Color color);
  818.  
  819.     /**
  820.      * Returns the background color used for clearing a region.
  821.      * @see setBackground
  822.      */
  823.     public abstract Color getBackground();
  824.  
  825.     /**
  826.      * Returns the current Stroke in the Graphics2D state.
  827.      * @see setStroke
  828.      */
  829.     public abstract Stroke getStroke();
  830.  
  831.     /**
  832.      * Intersects the current clip with the interior of the specified Shape
  833.      * and sets the current clip to the resulting intersection.
  834.      * The indicated shape is transformed with the current transform in the
  835.      * Graphics2D state before being intersected with the current clip.
  836.      * This method is used to make the current clip smaller.
  837.      * To make the clip larger, use any setClip method.
  838.      * @param s The Shape to be intersected with the current clip.
  839.      */
  840.      public abstract void clip(Shape s);
  841.  
  842. }
  843.