Class ShapePainter
java.lang.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);
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractAreaPainter
AbstractAreaPainter.StyleNested classes/interfaces inherited from class AbstractLayoutPainter
AbstractLayoutPainter.HorizontalAlignment, AbstractLayoutPainter.VerticalAlignmentNested classes/interfaces inherited from class AbstractPainter
AbstractPainter.Interpolation -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new ShapePainterShapePainter(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. -
Method Summary
Modifier and TypeMethodDescriptionprivate PaintcalculateFillPaint(Object component, int width, int height) private PaintcalculateStrokePaint(Object component, int width, int height) protected voiddoPaint(Graphics2D g, Object component, int w, int h) Subclasses must implement this method and perform custom painting operations here.private voiddrawPathEffects(Graphics2D g, Shape s, int w, int h) private voiddrawShape(Graphics2D g, Shape s, Object component, int w, int h) private voidfillShape(Graphics2D g, Shape s, Object component, int w, int h) getShape()Gets the current shapeprotected ShapeprovideShape(Graphics2D g, Object comp, int width, int height) Returns the outline shape of this painter.voidSets the shape to fillPaint.Methods inherited from class AbstractAreaPainter
calculateSnappedPaint, getAreaEffects, getBorderPaint, getBorderWidth, getFillPaint, getStyle, isPaintStretched, setAreaEffects, setBorderPaint, setBorderWidth, setFillPaint, setPaintStretched, setStyleMethods inherited from class AbstractLayoutPainter
calculateLayout, getHorizontalAlignment, getInsets, getVerticalAlignment, isFillHorizontal, isFillVertical, setFillHorizontal, setFillVertical, setHorizontalAlignment, setInsets, setVerticalAlignmentMethods inherited from class AbstractPainter
clearCache, configureGraphics, getFilters, getInterpolation, isAntialiasing, isCacheable, isCacheCleared, isDirty, isInPaintContext, isVisible, paint, setAntialiasing, setCacheable, setDirty, setFilters, setInPaintContext, setInterpolation, setVisible, shouldUseCache, validateMethods inherited from class AbstractBean
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
-
Field Details
-
shape
The Shape to fillPaint. If null, nothing is painted.
-
-
Constructor Details
-
ShapePainter
public ShapePainter()Create a new ShapePainter -
ShapePainter
Create a new ShapePainter with the specified shape.- Parameters:
shape- the shape to fillPaint
-
ShapePainter
-
ShapePainter
Create a new ShapePainter with the specified shape and fillPaint. The shape can be filled or stroked (only the outline is painted).- Parameters:
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 used
-
-
Method Details
-
setShape
Sets the shape to fillPaint. This shape is not resized when the component bounds are. To do that, create a custom shape that is bound to the component width/height- Parameters:
s- the Shape to fillPaint. May be null
-
getShape
-
doPaint
Subclasses must implement this method and perform custom painting operations here.- Specified by:
doPaintin classAbstractPainter<Object>- Parameters:
g- The Graphics2D object in which to paintcomponent-w-h-
-
drawShape
-
fillShape
-
provideShape
Description copied from class:AbstractAreaPainterReturns the outline shape of this painter. Subclasses must implement this method. This shape will be used for filling, stroking, and clipping.- Specified by:
provideShapein classAbstractAreaPainter<Object>- Parameters:
g- graphicscomp- The Object this painter will be painted on.width- the width to paintheight- the height to paint- Returns:
- the outline shape of this painter
-
calculateStrokePaint
-
calculateFillPaint
-
drawPathEffects
-