|
swingx Version 2005-08-19 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jdesktop.swingx.JavaBean
org.jdesktop.swingx.painter.AbstractPainter<T>
public abstract class AbstractPainter<T extends JComponent>
A convenient base class from which concrete Painter implementations may extend. It extends JavaBean and thus provides property change notification (which is crucial for the Painter implementations to be available in a GUI builder). It also saves off the Graphics2D state in its "saveState" method, and restores that state in the "restoreState" method. Sublasses simply need to extend AbstractPainter and implement the paintBackground method.
For example, here is the paintBackground method of BackgroundPainter:
public void paintBackground(Graphics2D g, JComponent component) {
g.setColor(component.getBackground());
g.fillRect(0, 0, component.getWidth(), component.getHeight());
}
AbstractPainter provides a very useful default implementation of the paint method. It:
Specifying rendering hints can greatly improve the visual impact of your applications. For example, by default Swing doesn't do much in the way of antialiasing (except for Fonts, but that's another story). Pinstripes don't look so good without antialiasing. So if I were going to paint pinstripes, I might do it like this:
PinstripePainter p = new PinstripePainter();
p.setAntialiasing(RenderingHints.VALUE_ANTIALIAS_ON);
You can read more about antialiasing and other rendering hints in the java.awt.RenderingHints documentation. By nature, changing the rendering hints may have an impact on performance. Certain hints require more computation, others require less
Constructor Summary | |
---|---|
AbstractPainter()
Creates a new instance of AbstractPainter |
Method Summary | |
---|---|
Object |
getAlphaInterpolation()
|
Object |
getAntialiasing()
|
Shape |
getClip()
|
Object |
getColorRendering()
|
Composite |
getComposite()
|
Object |
getDithering()
|
Effect[] |
getEffects()
|
Object |
getFractionalMetrics()
|
Object |
getInterpolation()
|
Object |
getRendering()
|
Object |
getRenderingHint(RenderingHints.Key key)
|
Map<RenderingHints.Key,Object> |
getRenderingHints()
|
Resize |
getResizeClip()
|
Object |
getStrokeControl()
|
Object |
getTextAntialiasing()
|
boolean |
isUseCache()
|
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. |
protected abstract void |
paintBackground(Graphics2D g,
T component)
Subclasses should implement this method and perform custom painting operations here. |
protected void |
restoreState(Graphics2D g)
Restores previously saved state. |
protected void |
saveState(Graphics2D g)
Saves the state in the given Graphics2D object so that it may be restored later. |
void |
setAlphaInterpolation(Object alphaInterpolation)
Sets the technique used for interpolating alpha values. |
void |
setAntialiasing(Object antialiasing)
Sets whether or not to antialias |
void |
setClip(Shape clip)
Specifies the Shape to use for clipping the painting area. |
void |
setColorRendering(Object colorRendering)
Sets the technique to use for rendering colors |
void |
setComposite(Composite c)
Sets the Composite to use. |
void |
setDithering(Object dithering)
Sets whether or not to dither |
void |
setEffects(BufferedImageOp... filters)
A convenience method for specifying the effects to use based on BufferedImageOps. |
void |
setEffects(Effect... effects)
Sets the effects to apply to the results of the AbstractPainter's painting operation. |
void |
setFractionalMetrics(Object fractionalMetrics)
Sets whether or not to use fractional metrics |
void |
setInterpolation(Object interpolation)
Sets the technique to use for interpolation (used esp. when scaling) |
void |
setRendering(Object rendering)
Specifies a hint as to techniques to use with regards to rendering quality vs. speed |
void |
setRenderingHint(RenderingHints.Key key,
Object hint)
Set the given hint for the given key. |
void |
setRenderingHints(Map<RenderingHints.Key,Object> renderingHints)
Sets the rendering hints to use. |
void |
setResizeClip(Resize r)
Specifies the resize behavior of the clip. |
void |
setStrokeControl(Object strokeControl)
Specifies a technique for rendering strokes |
void |
setTextAntialiasing(Object textAntialiasing)
Sets the technique for anti-aliasing text. |
void |
setUseCache(boolean b)
Sets whether to cache the painted image with a SoftReference in a BufferedImage between calls. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractPainter()
Method Detail |
---|
public void setUseCache(boolean b)
Sets whether to cache the painted image with a SoftReference in a BufferedImage between calls. If true, and if the size of the component hasn't changed, then the cached image will be used rather than causing a painting operation.
This should be considered a hint, rather than absolute. Several factors may force repainting, including low memory, different component sizes, or possibly new rendering hint settings, etc.
b
- whether or not to use the cachepublic boolean isUseCache()
public void setEffects(Effect... effects)
Sets the effects to apply to the results of the AbstractPainter's painting operation. Some common effects include blurs, shadows, embossing, and so forth. If the given effects is a null array, no effects will be used
effects
- the Effects to apply to the results of the AbstractPainter's
painting operationpublic void setEffects(BufferedImageOp... filters)
A convenience method for specifying the effects to use based on BufferedImageOps. These will each be individually wrapped by an ImageEffect and then setEffects(Effect... effects) will be called with the resulting array
filters
- the BufferedImageOps to wrap as effectspublic Effect[] getEffects()
public void setClip(Shape clip)
clip
- the Shape to use to clip the area. Whatever is inside this
shape will be kept, everything else "clipped". May be null. If
null, the clipping is not set on the graphics objectpublic Shape getClip()
public void setResizeClip(Resize r)
r
- value indication whether/how to resize the clip. If null,
Resize.NONE will be usedpublic Resize getResizeClip()
public void setComposite(Composite c)
c
- The composite to use. If null, then no composite will be
specified on the graphics objectpublic Composite getComposite()
public Object getAlphaInterpolation()
public void setAlphaInterpolation(Object alphaInterpolation)
alphaInterpolation
- May be one of:
public Object getAntialiasing()
public void setAntialiasing(Object antialiasing)
antialiasing
- May be one of:
public Object getColorRendering()
public void setColorRendering(Object colorRendering)
colorRendering
- May be one of:
public Object getDithering()
public void setDithering(Object dithering)
dithering
- May be one of:
public Object getFractionalMetrics()
public void setFractionalMetrics(Object fractionalMetrics)
fractionalMetrics
- May be one of:
public Object getInterpolation()
public void setInterpolation(Object interpolation)
interpolation
- May be one of:
public Object getRendering()
public void setRendering(Object rendering)
rendering
- May be one of:
public Object getStrokeControl()
public void setStrokeControl(Object strokeControl)
strokeControl
- May be one of:
public Object getTextAntialiasing()
public void setTextAntialiasing(Object textAntialiasing)
textAntialiasing
- May be one of:
public Object getRenderingHint(RenderingHints.Key key)
public void setRenderingHint(RenderingHints.Key key, Object hint)
key
- cannot be nullhint
- must be a hint compatible with the given keypublic Map<RenderingHints.Key,Object> getRenderingHints()
public void setRenderingHints(Map<RenderingHints.Key,Object> renderingHints)
renderingHints
- map of hints. May be null. I null, a new Map of
rendering hints will be createdprotected void saveState(Graphics2D g)
g
- the Graphics2D object who's state will be savedprotected void restoreState(Graphics2D g)
g
- the Graphics2D object to restore previously saved state topublic void paint(Graphics2D g, T component)
Painter
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.
paint
in interface Painter<T extends JComponent>
g
- The Graphics2D object in which to paintcomponent
- The JComponent that the Painter is delegate for.protected abstract void paintBackground(Graphics2D g, T component)
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 |