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

  1. /*
  2.  * @(#)Graphics.java    1.45 98/03/18
  3.  *
  4.  * Copyright 1995-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. package java.awt;
  15.  
  16. import java.io.*;
  17. import java.lang.*;
  18. import java.util.*;
  19. import java.awt.image.ImageObserver;
  20.  
  21. /**
  22.  * The <code>Graphics</code> class is the abstract base class for 
  23.  * all graphics contexts that allow an application to draw onto 
  24.  * components that are realized on various devices, as well as 
  25.  * onto off-screen images.
  26.  * <p>
  27.  * A <code>Graphics</code> object encapsulates state information needed
  28.  * for the basic rendering operations that Java supports.  This
  29.  * state information includes the following properties:
  30.  * <p>
  31.  * <ul>
  32.  * <li>The <code>Component</code> object on which to draw.
  33.  * <li>A translation origin for rendering and clipping coordinates.
  34.  * <li>The current clip.
  35.  * <li>The current color.
  36.  * <li>The current font.
  37.  * <li>The current logical pixel operation function (XOR or Paint).
  38.  * <li>The current XOR alternation color 
  39.  *     (see <a href="#setXORMode"><code>setXORMode</code></a>).
  40.  * </ul>
  41.  * <p>
  42.  * Coordinates are infinitely thin and lie between the pixels of the
  43.  * output device.
  44.  * Operations which draw the outline of a figure operate by traversing
  45.  * an infinitely thin path between pixels with a pixel-sized pen that hangs
  46.  * down and to the right of the anchor point on the path.
  47.  * Operations which fill a figure operate by filling the interior
  48.  * of that infinitely thin path.
  49.  * Operations which render horizontal text render the ascending
  50.  * portion of character glyphs entirely above the baseline coordinate.
  51.  * <p>
  52.  * The graphics pen hangs down and to the right from the path it traverses. 
  53.  * This has the following implications:
  54.  * <p><ul>
  55.  * <li>If you draw a figure that covers a given rectangle, that 
  56.  * figure occupies one extra row of pixels on the right and bottom edges 
  57.  * as compared to filling a figure that is bounded by that same rectangle.
  58.  * <li>If you draw a horizontal line along the same <i>y</i> coordinate as
  59.  * the baseline of a line of text, that line is drawn entirely below
  60.  * the text, except for any descenders.
  61.  * </ul><p>
  62.  * All coordinates which appear as arguments to the methods of this
  63.  * <code>Graphics</code> object are considered relative to the 
  64.  * translation origin of this <code>Graphics</code> object prior to 
  65.  * the invocation of the method.
  66.  * All rendering operations modify only pixels which lie within the
  67.  * area bounded by both the current clip of the graphics context
  68.  * and the extents of the component used to create the 
  69.  * <code>Graphics</code> object.
  70.  * All drawing or writing is done in the current color, 
  71.  * using the current paint mode, and in the current font. 
  72.  * 
  73.  * @version     1.45, 03/18/98
  74.  * @author     Sami Shaio
  75.  * @author     Arthur van Hoff
  76.  * @see     java.awt.Component
  77.  * @see     java.awt.Graphics#clipRect(int, int, int, int)
  78.  * @see     java.awt.Graphics#setColor(java.awt.Color)
  79.  * @see     java.awt.Graphics#setPaintMode()
  80.  * @see     java.awt.Graphics#setXORMode(java.awt.Color)
  81.  * @see     java.awt.Graphics#setFont(java.awt.Font)
  82.  * @since       JDK1.0
  83.  */
  84. public abstract class Graphics {
  85.  
  86.     /**
  87.      * Constructs a new <code>Graphics</code> object.  
  88.      * This constructor is the default contructor for a graphics 
  89.      * context. 
  90.      * <p>
  91.      * Since <code>Graphics</code> is an abstract class, applications 
  92.      * cannot call this constructor directly. Graphics contexts are 
  93.      * obtained from other graphics contexts or are created by calling 
  94.      * <code>getGraphics</code> on a component. 
  95.      * @see        java.awt.Graphics#create()
  96.      * @see        java.awt.Component#getGraphics
  97.      */
  98.     protected Graphics() {
  99.     }
  100.  
  101.     /**
  102.      * Creates a new <code>Graphics</code> object that is 
  103.      * a copy of this <code>Graphics</code> object.
  104.      * @return     a new graphics context that is a copy of 
  105.      *                       this graphics context.
  106.      */
  107.     public abstract Graphics create();
  108.  
  109.     /**
  110.      * Creates a new <code>Graphics</code> object based on this 
  111.      * <code>Graphics</code> object, but with a new translation and clip area.
  112.      * The new <code>Graphics</code> object has its origin 
  113.      * translated to the specified point (<i>x</i>, <i>y</i>). 
  114.      * Its clip area is determined by the intersection of the original
  115.      * clip area with the specified rectangle.  The arguments are all
  116.      * interpreted in the coordinate system of the original 
  117.      * <code>Graphics</code> object. The new graphics context is 
  118.      * identical to the original, except in two respects: 
  119.      * <p>
  120.      * <ul>
  121.      * <li>
  122.      * The new graphics context is translated by (<i>x</i>, <i>y</i>).  
  123.      * That is to say, the point (<code>0</code>, <code>0</code>) in the 
  124.      * new graphics context is the same as (<i>x</i>, <i>y</i>) in 
  125.      * the original graphics context. 
  126.      * <li>
  127.      * The new graphics context has an additional clipping rectangle, in 
  128.      * addition to whatever (translated) clipping rectangle it inherited 
  129.      * from the original graphics context. The origin of the new clipping 
  130.      * rectangle is at (<code>0</code>, <code>0</code>), and its size  
  131.      * is specified by the <code>width</code> and <code>height</code> arguments.
  132.      * </ul>
  133.      * <p>
  134.      * @param      x   the <i>x</i> coordinate.
  135.      * @param      y   the <i>y</i> coordinate.
  136.      * @param      width   the width of the clipping rectangle.
  137.      * @param      height   the height of the clipping rectangle.
  138.      * @return     a new graphics context.
  139.      * @see        java.awt.Graphics#translate
  140.      * @see        java.awt.Graphics#clipRect
  141.      */
  142.     public Graphics create(int x, int y, int width, int height) {
  143.     Graphics g = create();
  144.     g.translate(x, y);
  145.     g.clipRect(0, 0, width, height);
  146.     return g;
  147.     }
  148.  
  149.     /**
  150.      * Translates the origin of the graphics context to the point
  151.      * (<i>x</i>, <i>y</i>) in the current coordinate system. 
  152.      * Modifies this graphics context so that its new origin corresponds 
  153.      * to the point (<i>x</i>, <i>y</i>) in this graphics context's 
  154.      * original coordinate system.  All coordinates used in subsequent 
  155.      * rendering operations on this graphics context will be relative 
  156.      * to this new origin.
  157.      * @param  x   the <i>x</i> coordinate.
  158.      * @param  y   the <i>y</i> coordinate.
  159.      */
  160.     public abstract void translate(int x, int y);
  161.  
  162.     /**
  163.      * Gets this graphics context's current color.
  164.      * @return    this graphics context's current color.
  165.      * @see       java.awt.Color
  166.      * @see       java.awt.Graphics#setColor
  167.      */
  168.     public abstract Color getColor();
  169.  
  170.     /**
  171.      * Sets this graphics context's current color to the specified 
  172.      * color. All subsequent graphics operations using this graphics 
  173.      * context use this specified color. 
  174.      * @param     c   the new rendering color.
  175.      * @see       java.awt.Color
  176.      * @see       java.awt.Graphics#getColor
  177.      */
  178.     public abstract void setColor(Color c);
  179.  
  180.     /**
  181.      * Sets the paint mode of this graphics context to overwrite the 
  182.      * destination with this graphics context's current color. 
  183.      * This sets the logical pixel operation function to the paint or
  184.      * overwrite mode.  All subsequent rendering operations will
  185.      * overwrite the destination with the current color. 
  186.      */
  187.     public abstract void setPaintMode();
  188.  
  189.     /**
  190.      * Sets the paint mode of this graphics context to alternate between 
  191.      * this graphics context's current color and the new specified color. 
  192.      * This specifies that logical pixel operations are performed in the 
  193.      * XOR mode, which alternates pixels between the current color and 
  194.      * a specified XOR color. 
  195.      * <p>
  196.      * When drawing operations are performed, pixels which are the 
  197.      * current color are changed to the specified color, and vice versa. 
  198.      * <p>
  199.      * Pixels that are of colors other than those two colors are changed 
  200.      * in an unpredictable but reversible manner; if the same figure is 
  201.      * drawn twice, then all pixels are restored to their original values. 
  202.      * @param     c1 the XOR alternation color
  203.      */
  204.     public abstract void setXORMode(Color c1);
  205.  
  206.     /**
  207.      * Gets the current font.
  208.      * @return    this graphics context's current font.
  209.      * @see       java.awt.Font
  210.      * @see       java.awt.Graphics#setFont
  211.      */
  212.     public abstract Font getFont();
  213.  
  214.     /**
  215.      * Sets this graphics context's font to the specified font. 
  216.      * All subsequent text operations using this graphics context 
  217.      * use this font. 
  218.      * @param  font   the font.
  219.      * @see     java.awt.Graphics#getFont
  220.      * @see     java.awt.Graphics#drawChars(java.lang.String, int, int)
  221.      * @see     java.awt.Graphics#drawString(byte[], int, int, int, int)
  222.      * @see     java.awt.Graphics#drawBytes(char[], int, int, int, int)
  223.     */
  224.     public abstract void setFont(Font font);
  225.  
  226.     /**
  227.      * Gets the font metrics of the current font.
  228.      * @return    the font metrics of this graphics 
  229.      *                    context's current font.
  230.      * @see       java.awt.Graphics#getFont
  231.      * @see       java.awt.FontMetrics
  232.      * @see       java.awt.Graphics#getFontMetrics(Font)
  233.      */
  234.     public FontMetrics getFontMetrics() {
  235.     return getFontMetrics(getFont());
  236.     }
  237.  
  238.     /**
  239.      * Gets the font metrics for the specified font.
  240.      * @return    the font metrics for the specified font.
  241.      * @param     f the specified font
  242.      * @see       java.awt.Graphics#getFont
  243.      * @see       java.awt.FontMetrics
  244.      * @see       java.awt.Graphics#getFontMetrics()
  245.      */
  246.     public abstract FontMetrics getFontMetrics(Font f);
  247.  
  248.  
  249.     /**
  250.      * Returns the bounding rectangle of the current clipping area.
  251.      * The coordinates in the rectangle are relative to the coordinate
  252.      * system origin of this graphics context.
  253.      * @return      the bounding rectangle of the current clipping area.
  254.      * @see         java.awt.Graphics#getClip
  255.      * @see         java.awt.Graphics#clipRect
  256.      * @see         java.awt.Graphics#setClip(int, int, int, int)
  257.      * @see         java.awt.Graphics#setClip(Shape)
  258.      * @since       JDK1.1
  259.      */
  260.     public abstract Rectangle getClipBounds();
  261.  
  262.     /** 
  263.      * Intersects the current clip with the specified rectangle.
  264.      * The resulting clipping area is the intersection of the current
  265.      * clipping area and the specified rectangle.
  266.      * This method can only be used to make the current clip smaller.
  267.      * To set the current clip larger, use any of the setClip methods.
  268.      * Rendering operations have no effect outside of the clipping area.
  269.      * @param x the x coordinate of the rectangle to intersect the clip with
  270.      * @param y the y coordinate of the rectangle to intersect the clip with
  271.      * @param width the width of the rectangle to intersect the clip with
  272.      * @param height the height of the rectangle to intersect the clip with
  273.      * @see #setClip(int, int, int, int)
  274.      * @see #setClip(Shape)
  275.      */
  276.     public abstract void clipRect(int x, int y, int width, int height);
  277.  
  278.     /**
  279.      * Sets the current clip to the rectangle specified by the given
  280.      * coordinates.
  281.      * Rendering operations have no effect outside of the clipping area.
  282.      * @param       x the <i>x</i> coordinate of the new clip rectangle.
  283.      * @param       y the <i>y</i> coordinate of the new clip rectangle.
  284.      * @param       width the width of the new clip rectangle.
  285.      * @param       height the height of the new clip rectangle.
  286.      * @see         java.awt.Graphics#clipRect
  287.      * @see         java.awt.Graphics#setClip(Shape)
  288.      * @since       JDK1.1
  289.      */
  290.     public abstract void setClip(int x, int y, int width, int height);
  291.  
  292.     /**
  293.      * Gets the current clipping area.
  294.      * @return      a <code>Shape</code> object representing the 
  295.      *                      current clipping area.
  296.      * @see         java.awt.Graphics#getClipBounds
  297.      * @see         java.awt.Graphics#clipRect
  298.      * @see         java.awt.Graphics#setClip(int, int, int, int)
  299.      * @see         java.awt.Graphics#setClip(Shape)
  300.      * @since       JDK1.1
  301.      */
  302.     public abstract Shape getClip();
  303.  
  304.     /**
  305.      * Sets the current clipping area to an arbitrary clip shape.
  306.      * Not all objects which implement the <code>Shape</code> 
  307.      * interface can be used to set the clip.  The only 
  308.      * <code>Shape</code> objects which are guaranteed to be 
  309.      * supported are <code>Shape</code> objects which are
  310.      * obtained via the <code>getClip</code> method and via 
  311.      * <code>Rectangle</code> objects.
  312.      * @see         java.awt.Graphics#getClip()
  313.      * @see         java.awt.Graphics#clipRect
  314.      * @see         java.awt.Graphics#setClip(int, int, int, int)
  315.      * @since       JDK1.1
  316.      */
  317.     public abstract void setClip(Shape clip);
  318.  
  319.     /**
  320.      * Copies an area of the component by a distance specified by 
  321.      * <code>dx</code> and <code>dy</code>. From the point specified
  322.      * by <code>x</code> and <code>y</code>, this method
  323.      * copies downwards and to the right.  To copy an area of the 
  324.      * component to the left or upwards, specify a negative value for 
  325.      * <code>dx</code> or <code>dy</code>.
  326.      * If a portion of the source rectangle lies outside the bounds 
  327.      * of the component, or is obscured by another window or component, 
  328.      * <code>copyArea</code> will be unable to copy the associated
  329.      * pixels. The area that is omitted can be refreshed by calling 
  330.      * the component's <code>paint</code> method.
  331.      * @param       x the <i>x</i> coordinate of the source rectangle.
  332.      * @param       y the <i>y</i> coordinate of the source rectangle.
  333.      * @param       width the width of the source rectangle.
  334.      * @param       height the height of the source rectangle.
  335.      * @param       dx the horizontal distance to copy the pixels.
  336.      * @param       dy the vertical distance to copy the pixels.
  337.      */
  338.     public abstract void copyArea(int x, int y, int width, int height,
  339.                   int dx, int dy);
  340.  
  341.     /** 
  342.      * Draws a line, using the current color, between the points 
  343.      * <code>(x1, y1)</code> and <code>(x2, y2)</code> 
  344.      * in this graphics context's coordinate system. 
  345.      * @param   x1  the first point's <i>x</i> coordinate.
  346.      * @param   y1  the first point's <i>y</i> coordinate.
  347.      * @param   x2  the second point's <i>x</i> coordinate.
  348.      * @param   y2  the second point's <i>y</i> coordinate.
  349.      */
  350.     public abstract void drawLine(int x1, int y1, int x2, int y2);
  351.  
  352.     /** 
  353.      * Fills the specified rectangle. 
  354.      * The left and right edges of the rectangle are at 
  355.      * <code>x</code> and <code>x + width - 1</code>. 
  356.      * The top and bottom edges are at 
  357.      * <code>y</code> and <code>y + height - 1</code>. 
  358.      * The resulting rectangle covers an area 
  359.      * <code>width</code> pixels wide by 
  360.      * <code>height</code> pixels tall.
  361.      * The rectangle is filled using the graphics context's current color. 
  362.      * @param         x   the <i>x</i> coordinate 
  363.      *                         of the rectangle to be filled.
  364.      * @param         y   the <i>y</i> coordinate 
  365.      *                         of the rectangle to be filled.
  366.      * @param         width   the width of the rectangle to be filled.
  367.      * @param         height   the height of the rectangle to be filled.
  368.      * @see           java.awt.Graphics#fillRect
  369.      * @see           java.awt.Graphics#clearRect
  370.      */
  371.     public abstract void fillRect(int x, int y, int width, int height);
  372.  
  373.     /** 
  374.      * Draws the outline of the specified rectangle. 
  375.      * The left and right edges of the rectangle are at 
  376.      * <code>x</code> and <code>x + width</code>. 
  377.      * The top and bottom edges are at 
  378.      * <code>y</code> and <code>y + height</code>. 
  379.      * The rectangle is drawn using the graphics context's current color.
  380.      * @param         x   the <i>x</i> coordinate 
  381.      *                         of the rectangle to be drawn.
  382.      * @param         y   the <i>y</i> coordinate 
  383.      *                         of the rectangle to be drawn.
  384.      * @param         width   the width of the rectangle to be drawn.
  385.      * @param         height   the height of the rectangle to be drawn.
  386.      * @see          java.awt.Graphics#fillRect
  387.      * @see          java.awt.Graphics#clearRect
  388.      */
  389.     public void drawRect(int x, int y, int width, int height) {
  390.     if ((width < 0) || (height < 0)) {
  391.         return;
  392.     }
  393.  
  394.     if (height == 0 || width == 0) {
  395.         drawLine(x, y, x + width, y + height);
  396.     } else {
  397.         drawLine(x, y, x + width - 1, y);
  398.         drawLine(x + width, y, x + width, y + height - 1);
  399.         drawLine(x + width, y + height, x + 1, y + height);
  400.         drawLine(x, y + height, x, y + 1);
  401.     }
  402.     }
  403.     
  404.     /** 
  405.      * Clears the specified rectangle by filling it with the background
  406.      * color of the current drawing surface. This operation does not 
  407.      * use the current paint mode. 
  408.      * <p>
  409.      * Beginning with Java 1.1, the background color 
  410.      * of offscreen images may be system dependent. Applications should 
  411.      * use <code>setColor</code> followed by <code>fillRect</code> to 
  412.      * ensure that an offscreen image is cleared to a specific color. 
  413.      * @param       x the <i>x</i> coordinate of the rectangle to clear.
  414.      * @param       y the <i>y</i> coordinate of the rectangle to clear.
  415.      * @param       width the width of the rectangle to clear.
  416.      * @param       height the height of the rectangle to clear.
  417.      * @see         java.awt.Graphics#fillRect(int, int, int, int)
  418.      * @see         java.awt.Graphics#drawRect
  419.      * @see         java.awt.Graphics#setColor(java.awt.Color)
  420.      * @see         java.awt.Graphics#setPaintMode
  421.      * @see         java.awt.Graphics#setXORMode(java.awt.Color)
  422.      */
  423.     public abstract void clearRect(int x, int y, int width, int height);
  424.  
  425.     /** 
  426.      * Draws an outlined round-cornered rectangle using this graphics 
  427.      * context's current color. The left and right edges of the rectangle 
  428.      * are at <code>x</code> and <code>x + width</code>, 
  429.      * respectively. The top and bottom edges of the rectangle are at 
  430.      * <code>y</code> and <code>y + height</code>. 
  431.      * @param      x the <i>x</i> coordinate of the rectangle to be drawn.
  432.      * @param      y the <i>y</i> coordinate of the rectangle to be drawn.
  433.      * @param      width the width of the rectangle to be drawn.
  434.      * @param      height the height of the rectangle to be drawn.
  435.      * @param      arcWidth the horizontal diameter of the arc 
  436.      *                    at the four corners.
  437.      * @param      arcHeight the vertical diameter of the arc 
  438.      *                    at the four corners.
  439.      * @see        java.awt.Graphics#fillRoundRect
  440.      */
  441.     public abstract void drawRoundRect(int x, int y, int width, int height,
  442.                        int arcWidth, int arcHeight);
  443.  
  444.     /** 
  445.      * Fills the specified rounded corner rectangle with the current color.
  446.      * The left and right edges of the rectangle 
  447.      * are at <code>x</code> and <code>x + width - 1</code>, 
  448.      * respectively. The top and bottom edges of the rectangle are at 
  449.      * <code>y</code> and <code>y + height - 1</code>. 
  450.      * @param       x the <i>x</i> coordinate of the rectangle to be filled.
  451.      * @param       y the <i>y</i> coordinate of the rectangle to be filled.
  452.      * @param       width the width of the rectangle to be filled.
  453.      * @param       height the height of the rectangle to be filled.
  454.      * @param       arcWidth the horizontal diameter 
  455.      *                     of the arc at the four corners.
  456.      * @param       arcHeight the vertical diameter 
  457.      *                     of the arc at the four corners.
  458.      * @see         java.awt.Graphics#drawRoundRect
  459.      */
  460.     public abstract void fillRoundRect(int x, int y, int width, int height,
  461.                        int arcWidth, int arcHeight);
  462.  
  463.     /**
  464.      * Draws a 3-D highlighted outline of the specified rectangle.
  465.      * The edges of the rectangle are highlighted so that they
  466.      * appear to be beveled and lit from the upper left corner.
  467.      * <p>
  468.      * The colors used for the highlighting effect are determined 
  469.      * based on the current color.
  470.      * The resulting rectangle covers an area that is 
  471.      * <code>width + 1</code> pixels wide
  472.      * by <code>height + 1</code> pixels tall.
  473.      * @param       x the <i>x</i> coordinate of the rectangle to be drawn.
  474.      * @param       y the <i>y</i> coordinate of the rectangle to be drawn.
  475.      * @param       width the width of the rectangle to be drawn.
  476.      * @param       height the height of the rectangle to be drawn.
  477.      * @param       raised a boolean that determines whether the rectangle
  478.      *                      appears to be raised above the surface 
  479.      *                      or sunk into the surface.
  480.      * @see         java.awt.Graphics#fill3DRect
  481.      */
  482.     public void draw3DRect(int x, int y, int width, int height,
  483.                boolean raised) {
  484.     Color c = getColor();
  485.     Color brighter = c.brighter();
  486.     Color darker = c.darker();
  487.  
  488.     setColor(raised ? brighter : darker);
  489.     drawLine(x, y, x, y + height);
  490.     drawLine(x + 1, y, x + width - 1, y);
  491.     setColor(raised ? darker : brighter);
  492.     drawLine(x + 1, y + height, x + width, y + height);
  493.     drawLine(x + width, y, x + width, y + height - 1);
  494.     setColor(c);
  495.     }    
  496.  
  497.     /**
  498.      * Paints a 3-D highlighted rectangle filled with the current color.
  499.      * The edges of the rectangle will be highlighted so that it appears
  500.      * as if the edges were beveled and lit from the upper left corner.
  501.      * The colors used for the highlighting effect will be determined from
  502.      * the current color.
  503.      * @param       x the <i>x</i> coordinate of the rectangle to be filled.
  504.      * @param       y the <i>y</i> coordinate of the rectangle to be filled.
  505.      * @param       width the width of the rectangle to be filled.
  506.      * @param       height the height of the rectangle to be filled.
  507.      * @param       raised a boolean value that determines whether the 
  508.      *                      rectangle appears to be raised above the surface 
  509.      *                      or etched into the surface.
  510.      * @see         java.awt.Graphics#draw3DRect
  511.      */
  512.     public void fill3DRect(int x, int y, int width, int height,
  513.                boolean raised) {
  514.     Color c = getColor();
  515.     Color brighter = c.brighter();
  516.     Color darker = c.darker();
  517.  
  518.     if (!raised) {
  519.         setColor(darker);
  520.     }
  521.     fillRect(x+1, y+1, width-2, height-2);
  522.     setColor(raised ? brighter : darker);
  523.     drawLine(x, y, x, y + height - 1);
  524.     drawLine(x + 1, y, x + width - 2, y);
  525.     setColor(raised ? darker : brighter);
  526.     drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
  527.     drawLine(x + width - 1, y, x + width - 1, y + height - 2);
  528.     setColor(c);
  529.     }    
  530.  
  531.     /** 
  532.      * Draws the outline of an oval.
  533.      * The result is a circle or ellipse that fits within the 
  534.      * rectangle specified by the <code>x</code>, <code>y</code>, 
  535.      * <code>width</code>, and <code>height</code> arguments. 
  536.      * <p> 
  537.      * The oval covers an area that is 
  538.      * <code>width + 1</code> pixels wide 
  539.      * and <code>height + 1<code> pixels tall. 
  540.      * @param       x the <i>x</i> coordinate of the upper left 
  541.      *                     corner of the oval to be drawn.
  542.      * @param       y the <i>y</i> coordinate of the upper left 
  543.      *                     corner of the oval to be drawn.
  544.      * @param       width the width of the oval to be drawn.
  545.      * @param       height the height of the oval to be drawn.
  546.      * @see         java.awt.Graphics#fillOval
  547.      */
  548.     public abstract void drawOval(int x, int y, int width, int height);
  549.  
  550.     /** 
  551.      * Fills an oval bounded by the specified rectangle with the
  552.      * current color.
  553.      * @param       x the <i>x</i> coordinate of the upper left corner 
  554.      *                     of the oval to be filled.
  555.      * @param       y the <i>y</i> coordinate of the upper left corner 
  556.      *                     of the oval to be filled.
  557.      * @param       width the width of the oval to be filled.
  558.      * @param       height the height of the oval to be filled.
  559.      * @see         java.awt.Graphics#drawOval
  560.      */
  561.     public abstract void fillOval(int x, int y, int width, int height);
  562.  
  563.     /**
  564.      * Draws the outline of a circular or elliptical arc 
  565.      * covering the specified rectangle.
  566.      * <p>
  567.      * The resulting arc begins at <code>startAngle</code> and extends  
  568.      * for <code>arcAngle</code> degrees, using the current color.
  569.      * Angles are interpreted such that 0 degrees 
  570.      * is at the 3 o'clock position. 
  571.      * A positive value indicates a counter-clockwise rotation
  572.      * while a negative value indicates a clockwise rotation.
  573.      * <p>
  574.      * The center of the arc is the center of the rectangle whose origin 
  575.      * is (<i>x</i>, <i>y</i>) and whose size is specified by the 
  576.      * <code>width</code> and <code>height</code> arguments. 
  577.      * <p>
  578.      * The resulting arc covers an area 
  579.      * <code>width + 1</code> pixels wide
  580.      * by <code>height + 1</code> pixels tall.
  581.      * <p>
  582.      * The angles are specified relative to the non-square extents of
  583.      * the bounding rectangle such that 45 degrees always falls on the
  584.      * line from the center of the ellipse to the upper right corner of
  585.      * the bounding rectangle. As a result, if the bounding rectangle is
  586.      * noticeably longer in one axis than the other, the angles to the
  587.      * start and end of the arc segment will be skewed farther along the
  588.      * longer axis of the bounds.
  589.      * @param        x the <i>x</i> coordinate of the 
  590.      *                    upper-left corner of the arc to be drawn.
  591.      * @param        y the <i>y</i>  coordinate of the 
  592.      *                    upper-left corner of the arc to be drawn.
  593.      * @param        width the width of the arc to be drawn.
  594.      * @param        height the height of the arc to be drawn.
  595.      * @param        startAngle the beginning angle.
  596.      * @param        arcAngle the angular extent of the arc, 
  597.      *                    relative to the start angle.
  598.      * @see         java.awt.Graphics#fillArc
  599.      */
  600.     public abstract void drawArc(int x, int y, int width, int height,
  601.                  int startAngle, int arcAngle);
  602.  
  603.     /** 
  604.      * Fills a circular or elliptical arc covering the specified rectangle.
  605.      * <p>
  606.      * The resulting arc begins at <code>startAngle</code> and extends  
  607.      * for <code>arcAngle</code> degrees.
  608.      * Angles are interpreted such that 0 degrees 
  609.      * is at the 3 o'clock position. 
  610.      * A positive value indicates a counter-clockwise rotation
  611.      * while a negative value indicates a clockwise rotation.
  612.      * <p>
  613.      * The center of the arc is the center of the rectangle whose origin 
  614.      * is (<i>x</i>, <i>y</i>) and whose size is specified by the 
  615.      * <code>width</code> and <code>height</code> arguments. 
  616.      * <p>
  617.      * The resulting arc covers an area 
  618.      * <code>width + 1</code> pixels wide
  619.      * by <code>height + 1</code> pixels tall.
  620.      * <p>
  621.      * The angles are specified relative to the non-square extents of
  622.      * the bounding rectangle such that 45 degrees always falls on the
  623.      * line from the center of the ellipse to the upper right corner of
  624.      * the bounding rectangle. As a result, if the bounding rectangle is
  625.      * noticeably longer in one axis than the other, the angles to the
  626.      * start and end of the arc segment will be skewed farther along the
  627.      * longer axis of the bounds.
  628.      * @param        x the <i>x</i> coordinate of the 
  629.      *                    upper-left corner of the arc to be filled.
  630.      * @param        y the <i>y</i>  coordinate of the 
  631.      *                    upper-left corner of the arc to be filled.
  632.      * @param        width the width of the arc to be filled.
  633.      * @param        height the height of the arc to be filled.
  634.      * @param        startAngle the beginning angle.
  635.      * @param        arcAngle the angular extent of the arc, 
  636.      *                    relative to the start angle.
  637.      * @see         java.awt.Graphics#drawArc
  638.      */
  639.     public abstract void fillArc(int x, int y, int width, int height,
  640.                  int startAngle, int arcAngle);
  641.  
  642.     /** 
  643.      * Draws a sequence of connected lines defined by 
  644.      * arrays of <i>x</i> and <i>y</i> coordinates. 
  645.      * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
  646.      * The figure is not closed if the first point 
  647.      * differs from the last point.
  648.      * @param       xPoints an array of <i>x</i> points
  649.      * @param       yPoints an array of <i>y</i> points
  650.      * @param       nPoints the total number of points
  651.      * @see         java.awt.Graphics#drawPolygon(int[], int[], int)
  652.      * @since       JDK1.1
  653.      */
  654.     public abstract void drawPolyline(int xPoints[], int yPoints[],
  655.                       int nPoints);
  656.  
  657.     /** 
  658.      * Draws a closed polygon defined by 
  659.      * arrays of <i>x</i> and <i>y</i> coordinates. 
  660.      * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
  661.      * <p>
  662.      * This method draws the polygon defined by <code>nPoint</code> line 
  663.      * segments, where the first <code>nPoint - 1</code> 
  664.      * line segments are line segments from 
  665.      * <code>(xPoints[i - 1], yPoints[i - 1])</code> 
  666.      * to <code>(xPoints[i], yPoints[i])</code>, for 
  667.      * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.  
  668.      * The figure is automatically closed by drawing a line connecting
  669.      * the final point to the first point, if those points are different.
  670.      * @param        xPoints   a an array of <code>x</code> coordinates.
  671.      * @param        yPoints   a an array of <code>y</code> coordinates.
  672.      * @param        nPoints   a the total number of points.
  673.      * @see          java.awt.Graphics#fillPolygon
  674.      * @see          java.awt.Graphics#drawPolyline
  675.      */
  676.     public abstract void drawPolygon(int xPoints[], int yPoints[],
  677.                      int nPoints);
  678.  
  679.     /** 
  680.      * Draws the outline of a polygon defined by the specified 
  681.      * <code>Polygon</code> object. 
  682.      * @param        p the polygon to draw.
  683.      * @see          java.awt.Graphics#fillPolygon
  684.      * @see          java.awt.Graphics#drawPolyline
  685.      */
  686.     public void drawPolygon(Polygon p) {
  687.     drawPolygon(p.xpoints, p.ypoints, p.npoints);
  688.     }
  689.  
  690.     /** 
  691.      * Fills a closed polygon defined by 
  692.      * arrays of <i>x</i> and <i>y</i> coordinates. 
  693.      * <p>
  694.      * This method draws the polygon defined by <code>nPoint</code> line 
  695.      * segments, where the first <code>nPoint - 1</code> 
  696.      * line segments are line segments from 
  697.      * <code>(xPoints[i - 1], yPoints[i - 1])</code> 
  698.      * to <code>(xPoints[i], yPoints[i])</code>, for 
  699.      * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.  
  700.      * The figure is automatically closed by drawing a line connecting
  701.      * the final point to the first point, if those points are different.
  702.      * <p>
  703.      * The area inside the polygon is defined using an 
  704.      * even-odd fill rule, also known as the alternating rule.
  705.      * @param        xPoints   a an array of <code>x</code> coordinates.
  706.      * @param        yPoints   a an array of <code>y</code> coordinates.
  707.      * @param        nPoints   a the total number of points.
  708.      * @see          java.awt.Graphics#drawPolygon(int[], int[], int)
  709.      */
  710.     public abstract void fillPolygon(int xPoints[], int yPoints[],
  711.                      int nPoints);
  712.  
  713.     /** 
  714.      * Fills the polygon defined by the specified Polygon object with
  715.      * the graphics context's current color. 
  716.      * <p>
  717.      * The area inside the polygon is defined using an 
  718.      * even-odd fill rule, also known as the alternating rule.
  719.      * @param        p the polygon to fill.
  720.      * @see          java.awt.Graphics#drawPolygon(int[], int[], int)
  721.      */
  722.     public void fillPolygon(Polygon p) {
  723.     fillPolygon(p.xpoints, p.ypoints, p.npoints);
  724.     }
  725.  
  726.     /** 
  727.      * Draws the text given by the specified string, using this 
  728.      * graphics context's current font and color. The baseline of the 
  729.      * first character is at position (<i>x</i>, <i>y</i>) in this 
  730.      * graphics context's coordinate system. 
  731.      * @param       str      the string to be drawn.
  732.      * @param       x        the <i>x</i> coordinate.
  733.      * @param       y        the <i>y</i> coordinate.
  734.      * @see         java.awt.Graphics#drawBytes
  735.      * @see         java.awt.Graphics#drawChars
  736.      */
  737.     public abstract void drawString(String str, int x, int y);
  738.  
  739.     /** 
  740.      * Draws the text given by the specified character array, using this 
  741.      * graphics context's current font and color. The baseline of the 
  742.      * first character is at position (<i>x</i>, <i>y</i>) in this 
  743.      * graphics context's coordinate system. 
  744.      * @param data the array of characters to be drawn
  745.      * @param offset the start offset in the data
  746.      * @param length the number of characters to be drawn
  747.      * @param x the <i>x</i> coordinate of the baseline of the text
  748.      * @param y the <i>y</i> coordinate of the baseline of the text
  749.      * @see         java.awt.Graphics#drawBytes
  750.      * @see         java.awt.Graphics#drawString
  751.      */
  752.     public void drawChars(char data[], int offset, int length, int x, int y) {
  753.     drawString(new String(data, offset, length), x, y);
  754.     }
  755.  
  756.     /** 
  757.      * Draws the text given by the specified byte array, using this 
  758.      * graphics context's current font and color. The baseline of the 
  759.      * first character is at position (<i>x</i>, <i>y</i>) in this 
  760.      * graphics context's coordinate system.
  761.      * @param data the data to be drawn
  762.      * @param offset the start offset in the data
  763.      * @param length the number of bytes that are drawn
  764.      * @param x the <i>x</i> coordinate of the baseline of the text
  765.      * @param y the <i>y</i> coordinate of the baseline of the text
  766.      * @see         java.awt.Graphics#drawChars
  767.      * @see         java.awt.Graphics#drawString
  768.      */
  769.     public void drawBytes(byte data[], int offset, int length, int x, int y) {
  770.     drawString(new String(data, 0, offset, length), x, y);
  771.     }
  772.  
  773.     /** 
  774.      * Draws as much of the specified image as is currently available.
  775.      * The image is drawn with its top-left corner at 
  776.      * (<i>x</i>, <i>y</i>) in this graphics context's coordinate 
  777.      * space. Transparent pixels in the image do not affect whatever 
  778.      * pixels are already there. 
  779.      * <p>
  780.      * This method returns immediately in all cases, even if the
  781.      * complete image has not yet been loaded, and it has not been dithered 
  782.      * and converted for the current output device.
  783.      * <p>
  784.      * If the image has not yet been completely loaded, then
  785.      * <code>drawImage</code> returns <code>false</code>. As more of
  786.      * the image becomes available, the process that draws the image notifies 
  787.      * the specified image observer.
  788.      * @param    img the specified image to be drawn.
  789.      * @param    x   the <i>x</i> coordinate.
  790.      * @param    y   the <i>y</i> coordinate.
  791.      * @param    observer    object to be notified as more of 
  792.      *                          the image is converted.
  793.      * @see      java.awt.Image
  794.      * @see      java.awt.image.ImageObserver
  795.      * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  796.      */
  797.     public abstract boolean drawImage(Image img, int x, int y, 
  798.                       ImageObserver observer);
  799.  
  800.     /**
  801.      * Draws as much of the specified image as has already been scaled
  802.      * to fit inside the specified rectangle.
  803.      * <p>
  804.      * The image is drawn inside the specified rectangle of this 
  805.      * graphics context's coordinate space, and is scaled if 
  806.      * necessary. Transparent pixels do not affect whatever pixels
  807.      * are already there. 
  808.      * <p>
  809.      * This method returns immediately in all cases, even if the
  810.      * entire image has not yet been scaled, dithered, and converted
  811.      * for the current output device.
  812.      * If the current output representation is not yet complete, then
  813.      * <code>drawImage</code> returns <code>false</code>. As more of
  814.      * the image becomes available, the process that draws the image notifies 
  815.      * the image observer by calling its <code>imageUpdate</code> method.
  816.      * <p>
  817.      * A scaled version of an image will not necessarily be
  818.      * available immediately just because an unscaled version of the
  819.      * image has been constructed for this output device.  Each size of
  820.      * the image may be cached separately and generated from the original
  821.      * data in a separate image production sequence.
  822.      * @param    img    the specified image to be drawn.
  823.      * @param    x      the <i>x</i> coordinate.
  824.      * @param    y      the <i>y</i> coordinate.
  825.      * @param    width  the width of the rectangle.
  826.      * @param    height the height of the rectangle.
  827.      * @param    observer    object to be notified as more of 
  828.      *                          the image is converted.
  829.      * @see      java.awt.Image
  830.      * @see      java.awt.image.ImageObserver
  831.      * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  832.      */
  833.     public abstract boolean drawImage(Image img, int x, int y,
  834.                       int width, int height, 
  835.                       ImageObserver observer);
  836.     
  837.     /** 
  838.      * Draws as much of the specified image as is currently available.
  839.      * The image is drawn with its top-left corner at 
  840.      * (<i>x</i>, <i>y</i>) in this graphics context's coordinate 
  841.      * space.  Transparent pixels are drawn in the specified
  842.      * background color.
  843.      * <p> 
  844.      * This operation is equivalent to filling a rectangle of the
  845.      * width and height of the specified image with the given color and then
  846.      * drawing the image on top of it, but possibly more efficient.
  847.      * <p>
  848.      * This method returns immediately in all cases, even if the
  849.      * complete image has not yet been loaded, and it has not been dithered 
  850.      * and converted for the current output device.
  851.      * <p>
  852.      * If the image has not yet been completely loaded, then
  853.      * <code>drawImage</code> returns <code>false</code>. As more of
  854.      * the image becomes available, the process that draws the image notifies 
  855.      * the specified image observer.
  856.      * @param    img    the specified image to be drawn.
  857.      * @param    x      the <i>x</i> coordinate.
  858.      * @param    y      the <i>y</i> coordinate.
  859.      * @param    bgcolor the background color to paint under the
  860.      *                         non-opaque portions of the image.
  861.      * @param    observer    object to be notified as more of 
  862.      *                          the image is converted.
  863.      * @see      java.awt.Image
  864.      * @see      java.awt.image.ImageObserver
  865.      * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  866.      */
  867.     public abstract boolean drawImage(Image img, int x, int y, 
  868.                       Color bgcolor,
  869.                       ImageObserver observer);
  870.  
  871.     /**
  872.      * Draws as much of the specified image as has already been scaled
  873.      * to fit inside the specified rectangle.
  874.      * <p>
  875.      * The image is drawn inside the specified rectangle of this 
  876.      * graphics context's coordinate space, and is scaled if 
  877.      * necessary. Transparent pixels are drawn in the specified
  878.      * background color. 
  879.      * This operation is equivalent to filling a rectangle of the
  880.      * width and height of the specified image with the given color and then
  881.      * drawing the image on top of it, but possibly more efficient.
  882.      * <p>
  883.      * This method returns immediately in all cases, even if the
  884.      * entire image has not yet been scaled, dithered, and converted
  885.      * for the current output device.
  886.      * If the current output representation is not yet complete then
  887.      * <code>drawImage</code> returns <code>false</code>. As more of
  888.      * the image becomes available, the process that draws the image notifies 
  889.      * the specified image observer.
  890.      * <p>
  891.      * A scaled version of an image will not necessarily be
  892.      * available immediately just because an unscaled version of the
  893.      * image has been constructed for this output device.  Each size of
  894.      * the image may be cached separately and generated from the original
  895.      * data in a separate image production sequence.
  896.      * @param    img       the specified image to be drawn.
  897.      * @param    x         the <i>x</i> coordinate.
  898.      * @param    y         the <i>y</i> coordinate.
  899.      * @param    width     the width of the rectangle.
  900.      * @param    height    the height of the rectangle.
  901.      * @param    bgcolor   the background color to paint under the
  902.      *                         non-opaque portions of the image.
  903.      * @param    observer    object to be notified as more of 
  904.      *                          the image is converted.
  905.      * @see      java.awt.Image
  906.      * @see      java.awt.image.ImageObserver
  907.      * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  908.      */
  909.     public abstract boolean drawImage(Image img, int x, int y,
  910.                       int width, int height, 
  911.                       Color bgcolor,
  912.                       ImageObserver observer);
  913.     
  914.     /**
  915.      * Draws as much of the specified area of the specified image as is
  916.      * currently available, scaling it on the fly to fit inside the
  917.      * specified area of the destination drawable surface. Transparent pixels 
  918.      * do not affect whatever pixels are already there.
  919.      * <p>
  920.      * This method returns immediately in all cases, even if the
  921.      * image area to be drawn has not yet been scaled, dithered, and converted
  922.      * for the current output device.
  923.      * If the current output representation is not yet complete then
  924.      * <code>drawImage</code> returns <code>false</code>. As more of
  925.      * the image becomes available, the process that draws the image notifies 
  926.      * the specified image observer.
  927.      * <p>
  928.      * This method always uses the unscaled version of the image
  929.      * to render the scaled rectangle and performs the required
  930.      * scaling on the fly. It does not use a cached, scaled version
  931.      * of the image for this operation. Scaling of the image from source
  932.      * to destination is performed such that the first coordinate
  933.      * of the source rectangle is mapped to the first coordinate of
  934.      * the destination rectangle, and the second source coordinate is
  935.      * mapped to the second destination coordinate. The subimage is
  936.      * scaled and flipped as needed to preserve those mappings.
  937.      * @param       img the specified image to be drawn
  938.      * @param       dx1 the <i>x</i> coordinate of the first corner of the
  939.      *                    destination rectangle.
  940.      * @param       dy1 the <i>y</i> coordinate of the first corner of the
  941.      *                    destination rectangle.
  942.      * @param       dx2 the <i>x</i> coordinate of the second corner of the
  943.      *                    destination rectangle.
  944.      * @param       dy2 the <i>y</i> coordinate of the second corner of the
  945.      *                    destination rectangle.
  946.      * @param       sx1 the <i>x</i> coordinate of the first corner of the
  947.      *                    source rectangle.
  948.      * @param       sy1 the <i>y</i> coordinate of the first corner of the
  949.      *                    source rectangle.
  950.      * @param       sx2 the <i>x</i> coordinate of the second corner of the
  951.      *                    source rectangle.
  952.      * @param       sy2 the <i>y</i> coordinate of the second corner of the
  953.      *                    source rectangle.
  954.      * @param       observer object to be notified as more of the image is
  955.      *                    scaled and converted.
  956.      * @see         java.awt.Image
  957.      * @see         java.awt.image.ImageObserver
  958.      * @see         java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  959.      * @since       JDK1.1
  960.      */
  961.     public abstract boolean drawImage(Image img,
  962.                       int dx1, int dy1, int dx2, int dy2,
  963.                       int sx1, int sy1, int sx2, int sy2,
  964.                       ImageObserver observer);
  965.  
  966.     /**
  967.      * Draws as much of the specified area of the specified image as is
  968.      * currently available, scaling it on the fly to fit inside the
  969.      * specified area of the destination drawable surface. 
  970.      * <p>
  971.      * Transparent pixels are drawn in the specified background color. 
  972.      * This operation is equivalent to filling a rectangle of the
  973.      * width and height of the specified image with the given color and then
  974.      * drawing the image on top of it, but possibly more efficient.
  975.      * <p>
  976.      * This method returns immediately in all cases, even if the
  977.      * image area to be drawn has not yet been scaled, dithered, and converted
  978.      * for the current output device.
  979.      * If the current output representation is not yet complete then
  980.      * <code>drawImage</code> returns <code>false</code>. As more of
  981.      * the image becomes available, the process that draws the image notifies 
  982.      * the specified image observer.
  983.      * <p>
  984.      * This method always uses the unscaled version of the image
  985.      * to render the scaled rectangle and performs the required
  986.      * scaling on the fly. It does not use a cached, scaled version
  987.      * of the image for this operation. Scaling of the image from source
  988.      * to destination is performed such that the first coordinate
  989.      * of the source rectangle is mapped to the first coordinate of
  990.      * the destination rectangle, and the second source coordinate is
  991.      * mapped to the second destination coordinate. The subimage is
  992.      * scaled and flipped as needed to preserve those mappings.
  993.      * @param       img the specified image to be drawn
  994.      * @param       dx1 the <i>x</i> coordinate of the first corner of the
  995.      *                    destination rectangle.
  996.      * @param       dy1 the <i>y</i> coordinate of the first corner of the
  997.      *                    destination rectangle.
  998.      * @param       dx2 the <i>x</i> coordinate of the second corner of the
  999.      *                    destination rectangle.
  1000.      * @param       dy2 the <i>y</i> coordinate of the second corner of the
  1001.      *                    destination rectangle.
  1002.      * @param       sx1 the <i>x</i> coordinate of the first corner of the
  1003.      *                    source rectangle.
  1004.      * @param       sy1 the <i>y</i> coordinate of the first corner of the
  1005.      *                    source rectangle.
  1006.      * @param       sx2 the <i>x</i> coordinate of the second corner of the
  1007.      *                    source rectangle.
  1008.      * @param       sy2 the <i>y</i> coordinate of the second corner of the
  1009.      *                    source rectangle.
  1010.      * @param       bgcolor the background color to paint under the
  1011.      *                    non-opaque portions of the image.
  1012.      * @param       observer object to be notified as more of the image is
  1013.      *                    scaled and converted.
  1014.      * @see         java.awt.Image
  1015.      * @see         java.awt.image.ImageObserver
  1016.      * @see         java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  1017.      * @since       JDK1.1
  1018.      */
  1019.     public abstract boolean drawImage(Image img,
  1020.                       int dx1, int dy1, int dx2, int dy2,
  1021.                       int sx1, int sy1, int sx2, int sy2,
  1022.                       Color bgcolor,
  1023.                       ImageObserver observer);
  1024.  
  1025.     /**
  1026.      * Disposes of this graphics context and releases 
  1027.      * any system resources that it is using. 
  1028.      * A <code>Graphics</code> object cannot be used after 
  1029.      * <code>dispose</code>has been called.
  1030.      * <p>
  1031.      * When a Java program runs, a large number of <code>Graphics</code>
  1032.      * objects can be created within a short time frame.
  1033.      * Although the finalization process of the garbage collector 
  1034.      * also disposes of the same system resources, it is preferable 
  1035.      * to manually free the associated resources by calling this
  1036.      * method rather than to rely on a finalization process which 
  1037.      * may not run to completion for a long period of time.
  1038.      * <p>
  1039.      * Graphics objects which are provided as arguments to the 
  1040.      * <code>paint</code> and <code>update</code> methods 
  1041.      * of components are automatically released by the system when 
  1042.      * those methods return. For efficiency, programmers should
  1043.      * call <code>dispose</code> when finished using
  1044.      * a <code>Graphics</code> object only if it was created 
  1045.      * directly from a component or another <code>Graphics</code> object.
  1046.      * @see         java.awt.Graphics#finalize
  1047.      * @see         java.awt.Component#paint
  1048.      * @see         java.awt.Component#update
  1049.      * @see         java.awt.Component#getGraphics
  1050.      * @see         java.awt.Graphics#create
  1051.      */
  1052.     public abstract void dispose();
  1053.  
  1054.     /**
  1055.      * Disposes of this graphics context once it is no longer referenced.
  1056.      * @see #dispose
  1057.      */
  1058.     public void finalize() {
  1059.     dispose();
  1060.     }
  1061.  
  1062.     /**
  1063.      * Returns a <code>String</code> object representing this 
  1064.      *                        <code>Graphics</code> object's value.
  1065.      * @return       a string representation of this graphics context.
  1066.      */
  1067.     public String toString() {    
  1068.     return getClass().getName() + "[font=" + getFont() + ",color=" + getColor() + "]";
  1069.     }
  1070.  
  1071.     /**
  1072.      * @deprecated As of JDK version 1.1,
  1073.      * replaced by <code>getClipBounds()</code>.
  1074.      */
  1075.     public Rectangle getClipRect() {
  1076.     return getClipBounds();
  1077.     }
  1078.  
  1079.     /**
  1080.      * Returns true if the specified rectangular area intersects 
  1081.      * the bounding rectangle of the current clipping area.
  1082.      * The coordinates in the rectangle are relative to the coordinate
  1083.      * system origin of this graphics context.
  1084.      *
  1085.      * @param x the x coordinate of the rectangle to test against the clip
  1086.      * @param y the y coordinate of the rectangle to test against the clip
  1087.      * @param width the width of the rectangle to test against the clip
  1088.      * @param height the height of the rectangle to test against the clip
  1089.      */
  1090.     public boolean hitClip(int x, int y, int width, int height) {
  1091.         // FIXME: 1.2 beta3 placeholder, replace for beta4
  1092.         return new Rectangle(x,y,width,height).intersects(getClipBounds());
  1093.     }
  1094.  
  1095.     /**
  1096.      * Returns the bounding rectangle of the current clipping area.
  1097.      * The coordinates in the rectangle are relative to the coordinate
  1098.      * system origin of this graphics context.  This method differs
  1099.      * getClipBounds() in that an existing rectangle is used instead
  1100.      * of allocating a new one.
  1101.      * @param  r    the rectangle where the current clipping area is
  1102.      *              copied to.  Any current values in this rectangle are
  1103.      *              overwritten.
  1104.      * @return      the bounding rectangle of the current clipping area.
  1105.      */
  1106.     public Rectangle getClipBounds(Rectangle r) {
  1107.         // FIXME: 1.2 beta3 placeholder, replace for beta4
  1108.         Rectangle clipRect = getClipBounds();
  1109.         r.x = clipRect.x;
  1110.         r.y = clipRect.y;
  1111.         r.width = clipRect.width;
  1112.         r.height = clipRect.height;
  1113.         return r;
  1114.     }
  1115. }
  1116.