swingx
Version 2005-08-19

org.jdesktop.swingx.painter
Class CheckerboardPainter

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

public class CheckerboardPainter
extends AbstractPainter

A Painter implementation that paints a checkerboard pattern. The light and dark colors (Paint instances) are configurable, as are the size of the squares (squareLength).

To configure a checkerboard pattern that used a gradient for the dark tiles and Color.WHITE for the light tiles, you could:


  GradientPaint gp = new GradientPaint(
      new Point2D.Double(0, 0),
      Color.BLACK,
      new Point2D.Double(0, 32),
      Color.GRAY);
  CheckerboardPainter p = new CheckerboardPainter();
  p.setDarkPaint(gp);
  p.setLightPaint(Color.WHITE);
  p.setSquareLength(32);
  panel.seBackgroundPainter(p);
 

Note that in this example, the "32" in the GradientPaint matches the "32" set for the squareLength. This is necessary because GradientPaints don't readjust themselves for the size of the square. They are fixed and immutable at the time of creation.


Constructor Summary
CheckerboardPainter()
          Create a new CheckerboardPainter.
CheckerboardPainter(Paint darkPaint, Paint lightPaint)
          Create a new CheckerboardPainter with the specified light and dark paints.
CheckerboardPainter(Paint darkPaint, Paint lightPaint, int length)
          Create a new CheckerboardPainter with the specified light and dark paints and the specified square size.
 
Method Summary
 Paint getDarkPaint()
           
 Paint getLightPaint()
           
 int getSquareLength()
           
 void paintBackground(Graphics2D g, JComponent component)
          Subclasses should implement this method and perform custom painting operations here.
 void setDarkPaint(Paint color)
          Specifies the paint to use for dark tiles.
 void setLightPaint(Paint color)
          Specifies the paint to use for light tiles.
 void setSquareLength(int length)
          Specifies the length of the squares.
 
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

CheckerboardPainter

public CheckerboardPainter()
Create a new CheckerboardPainter. By default the light color is Color.WHITE, the dark color is a light gray, and the square length is 8.


CheckerboardPainter

public CheckerboardPainter(Paint darkPaint,
                           Paint lightPaint)
Create a new CheckerboardPainter with the specified light and dark paints. By default the square length is 8.

Parameters:
darkPaint - the paint used to draw the dark squares
lightPaint - the paint used to draw the light squares

CheckerboardPainter

public CheckerboardPainter(Paint darkPaint,
                           Paint lightPaint,
                           int length)
Create a new CheckerboardPainter with the specified light and dark paints and the specified square size.

Parameters:
darkPaint - the paint used to draw the dark squares
lightPaint - the paint used to draw the light squares
length - the length of the checker board squares
Method Detail

setSquareLength

public void setSquareLength(int length)
Specifies the length of the squares. By default, it is 8. A length of <= 0 will cause an IllegalArgumentException to be thrown.

Parameters:
length - the length of one side of a square tile. Must be > 0.

getSquareLength

public int getSquareLength()
Returns:
the squareLength. Will be > 0

setDarkPaint

public void setDarkPaint(Paint color)
Specifies the paint to use for dark tiles. This is a Paint and may be anything, including a TexturePaint for painting images. If null, the background color of the component is used.

Parameters:
color - the Paint to use for painting the "dark" tiles. May be null.

getDarkPaint

public Paint getDarkPaint()
Returns:
the Paint used for painting the "dark" tiles. May be null

setLightPaint

public void setLightPaint(Paint color)
Specifies the paint to use for light tiles. This is a Paint and may be anything, including a TexturePaint for painting images. If null, the foreground color of the component is used.

Parameters:
color - the Paint to use for painting the "light" tiles. May be null.

getLightPaint

public Paint getLightPaint()
Returns:
the Paint used for painting the "light" tiles. May 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