swingx
Version 2005-08-19

org.jdesktop.swingx.painter
Class CompoundPainter

java.lang.Object
  extended by org.jdesktop.swingx.JavaBean
      extended by org.jdesktop.swingx.painter.AbstractPainter
          extended by org.jdesktop.swingx.painter.CompoundPainter
All Implemented Interfaces:
Painter

public class CompoundPainter
extends AbstractPainter

A Painter implemention that contains an array of Painters, and executes them in order. This allows you to create a layered series of painters, similar to the layer design style in Photoshop or other image processing software.

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);
 


Constructor Summary
CompoundPainter()
          Creates a new instance of CompoundPainter
CompoundPainter(Painter... painters)
          Convenience constructor for creating a CompoundPainter for an array of painters.
 
Method Summary
 Painter[] getPainters()
           
 void paintBackground(Graphics2D g, JComponent component)
          Subclasses should implement this method and perform custom painting operations here.
 void setPainters(Painter... painters)
          Sets the array of Painters to use.
 
Methods inherited from class org.jdesktop.swingx.painter.AbstractPainter
getAlphaInterpolation, getAntialiasing, getClip, getColorRendering, getComposite, getDithering, getEffects, getFractionalMetrics, getInterpolation, getRendering, getRenderingHint, getRenderingHints, getResizeClip, getStrokeControl, getTextAntialiasing, isUseCache, paint, restoreState, saveState, setAlphaInterpolation, setAntialiasing, setClip, setColorRendering, setComposite, setDithering, setEffects, setEffects, setFractionalMetrics, setInterpolation, setRendering, setRenderingHint, setRenderingHints, setResizeClip, setStrokeControl, setTextAntialiasing, setUseCache
 
Methods inherited from class org.jdesktop.swingx.JavaBean
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, hasListeners, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompoundPainter

public CompoundPainter()
Creates a new instance of CompoundPainter


CompoundPainter

public CompoundPainter(Painter... painters)
Convenience constructor for creating a CompoundPainter for an array of painters. A defensive copy of the given array is made, so that future modification to the array does not result in changes to the CompoundPainter.

Parameters:
painters - array of painters, which will be painted in order
Method Detail

setPainters

public void setPainters(Painter... painters)
Sets the array of Painters to use. These painters will be executed in order. A null value will be treated as an empty array.

Parameters:
painters - array of painters, which will be painted in order

getPainters

public Painter[] getPainters()
Returns:
a defensive copy of the painters used by this CompoundPainter. This will never be null.

paintBackground

public void paintBackground(Graphics2D g,
                            JComponent component)
Description copied from class: AbstractPainter
Subclasses should implement this method and perform custom painting operations here. Common behavior, such as setting the clip and composite, saving and restoring state, is performed in the "paint" method automatically, and then delegated here.

Specified by:
paintBackground in class AbstractPainter
Parameters:
g - The Graphics2D object in which to paint
component - The JComponent that the Painter is delegate for.

swingx
Version 2005-08-19