1918 lines · 70.2 KB · Java
RawDownload
    }     /**     * Draws a line, using the current color, between the points     * <code>(x1,&nbsp;y1)</code> and <code>(x2,&nbsp;y2)</code>     * in this graphics context's coordinate system.     * @param   x1  the first point's <i>x</i> coordinate.     * @param   y1  the first point's <i>y</i> coordinate.     * @param   x2  the second point's <i>x</i> coordinate.     * @param   y2  the second point's <i>y</i> coordinate.     * @since   JDK1.0     */    public void drawLine(int x1, int y1, int x2, int y2) {        addStrokeShape(new Line2D.Float(x1, y1, x2, y2));        mPrintMetrics.draw(this);    }       /**     * Fills the specified rectangle.     * The left and right edges of the rectangle are at     * <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>.     * The top and bottom edges are at     * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.     * The resulting rectangle covers an area     * <code>width</code> pixels wide by     * <code>height</code> pixels tall.     * The rectangle is filled using the graphics context's current color.     * @param         x   the <i>x</i> coordinate     *                         of the rectangle to be filled.     * @param         y   the <i>y</i> coordinate     *                         of the rectangle to be filled.     * @param         width   the width of the rectangle to be filled.     * @param         height   the height of the rectangle to be filled.     * @see           java.awt.Graphics#fillRect     * @see           java.awt.Graphics#clearRect     * @since         JDK1.0     */    public void fillRect(int x, int y, int width, int height) {         addDrawingRect(new Rectangle2D.Float(x, y, width, height));        mPrintMetrics.fill(this);     }     /**     * Clears the specified rectangle by filling it with the background     * color of the current drawing surface. This operation does not     * use the current paint mode.     * <p>     * Beginning with Java&nbsp;1.1, the background color     * of offscreen images may be system dependent. Applications should     * use <code>setColor</code> followed by <code>fillRect</code> to     * ensure that an offscreen image is cleared to a specific color.     * @param       x the <i>x</i> coordinate of the rectangle to clear.     * @param       y the <i>y</i> coordinate of the rectangle to clear.     * @param       width the width of the rectangle to clear.     * @param       height the height of the rectangle to clear.     * @see         java.awt.Graphics#fillRect(int, int, int, int)     * @see         java.awt.Graphics#drawRect     * @see         java.awt.Graphics#setColor(java.awt.Color)     * @see         java.awt.Graphics#setPaintMode     * @see         java.awt.Graphics#setXORMode(java.awt.Color)     * @since       JDK1.0     */    public void clearRect(int x, int y, int width, int height) {        Rectangle2D.Float rect = new Rectangle2D.Float(x, y, width, height);        addDrawingRect(rect);        mPrintMetrics.clear(this);    }     /**     * Draws an outlined round-cornered rectangle using this graphics     * context's current color. The left and right edges of the rectangle     * are at <code>x</code> and <code>x&nbsp;+&nbsp;width</code>,     * respectively. The top and bottom edges of the rectangle are at     * <code>y</code> and <code>y&nbsp;+&nbsp;height</code>.     * @param      x the <i>x</i> coordinate of the rectangle to be drawn.     * @param      y the <i>y</i> coordinate of the rectangle to be drawn.     * @param      width the width of the rectangle to be drawn.     * @param      height the height of the rectangle to be drawn.     * @param      arcWidth the horizontal diameter of the arc     *                    at the four corners.     * @param      arcHeight the vertical diameter of the arc     *                    at the four corners.     * @see        java.awt.Graphics#fillRoundRect     * @since      JDK1.0     */    public void drawRoundRect(int x, int y, int width, int height,                              int arcWidth, int arcHeight) {        addStrokeShape(new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight));        mPrintMetrics.draw(this);     }     /**     * Fills the specified rounded corner rectangle with the current color.     * The left and right edges of the rectangle     * are at <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>,     * respectively. The top and bottom edges of the rectangle are at     * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.     * @param       x the <i>x</i> coordinate of the rectangle to be filled.     * @param       y the <i>y</i> coordinate of the rectangle to be filled.     * @param       width the width of the rectangle to be filled.     * @param       height the height of the rectangle to be filled.     * @param       arcWidth the horizontal diameter     *                     of the arc at the four corners.     * @param       arcHeight the vertical diameter     *                     of the arc at the four corners.     * @see         java.awt.Graphics#drawRoundRect     * @since       JDK1.0     */    public void fillRoundRect(int x, int y, int width, int height,                                       int arcWidth, int arcHeight) {        Rectangle2D.Float rect = new Rectangle2D.Float(x, y,width, height);        addDrawingRect(rect);        mPrintMetrics.fill(this);    }     /**     * Draws the outline of an oval.     * The result is a circle or ellipse that fits within the     * rectangle specified by the <code>x</code>, <code>y</code>,     * <code>width</code>, and <code>height</code> arguments.     * <p>     * The oval covers an area that is     * <code>width&nbsp;+&nbsp;1</code> pixels wide     * and <code>height&nbsp;+&nbsp;1</code> pixels tall.     * @param       x the <i>x</i> coordinate of the upper left     *                     corner of the oval to be drawn.     * @param       y the <i>y</i> coordinate of the upper left     *                     corner of the oval to be drawn.     * @param       width the width of the oval to be drawn.     * @param       height the height of the oval to be drawn.     * @see         java.awt.Graphics#fillOval     * @since       JDK1.0     */    public void drawOval(int x, int y, int width, int height) {        addStrokeShape(new Rectangle2D.Float(x, y,  width, height));        mPrintMetrics.draw(this);    }     /**     * Fills an oval bounded by the specified rectangle with the     * current color.     * @param       x the <i>x</i> coordinate of the upper left corner     *                     of the oval to be filled.     * @param       y the <i>y</i> coordinate of the upper left corner     *                     of the oval to be filled.     * @param       width the width of the oval to be filled.     * @param       height the height of the oval to be filled.     * @see         java.awt.Graphics#drawOval     * @since       JDK1.0     */    public void fillOval(int x, int y, int width, int height) {        Rectangle2D.Float rect = new Rectangle2D.Float(x, y, width, height);        addDrawingRect(rect);        mPrintMetrics.fill(this);     }      /**     * Draws the outline of a circular or elliptical arc     * covering the specified rectangle.     * <p>     * The resulting arc begins at <code>startAngle</code> and extends     * for <code>arcAngle</code> degrees, using the current color.     * Angles are interpreted such that 0&nbsp;degrees     * is at the 3&nbsp;o'clock position.     * A positive value indicates a counter-clockwise rotation     * while a negative value indicates a clockwise rotation.     * <p>     * The center of the arc is the center of the rectangle whose origin     * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the     * <code>width</code> and <code>height</code> arguments.     * <p>     * The resulting arc covers an area     * <code>width&nbsp;+&nbsp;1</code> pixels wide     * by <code>height&nbsp;+&nbsp;1</code> pixels tall.     * @param        x the <i>x</i> coordinate of the     *                    upper-left corner of the arc to be drawn.     * @param        y the <i>y</i>  coordinate of the     *                    upper-left corner of the arc to be drawn.     * @param        width the width of the arc to be drawn.     * @param        height the height of the arc to be drawn.     * @param        startAngle the beginning angle.     * @param        arcAngle the angular extent of the arc,     *                    relative to the start angle.     * @see         java.awt.Graphics#fillArc     * @since       JDK1.0     */    public void drawArc(int x, int y, int width, int height,                                 int startAngle, int arcAngle) {        addStrokeShape(new Rectangle2D.Float(x, y,  width, height));        mPrintMetrics.draw(this);     }     /**     * Fills a circular or elliptical arc covering the specified rectangle.     * <p>     * The resulting arc begins at <code>startAngle</code> and extends     * for <code>arcAngle</code> degrees.     * Angles are interpreted such that 0&nbsp;degrees     * is at the 3&nbsp;o'clock position.     * A positive value indicates a counter-clockwise rotation     * while a negative value indicates a clockwise rotation.     * <p>     * The center of the arc is the center of the rectangle whose origin     * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the     * <code>width</code> and <code>height</code> arguments.     * <p>     * The resulting arc covers an area     * <code>width&nbsp;+&nbsp;1</code> pixels wide     * by <code>height&nbsp;+&nbsp;1</code> pixels tall.     * @param        x the <i>x</i> coordinate of the     *                    upper-left corner of the arc to be filled.     * @param        y the <i>y</i>  coordinate of the     *                    upper-left corner of the arc to be filled.     * @param        width the width of the arc to be filled.     * @param        height the height of the arc to be filled.     * @param        startAngle the beginning angle.     * @param        arcAngle the angular extent of the arc,     *                    relative to the start angle.     * @see         java.awt.Graphics#drawArc     * @since       JDK1.0     */    public void fillArc(int x, int y, int width, int height,                        int startAngle, int arcAngle) {        Rectangle2D.Float rect = new Rectangle2D.Float(x, y,width, height);        addDrawingRect(rect);        mPrintMetrics.fill(this);     }     /**     * Draws a sequence of connected lines defined by     * arrays of <i>x</i> and <i>y</i> coordinates.     * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.     * The figure is not closed if the first point     * differs from the last point.     * @param       xPoints an array of <i>x</i> points     * @param       yPoints an array of <i>y</i> points     * @param       nPoints the total number of points     * @see         java.awt.Graphics#drawPolygon(int[], int[], int)     * @since       JDK1.1     */   public void drawPolyline(int xPoints[], int yPoints[],                             int nPoints) {        if (nPoints > 0) {            int x = xPoints[0];            int y = yPoints[0];             for (int i = 1; i < nPoints; i++) {                drawLine(x, y, xPoints[i], yPoints[i]);                x = xPoints[i];                y = yPoints[i];            }        }     }     /**     * Draws a closed polygon defined by     * arrays of <i>x</i> and <i>y</i> coordinates.     * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.     * <p>     * This method draws the polygon defined by <code>nPoint</code> line     * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>     * line segments are line segments from     * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>     * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for     * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.     * The figure is automatically closed by drawing a line connecting     * the final point to the first point, if those points are different.     * @param        xPoints   a an array of <code>x</code> coordinates.     * @param        yPoints   a an array of <code>y</code> coordinates.     * @param        nPoints   a the total number of points.     * @see          java.awt.Graphics#fillPolygon     * @see          java.awt.Graphics#drawPolyline     * @since        JDK1.0     */    public void drawPolygon(int xPoints[], int yPoints[],                            int nPoints) {        if (nPoints > 0) {            drawPolyline(xPoints, yPoints, nPoints);            drawLine(xPoints[nPoints - 1], yPoints[nPoints - 1],                     xPoints[0], yPoints[0]);        }     }     /**     * Fills a closed polygon defined by     * arrays of <i>x</i> and <i>y</i> coordinates.     * <p>     * This method draws the polygon defined by <code>nPoint</code> line     * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>     * line segments are line segments from     * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>     * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for     * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.     * The figure is automatically closed by drawing a line connecting     * the final point to the first point, if those points are different.     * <p>     * The area inside the polygon is defined using an     * even-odd fill rule, also known as the alternating rule.     * @param        xPoints   a an array of <code>x</code> coordinates.     * @param        yPoints   a an array of <code>y</code> coordinates.     * @param        nPoints   a the total number of points.     * @see          java.awt.Graphics#drawPolygon(int[], int[], int)     * @since        JDK1.0     */    public void fillPolygon(int xPoints[], int yPoints[],                            int nPoints) {        if (nPoints > 0) {            int minX = xPoints[0];            int minY = yPoints[0];            int maxX = xPoints[0];            int maxY = yPoints[0];             for (int i = 1; i < nPoints; i++) {                 if (xPoints[i] < minX) {                    minX = xPoints[i];                } else if (xPoints[i] > maxX) {                    maxX = xPoints[i];                }                 if (yPoints[i] < minY) {                    minY = yPoints[i];                } else if (yPoints[i] > maxY) {                    maxY = yPoints[i];                }            }             addDrawingRect(minX, minY, maxX - minX, maxY - minY);        }         mPrintMetrics.fill(this);     }      /**     * Draws the text given by the specified string, using this     * graphics context's current font and color. The baseline of the     * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this     * graphics context's coordinate system.     * @param       str      the string to be drawn.     * @param       x        the <i>x</i> coordinate.     * @param       y        the <i>y</i> coordinate.     * @see         java.awt.Graphics#drawBytes     * @see         java.awt.Graphics#drawChars     * @since       JDK1.0     */    public void drawString(String str, int x, int y) {         drawString(str, (float)x, (float)y);    }     /**     * Draws the text given by the specified iterator, using this     * graphics context's current color. The iterator has to specify a font     * for each character. The baseline of the     * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this     * graphics context's coordinate system.     * The rendering attributes applied include the clip, transform,     * paint or color, and composite attributes.     * For characters in script systems such as Hebrew and Arabic,     * the glyphs may be draw from right to left, in which case the     * coordinate supplied is the the location of the leftmost character     * on the baseline.     * @param iterator the iterator whose text is to be drawn     * @param x,y the coordinates where the iterator's text should be drawn.     * @see #setPaint     * @see java.awt.Graphics#setColor     * @see #setTransform     * @see #setComposite     * @see #setClip     */    public void drawString(AttributedCharacterIterator iterator,                                    int x, int y) {         drawString(iterator,  (float)x, (float)y);    }     /**     * Draws the text given by the specified iterator, using this     * graphics context's current color. The iterator has to specify a font     * for each character. The baseline of the     * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this     * graphics context's coordinate system.     * The rendering attributes applied include the clip, transform,     * paint or color, and composite attributes.     * For characters in script systems such as Hebrew and Arabic,     * the glyphs may be draw from right to left, in which case the     * coordinate supplied is the the location of the leftmost character     * on the baseline.     * @param iterator the iterator whose text is to be drawn     * @param x,y the coordinates where the iterator's text should be drawn.     * @see #setPaint     * @see java.awt.Graphics#setColor     * @see #setTransform     * @see #setComposite     * @see #setClip     */    public void drawString(AttributedCharacterIterator iterator,                                    float x, float y) {        if (iterator == null) {            throw new                NullPointerException("AttributedCharacterIterator is null");        }         TextLayout layout = new TextLayout(iterator, getFontRenderContext());        layout.draw(this, x, y);    }      /**     * Draws as much of the specified image as is currently available.     * The image is drawn with its top-left corner at     * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate     * space. Transparent pixels in the image do not affect whatever     * pixels are already there.     * <p>     * This method returns immediately in all cases, even if the     * complete image has not yet been loaded, and it has not been dithered     * and converted for the current output device.     * <p>     * If the image has not yet been completely loaded, then     * <code>drawImage</code> returns <code>false</code>. As more of     * the image becomes available, the process that draws the image notifies     * the specified image observer.     * @param    img the specified image to be drawn.     * @param    x   the <i>x</i> coordinate.     * @param    y   the <i>y</i> coordinate.     * @param    observer    object to be notified as more of     *                          the image is converted.     * @see      java.awt.Image     * @see      java.awt.image.ImageObserver     * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)     * @since    JDK1.0     */    public boolean drawImage(Image img, int x, int y,                             ImageObserver observer) {         if (img == null) {            return true;        }         /* The ImageWaiter creation does not return until the         * image is loaded.         */        ImageWaiter dim = new ImageWaiter(img);         addDrawingRect(x, y, dim.getWidth(), dim.getHeight());        mPrintMetrics.drawImage(this, img);         return mGraphics.drawImage(img, x, y, observer);    }      /**     * Draws as much of the specified image as has already been scaled     * to fit inside the specified rectangle.     * <p>     * The image is drawn inside the specified rectangle of this     * graphics context's coordinate space, and is scaled if     * necessary. Transparent pixels do not affect whatever pixels     * are already there.     * <p>     * This method returns immediately in all cases, even if the     * entire image has not yet been scaled, dithered, and converted     * for the current output device.     * If the current output representation is not yet complete, then     * <code>drawImage</code> returns <code>false</code>. As more of     * the image becomes available, the process that draws the image notifies     * the image observer by calling its <code>imageUpdate</code> method.     * <p>     * A scaled version of an image will not necessarily be     * available immediately just because an unscaled version of the     * image has been constructed for this output device.  Each size of     * the image may be cached separately and generated from the original     * data in a separate image production sequence.     * @param    img    the specified image to be drawn.     * @param    x      the <i>x</i> coordinate.     * @param    y      the <i>y</i> coordinate.     * @param    width  the width of the rectangle.     * @param    height the height of the rectangle.     * @param    observer    object to be notified as more of     *                          the image is converted.     * @see      java.awt.Image     * @see      java.awt.image.ImageObserver     * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)     * @since    JDK1.0     */    public boolean drawImage(Image img, int x, int y,

Lines 501–1000 of 1918. Previous lines