1474 lines · 49.2 KB · Java
RawDownload
/* * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.  Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package java.awt.geom; import java.io.Serializable; /** * <CODE>Arc2D</CODE> is the abstract superclass for all objects that * store a 2D arc defined by a framing rectangle, * start angle, angular extent (length of the arc), and a closure type * (<CODE>OPEN</CODE>, <CODE>CHORD</CODE>, or <CODE>PIE</CODE>). * <p> * <a name="inscribes"> * The arc is a partial section of a full ellipse which * inscribes the framing rectangle of its parent {@link RectangularShape}. * </a> * <a name="angles"> * The angles are specified relative to the non-square * framing rectangle such that 45 degrees always falls on the line from * the center of the ellipse to the upper right corner of the framing * rectangle. * As a result, if the framing rectangle is noticeably longer along one * axis than the other, the angles to the start and end of the arc segment * will be skewed farther along the longer axis of the frame. * </a> * <p> * The actual storage representation of the coordinates is left to * the subclass. * * @author      Jim Graham * @since 1.2 */public abstract class Arc2D extends RectangularShape {     /**     * The closure type for an open arc with no path segments     * connecting the two ends of the arc segment.     * @since 1.2     */    public final static int OPEN = 0;     /**     * The closure type for an arc closed by drawing a straight     * line segment from the start of the arc segment to the end of the     * arc segment.     * @since 1.2     */    public final static int CHORD = 1;     /**     * The closure type for an arc closed by drawing straight line     * segments from the start of the arc segment to the center     * of the full ellipse and from that point to the end of the arc segment.     * @since 1.2     */    public final static int PIE = 2;     /**     * This class defines an arc specified in {@code float} precision.     * @since 1.2     */    public static class Float extends Arc2D implements Serializable {        /**         * The X coordinate of the upper-left corner of the framing         * rectangle of the arc.         * @since 1.2         * @serial         */        public float x;         /**         * The Y coordinate of the upper-left corner of the framing         * rectangle of the arc.         * @since 1.2         * @serial         */        public float y;         /**         * The overall width of the full ellipse of which this arc is         * a partial section (not considering the         * angular extents).         * @since 1.2         * @serial         */        public float width;         /**         * The overall height of the full ellipse of which this arc is         * a partial section (not considering the         * angular extents).         * @since 1.2         * @serial         */        public float height;         /**         * The starting angle of the arc in degrees.         * @since 1.2         * @serial         */        public float start;         /**         * The angular extent of the arc in degrees.         * @since 1.2         * @serial         */        public float extent;         /**         * Constructs a new OPEN arc, initialized to location (0, 0),         * size (0, 0), angular extents (start = 0, extent = 0).         * @since 1.2         */        public Float() {            super(OPEN);        }         /**         * Constructs a new arc, initialized to location (0, 0),         * size (0, 0), angular extents (start = 0, extent = 0), and         * the specified closure type.         *         * @param type The closure type for the arc:         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.         * @since 1.2         */        public Float(int type) {            super(type);        }         /**         * Constructs a new arc, initialized to the specified location,         * size, angular extents, and closure type.         *         * @param x The X coordinate of the upper-left corner of         *          the arc's framing rectangle.         * @param y The Y coordinate of the upper-left corner of         *          the arc's framing rectangle.         * @param w The overall width of the full ellipse of which         *          this arc is a partial section.         * @param h The overall height of the full ellipse of which this         *          arc is a partial section.         * @param start The starting angle of the arc in degrees.         * @param extent The angular extent of the arc in degrees.         * @param type The closure type for the arc:         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.         * @since 1.2         */        public Float(float x, float y, float w, float h,                     float start, float extent, int type) {            super(type);            this.x = x;            this.y = y;            this.width = w;            this.height = h;            this.start = start;            this.extent = extent;        }         /**         * Constructs a new arc, initialized to the specified location,         * size, angular extents, and closure type.         *         * @param ellipseBounds The framing rectangle that defines the         * outer boundary of the full ellipse of which this arc is a         * partial section.         * @param start The starting angle of the arc in degrees.         * @param extent The angular extent of the arc in degrees.         * @param type The closure type for the arc:         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.         * @since 1.2         */        public Float(Rectangle2D ellipseBounds,                     float start, float extent, int type) {            super(type);            this.x = (float) ellipseBounds.getX();            this.y = (float) ellipseBounds.getY();            this.width = (float) ellipseBounds.getWidth();            this.height = (float) ellipseBounds.getHeight();            this.start = start;            this.extent = extent;        }         /**         * {@inheritDoc}         * Note that the arc         * <a href="Arc2D.html#inscribes">partially inscribes</a>         * the framing rectangle of this {@code RectangularShape}.         *         * @since 1.2         */        public double getX() {            return (double) x;        }         /**         * {@inheritDoc}         * Note that the arc         * <a href="Arc2D.html#inscribes">partially inscribes</a>         * the framing rectangle of this {@code RectangularShape}.         *         * @since 1.2         */        public double getY() {            return (double) y;        }         /**         * {@inheritDoc}         * Note that the arc         * <a href="Arc2D.html#inscribes">partially inscribes</a>         * the framing rectangle of this {@code RectangularShape}.         *         * @since 1.2         */        public double getWidth() {            return (double) width;        }         /**         * {@inheritDoc}         * Note that the arc         * <a href="Arc2D.html#inscribes">partially inscribes</a>         * the framing rectangle of this {@code RectangularShape}.         *         * @since 1.2         */        public double getHeight() {            return (double) height;        }         /**         * {@inheritDoc}         * @since 1.2         */        public double getAngleStart() {            return (double) start;        }         /**         * {@inheritDoc}         * @since 1.2         */        public double getAngleExtent() {            return (double) extent;        }         /**         * {@inheritDoc}         * @since 1.2         */        public boolean isEmpty() {            return (width <= 0.0 || height <= 0.0);        }         /**         * {@inheritDoc}         * @since 1.2         */        public void setArc(double x, double y, double w, double h,                           double angSt, double angExt, int closure) {            this.setArcType(closure);            this.x = (float) x;            this.y = (float) y;            this.width = (float) w;            this.height = (float) h;            this.start = (float) angSt;            this.extent = (float) angExt;        }         /**         * {@inheritDoc}         * @since 1.2         */        public void setAngleStart(double angSt) {            this.start = (float) angSt;        }         /**         * {@inheritDoc}         * @since 1.2         */        public void setAngleExtent(double angExt) {            this.extent = (float) angExt;        }         /**         * {@inheritDoc}         * @since 1.2         */        protected Rectangle2D makeBounds(double x, double y,                                         double w, double h) {            return new Rectangle2D.Float((float) x, (float) y,                                         (float) w, (float) h);        }         /*         * JDK 1.6 serialVersionUID         */        private static final long serialVersionUID = 9130893014586380278L;         /**         * Writes the default serializable fields to the         * <code>ObjectOutputStream</code> followed by a byte         * indicating the arc type of this <code>Arc2D</code>         * instance.         *         * @serialData         * <ol>         * <li>The default serializable fields.         * <li>         * followed by a <code>byte</code> indicating the arc type         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.         * </ol>         */        private void writeObject(java.io.ObjectOutputStream s)            throws java.io.IOException        {            s.defaultWriteObject();             s.writeByte(getArcType());        }         /**         * Reads the default serializable fields from the         * <code>ObjectInputStream</code> followed by a byte         * indicating the arc type of this <code>Arc2D</code>         * instance.         *         * @serialData         * <ol>         * <li>The default serializable fields.         * <li>         * followed by a <code>byte</code> indicating the arc type         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.         * </ol>         */        private void readObject(java.io.ObjectInputStream s)            throws java.lang.ClassNotFoundException, java.io.IOException        {            s.defaultReadObject();             try {                setArcType(s.readByte());            } catch (IllegalArgumentException iae) {                throw new java.io.InvalidObjectException(iae.getMessage());            }        }    }     /**     * This class defines an arc specified in {@code double} precision.     * @since 1.2     */    public static class Double extends Arc2D implements Serializable {        /**         * The X coordinate of the upper-left corner of the framing         * rectangle of the arc.         * @since 1.2         * @serial         */        public double x;         /**         * The Y coordinate of the upper-left corner of the framing         * rectangle of the arc.         * @since 1.2         * @serial         */        public double y;         /**         * The overall width of the full ellipse of which this arc is         * a partial section (not considering the angular extents).         * @since 1.2         * @serial         */        public double width;         /**         * The overall height of the full ellipse of which this arc is         * a partial section (not considering the angular extents).         * @since 1.2         * @serial         */        public double height;         /**         * The starting angle of the arc in degrees.         * @since 1.2         * @serial         */        public double start;         /**         * The angular extent of the arc in degrees.         * @since 1.2         * @serial         */        public double extent;         /**         * Constructs a new OPEN arc, initialized to location (0, 0),         * size (0, 0), angular extents (start = 0, extent = 0).         * @since 1.2         */        public Double() {            super(OPEN);        }         /**         * Constructs a new arc, initialized to location (0, 0),         * size (0, 0), angular extents (start = 0, extent = 0), and         * the specified closure type.         *         * @param type The closure type for the arc:         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.         * @since 1.2         */        public Double(int type) {            super(type);        }         /**         * Constructs a new arc, initialized to the specified location,         * size, angular extents, and closure type.         *         * @param x The X coordinate of the upper-left corner         *          of the arc's framing rectangle.         * @param y The Y coordinate of the upper-left corner         *          of the arc's framing rectangle.         * @param w The overall width of the full ellipse of which this         *          arc is a partial section.         * @param h The overall height of the full ellipse of which this         *          arc is a partial section.         * @param start The starting angle of the arc in degrees.         * @param extent The angular extent of the arc in degrees.         * @param type The closure type for the arc:         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.         * @since 1.2         */        public Double(double x, double y, double w, double h,                      double start, double extent, int type) {            super(type);            this.x = x;            this.y = y;            this.width = w;            this.height = h;            this.start = start;            this.extent = extent;        }         /**         * Constructs a new arc, initialized to the specified location,         * size, angular extents, and closure type.         *         * @param ellipseBounds The framing rectangle that defines the         * outer boundary of the full ellipse of which this arc is a         * partial section.         * @param start The starting angle of the arc in degrees.         * @param extent The angular extent of the arc in degrees.         * @param type The closure type for the arc:         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.         * @since 1.2         */        public Double(Rectangle2D ellipseBounds,                      double start, double extent, int type) {            super(type);            this.x = ellipseBounds.getX();            this.y = ellipseBounds.getY();            this.width = ellipseBounds.getWidth();            this.height = ellipseBounds.getHeight();            this.start = start;            this.extent = extent;        }

Lines 1–500 of 1474.