|
swingx Version 2005-08-19 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Painter<T extends JComponent>
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
Method Summary | |
---|---|
void |
paint(Graphics2D g,
T component)
Paints on the given Graphics2D object some effect which may or may not be related to the given component. |
Method Detail |
---|
void paint(Graphics2D g, T component)
Paints on the given Graphics2D object some effect which may or may not be related to the given component. For example, BackgroundPainter will use the background property of the component and the width/height of the component to perform a fill rect. Most other Painters will disregard the component entirely, except to get the component width/height.
The Graphics2D object must be returned to the same state it started at by the end of the method. For example, if "setColor(c)" was called on the graphics object, it should be reset to the original color before the method returns.
g
- The Graphics2D object in which to paintcomponent
- The JComponent that the Painter is delegate for.
|
swingx Version 2005-08-19 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |