APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt

pack-priv final Class RadialGradientPaintContext

extends MultipleGradientPaintContext
Class Inheritance
Imports
java.awt.MultipleGradientPaint.CycleMethod, .MultipleGradientPaint.ColorSpaceType, java.awt.geom.AffineTransform, .Rectangle2D, java.awt.image.ColorModel

Provides the actual implementation for the RadialGradientPaint. This is where the pixel processing is done. A RadialGradientPaint only supports circular gradients, but it should be possible to scale the circle to look approximately elliptical, by means of a gradient transform passed into the RadialGradientPaint constructor.
Author
Nicholas Talian, Vincent Hardy, Jim Graham, Jerry Evans

Field Summary

Modifier and TypeField and Description
private float
centerX

Variables representing center and focus points.

private float
centerY

Variables representing center and focus points.

private float
constA

Constant part of X, Y user space coordinates.

private float
constB

Constant part of X, Y user space coordinates.

private float
focusX

Variables representing center and focus points.

private float
focusY

Variables representing center and focus points.

private float
gDeltaDelta

Constant second order delta for simple loop.

private boolean
isNonCyclic

True when (cycleMethod == NO_CYCLE).

private boolean
isSimpleFocus

True when (focus == center).

private float
radius

Radius of the outermost circle defining the 100% gradient stop.

private float
radiusSq

Radius of the gradient circle squared.

private static final float
SCALEBACK

Amount for offset when clamping focus.

private static final int
private static float[]
private float
trivial

This value represents the solution when focusX == X.

Inherited from java.awt.MultipleGradientPaintContext:
a00a01a02a10a11a12cachedcachedModelcolorSpacecycleMethodfastGradientArraySizegradientGRADIENT_SIZEGRADIENT_SIZE_INDEXisSimpleLookupmodelsaved

Constructor Summary

AccessConstructor and Description
pack-priv
RadialGradientPaintContext(RadialGradientPaint
the RadialGradientPaint from which this context is created
paint
,
ColorModel
the ColorModel that receives the Paint data (this is used only as a hint)
cm
,
Rectangle
the device space bounding box of the graphics primitive being rendered
deviceBounds
,
Rectangle2D
the user space bounding box of the graphics primitive being rendered
userBounds
,
AffineTransform
the AffineTransform from user space into device space (gradientTransform should be concatenated with this)
t
,
RenderingHints
the hints that the context object uses to choose between rendering alternatives
hints
,
float
the center X coordinate in user space of the circle defining the gradient. The last color of the gradient is mapped to the perimeter of this circle.
cx
,
float
the center Y coordinate in user space of the circle defining the gradient. The last color of the gradient is mapped to the perimeter of this circle.
cy
,
float
the radius of the circle defining the extents of the color gradient
r
,
float
the X coordinate in user space to which the first color is mapped
fx
,
float
the Y coordinate in user space to which the first color is mapped
fy
,
float[]
the fractions specifying the gradient distribution
fractions
,
Color[]
the gradient colors
colors
,
MultipleGradientPaint.CycleMethod
either NO_CYCLE, REFLECT, or REPEAT
cycleMethod
,
MultipleGradientPaint.ColorSpaceType
which colorspace to use for interpolation, either SRGB or LINEAR_RGB
colorSpace
)

Constructor for RadialGradientPaintContext.

Method Summary

Modifier and TypeMethod and Description
private void
cyclicCircularGradientFillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)

Fill the raster, cycling the gradient colors when a point falls outside of the perimeter of the 100% stop circle.

protected void
fillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)

Implements abstract java.awt.MultipleGradientPaintContext.fillRaster.

Return a Raster containing the colors generated for the graphics operation.

private void
simpleNonCyclicFillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)

This code works in the simplest of cases, where the focus == center point, the gradient is noncyclic, and the gradient lookup method is fast (single array index, no conversion necessary).

Inherited from java.awt.MultipleGradientPaintContext:
disposegetColorModelgetRasterindexIntoGradientsArrays

Field Detail

centerXback to summary
private float centerX

