Simple API for delegating painting. The JXPanel supports using this class
as a delegate for painting the background of the panel. This allows developers
to be able to customize the background painting of a JXPanel without having
to override it. Since many components within SwingX extend JXPanel, the
developer can implement custom painting on many parts of SwingX.
Painters are generally expected to work with JComponent or one of its
subclasses. Most painters don't use the component beyond requesting its width
and height, but it is conceivable that certain painters will only work with
specific subclasses (JXTitledPanel, for instance, so that the text can
be extracted and used to paint a glow effect).
Painters can be combined together by using the CompoundPainter. CompoundPainter
uses an array to store several painters, and the order in which they should be
painted.
For example, if I want to create a CompoundPainter that started with a blue
background, had pinstripes on it running at a 45 degree angle, and those
pinstripes appeared to "fade in" from left to right, I would write the following:
Color blue = new Color(0x417DDD);
Color translucent = new Color(blue.getRed(), blue.getGreen(), blue.getBlue(), 0);
panel.setBackground(blue);
panel.setForeground(Color.LIGHT_GRAY);
GradientPaint blueToTranslucent = new GradientPaint(
new Point2D.Double(.4, 0),
blue,
new Point2D.Double(1, 0),
translucent);
Painter veil = new BasicGradientPainter(blueToTranslucent);
Painter pinstripes = new PinstripePainter(45);
Painter backgroundPainter = new BackgroundPainter();
Painter p = new CompoundPainter(backgroundPainter, pinstripes, veil);
panel.setBackgroundPainter(p);
For convenience, AbstractPainter handles some basic painting chores and
should be extended for most concrete Painter implementations
author: rbair |