1 /*
2 * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
62 * <p>
63 * In the event that the user does not set the first keyframe value equal
64 * to 0 and/or the last keyframe value equal to 1, keyframes will be created
65 * at these positions and the first and last colors will be replicated there.
66 * So, if a user specifies the following arrays to construct a gradient:<br>
67 * <pre>
68 * {Color.BLUE, Color.RED}, {.3f, .7f}
69 * </pre>
70 * this will be converted to a gradient with the following keyframes:<br>
71 * <pre>
72 * {Color.BLUE, Color.BLUE, Color.RED, Color.RED}, {0f, .3f, .7f, 1f}
73 * </pre>
74 *
75 * <p>
76 * The user may also select what action the {@code RadialGradientPaint} object
77 * takes when it is filling the space outside the circle's radius by
78 * setting {@code CycleMethod} to either {@code REFLECTION} or {@code REPEAT}.
79 * The gradient color proportions are equal for any particular line drawn
80 * from the focus point. The following figure shows that the distance AB
81 * is equal to the distance BC, and the distance AD is equal to the distance DE.
82 * <center>
83 * <img src = "doc-files/RadialGradientPaint-3.png" alt="image showing the
84 * distance AB=BC, and AD=DE">
85 * </center>
86 * If the gradient and graphics rendering transforms are uniformly scaled and
87 * the user sets the focus so that it coincides with the center of the circle,
88 * the gradient color proportions are equal for any line drawn from the center.
89 * The following figure shows the distances AB, BC, AD, and DE. They are all equal.
90 * <center>
91 * <img src = "doc-files/RadialGradientPaint-4.png" alt="image showing the
92 * distance of AB, BC, AD, and DE are all equal">
93 * </center>
94 * Note that some minor variations in distances may occur due to sampling at
95 * the granularity of a pixel.
96 * If no cycle method is specified, {@code NO_CYCLE} will be chosen by
97 * default, which means the last keyframe color will be used to fill the
98 * remaining area.
99 * <p>
100 * The colorSpace parameter allows the user to specify in which colorspace
101 * the interpolation should be performed, default sRGB or linearized RGB.
102 *
103 * <p>
104 * The following code demonstrates typical usage of
105 * {@code RadialGradientPaint}, where the center and focus points are
106 * the same:
107 * <pre>
108 * Point2D center = new Point2D.Float(50, 50);
109 * float radius = 25;
110 * float[] dist = {0.0f, 0.2f, 1.0f};
111 * Color[] colors = {Color.RED, Color.WHITE, Color.BLUE};
112 * RadialGradientPaint p =
113 * new RadialGradientPaint(center, radius, dist, colors);
114 * </pre>
115 *
116 * <p>
117 * This image demonstrates the example code above, with default
118 * (centered) focus for each of the three cycle methods:
119 * <center>
120 * <img src = "doc-files/RadialGradientPaint-1.png" alt="image showing the
121 * output of the sameple code">
122 * </center>
123 *
124 * <p>
125 * It is also possible to specify a non-centered focus point, as
126 * in the following code:
127 * <pre>
128 * Point2D center = new Point2D.Float(50, 50);
129 * float radius = 25;
130 * Point2D focus = new Point2D.Float(40, 40);
131 * float[] dist = {0.0f, 0.2f, 1.0f};
132 * Color[] colors = {Color.RED, Color.WHITE, Color.BLUE};
133 * RadialGradientPaint p =
134 * new RadialGradientPaint(center, radius, focus,
135 * dist, colors,
136 * CycleMethod.NO_CYCLE);
137 * </pre>
138 *
139 * <p>
140 * This image demonstrates the previous example code, with non-centered
141 * focus for each of the three cycle methods:
142 * <center>
143 * <img src = "doc-files/RadialGradientPaint-2.png" alt="image showing the
144 * output of the sample code">
145 * </center>
146 *
147 * @see java.awt.Paint
148 * @see java.awt.Graphics2D#setPaint
149 * @author Nicholas Talian, Vincent Hardy, Jim Graham, Jerry Evans
150 * @since 1.6
151 */
152 public final class RadialGradientPaint extends MultipleGradientPaint {
153
154 /** Focus point which defines the 0% gradient stop X coordinate. */
155 private final Point2D focus;
156
157 /** Center of the circle defining the 100% gradient stop X coordinate. */
158 private final Point2D center;
159
160 /** Radius of the outermost circle defining the 100% gradient stop. */
161 private final float radius;
162
163 /**
164 * Constructs a {@code RadialGradientPaint} with a default
165 * {@code NO_CYCLE} repeating method and {@code SRGB} color space,
|
1 /*
2 * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
62 * <p>
63 * In the event that the user does not set the first keyframe value equal
64 * to 0 and/or the last keyframe value equal to 1, keyframes will be created
65 * at these positions and the first and last colors will be replicated there.
66 * So, if a user specifies the following arrays to construct a gradient:<br>
67 * <pre>
68 * {Color.BLUE, Color.RED}, {.3f, .7f}
69 * </pre>
70 * this will be converted to a gradient with the following keyframes:<br>
71 * <pre>
72 * {Color.BLUE, Color.BLUE, Color.RED, Color.RED}, {0f, .3f, .7f, 1f}
73 * </pre>
74 *
75 * <p>
76 * The user may also select what action the {@code RadialGradientPaint} object
77 * takes when it is filling the space outside the circle's radius by
78 * setting {@code CycleMethod} to either {@code REFLECTION} or {@code REPEAT}.
79 * The gradient color proportions are equal for any particular line drawn
80 * from the focus point. The following figure shows that the distance AB
81 * is equal to the distance BC, and the distance AD is equal to the distance DE.
82 * <p style="text-align:center">
83 * <img src = "doc-files/RadialGradientPaint-3.png" alt="image showing the
84 * distance AB=BC, and AD=DE">
85 * <p>
86 * If the gradient and graphics rendering transforms are uniformly scaled and
87 * the user sets the focus so that it coincides with the center of the circle,
88 * the gradient color proportions are equal for any line drawn from the center.
89 * The following figure shows the distances AB, BC, AD, and DE. They are all equal.
90 * <p style="text-align:center">
91 * <img src = "doc-files/RadialGradientPaint-4.png" alt="image showing the
92 * distance of AB, BC, AD, and DE are all equal">
93 * <p>
94 * Note that some minor variations in distances may occur due to sampling at
95 * the granularity of a pixel.
96 * If no cycle method is specified, {@code NO_CYCLE} will be chosen by
97 * default, which means the last keyframe color will be used to fill the
98 * remaining area.
99 * <p>
100 * The colorSpace parameter allows the user to specify in which colorspace
101 * the interpolation should be performed, default sRGB or linearized RGB.
102 *
103 * <p>
104 * The following code demonstrates typical usage of
105 * {@code RadialGradientPaint}, where the center and focus points are
106 * the same:
107 * <pre>
108 * Point2D center = new Point2D.Float(50, 50);
109 * float radius = 25;
110 * float[] dist = {0.0f, 0.2f, 1.0f};
111 * Color[] colors = {Color.RED, Color.WHITE, Color.BLUE};
112 * RadialGradientPaint p =
113 * new RadialGradientPaint(center, radius, dist, colors);
114 * </pre>
115 *
116 * <p>
117 * This image demonstrates the example code above, with default
118 * (centered) focus for each of the three cycle methods:
119 * <p style="text-align:center">
120 * <img src = "doc-files/RadialGradientPaint-1.png" alt="image showing the
121 * output of the sameple code">
122 * <p>
123 * It is also possible to specify a non-centered focus point, as
124 * in the following code:
125 * <pre>
126 * Point2D center = new Point2D.Float(50, 50);
127 * float radius = 25;
128 * Point2D focus = new Point2D.Float(40, 40);
129 * float[] dist = {0.0f, 0.2f, 1.0f};
130 * Color[] colors = {Color.RED, Color.WHITE, Color.BLUE};
131 * RadialGradientPaint p =
132 * new RadialGradientPaint(center, radius, focus,
133 * dist, colors,
134 * CycleMethod.NO_CYCLE);
135 * </pre>
136 *
137 * <p>
138 * This image demonstrates the previous example code, with non-centered
139 * focus for each of the three cycle methods:
140 * <p style="text-align:center">
141 * <img src = "doc-files/RadialGradientPaint-2.png" alt="image showing the
142 * output of the sample code">
143 *
144 * @see java.awt.Paint
145 * @see java.awt.Graphics2D#setPaint
146 * @author Nicholas Talian, Vincent Hardy, Jim Graham, Jerry Evans
147 * @since 1.6
148 */
149 public final class RadialGradientPaint extends MultipleGradientPaint {
150
151 /** Focus point which defines the 0% gradient stop X coordinate. */
152 private final Point2D focus;
153
154 /** Center of the circle defining the 100% gradient stop X coordinate. */
155 private final Point2D center;
156
157 /** Radius of the outermost circle defining the 100% gradient stop. */
158 private final float radius;
159
160 /**
161 * Constructs a {@code RadialGradientPaint} with a default
162 * {@code NO_CYCLE} repeating method and {@code SRGB} color space,
|