public class ShapePainter extends AbstractAreaPainter<Object>
A Painter that paints java.awt.Shapes. It uses a stroke and a fillPaint to do so. The shape is painted as is, at a specific location. If no Shape is specified, nothing will be painted. If no stroke is specified, the default for the Graphics2D will be used. If no fillPaint is specified, the component background color will be used. The shape can be positioned using the insets, horizontal, and vertical properties.
Here is an example that draws a rectangle aligned on the center right:
Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, 50, 50);
ShapePainter p = new ShapePainter(rect);
p.setHorizontal(HorizontalAlignment.RIGHT);
p.setVertical(VerticalAlignment.CENTER);
AbstractAreaPainter.Style
AbstractLayoutPainter.HorizontalAlignment, AbstractLayoutPainter.VerticalAlignment
AbstractPainter.Interpolation
Modifier and Type | Field and Description |
---|---|
private Shape |
shape
The Shape to fillPaint.
|
Constructor and Description |
---|
ShapePainter()
Create a new ShapePainter
|
ShapePainter(Shape shape)
Create a new ShapePainter with the specified shape.
|
ShapePainter(Shape shape,
Paint paint)
Create a new ShapePainter with the specified shape and fillPaint.
|
ShapePainter(Shape shape,
Paint paint,
AbstractAreaPainter.Style style)
Create a new ShapePainter with the specified shape and fillPaint.
|
Modifier and Type | Method and Description |
---|---|
private Paint |
calculateFillPaint(Object component,
int width,
int height) |
private Paint |
calculateStrokePaint(Object component,
int width,
int height) |
protected void |
doPaint(Graphics2D g,
Object component,
int w,
int h)
Subclasses must implement this method and perform custom painting operations
here.
|
private void |
drawPathEffects(Graphics2D g,
Shape s,
int w,
int h) |
private void |
drawShape(Graphics2D g,
Shape s,
Object component,
int w,
int h) |
private void |
fillShape(Graphics2D g,
Shape s,
Object component,
int w,
int h) |
Shape |
getShape()
Gets the current shape
|
protected Shape |
provideShape(Graphics2D g,
Object comp,
int width,
int height)
Returns the outline shape of this painter.
|
void |
setShape(Shape s)
Sets the shape to fillPaint.
|
calculateSnappedPaint, getAreaEffects, getBorderPaint, getBorderWidth, getFillPaint, getStyle, isPaintStretched, setAreaEffects, setBorderPaint, setBorderWidth, setFillPaint, setPaintStretched, setStyle
calculateLayout, getHorizontalAlignment, getInsets, getVerticalAlignment, isFillHorizontal, isFillVertical, setFillHorizontal, setFillVertical, setHorizontalAlignment, setInsets, setVerticalAlignment
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
public ShapePainter()
public ShapePainter(Shape shape)
shape
- the shape to fillPaintpublic ShapePainter(Shape shape, Paint paint)
shape
- the shape to fillPaintpaint
- the fillPaint to be used to fillPaint the shapepublic ShapePainter(Shape shape, Paint paint, AbstractAreaPainter.Style style)
shape
- the shape to fillPaintpaint
- the fillPaint to be used to fillPaint the shapestyle
- specifies the ShapePainter.Style to use for painting this shape.
If null, then Style.BOTH is usedpublic void setShape(Shape s)
s
- the Shape to fillPaint. May be nullpublic Shape getShape()
protected void doPaint(Graphics2D g, Object component, int w, int h)
doPaint
in class AbstractPainter<Object>
g
- The Graphics2D object in which to paintprivate void drawShape(Graphics2D g, Shape s, Object component, int w, int h)
private void fillShape(Graphics2D g, Shape s, Object component, int w, int h)
protected Shape provideShape(Graphics2D g, Object comp, int width, int height)
AbstractAreaPainter
provideShape
in class AbstractAreaPainter<Object>
g
- graphicscomp
- The Object this painter will be painted on.width
- the width to paintheight
- the height to paintprivate Paint calculateStrokePaint(Object component, int width, int height)
private Paint calculateFillPaint(Object component, int width, int height)
private void drawPathEffects(Graphics2D g, Shape s, int w, int h)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses