jdk/src/share/classes/java/awt/geom/RectangularShape.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 466
diff changeset
     2
 * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 466
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 466
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 466
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 466
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 466
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.geom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Shape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Rectangle;
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    30
import java.beans.Transient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <code>RectangularShape</code> is the base class for a number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * {@link Shape} objects whose geometry is defined by a rectangular frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This class does not directly specify any specific geometry by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * itself, but merely provides manipulation methods inherited by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * a whole category of <code>Shape</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The manipulation methods provided by this class can be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * query and modify the rectangular frame, which provides a reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * for the subclasses to define their geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author      Jim Graham
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public abstract class RectangularShape implements Shape, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * This is an abstract class that cannot be instantiated directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @see Arc2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @see Ellipse2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * @see Rectangle2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @see RoundRectangle2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    protected RectangularShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Returns the X coordinate of the upper-left corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * the framing rectangle in <code>double</code> precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @return the X coordinate of the upper-left corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * the framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public abstract double getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Returns the Y coordinate of the upper-left corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * the framing rectangle in <code>double</code> precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @return the Y coordinate of the upper-left corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * the framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public abstract double getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Returns the width of the framing rectangle in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * <code>double</code> precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @return the width of the framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public abstract double getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Returns the height of the framing rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * in <code>double</code> precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @return the height of the framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public abstract double getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Returns the smallest X coordinate of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * rectangle of the <code>Shape</code> in <code>double</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @return the smallest X coordinate of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *          rectangle of the <code>Shape</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public double getMinX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Returns the smallest Y coordinate of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * rectangle of the <code>Shape</code> in <code>double</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @return the smallest Y coordinate of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *          rectangle of the <code>Shape</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public double getMinY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Returns the largest X coordinate of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * rectangle of the <code>Shape</code> in <code>double</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return the largest X coordinate of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *          rectangle of the <code>Shape</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public double getMaxX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return getX() + getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Returns the largest Y coordinate of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * rectangle of the <code>Shape</code> in <code>double</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return the largest Y coordinate of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *          rectangle of the <code>Shape</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public double getMaxY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return getY() + getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Returns the X coordinate of the center of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * rectangle of the <code>Shape</code> in <code>double</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return the X coordinate of the center of the framing rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *          of the <code>Shape</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public double getCenterX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return getX() + getWidth() / 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Returns the Y coordinate of the center of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * rectangle of the <code>Shape</code> in <code>double</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @return the Y coordinate of the center of the framing rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *          of the <code>Shape</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public double getCenterY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return getY() + getHeight() / 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Returns the framing {@link Rectangle2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * that defines the overall shape of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @return a <code>Rectangle2D</code>, specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <code>double</code> coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see #setFrame(double, double, double, double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @see #setFrame(Point2D, Dimension2D)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @see #setFrame(Rectangle2D)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   175
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public Rectangle2D getFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Determines whether the <code>RectangularShape</code> is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * When the <code>RectangularShape</code> is empty, it encloses no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @return <code>true</code> if the <code>RectangularShape</code> is empty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *          <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public abstract boolean isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Sets the location and size of the framing rectangle of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * <code>Shape</code> to the specified rectangular values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @param x the X coordinate of the upper-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *          specified rectangular shape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param y the Y coordinate of the upper-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *          specified rectangular shape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param w the width of the specified rectangular shape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param h the height of the specified rectangular shape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @see #getFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public abstract void setFrame(double x, double y, double w, double h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Sets the location and size of the framing rectangle of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <code>Shape</code> to the specified {@link Point2D} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * {@link Dimension2D}, respectively.  The framing rectangle is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * by the subclasses of <code>RectangularShape</code> to define
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * their geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param loc the specified <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param size the specified <code>Dimension2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @see #getFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public void setFrame(Point2D loc, Dimension2D size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        setFrame(loc.getX(), loc.getY(), size.getWidth(), size.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Sets the framing rectangle of this <code>Shape</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * be the specified <code>Rectangle2D</code>.  The framing rectangle is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * used by the subclasses of <code>RectangularShape</code> to define
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * their geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param r the specified <code>Rectangle2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @see #getFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public void setFrame(Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        setFrame(r.getX(), r.getY(), r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Sets the diagonal of the framing rectangle of this <code>Shape</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * based on the two specified coordinates.  The framing rectangle is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * used by the subclasses of <code>RectangularShape</code> to define
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * their geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param x1 the X coordinate of the start point of the specified diagonal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param y1 the Y coordinate of the start point of the specified diagonal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param x2 the X coordinate of the end point of the specified diagonal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param y2 the Y coordinate of the end point of the specified diagonal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public void setFrameFromDiagonal(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                     double x2, double y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (x2 < x1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            double t = x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            x1 = x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            x2 = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (y2 < y1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            double t = y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            y1 = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            y2 = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        setFrame(x1, y1, x2 - x1, y2 - y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Sets the diagonal of the framing rectangle of this <code>Shape</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * based on two specified <code>Point2D</code> objects.  The framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * rectangle is used by the subclasses of <code>RectangularShape</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * to define their geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param p1 the start <code>Point2D</code> of the specified diagonal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param p2 the end <code>Point2D</code> of the specified diagonal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public void setFrameFromDiagonal(Point2D p1, Point2D p2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        setFrameFromDiagonal(p1.getX(), p1.getY(), p2.getX(), p2.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Sets the framing rectangle of this <code>Shape</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * based on the specified center point coordinates and corner point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * coordinates.  The framing rectangle is used by the subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <code>RectangularShape</code> to define their geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param centerX the X coordinate of the specified center point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @param centerY the Y coordinate of the specified center point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param cornerX the X coordinate of the specified corner point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param cornerY the Y coordinate of the specified corner point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public void setFrameFromCenter(double centerX, double centerY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                                   double cornerX, double cornerY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        double halfW = Math.abs(cornerX - centerX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        double halfH = Math.abs(cornerY - centerY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        setFrame(centerX - halfW, centerY - halfH, halfW * 2.0, halfH * 2.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Sets the framing rectangle of this <code>Shape</code> based on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * specified center <code>Point2D</code> and corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * <code>Point2D</code>.  The framing rectangle is used by the subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * of <code>RectangularShape</code> to define their geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @param center the specified center <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param corner the specified corner <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public void setFrameFromCenter(Point2D center, Point2D corner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        setFrameFromCenter(center.getX(), center.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                           corner.getX(), corner.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public boolean contains(Point2D p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return contains(p.getX(), p.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public boolean intersects(Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    public boolean contains(Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        double width = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        double height = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (width < 0 || height < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            return new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        double x = getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        double y = getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        double x1 = Math.floor(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        double y1 = Math.floor(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        double x2 = Math.ceil(x + width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        double y2 = Math.ceil(y + height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return new Rectangle((int) x1, (int) y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                      (int) (x2 - x1), (int) (y2 - y1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Returns an iterator object that iterates along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * <code>Shape</code> object's boundary and provides access to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * flattened view of the outline of the <code>Shape</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * object's geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * be returned by the iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * The amount of subdivision of the curved segments is controlled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * by the <code>flatness</code> parameter, which specifies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * maximum distance that any point on the unflattened transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * curve can deviate from the returned flattened path segments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * An optional {@link AffineTransform} can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * be specified so that the coordinates returned in the iteration are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * transformed accordingly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param at an optional <code>AffineTransform</code> to be applied to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *          coordinates as they are returned in the iteration,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *          or <code>null</code> if untransformed coordinates are desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param flatness the maximum distance that the line segments used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *          approximate the curved segments are allowed to deviate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *          from any point on the original curve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @return a <code>PathIterator</code> object that provides access to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *          the <code>Shape</code> object's flattened geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public PathIterator getPathIterator(AffineTransform at, double flatness) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        return new FlatteningPathIterator(getPathIterator(at), flatness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Creates a new object of the same class and with the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * contents as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @return     a clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @exception  OutOfMemoryError            if there is not enough memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @see        java.lang.Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            // this shouldn't happen, since we are Cloneable
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   394
            throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
}