MultipleGradientPaintpublic abstract class MultipleGradientPaint extends Object implements PaintThis is the superclass for Paints which use a multiple color
gradient to fill in their raster. It provides storage for variables and
enumerated values common to
{@code LinearGradientPaint} and {@code RadialGradientPaint}. |
Fields Summary |
---|
final int | transparencyThe transparency of this paint object. | final float[] | fractionsGradient keyframe values in the range 0 to 1. | final Color[] | colorsGradient colors. | final AffineTransform | gradientTransformTransform to apply to gradient. | final CycleMethod | cycleMethodThe method to use when painting outside the gradient bounds. | final ColorSpaceType | colorSpaceThe color space in which to perform the gradient interpolation. | ColorModel | modelThe following fields are used only by MultipleGradientPaintContext
to cache certain values that remain constant and do not need to be
recalculated for each context created from this paint instance. | float[] | normalizedIntervals | boolean | isSimpleLookup | SoftReference | gradients | SoftReference | gradient | int | fastGradientArraySize |
Constructors Summary |
---|
MultipleGradientPaint(float[] fractions, Color[] colors, CycleMethod cycleMethod, ColorSpaceType colorSpace, AffineTransform gradientTransform)Package-private constructor.
if (fractions == null) {
throw new NullPointerException("Fractions array cannot be null");
}
if (colors == null) {
throw new NullPointerException("Colors array cannot be null");
}
if (cycleMethod == null) {
throw new NullPointerException("Cycle method cannot be null");
}
if (colorSpace == null) {
throw new NullPointerException("Color space cannot be null");
}
if (gradientTransform == null) {
throw new NullPointerException("Gradient transform cannot be "+
"null");
}
if (fractions.length != colors.length) {
throw new IllegalArgumentException("Colors and fractions must " +
"have equal size");
}
if (colors.length < 2) {
throw new IllegalArgumentException("User must specify at least " +
"2 colors");
}
// check that values are in the proper range and progress
// in increasing order from 0 to 1
float previousFraction = -1.0f;
for (float currentFraction : fractions) {
if (currentFraction < 0f || currentFraction > 1f) {
throw new IllegalArgumentException("Fraction values must " +
"be in the range 0 to 1: " +
currentFraction);
}
if (currentFraction <= previousFraction) {
throw new IllegalArgumentException("Keyframe fractions " +
"must be increasing: " +
currentFraction);
}
previousFraction = currentFraction;
}
// We have to deal with the cases where the first gradient stop is not
// equal to 0 and/or the last gradient stop is not equal to 1.
// In both cases, create a new point and replicate the previous
// extreme point's color.
boolean fixFirst = false;
boolean fixLast = false;
int len = fractions.length;
int off = 0;
if (fractions[0] != 0f) {
// first stop is not equal to zero, fix this condition
fixFirst = true;
len++;
off++;
}
if (fractions[fractions.length-1] != 1f) {
// last stop is not equal to one, fix this condition
fixLast = true;
len++;
}
this.fractions = new float[len];
System.arraycopy(fractions, 0, this.fractions, off, fractions.length);
this.colors = new Color[len];
System.arraycopy(colors, 0, this.colors, off, colors.length);
if (fixFirst) {
this.fractions[0] = 0f;
this.colors[0] = colors[0];
}
if (fixLast) {
this.fractions[len-1] = 1f;
this.colors[len-1] = colors[colors.length - 1];
}
// copy some flags
this.colorSpace = colorSpace;
this.cycleMethod = cycleMethod;
// copy the gradient transform
this.gradientTransform = new AffineTransform(gradientTransform);
// determine transparency
boolean opaque = true;
for (int i = 0; i < colors.length; i++){
opaque = opaque && (colors[i].getAlpha() == 0xff);
}
this.transparency = opaque ? OPAQUE : TRANSLUCENT;
|
Methods Summary |
---|
public final java.awt.MultipleGradientPaint$ColorSpaceType | getColorSpace()Returns the enumerated type which specifies color space for
interpolation.
return colorSpace;
| public final java.awt.Color[] | getColors()Returns a copy of the array of colors used by this gradient.
The first color maps to the first value in the fractions array,
and the last color maps to the last value in the fractions array.
return Arrays.copyOf(colors, colors.length);
| public final java.awt.MultipleGradientPaint$CycleMethod | getCycleMethod()Returns the enumerated type which specifies cycling behavior.
return cycleMethod;
| public final float[] | getFractions()Returns a copy of the array of floats used by this gradient
to calculate color distribution.
The returned array always has 0 as its first value and 1 as its
last value, with increasing values in between.
return Arrays.copyOf(fractions, fractions.length);
| public final java.awt.geom.AffineTransform | getTransform()Returns a copy of the transform applied to the gradient.
return new AffineTransform(gradientTransform);
| public final int | getTransparency()Returns the transparency mode for this Paint object.
return transparency;
|
|