prefuse.render
Class EdgeRenderer

java.lang.Object
  extended by prefuse.render.AbstractShapeRenderer
      extended by prefuse.render.EdgeRenderer
All Implemented Interfaces:
Renderer

public class EdgeRenderer
extends AbstractShapeRenderer

Renderer that draws edges as lines connecting nodes. Both straight and curved lines are supported. Curved lines are drawn using cubic Bezier curves. Subclasses can override the getCurveControlPoints(EdgeItem, Point2D[], double, double, double, double) method to provide custom control point assignment for such curves.

This class also supports arrows for directed edges. See the setArrowType(int) method for more.

Version:
1.0
Author:
jeffrey heer

Field Summary
static java.lang.String EDGE_TYPE
           
protected static double HALF_PI
           
protected  java.awt.Polygon m_arrowHead
           
protected  int m_arrowHeight
           
protected  java.awt.geom.AffineTransform m_arrowTrans
           
protected  int m_arrowWidth
           
protected  java.awt.geom.Point2D[] m_ctrlPoints
           
protected  java.awt.geom.CubicCurve2D m_cubic
           
protected  java.awt.Shape m_curArrow
           
protected  float m_curWidth
           
protected  int m_edgeArrow
           
protected  int m_edgeType
           
protected  java.awt.geom.Point2D[] m_isctPoints
           
protected  java.awt.geom.Line2D m_line
           
protected  java.awt.geom.Point2D[] m_tmpPoints
           
protected  double m_width
           
protected  int m_xAlign1
           
protected  int m_xAlign2
           
protected  int m_yAlign1
           
protected  int m_yAlign2
           
 
Fields inherited from class prefuse.render.AbstractShapeRenderer
m_manageBounds, m_transform, RENDER_TYPE_DRAW, RENDER_TYPE_DRAW_AND_FILL, RENDER_TYPE_FILL, RENDER_TYPE_NONE
 
Fields inherited from interface prefuse.render.Renderer
DEFAULT_GRAPHICS
 
Constructor Summary
EdgeRenderer()
          Create a new EdgeRenderer.
EdgeRenderer(int edgeType)
          Create a new EdgeRenderer with the given edge type.
EdgeRenderer(int edgeType, int arrowType)
          Create a new EdgeRenderer with the given edge and arrow types.
 
Method Summary
protected static void getAlignedPoint(java.awt.geom.Point2D p, java.awt.geom.Rectangle2D r, int xAlign, int yAlign)
          Helper method, which calculates the top-left co-ordinate of a rectangle given the rectangle's alignment.
 int getArrowHeadHeight()
          Get the height of the untransformed arrow head.
 int getArrowHeadWidth()
          Get the width of the untransformed arrow head.
protected  java.awt.geom.AffineTransform getArrowTrans(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, double width)
          Returns an affine transformation that maps the arrowhead shape to the position and orientation specified by the provided line segment end points.
 int getArrowType()
          Returns the type of the drawn edge.
protected  void getCurveControlPoints(EdgeItem eitem, java.awt.geom.Point2D[] cp, double x1, double y1, double x2, double y2)
          Determines the control points to use for cubic (Bezier) curve edges.
 double getDefaultLineWidth()
          Gets the default width of lines.
 int getEdgeType()
          Returns the type of the drawn edge.
 int getHorizontalAlignment1()
          Get the horizontal aligment of the edge mount point with the first node.
 int getHorizontalAlignment2()
          Get the horizontal aligment of the edge mount point with the second node.
protected  double getLineWidth(VisualItem item)
          Returns the line width to be used for this VisualItem.
protected  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.
protected  java.awt.BasicStroke getStroke(VisualItem item)
          Returns the stroke value returned by VisualItem.getStroke(), scaled by the current line width determined by the getLineWidth(VisualItem) method.
