jdk/src/share/classes/java/awt/GradientPaint.java
author henryjen
Tue, 10 Jun 2014 16:18:54 -0700
changeset 24865 09b1d992ca72
parent 7006 05505fff1342
permissions -rw-r--r--
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo Reviewed-by: mduigou, lancea, alanb, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7006
05505fff1342 4358979: javax.swing.border should have a DashedBorder
malenkov
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2010, 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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.image.ColorModel;
7006
05505fff1342 4358979: javax.swing.border should have a DashedBorder
malenkov
parents: 5506
diff changeset
    32
import java.beans.ConstructorProperties;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * The <code>GradientPaint</code> class provides a way to fill
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * a {@link Shape} with a linear color gradient pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * If {@link Point} P1 with {@link Color} C1 and <code>Point</code> P2 with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <code>Color</code> C2 are specified in user space, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <code>Color</code> on the P1, P2 connecting line is proportionally
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * changed from C1 to C2.  Any point P not on the extended P1, P2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * connecting line has the color of the point P' that is the perpendicular
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * projection of P on the extended P1, P2 connecting line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Points on the extended line outside of the P1, P2 segment can be colored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * in one of two ways.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * If the gradient is cyclic then the points on the extended P1, P2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * connecting line cycle back and forth between the colors C1 and C2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * If the gradient is acyclic then points on the P1 side of the segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * have the constant <code>Color</code> C1 while points on the P2 side
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * have the constant <code>Color</code> C2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see Paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see Graphics2D#setPaint
436
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
    57
 * @version 10 Feb 1997
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class GradientPaint implements Paint {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    Point2D.Float p1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    Point2D.Float p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    Color color1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    Color color2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    boolean cyclic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Constructs a simple acyclic <code>GradientPaint</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @param x1 x coordinate of the first specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * <code>Point</code> in user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param y1 y coordinate of the first specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * <code>Point</code> in user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param color1 <code>Color</code> at the first specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param x2 x coordinate of the second specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <code>Point</code> in user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param y2 y coordinate of the second specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * <code>Point</code> in user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param color2 <code>Color</code> at the second specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @throws NullPointerException if either one of colors is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public GradientPaint(float x1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                         float y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                         Color color1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                         float x2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                         float y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                         Color color2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if ((color1 == null) || (color2 == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            throw new NullPointerException("Colors cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        p1 = new Point2D.Float(x1, y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        p2 = new Point2D.Float(x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        this.color1 = color1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        this.color2 = color2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Constructs a simple acyclic <code>GradientPaint</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param pt1 the first specified <code>Point</code> in user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param color1 <code>Color</code> at the first specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param pt2 the second specified <code>Point</code> in user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param color2 <code>Color</code> at the second specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @throws NullPointerException if either one of colors or points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public GradientPaint(Point2D pt1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                         Color color1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                         Point2D pt2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                         Color color2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if ((color1 == null) || (color2 == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            (pt1 == null) || (pt2 == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throw new NullPointerException("Colors and points should be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        p1 = new Point2D.Float((float)pt1.getX(), (float)pt1.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        p2 = new Point2D.Float((float)pt2.getX(), (float)pt2.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.color1 = color1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.color2 = color2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Constructs either a cyclic or acyclic <code>GradientPaint</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * object depending on the <code>boolean</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param x1 x coordinate of the first specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <code>Point</code> in user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param y1 y coordinate of the first specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <code>Point</code> in user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param color1 <code>Color</code> at the first specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param x2 x coordinate of the second specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <code>Point</code> in user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param y2 y coordinate of the second specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * <code>Point</code> in user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param color2 <code>Color</code> at the second specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param cyclic <code>true</code> if the gradient pattern should cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * repeatedly between the two colors; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public GradientPaint(float x1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                         float y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                         Color color1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                         float x2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                         float y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                         Color color2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                         boolean cyclic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        this (x1, y1, color1, x2, y2, color2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this.cyclic = cyclic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Constructs either a cyclic or acyclic <code>GradientPaint</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * object depending on the <code>boolean</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param pt1 the first specified <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * in user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param color1 <code>Color</code> at the first specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param pt2 the second specified <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * in user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param color2 <code>Color</code> at the second specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param cyclic <code>true</code> if the gradient pattern should cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * repeatedly between the two colors; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @throws NullPointerException if either one of colors or points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
7006
05505fff1342 4358979: javax.swing.border should have a DashedBorder
malenkov
parents: 5506
diff changeset
   170
    @ConstructorProperties({ "point1", "color1", "point2", "color2", "cyclic" })
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public GradientPaint(Point2D pt1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                         Color color1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                         Point2D pt2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                         Color color2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                         boolean cyclic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        this (pt1, color1, pt2, color2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        this.cyclic = cyclic;
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
     * Returns a copy of the point P1 that anchors the first color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @return a {@link Point2D} object that is a copy of the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * that anchors the first color of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <code>GradientPaint</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public Point2D getPoint1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return new Point2D.Float(p1.x, p1.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Returns the color C1 anchored by the point P1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @return a <code>Color</code> object that is the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * anchored by P1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public Color getColor1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return color1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Returns a copy of the point P2 which anchors the second color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @return a {@link Point2D} object that is a copy of the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * that anchors the second color of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * <code>GradientPaint</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public Point2D getPoint2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return new Point2D.Float(p2.x, p2.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Returns the color C2 anchored by the point P2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return a <code>Color</code> object that is the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * anchored by P2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public Color getColor2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return color2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Returns <code>true</code> if the gradient cycles repeatedly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * between the two colors C1 and C2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @return <code>true</code> if the gradient cycles repeatedly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * between the two colors; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public boolean isCyclic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return cyclic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
436
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   229
     * 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
   230
     * generate a linear 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
   231
     * See the {@link Paint#createContext specification} of the
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   232
     * method in the {@link Paint} interface for information
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   233
     * 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
   234
     *
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   235
     * @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
   236
     *           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
   237
     *           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
   238
     * @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
   239
     *                     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
   240
     * @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
   241
     *                   of the graphics primitive being rendered.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param xform the {@link AffineTransform} from user
436
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   243
     *              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
   244
     * @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
   245
     *              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
   246
     * @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
   247
     *         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
   248
     * @see Paint
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @see PaintContext
436
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   250
     * @see ColorModel
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   251
     * @see Rectangle
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   252
     * @see Rectangle2D
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   253
     * @see AffineTransform
1cc586a58a3e 6573289: api/java_awt/Color/index.html#CreateContextTesttestCase4,5,6,7 fail since JDK 7 b14
dav
parents: 2
diff changeset
   254
     * @see RenderingHints
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public PaintContext createContext(ColorModel cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                      Rectangle deviceBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                      Rectangle2D userBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                      AffineTransform xform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                      RenderingHints hints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return new GradientPaintContext(cm, p1, p2, xform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                                        color1, color2, cyclic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Returns the transparency mode for this <code>GradientPaint</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @return an integer value representing this <code>GradientPaint</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * object's transparency mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @see Transparency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public int getTransparency() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        int a1 = color1.getAlpha();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        int a2 = color2.getAlpha();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return (((a1 & a2) == 0xff) ? OPAQUE : TRANSLUCENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
}