LinearGradientPaint.java revision 3724
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * This code is free software; you can redistribute it and/or modify it
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * under the terms of the GNU General Public License version 2 only, as
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * published by the Free Software Foundation. Oracle designates this
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * particular file as subject to the "Classpath" exception as provided
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * by Oracle in the LICENSE file that accompanied this code.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * This code is distributed in the hope that it will be useful, but WITHOUT
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * version 2 for more details (a copy is included in the LICENSE file that
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * accompanied this code).
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * You should have received a copy of the GNU General Public License version
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * 2 along with this work; if not, write to the Free Software Foundation,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * or visit www.oracle.com if you need additional information or have any
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * questions.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * The {@code LinearGradientPaint} class provides a way to fill
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * a {@link java.awt.Shape} with a linear color gradient pattern. The user
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * may specify two or more gradient colors, and this paint will provide an
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * interpolation between each color. The user also specifies start and end
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * points which define where in user space the color gradient should begin
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * and end.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * The user must provide an array of floats specifying how to distribute the
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * colors along the gradient. These values should range from 0.0 to 1.0 and
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * act like keyframes along the gradient (they mark where the gradient should
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * be exactly a particular color).
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * In the event that the user does not set the first keyframe value equal
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * to 0 and/or the last keyframe value equal to 1, keyframes will be created
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * at these positions and the first and last colors will be replicated there.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * So, if a user specifies the following arrays to construct a gradient:<br>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * {Color.BLUE, Color.RED}, {.3f, .7f}
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * this will be converted to a gradient with the following keyframes:<br>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * {Color.BLUE, Color.BLUE, Color.RED, Color.RED}, {0f, .3f, .7f, 1f}
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * The user may also select what action the {@code LinearGradientPaint} object
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * takes when it is filling the space outside the start and end points by
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * setting {@code CycleMethod} to either {@code REFLECTION} or {@code REPEAT}.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * The distances between any two colors in any of the reflected or repeated
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * copies of the gradient are the same as the distance between those same two
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * colors between the start and end points.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Note that some minor variations in distances may occur due to sampling at
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * the granularity of a pixel.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * If no cycle method is specified, {@code NO_CYCLE} will be chosen by
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * default, which means the endpoint colors will be used to fill the
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * remaining area.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * The colorSpace parameter allows the user to specify in which colorspace
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * the interpolation should be performed, default sRGB or linearized RGB.
28c9d384aa958b321280b4ac886941dcad25396bnd * The following code demonstrates typical usage of
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * {@code LinearGradientPaint}:
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Point2D start = new Point2D.Float(0, 0);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Point2D end = new Point2D.Float(50, 50);
* <img src = "doc-files/LinearGradientPaint.png">
new AffineTransform());
@ConstructorProperties({ "startPoint", "endPoint", "fractions", "colors", "cycleMethod", "colorSpace", "transform" })
cyclic);