protected  java.awt.geom.AffineTransform getTransform(VisualItem item)
          Return the graphics space transform applied to this item's shape, if any.
 int getVerticalAlignment1()
          Get the vertical aligment of the edge mount point with the first node.
 int getVerticalAlignment2()
          Get the vertical aligment of the edge mount point with the second node.
 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 setArrowHeadSize(int width, int height)
          Sets the dimensions of an arrow head for a directed edge.
 void setArrowType(int type)
          Sets the type of the drawn edge.
 void setBounds(VisualItem item)
          Calculates and sets the bounding rectangle for an item.
 void setDefaultLineWidth(double w)
          Sets the default width of lines.
 void setEdgeType(int type)
          Sets the type of the drawn edge.
 void setHorizontalAlignment1(int align)
          Set the horizontal aligment of the edge mount point with the first node.
 void setHorizontalAlignment2(int align)
          Set the horizontal aligment of the edge mount point with the second node.
 void setVerticalAlignment1(int align)
          Set the vertical aligment of the edge mount point with the first node.
 void setVerticalAlignment2(int align)
          Set the vertical aligment of the edge mount point with the second node.
protected  java.awt.Polygon updateArrowHead(int w, int h)
          Update the dimensions of the arrow head, creating a new arrow head if necessary.
 
Methods inherited from class prefuse.render.AbstractShapeRenderer
drawShape, getShape, setManageBounds, setRenderType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EDGE_TYPE

public static final java.lang.String EDGE_TYPE
See Also:
Constant Field Values

HALF_PI

protected static final double HALF_PI
See Also:
Constant Field Values

m_line

protected java.awt.geom.Line2D m_line

m_cubic

protected java.awt.geom.CubicCurve2D m_cubic

m_edgeType

protected int m_edgeType

m_xAlign1

protected int m_xAlign1

m_yAlign1

protected int m_yAlign1

m_xAlign2

protected int m_xAlign2

m_yAlign2

protected int m_yAlign2

m_width

protected double m_width

m_curWidth

protected float m_curWidth

m_tmpPoints

protected java.awt.geom.Point2D[] m_tmpPoints

m_ctrlPoints

protected java.awt.geom.Point2D[] m_ctrlPoints

m_isctPoints

protected java.awt.geom.Point2D[] m_isctPoints

m_edgeArrow

protected int m_edgeArrow

m_arrowWidth

protected int m_arrowWidth

m_arrowHeight

protected int m_arrowHeight

m_arrowHead

protected java.awt.Polygon m_arrowHead

m_arrowTrans

protected java.awt.geom.AffineTransform m_arrowTrans

m_curArrow

protected java.awt.Shape m_curArrow
Constructor Detail

EdgeRenderer

public EdgeRenderer()
Create a new EdgeRenderer.


EdgeRenderer

public EdgeRenderer(int edgeType)
Create a new EdgeRenderer with the given edge type.

Parameters:
edgeType - the edge type, one of Constants.EDGE_TYPE_LINE or Constants.EDGE_TYPE_CURVE.

EdgeRenderer

public EdgeRenderer(int edgeType,
                    int arrowType)
Create a new EdgeRenderer with the given edge and arrow types.

Parameters:
edgeType - the edge type, one of Constants.EDGE_TYPE_LINE or Constants.EDGE_TYPE_CURVE.
arrowType - the arrow type, one of Constants.EDGE_ARROW_FORWARD, Constants.EDGE_ARROW_REVERSE, or Constants.EDGE_ARROW_NONE.
See Also:
setArrowType(int)
Method Detail

getRenderType

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

Overrides:
getRenderType in class AbstractShapeRenderer
Returns:
the rendering type
See Also:
AbstractShapeRenderer.getRenderType(prefuse.visual.VisualItem)

getRawShape

protected java.awt.Shape getRawShape(VisualItem item)
Description copied from class: AbstractShapeRenderer
Return a non-transformed shape for the visual representation of the item. Subclasses must implement this method.

Specified by:
getRawShape in class AbstractShapeRenderer
Parameters:
item - the VisualItem being drawn
Returns:
the "raw", untransformed shape.
See Also:
AbstractShapeRenderer.getRawShape(prefuse.visual.VisualItem)

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
Overrides:
render in class AbstractShapeRenderer
Parameters:
g - the Graphics2D context
item - the visual item to draw
See Also:
Renderer.render(java.awt.Graphics2D, prefuse.visual.VisualItem)

getArrowTrans

protected java.awt.geom.AffineTransform getArrowTrans(java.awt.geom.Point2D p1,
                                                      java.awt.geom.Point2D p2,
                                                      double width)
Returns an affine transformation that maps the arrowhead shape to the position and orientation specified by the provided line segment end points.


updateArrowHead

protected java.awt.Polygon updateArrowHead(int w,
                                           int h)
Update the dimensions of the arrow head, creating a new arrow head if necessary. The return value is also set as the member variable m_arrowHead

Parameters:
w - the width of the untransformed arrow head base, in pixels
h - the height of the untransformed arrow head, in pixels
Returns:
the untransformed arrow head shape

getTransform

protected java.awt.geom.AffineTransform getTransform(VisualItem item)
Description copied from class: AbstractShapeRenderer
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.

Overrides:
getTransform in class AbstractShapeRenderer
Parameters:
item - the VisualItem
Returns:
the graphics space transform, or null if none
See Also:
AbstractShapeRenderer.getTransform(prefuse.visual.VisualItem)

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
Overrides:
locatePoint in class AbstractShapeRenderer
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
Overrides:
setBounds in class AbstractShapeRenderer
Parameters:
item - the item to compute the bounding box for
See Also:
Renderer.setBounds(prefuse.visual.VisualItem)

getLineWidth

protected double getLineWidth(VisualItem item)
Returns the line width to be used for this VisualItem. By default, returns the base width value set using the setDefaultLineWidth(double) method, scaled by the item size returned by VisualItem.getSize(). Subclasses can override this method to perform custom line width determination, however, the preferred method is to change the item size value itself.

Parameters:
item - the VisualItem for which to determine the line width
Returns:
the desired line width, in pixels

getStroke

protected java.awt.BasicStroke getStroke(VisualItem item)
Returns the stroke value returned by VisualItem.getStroke(), scaled by the current line width determined by the getLineWidth(VisualItem) method. Subclasses may override this method to perform custom stroke assignment, but should respect the line width paremeter stored in the m_curWidth member variable, which caches the result of getLineWidth.

Overrides:
getStroke in class AbstractShapeRenderer
Parameters:
item - the VisualItem
Returns:
the strok to use for drawing lines and shape outlines
See Also:
AbstractShapeRenderer.getStroke(prefuse.visual.VisualItem)

getCurveControlPoints

protected void getCurveControlPoints(EdgeItem eitem,
                                     java.awt.geom.Point2D[] cp,
                                     double x1,
                                     double y1,
                                     double x2,
                                     double y2)
Determines the control points to use for cubic (Bezier) curve edges. Override this method to provide custom curve specifications. To reduce object initialization, the entries of the Point2D array are already initialized, so use the Point2D.setLocation() method rather than new Point2D.Double() to more efficiently set custom control points.

Parameters:
eitem - the EdgeItem we are determining the control points for
cp - array of Point2D's (length >= 2) in which to return the control points
x1 - the x co-ordinate of the first node this edge connects to
y1 - the y co-ordinate of the first node this edge connects to
x2 - the x co-ordinate of the second node this edge connects to
y2 - the y co-ordinate of the second node this edge connects to

getAlignedPoint

protected static void getAlignedPoint(java.awt.geom.Point2D p,
                                      java.awt.geom.Rectangle2D r,
                                      int xAlign,
                                      int yAlign)
Helper method, which calculates the top-left co-ordinate of a rectangle given the rectangle's alignment.


getEdgeType

public int getEdgeType()
Returns the type of the drawn edge. This is one of Constants.EDGE_TYPE_LINE or Constants.EDGE_TYPE_CURVE.

Returns:
the edge type

setEdgeType

