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(EdgeArrowType) method for more.

Version:
1.0
Author:
jeffrey heer

Nested Class Summary
static class EdgeRenderer.EdgeArrowType
           
static class EdgeRenderer.EdgeType
           
 
Field Summary
protected  boolean hideNodeInternalSegments
           
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  EdgeRenderer.EdgeArrowType m_edgeArrow
           
protected  EdgeRenderer.EdgeType m_edgeType
           
protected  java.awt.geom.Point2D[] m_intersectSourcePoints
           
protected  java.awt.geom.Point2D[] m_intersectTargetPoints
           
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  Alignment m_xAlign1
           
protected  Alignment m_xAlign2
           
protected  Alignment m_yAlign1
           
protected  Alignment m_yAlign2
           
protected  float splineSlack
           
 
Fields inherited from class prefuse.render.AbstractShapeRenderer
m_manageBounds, m_transform
 
Fields inherited from interface prefuse.render.Renderer
DEFAULT_GRAPHICS
 
Constructor Summary
EdgeRenderer()
          Create a new EdgeRenderer.
EdgeRenderer(EdgeRenderer.EdgeType edgeType)
          Create a new EdgeRenderer with the given edge type.
EdgeRenderer(EdgeRenderer.EdgeType edgeType, EdgeRenderer.EdgeArrowType arrowType)
          Create a new EdgeRenderer with the given edge and arrow types.
 
Method Summary
 void calculateBounds(VisualItem<?> item, java.awt.geom.Rectangle2D bounds)
          Calculates the bounding rectangle for an item.
protected  java.awt.Shape createCurvedEdge(float[] poly, boolean[] invisibleSegments)
           
 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.
 EdgeRenderer.EdgeArrowType 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.
 EdgeRenderer.EdgeType getEdgeType()
          Returns the type of the drawn edge.
 Alignment getHorizontalAlignment1()
          Get the horizontal alignment of the edge mount point with the first node.
 Alignment getHorizontalAlignment2()
          Get the horizontal alignment 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.
 RenderType getRenderType(VisualItem<?> item)
          Returns a value indicating if a shape is drawn by its outline, by a fill, or both.
 float getSplineSlack()
           
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.
 Alignment getVerticalAlignment1()
          Get the vertical alignment of the edge mount point with the first node.
 Alignment getVerticalAlignment2()
          Get the vertical alignment of the edge mount point with the second node.
 boolean isHideNodeInternalSegments()
           
 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(EdgeRenderer.EdgeArrowType type)
          Sets the type of the drawn edge.
 void setDefaultLineWidth(double w)
          Sets the default width of lines.
 void setEdgeType(EdgeRenderer.EdgeType type)
          Sets the type of the drawn edge.
 void setHideNodeInternalSegments(boolean hideNodeInternalSegments)
           
 void setHorizontalAlignment1(Alignment align)
          Set the horizontal alignment of the edge mount point with the first node.
 void setHorizontalAlignment2(Alignment align)
          Set the horizontal alignment of the edge mount point with the second node.
 void setSplineSlack(float splineSlack)
           
 void setVerticalAlignment1(Alignment align)
          Set the vertical alignment of the edge mount point with the first node.
 void setVerticalAlignment2(Alignment align)
          Set the vertical alignment 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, getFillColor, getShape, getStrokeColor, managesBounds, setManageBounds, setRenderType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_line

protected java.awt.geom.Line2D m_line

m_cubic

protected java.awt.geom.CubicCurve2D m_cubic

m_edgeType

protected EdgeRenderer.EdgeType m_edgeType

m_xAlign1

protected Alignment m_xAlign1

m_yAlign1

protected Alignment m_yAlign1

m_xAlign2

protected Alignment m_xAlign2

m_yAlign2

protected Alignment 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_intersectSourcePoints

protected java.awt.geom.Point2D[] m_intersectSourcePoints

m_intersectTargetPoints

protected java.awt.geom.Point2D[] m_intersectTargetPoints

hideNodeInternalSegments

protected boolean hideNodeInternalSegments

m_edgeArrow

protected EdgeRenderer.EdgeArrowType 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

splineSlack

protected float splineSlack
Constructor Detail

EdgeRenderer

public EdgeRenderer()
Create a new EdgeRenderer.


EdgeRenderer

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

Parameters:
edgeType - the edge type

EdgeRenderer

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

Parameters:
edgeType - the edge type
arrowType - the arrow type
See Also:
setArrowType(EdgeArrowType)
Method Detail

getRenderType

public RenderType 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:
TODO: refactor this method - it is far too complicated now

createCurvedEdge

protected java.awt.Shape createCurvedEdge(float[] poly,
                                          boolean[] invisibleSegments)

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

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
Overrides:
calculateBounds in class AbstractShapeRenderer
Parameters:
item - the item to compute the bounding box for
bounds - the rectangle to populate with the bounding box
See Also:
Renderer.calculateBounds(VisualItem,Rectangle2D)

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 stroke 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

getEdgeType

public EdgeRenderer.EdgeType getEdgeType()
Returns the type of the drawn edge.

Returns:
the edge type

setEdgeType

public void setEdgeType(EdgeRenderer.EdgeType type)
Sets the type of the drawn edge.

Parameters:
type - the new edge type

getArrowType

public EdgeRenderer.EdgeArrowType getArrowType()
Returns the type of the drawn edge.


setArrowType

public void setArrowType(EdgeRenderer.EdgeArrowType type)
Sets the type of the drawn edge.

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 Alignment getHorizontalAlignment1()
Get the horizontal alignment of the edge mount point with the first node.

Returns:
the horizontal alignment

getVerticalAlignment1

public Alignment getVerticalAlignment1()
Get the vertical alignment of the edge mount point with the first node.

Returns:
the vertical alignment

getHorizontalAlignment2

public Alignment getHorizontalAlignment2()
Get the horizontal alignment of the edge mount point with the second node.

Returns:
the horizontal alignment

getVerticalAlignment2

public Alignment getVerticalAlignment2()
Get the vertical alignment of the edge mount point with the second node.

Returns:
the vertical alignment

setHorizontalAlignment1

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

Parameters:
align - the horizontal alignment

setVerticalAlignment1

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

Parameters:
align - the vertical alignment

setHorizontalAlignment2

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

Parameters:
align - the horizontal alignment

setVerticalAlignment2

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

Parameters:
align - the vertical alignment

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

getSplineSlack

public float getSplineSlack()

setSplineSlack

public void setSplineSlack(float splineSlack)

isHideNodeInternalSegments

public boolean isHideNodeInternalSegments()

setHideNodeInternalSegments

public void setHideNodeInternalSegments(boolean hideNodeInternalSegments)


Copyright © 2008 Regents of the University of California