public class CheckerboardPainter extends AbstractPainter<Object>
A Painter implementation that paints a checkerboard pattern. The light and dark colors (Paint instances) are configurable, as are the size of the squares (squareSize).
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.setSquareSize(32);
panel.seBackgroundPainter(p);
Note that in this example, the "32" in the GradientPaint matches the "32" set for the squareSize. 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.
AbstractPainter.Interpolation
Modifier and Type | Field and Description |
---|---|
private Paint |
checkerPaint |
private Paint |
darkPaint |
private Paint |
lightPaint |
private double |
squareSize |
Constructor and Description |
---|
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,
double squareSize)
Create a new CheckerboardPainter with the specified light and dark paints
and the specified square size.
|
Modifier and Type | Method and Description |
---|---|
protected void |
doPaint(Graphics2D g,
Object t,
int width,
int height)
Subclasses must implement this method and perform custom painting operations
here.
|
private Paint |
getCheckerPaint(Object c)
Helper method that creates and returns the Paint that incorporates the
sizes and light and dark Paints in one TexturePaint.
|
Paint |
getDarkPaint()
Gets the current dark paint.
|
Paint |
getLightPaint()
gets the current light paint
|
double |
getSquareSize()
Gets the current square length.
|
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 |
setSquareSize(double squareSize)
Specifies the squareSize of the squares.
|
clearCache, configureGraphics, getFilters, getInterpolation, isAntialiasing, isCacheable, isCacheCleared, isDirty, isInPaintContext, isVisible, paint, setAntialiasing, setCacheable, setDirty, setFilters, setInPaintContext, setInterpolation, setVisible, shouldUseCache, validate
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
private transient Paint checkerPaint
private Paint lightPaint
private double squareSize
public CheckerboardPainter()
public CheckerboardPainter(Paint darkPaint, Paint lightPaint)
darkPaint
- the paint used to draw the dark squareslightPaint
- the paint used to draw the light squarespublic CheckerboardPainter(Paint darkPaint, Paint lightPaint, double squareSize)
darkPaint
- the paint used to draw the dark squareslightPaint
- the paint used to draw the light squaressquareSize
- the squareSize of the checker board squarespublic void setSquareSize(double squareSize)
squareSize
- the squareSize of one side of a square tile. Must be > 0.public double getSquareSize()
public void setDarkPaint(Paint color)
color
- the Paint to use for painting the "dark" tiles. May be null.public Paint getDarkPaint()
public void setLightPaint(Paint color)
color
- the Paint to use for painting the "light" tiles. May be null.public Paint getLightPaint()
private Paint getCheckerPaint(Object c)
protected void doPaint(Graphics2D g, Object t, int width, int height)
doPaint
in class AbstractPainter<Object>
g
- The Graphics2D object in which to paintWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses