public abstract class AbstractShapeRenderer extends java.lang.Object implements Renderer
Abstract base class implementation of the Renderer interface for
supporting the drawing of basic shapes. Subclasses should override the
getRawShape
method,
which returns the shape to draw. Optionally, subclasses can also override the
getTransform
method to apply a desired
AffineTransform
to the shape.
NOTE: For more efficient rendering, subclasses should use a single shape instance in memory, and update its parameters on each call to getRawShape, rather than allocating a new Shape object each time. Otherwise, a new object will be allocated every time something needs to be drawn, and then subsequently be arbage collected. This can significantly reduce performance, especially when there are many things to draw.
Modifier and Type | Field and Description |
---|---|
protected boolean |
m_manageBounds |
protected java.awt.geom.AffineTransform |
m_transform |
static int |
RENDER_TYPE_DRAW |
static int |
RENDER_TYPE_DRAW_AND_FILL |
static int |
RENDER_TYPE_FILL |
static int |
RENDER_TYPE_NONE |
DEFAULT_GRAPHICS
Constructor and Description |
---|
AbstractShapeRenderer() |
Modifier and Type | Method and Description |
---|---|
protected void |
drawShape(java.awt.Graphics2D g,
VisualItem item,
java.awt.Shape shape)
Draws the specified shape into the provided Graphics context, using
stroke and fill color values from the specified VisualItem.
|
protected abstract java.awt.Shape |
getRawShape(VisualItem item)
Return a non-transformed shape for the visual representation of the
item.
|
int |
getRenderType(VisualItem item)
Returns a value indicating if a shape is drawn by its outline, by a
fill, or both.
|
java.awt.Shape |
getShape(VisualItem item)
Returns the shape describing the boundary of an item.
|
protected java.awt.BasicStroke |
getStroke(VisualItem item)
Retursn the stroke to use for drawing lines and shape outlines.
|
protected java.awt.geom.AffineTransform |
getTransform(VisualItem item)
Return the graphics space transform applied to this item's shape, if any.
|
boolean |
locatePoint(java.awt.geom.Point2D p,
VisualItem item)
Returns true if the Point is located inside the extents of the item.
|
void |
render(java.awt.Graphics2D g,
VisualItem item)
Render item into a Graphics2D context.
|
void |
setBounds(VisualItem item)
Calculates and sets the bounding rectangle for an item.
|
void |
setManageBounds(boolean b) |
void |
setRenderType(int type)
Sets a value indicating if a shape is drawn by its outline, by a fill,
or both.
|
public static final int RENDER_TYPE_NONE
public static final int RENDER_TYPE_DRAW
public static final int RENDER_TYPE_FILL
public static final int RENDER_TYPE_DRAW_AND_FILL
protected java.awt.geom.AffineTransform m_transform
protected boolean m_manageBounds
public void setManageBounds(boolean b)
public void render(java.awt.Graphics2D g, VisualItem item)
Renderer
render
in interface Renderer
g
- the Graphics2D contextitem
- the visual item to drawRenderer.render(java.awt.Graphics2D, prefuse.visual.VisualItem)
protected void drawShape(java.awt.Graphics2D g, VisualItem item, java.awt.Shape shape)
public java.awt.Shape getShape(VisualItem item)
item
- the item for which to get the Shapeprotected java.awt.BasicStroke getStroke(VisualItem item)
VisualItem.getStroke()
.
Subclasses can override this method to implement custom stroke
assignment, though changing the VisualItem
's stroke
value is preferred.item
- the VisualItemprotected abstract java.awt.Shape getRawShape(VisualItem item)
item
- the VisualItem being drawnprotected java.awt.geom.AffineTransform getTransform(VisualItem item)
item
- the VisualItempublic int getRenderType(VisualItem item)
public void setRenderType(int type)
type
- the new rendering type. Should be one of
RENDER_TYPE_NONE
, RENDER_TYPE_DRAW
,
RENDER_TYPE_FILL
, or RENDER_TYPE_DRAW_AND_FILL
.public boolean locatePoint(java.awt.geom.Point2D p, VisualItem item)
Renderer
locatePoint
in interface Renderer
p
- the point to test for containmentitem
- the item to test containment againstRenderer.locatePoint(java.awt.geom.Point2D, prefuse.visual.VisualItem)
public void setBounds(VisualItem item)
Renderer
setBounds
in interface Renderer
item
- the item to compute the bounding box forRenderer.setBounds(prefuse.visual.VisualItem)
Copyright ? 2013 Regents of the University of California