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