prefuse.render
Class AbstractShapeRenderer

java.lang.Object
  extended by prefuse.render.AbstractShapeRenderer
All Implemented Interfaces:
Renderer
Direct Known Subclasses:
AxisRenderer, EdgeRenderer, LabelRenderer, PolygonRenderer, ShapeRenderer

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.

Version:
1.0
Author:
alan newberger, jeffrey heer

Field Summary
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
           
 
Fields inherited from interface prefuse.render.Renderer
DEFAULT_GRAPHICS
 
Constructor Summary
AbstractShapeRenderer()
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RENDER_TYPE_NONE

public static final int RENDER_TYPE_NONE
See Also:
Constant Field Values

RENDER_TYPE_DRAW

public static final int RENDER_TYPE_DRAW
See Also:
Constant Field Values

RENDER_TYPE_FILL

public static final int RENDER_TYPE_FILL
See Also:
Constant Field Values

RENDER_TYPE_DRAW_AND_FILL

public static final int RENDER_TYPE_DRAW_AND_FILL
See Also:
Constant Field Values

m_transform

protected java.awt.geom.AffineTransform m_transform

m_manageBounds

protected boolean m_manageBounds
Constructor Detail

AbstractShapeRenderer

public AbstractShapeRenderer()
Method Detail

setManageBounds

public void setManageBounds(boolean b)

render

public void render(java.awt.Graphics2D g,
                   VisualItem item)
Description copied from interface: Renderer
Render item into a Graphics2D context.

Specified by:
render in interface Renderer
Parameters:
g - the Graphics2D context
item - the visual item to draw
See Also:
Renderer.render(java.awt.Graphics2D, prefuse.visual.VisualItem)

drawShape

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. This method can be called by subclasses in custom rendering routines.


getShape

public java.awt.Shape getShape(VisualItem item)
Returns the shape describing the boundary of an item. The shape's coordinates should be in abolute (item-space) coordinates.

Parameters:
item - the item for which to get the Shape

getStroke

protected java.awt.BasicStroke getStroke(VisualItem item)
Retursn the stroke to use for drawing lines and shape outlines. By default returns the value of VisualItem.getStroke(). Subclasses can override this method to implement custom stroke assignment, though changing the VisualItem's stroke value is preferred.

Parameters:
item - the VisualItem
Returns:
the strok to use for drawing lines and shape outlines

getRawShape

protected abstract java.awt.Shape getRawShape(VisualItem item)
Return a non-transformed shape for the visual representation of the item. Subclasses must implement this method.

Parameters:
item - the VisualItem being drawn
Returns:
the "raw", untransformed shape.

getTransform

protected java.awt.geom.AffineTransform getTransform(VisualItem item)
Return the graphics space transform applied to this item's shape, if any. Subclasses can implement this method, otherwise it will return null to indicate no transformation is needed.

Parameters:
item - the VisualItem
Returns:
the graphics space transform, or null if none

getRenderType

public int getRenderType(VisualItem item)
Returns a value indicating if a shape is drawn by its outline, by a fill, or both. The default is to draw both.

Returns:
the rendering type

setRenderType

public void setRenderType(int type)
Sets a value indicating if a shape is drawn by its outline, by a fill, or both. The default is to draw both.

Parameters:
type - the new rendering type. Should be one of RENDER_TYPE_NONE, RENDER_TYPE_DRAW, RENDER_TYPE_FILL, or RENDER_TYPE_DRAW_AND_FILL.

locatePoint

public boolean locatePoint(java.awt.geom.Point2D p,
                           VisualItem item)
Description copied from interface: Renderer
Returns true if the Point is located inside the extents of the item. This calculation matches against the exaxt item shape, and so is more sensitive than just checking within a bounding box.

Specified by:
locatePoint in interface Renderer
Parameters:
p - the point to test for containment
item - the item to test containment against
Returns:
true if the point is contained within the the item, else false
See Also:
Renderer.locatePoint(java.awt.geom.Point2D, prefuse.visual.VisualItem)

setBounds

public void setBounds(VisualItem item)
Description copied from interface: Renderer
Calculates and sets the bounding rectangle for an item. This is called by a VisualItem when it validates its bounds.

Specified by:
setBounds in interface Renderer
Parameters:
item - the item to compute the bounding box for
See Also:
Renderer.setBounds(prefuse.visual.VisualItem)


Copyright © 2007 Regents of the University of California