| An abstract base class from which the various gradient oriented painter
classes extend. Gradient based painters perform an important task beyond what
a MattePainter with a GradientPaint will do -- they resize the gradient to
fit the Component regardless of its dimensions.
AbstractGradientPainter has a resize property of type Resize that specifies
whether the gradient should be resized horizontally, vertically, in both directions
or not at all (in which case you should really probably be using MattePainter).
Subclasses must implement calculateSizedPaint to return a new gradient paint
instance that is resized in the proper ways. If no Paint is returned from
this method call, then nothing is painted.
By default, the resize property is set to BOTH.
In order for resizing to work properly with GradientPaint, LinearGradientPaint,
and RadialGradientPaint, it is necessary that the various control points used in
these paints be specified in such a manner that they can be reliably resized.
For example, BasicGradientPainter takes GradientPaints who's point1 and point2
properties are specified between 0 and 1, representing at what percentage of
the distance from the origin the gradient begins and ends. Thus, if I created
a GradientPaint like this:
GradientPaint gp = new GradientPaint(
new Point2D.Double(.2d, 0),
Color.BLUE,
new Point2D.Double(.8d, 0),
Color.WHITE);
then when painted, the gradient will start with a BLUE at 20% of the width of
the component, and finish with WHITE at 80% of the width of the component.
See the various subclasses for more detailed examples.
author: rbair |