jdk/src/share/classes/java/awt/RadialGradientPaint.java
author alanb
Mon, 05 Oct 2009 16:45:55 +0100
changeset 3956 2586d23078e4
parent 715 f16baef3a20e
child 5506 202f599c92aa
permissions -rw-r--r--
6854954: Eliminate static dependency on java.awt.AWTPermission Reviewed-by: mullan, mchung, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 436
diff changeset
     2
 * Copyright 2006-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * The {@code RadialGradientPaint} class provides a way to fill a shape with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * a circular radial color gradient pattern. The user may specify 2 or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * gradient colors, and this paint will provide an interpolation between
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * each color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The user must specify the circle controlling the gradient pattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * which is described by a center point and a radius.  The user can also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * specify a separate focus point within that circle, which controls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * location of the first color of the gradient.  By default the focus is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * set to be the center of the circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * This paint will map the first color of the gradient to the focus point,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * and the last color to the perimeter of the circle, interpolating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * smoothly for any in-between colors specified by the user.  Any line drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * from the focus point to the circumference will thus span all the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * colors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Specifying a focus point outside of the circle's radius will result in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * focus being set to the intersection point of the focus-center line and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * perimeter of the circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * The user must provide an array of floats specifying how to distribute the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * colors along the gradient.  These values should range from 0.0 to 1.0 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * act like keyframes along the gradient (they mark where the gradient should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * be exactly a particular color).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * In the event that the user does not set the first keyframe value equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * to 0 and/or the last keyframe value equal to 1, keyframes will be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * at these positions and the first and last colors will be replicated there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * So, if a user specifies the following arrays to construct a gradient:<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *     {Color.BLUE, Color.RED}, {.3f, .7f}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * this will be converted to a gradient with the following keyframes:<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *     {Color.BLUE, Color.BLUE, Color.RED, Color.RED}, {0f, .3f, .7f, 1f}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * The user may also select what action the {@code RadialGradientPaint}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * should take when filling color outside the bounds of the circle's radius.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * If no cycle method is specified, {@code NO_CYCLE} will be chosen by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * default, which means the the last keyframe color will be used to fill the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * remaining area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * The colorSpace parameter allows the user to specify in which colorspace
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * the interpolation should be performed, default sRGB or linearized RGB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * The following code demonstrates typical usage of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * {@code RadialGradientPaint}, where the center and focus points are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * the same:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *     Point2D center = new Point2D.Float(50, 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *     float radius = 25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *     float[] dist = {0.0f, 0.2f, 1.0f};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *     Color[] colors = {Color.RED, Color.WHITE, Color.BLUE};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *     RadialGradientPaint p =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *         new RadialGradientPaint(center, radius, dist, colors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * This image demonstrates the example code above, with default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * (centered) focus for each of the three cycle methods:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <center>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * <img src = "doc-files/RadialGradientPaint-1.png">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * </center>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * It is also possible to specify a non-centered focus point, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * in the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *     Point2D center = new Point2D.Float(50, 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *     float radius = 25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *     Point2D focus = new Point2D.Float(40, 40);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *     float[] dist = {0.0f, 0.2f, 1.0f};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *     Color[] colors = {Color.RED, Color.WHITE, Color.BLUE};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *     RadialGradientPaint p =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *         new RadialGradientPaint(center, radius, focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *                                 dist, colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *                                 CycleMethod.NO_CYCLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * This image demonstrates the previous example code, with non-centered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * focus for each of the three cycle methods:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <center>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * <img src = "doc-files/RadialGradientPaint-2.png">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * </center>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * @see java.awt.Paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * @see java.awt.Graphics2D#setPaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * @author Nicholas Talian, Vincent Hardy, Jim Graham, Jerry Evans
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
public final class RadialGradientPaint extends MultipleGradientPaint {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /** Focus point which defines the 0% gradient stop X coordinate. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private final Point2D focus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /** Center of the circle defining the 100% gradient stop X coordinate. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private final Point2D center;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /** Radius of the outermost circle defining the 100% gradient stop. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private final float radius;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Constructs a {@code RadialGradientPaint} with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * {@code NO_CYCLE} repeating method and {@code SRGB} color space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * using the center as the focus point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param cx the X coordinate in user space of the center point of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *           circle defining the gradient.  The last color of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *           gradient is mapped to the perimeter of this circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param cy the Y coordinate in user space of the center point of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *           circle defining the gradient.  The last color of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *           gradient is mapped to the perimeter of this circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param radius the radius of the circle defining the extents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *               color gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param fractions numbers ranging from 0.0 to 1.0 specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *                  distribution of colors along the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param colors array of colors to use in the gradient.  The first color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *               is used at the focus point, the last color around the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *               perimeter of the circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @throws NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * if {@code fractions} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * or {@code colors} array is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * if {@code radius} is non-positive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * or {@code fractions.length != colors.length},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * or {@code colors} is less than 2 in size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * or a {@code fractions} value is less than 0.0 or greater than 1.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * or the {@code fractions} are not provided in strictly increasing order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public RadialGradientPaint(float cx, float cy, float radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                               float[] fractions, Color[] colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        this(cx, cy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
             radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
             cx, cy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
             fractions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
             colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
             CycleMethod.NO_CYCLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Constructs a {@code RadialGradientPaint} with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * {@code NO_CYCLE} repeating method and {@code SRGB} color space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * using the center as the focus point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @param center the center point, in user space, of the circle defining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *               the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param radius the radius of the circle defining the extents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *               color gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param fractions numbers ranging from 0.0 to 1.0 specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *                  distribution of colors along the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param colors array of colors to use in the gradient.  The first color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *               is used at the focus point, the last color around the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *               perimeter of the circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @throws NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * if {@code center} point is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * or {@code fractions} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * or {@code colors} array is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * if {@code radius} is non-positive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * or {@code fractions.length != colors.length},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * or {@code colors} is less than 2 in size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * or a {@code fractions} value is less than 0.0 or greater than 1.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * or the {@code fractions} are not provided in strictly increasing order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public RadialGradientPaint(Point2D center, float radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                               float[] fractions, Color[] colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        this(center,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
             radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
             center,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
             fractions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
             colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
             CycleMethod.NO_CYCLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Constructs a {@code RadialGradientPaint} with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * {@code SRGB} color space, using the center as the focus point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param cx the X coordinate in user space of the center point of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *           circle defining the gradient.  The last color of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *           gradient is mapped to the perimeter of this circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param cy the Y coordinate in user space of the center point of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *           circle defining the gradient.  The last color of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *           gradient is mapped to the perimeter of this circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param radius the radius of the circle defining the extents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *               color gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param fractions numbers ranging from 0.0 to 1.0 specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *                  distribution of colors along the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param colors array of colors to use in the gradient.  The first color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *               is used at the focus point, the last color around the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *               perimeter of the circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *                    or {@code REPEAT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @throws NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * if {@code fractions} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * or {@code colors} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * or {@code cycleMethod} is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * if {@code radius} is non-positive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * or {@code fractions.length != colors.length},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * or {@code colors} is less than 2 in size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * or a {@code fractions} value is less than 0.0 or greater than 1.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * or the {@code fractions} are not provided in strictly increasing order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public RadialGradientPaint(float cx, float cy, float radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                               float[] fractions, Color[] colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                               CycleMethod cycleMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        this(cx, cy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
             radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
             cx, cy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
             fractions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
             colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
             cycleMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Constructs a {@code RadialGradientPaint} with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * {@code SRGB} color space, using the center as the focus point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param center the center point, in user space, of the circle defining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *               the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @param radius the radius of the circle defining the extents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *               color gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @param fractions numbers ranging from 0.0 to 1.0 specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *                  distribution of colors along the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @param colors array of colors to use in the gradient.  The first color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *               is used at the focus point, the last color around the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *               perimeter of the circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *                    or {@code REPEAT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @throws NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * if {@code center} point is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * or {@code fractions} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * or {@code colors} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * or {@code cycleMethod} is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * if {@code radius} is non-positive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * or {@code fractions.length != colors.length},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * or {@code colors} is less than 2 in size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * or a {@code fractions} value is less than 0.0 or greater than 1.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * or the {@code fractions} are not provided in strictly increasing order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public RadialGradientPaint(Point2D center, float radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                               float[] fractions, Color[] colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                               CycleMethod cycleMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        this(center,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
             radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
             center,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
             fractions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
             colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
             cycleMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Constructs a {@code RadialGradientPaint} with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * {@code SRGB} color space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @param cx the X coordinate in user space of the center point of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *           circle defining the gradient.  The last color of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *           gradient is mapped to the perimeter of this circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @param cy the Y coordinate in user space of the center point of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *           circle defining the gradient.  The last color of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *           gradient is mapped to the perimeter of this circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @param radius the radius of the circle defining the extents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *               color gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @param fx the X coordinate of the point in user space to which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *           first color is mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @param fy the Y coordinate of the point in user space to which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *           first color is mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @param fractions numbers ranging from 0.0 to 1.0 specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *                  distribution of colors along the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @param colors array of colors to use in the gradient.  The first color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *               is used at the focus point, the last color around the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *               perimeter of the circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *                    or {@code REPEAT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @throws NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * if {@code fractions} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * or {@code colors} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * or {@code cycleMethod} is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * if {@code radius} is non-positive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * or {@code fractions.length != colors.length},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * or {@code colors} is less than 2 in size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * or a {@code fractions} value is less than 0.0 or greater than 1.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * or the {@code fractions} are not provided in strictly increasing order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public RadialGradientPaint(float cx, float cy, float radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                               float fx, float fy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                               float[] fractions, Color[] colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                               CycleMethod cycleMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        this(new Point2D.Float(cx, cy),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
             radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
             new Point2D.Float(fx, fy),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
             fractions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
             colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
             cycleMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Constructs a {@code RadialGradientPaint} with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * {@code SRGB} color space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @param center the center point, in user space, of the circle defining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *               the gradient.  The last color of the gradient is mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *               to the perimeter of this circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @param radius the radius of the circle defining the extents of the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *               gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @param focus the point in user space to which the first color is mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @param fractions numbers ranging from 0.0 to 1.0 specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *                  distribution of colors along the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @param colors array of colors to use in the gradient. The first color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *               is used at the focus point, the last color around the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *               perimeter of the circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *                    or {@code REPEAT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @throws NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * if one of the points is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * or {@code fractions} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * or {@code colors} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * or {@code cycleMethod} is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * if {@code radius} is non-positive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * or {@code fractions.length != colors.length},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * or {@code colors} is less than 2 in size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * or a {@code fractions} value is less than 0.0 or greater than 1.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * or the {@code fractions} are not provided in strictly increasing order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public RadialGradientPaint(Point2D center, float radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                               Point2D focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                               float[] fractions, Color[] colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                               CycleMethod cycleMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        this(center,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
             radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
             focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
             fractions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
             colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
             cycleMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
             ColorSpaceType.SRGB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
             new AffineTransform());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Constructs a {@code RadialGradientPaint}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @param center the center point in user space of the circle defining the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *               gradient.  The last color of the gradient is mapped to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *               the perimeter of this circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @param radius the radius of the circle defining the extents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *               color gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @param focus the point in user space to which the first color is mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @param fractions numbers ranging from 0.0 to 1.0 specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *                  distribution of colors along the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @param colors array of colors to use in the gradient.  The first color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *               is used at the focus point, the last color around the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *               perimeter of the circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *                    or {@code REPEAT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @param colorSpace which color space to use for interpolation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *                   either {@code SRGB} or {@code LINEAR_RGB}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @param gradientTransform transform to apply to the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @throws NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * if one of the points is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * or {@code fractions} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * or {@code colors} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * or {@code cycleMethod} is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * or {@code colorSpace} is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * or {@code gradientTransform} is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * if {@code radius} is non-positive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * or {@code fractions.length != colors.length},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * or {@code colors} is less than 2 in size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * or a {@code fractions} value is less than 0.0 or greater than 1.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * or the {@code fractions} are not provided in strictly increasing order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public RadialGradientPaint(Point2D center,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                               float radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                               Point2D focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                               float[] fractions, Color[] colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                               CycleMethod cycleMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                               ColorSpaceType colorSpace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                               AffineTransform gradientTransform)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        super(fractions, colors, cycleMethod, colorSpace, gradientTransform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        // check input arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        if (center == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            throw new NullPointerException("Center point must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        if (focus == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            throw new NullPointerException("Focus point must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (radius <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            throw new IllegalArgumentException("Radius must be greater " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                                               "than zero");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        // copy parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        this.center = new Point2D.Double(center.getX(), center.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        this.focus = new Point2D.Double(focus.getX(), focus.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        this.radius = radius;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * Constructs a {@code RadialGradientPaint} with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * {@code SRGB} color space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * The gradient circle of the {@code RadialGradientPaint} is defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * by the given bounding box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * This constructor is a more convenient way to express the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * following (equivalent) code:<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *     double gw = gradientBounds.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *     double gh = gradientBounds.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *     double cx = gradientBounds.getCenterX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *     double cy = gradientBounds.getCenterY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *     Point2D center = new Point2D.Double(cx, cy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *     AffineTransform gradientTransform = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *     gradientTransform.translate(cx, cy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *     gradientTransform.scale(gw / 2, gh / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *     gradientTransform.translate(-cx, -cy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *     RadialGradientPaint gp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     *         new RadialGradientPaint(center, 1.0f, center,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *                                 fractions, colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *                                 cycleMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *                                 ColorSpaceType.SRGB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *                                 gradientTransform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @param gradientBounds the bounding box, in user space, of the circle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *                       defining the outermost extent of the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @param fractions numbers ranging from 0.0 to 1.0 specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *                  distribution of colors along the gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @param colors array of colors to use in the gradient.  The first color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *               is used at the focus point, the last color around the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *               perimeter of the circle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *                    or {@code REPEAT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @throws NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * if {@code gradientBounds} is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * or {@code fractions} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * or {@code colors} array is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * or {@code cycleMethod} is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * if {@code gradientBounds} is empty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * or {@code fractions.length != colors.length},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * or {@code colors} is less than 2 in size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * or a {@code fractions} value is less than 0.0 or greater than 1.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * or the {@code fractions} are not provided in strictly increasing order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    public RadialGradientPaint(Rectangle2D gradientBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                               float[] fractions, Color[] colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                               CycleMethod cycleMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        // gradient center/focal point is the center of the bounding box,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        // radius is set to 1.0, and then we set a scale transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        // to achieve an elliptical gradient defined by the bounding box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        this(new Point2D.Double(gradientBounds.getCenterX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                                gradientBounds.getCenterY()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
             1.0f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
             new Point2D.Double(gradientBounds.getCenterX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                                gradientBounds.getCenterY()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
             fractions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
             colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
             cycleMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
             ColorSpaceType.SRGB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
             createGradientTransform(gradientBounds));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        if (gradientBounds.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            throw new IllegalArgumentException("Gradient bounds must be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                                               "non-empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    private static AffineTransform createGradientTransform(Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        double cx = r.getCenterX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        double cy = r.getCenterY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        AffineTransform xform = AffineTransform.getTranslateInstance(cx, cy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        xform.scale(r.getWidth()/2, r.getHeight()/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        xform.translate(-cx, -cy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        return xform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    /**
436
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   546
     * Creates and returns a {@link PaintContext} used to
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   547
     * generate a circular radial color gradient pattern.
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   548
     * See the description of the {@link Paint#createContext createContext} method
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   549
     * for information on null parameter handling.
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   550
     *
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   551
     * @param cm the preferred {@link ColorModel} which represents the most convenient
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   552
     *           format for the caller to receive the pixel data, or {@code null}
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   553
     *           if there is no preference.
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   554
     * @param deviceBounds the device space bounding box
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   555
     *                     of the graphics primitive being rendered.
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   556
     * @param userBounds the user space bounding box
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   557
     *                   of the graphics primitive being rendered.
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   558
     * @param transform the {@link AffineTransform} from user
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   559
     *              space into device space.
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   560
     * @param hints the set of hints that the context object can use to
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   561
     *              choose between rendering alternatives.
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   562
     * @return the {@code PaintContext} for
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   563
     *         generating color patterns.
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   564
     * @see Paint
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   565
     * @see PaintContext
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   566
     * @see ColorModel
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   567
     * @see Rectangle
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   568
     * @see Rectangle2D
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   569
     * @see AffineTransform
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   570
     * @see RenderingHints
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    public PaintContext createContext(ColorModel cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                                      Rectangle deviceBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                                      Rectangle2D userBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                                      AffineTransform transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                      RenderingHints hints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        // avoid modifying the user's transform...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        transform = new AffineTransform(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        // incorporate the gradient transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        transform.concatenate(gradientTransform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        return new RadialGradientPaintContext(this, cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                              deviceBounds, userBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                                              transform, hints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                                              (float)center.getX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                                              (float)center.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                                              radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                                              (float)focus.getX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                                              (float)focus.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                                              fractions, colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                                              cycleMethod, colorSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * Returns a copy of the center point of the radial gradient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @return a {@code Point2D} object that is a copy of the center point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    public Point2D getCenterPoint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        return new Point2D.Double(center.getX(), center.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * Returns a copy of the end point of the gradient axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @return a {@code Point2D} object that is a copy of the focus point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    public Point2D getFocusPoint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        return new Point2D.Double(focus.getX(), focus.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * Returns the radius of the circle defining the radial gradient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @return the radius of the circle defining the radial gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public float getRadius() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        return radius;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
}