public void setEdgeType(int type)
Sets the type of the drawn edge. This must be one of Constants.EDGE_TYPE_LINE or Constants.EDGE_TYPE_CURVE.

Parameters:
type - the new edge type

getArrowType

public int getArrowType()
Returns the type of the drawn edge. This is one of Constants.EDGE_ARROW_FORWARD, Constants.EDGE_ARROW_REVERSE, or Constants.EDGE_ARROW_NONE.

Returns:
the edge type

setArrowType

public void setArrowType(int type)
Sets the type of the drawn edge. This is either Constants.EDGE_ARROW_NONE for no edge arrows, Constants.EDGE_ARROW_FORWARD for arrows from source to target on directed edges, or Constants.EDGE_ARROW_REVERSE for arrows from target to source on directed edges.

Parameters:
type - the new arrow type

setArrowHeadSize

public void setArrowHeadSize(int width,
                             int height)
Sets the dimensions of an arrow head for a directed edge. This specifies the pixel dimensions when both the zoom level and the size factor (a combination of item size value and default stroke width) are 1.0.

Parameters:
width - the untransformed arrow head width, in pixels. This specifies the span of the base of the arrow head.
height - the untransformed arrow head height, in pixels. This specifies the distance from the point of the arrow to its base.

getArrowHeadHeight

public int getArrowHeadHeight()
Get the height of the untransformed arrow head. This is the distance, in pixels, from the tip of the arrow to its base.

Returns:
the default arrow head height

getArrowHeadWidth

public int getArrowHeadWidth()
Get the width of the untransformed arrow head. This is the length, in pixels, of the base of the arrow head.

Returns:
the default arrow head width

getHorizontalAlignment1

public int getHorizontalAlignment1()
Get the horizontal aligment of the edge mount point with the first node.

Returns:
the horizontal alignment, one of Constants.LEFT, Constants.RIGHT, or Constants.CENTER.

getVerticalAlignment1

public int getVerticalAlignment1()
Get the vertical aligment of the edge mount point with the first node.

Returns:
the vertical alignment, one of Constants.TOP, Constants.BOTTOM, or Constants.CENTER.

getHorizontalAlignment2

public int getHorizontalAlignment2()
Get the horizontal aligment of the edge mount point with the second node.

Returns:
the horizontal alignment, one of Constants.LEFT, Constants.RIGHT, or Constants.CENTER.

getVerticalAlignment2

public int getVerticalAlignment2()
Get the vertical aligment of the edge mount point with the second node.

Returns:
the vertical alignment, one of Constants.TOP, Constants.BOTTOM, or Constants.CENTER.

setHorizontalAlignment1

public void setHorizontalAlignment1(int align)
Set the horizontal aligment of the edge mount point with the first node.

Parameters:
align - the horizontal alignment, one of Constants.LEFT, Constants.RIGHT, or Constants.CENTER.

setVerticalAlignment1

public void setVerticalAlignment1(int align)
Set the vertical aligment of the edge mount point with the first node.

Parameters:
align - the vertical alignment, one of Constants.TOP, Constants.BOTTOM, or Constants.CENTER.

setHorizontalAlignment2

public void setHorizontalAlignment2(int align)
Set the horizontal aligment of the edge mount point with the second node.

Parameters:
align - the horizontal alignment, one of Constants.LEFT, Constants.RIGHT, or Constants.CENTER.

setVerticalAlignment2

public void setVerticalAlignment2(int align)
Set the vertical aligment of the edge mount point with the second node.

Parameters:
align - the vertical alignment, one of Constants.TOP, Constants.BOTTOM, or Constants.CENTER.

setDefaultLineWidth

public void setDefaultLineWidth(double w)
Sets the default width of lines. This width value will be scaled by the value of an item's size data field. The default base width is 1.

Parameters:
w - the desired default line width, in pixels

getDefaultLineWidth

public double getDefaultLineWidth()
Gets the default width of lines. This width value that will be scaled by the value of an item's size data field. The default base width is 1.

Returns:
the default line width, in pixels


Copyright 2007 Regents of the University of California