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 garbage 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
           
 
Fields inherited from interface prefuse.render.Renderer
DEFAULT_GRAPHICS
 
Constructor Summary
AbstractShapeRenderer()
           
 
Method Summary
 void calculateBounds(VisualItem<?> item, java.awt.geom.Rectangle2D bounds)
          Calculates the bounding rectangle for an item.
protected  void drawShape(java.awt.Graphics2D g, VisualItem<?> item, java.awt.Shape shape)
          Draws the specified shape into the provided Graphics context.
protected  java.awt.Color getFillColor(VisualItem<?> item)
          Returns the fill color to use for painting shapes.
protected abstract  java.awt.Shape getRawShape(VisualItem<?> item)
          Return a non-transformed shape for the visual representation of the item.
 RenderType 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)
          Returns the stroke to use for drawing lines and shape outlines.
protected  java.awt.Color getStrokeColor(VisualItem<?> item)
          Returns the stroke color 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.
 boolean managesBounds()
           
 void render(java.awt.Graphics2D g, VisualItem<?> item)
          Render item into a Graphics2D context.
 void setManageBounds(boolean b)
           
 void setRenderType(RenderType 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

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)

managesBounds

public boolean managesBounds()
Specified by:
managesBounds in interface Renderer
Returns:
true if and only if the renderer manages the bounds of the items it renders

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. 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 absolute (item-space) coordinates.

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

getStrokeColor

protected java.awt.Color getStrokeColor(VisualItem<?> item)
Returns the stroke color to use for drawing lines and shape outlines. By default returns the value of VisualItem.getStrokeColor(). Subclasses can override this method to implement custom stroke color assignment, though changing the VisualItem's stroke color value is preferred.

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

getFillColor

protected java.awt.Color getFillColor(VisualItem<?> item)
Returns the fill color to use for painting shapes. By default returns the value of VisualItem.getFillColor(). Subclasses can override this method to implement custom fill color assignment, though changing the VisualItem's fill color value is preferred.

Parameters:
item - the VisualItem
Returns:
the fill color to use for painting shapes

getStroke

protected java.awt.BasicStroke getStroke(VisualItem<?> item)
Returns 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 stroke 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 RenderType 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(RenderType 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

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 exact 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)

calculateBounds

public void calculateBounds(VisualItem<?> item,
                            java.awt.geom.Rectangle2D bounds)
Description copied from interface: Renderer
Calculates the bounding rectangle for an item. This is called by a VisualItem when it validates its bounds.

Specified by:
calculateBounds in interface Renderer
Parameters:
item - the item to compute the bounding box for
bounds - the rectangle to populate with the bounding box


Copyright © 2008 Regents of the University of California