Variables representing center and focus points.

centerYback to summary
private float centerY

Variables representing center and focus points.

constAback to summary
private float constA

Constant part of X, Y user space coordinates.

constBback to summary
private float constB

Constant part of X, Y user space coordinates.

focusXback to summary
private float focusX

Variables representing center and focus points.

focusYback to summary
private float focusY

Variables representing center and focus points.

gDeltaDeltaback to summary
private float gDeltaDelta

Constant second order delta for simple loop.

isNonCyclicback to summary
private boolean isNonCyclic

True when (cycleMethod == NO_CYCLE).

isSimpleFocusback to summary
private boolean isSimpleFocus

True when (focus == center).

radiusback to summary
private float radius

Radius of the outermost circle defining the 100% gradient stop.

radiusSqback to summary
private float radiusSq

Radius of the gradient circle squared.

SCALEBACKback to summary
private static final float SCALEBACK

Amount for offset when clamping focus.

SQRT_LUT_SIZEback to summary
private static final int SQRT_LUT_SIZE
sqrtLutback to summary
private static float[] sqrtLut
trivialback to summary
private float trivial

This value represents the solution when focusX == X. It is called trivial because it is easier to calculate than the general case.

Constructor Detail

RadialGradientPaintContextback to summary
pack-priv RadialGradientPaintContext(RadialGradientPaint paint, ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform t, RenderingHints hints, float cx, float cy, float r, float fx, float fy, float[] fractions, Color[] colors, MultipleGradientPaint.CycleMethod cycleMethod, MultipleGradientPaint.ColorSpaceType colorSpace)

Constructor for RadialGradientPaintContext.

Parameters
paint:RadialGradientPaint

the RadialGradientPaint from which this context is created

cm:ColorModel

the ColorModel that receives the Paint data (this is used only as a hint)

deviceBounds:Rectangle

the device space bounding box of the graphics primitive being rendered

userBounds:Rectangle2D

the user space bounding box of the graphics primitive being rendered

t:AffineTransform

the AffineTransform from user space into device space (gradientTransform should be concatenated with this)

hints:RenderingHints

the hints that the context object uses to choose between rendering alternatives

cx:float

the center X coordinate in user space of the circle defining the gradient. The last color of the gradient is mapped to the perimeter of this circle.

cy:float

the center Y coordinate in user space of the circle defining the gradient. The last color of the gradient is mapped to the perimeter of this circle.

r:float

the radius of the circle defining the extents of the color gradient

fx:float

the X coordinate in user space to which the first color is mapped

fy:float

the Y coordinate in user space to which the first color is mapped

fractions:float[]

the fractions specifying the gradient distribution

colors:Color[]

the gradient colors

cycleMethod:MultipleGradientPaint.CycleMethod

either NO_CYCLE, REFLECT, or REPEAT

colorSpace:MultipleGradientPaint.ColorSpaceType

which colorspace to use for interpolation, either SRGB or LINEAR_RGB

Method Detail

cyclicCircularGradientFillRasterback to summary
private void cyclicCircularGradientFillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)

Fill the raster, cycling the gradient colors when a point falls outside of the perimeter of the 100% stop circle. This calculation first computes the intersection point of the line from the focus through the current point in the raster, and the perimeter of the gradient circle. Then it determines the percentage distance of the current point along that line (focus is 0%, perimeter is 100%). Equation of a circle centered at (a,b) with radius r: (x-a)^2 + (y-b)^2 = r^2 Equation of a line with slope m and y-intercept b: y = mx + b Replacing y in the circle equation and solving using the quadratic formula produces the following set of equations. Constant factors have been extracted out of the inner loop.

fillRasterback to summary
protected void fillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)

Implements abstract java.awt.MultipleGradientPaintContext.fillRaster.

Return a Raster containing the colors generated for the graphics operation.

simpleNonCyclicFillRasterback to summary
private void simpleNonCyclicFillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)

This code works in the simplest of cases, where the focus == center point, the gradient is noncyclic, and the gradient lookup method is fast (single array index, no conversion necessary).