org.ceryle.graph
Class SubGraph

java.lang.Object
  extended by com.touchgraph.graphlayout.Node
      extended by org.ceryle.graph.GraphNode
          extended by org.ceryle.graph.SubGraph
All Implemented Interfaces:
Comparable

public class SubGraph
extends GraphNode
implements Comparable

Extends GraphNode, drawing a subgraph as an invisible node that displays a boundary around a group of nodes connected to it by GraphEdges.

The GraphEdges used are weak attractors and invisible. Bezier paths are used to bound the area, with the boundary's outer distance from the nodes setable, as well as line or fill mode, fill color, and line stroke.

Since:
JDK1.3
Version:
$Id: SubGraph.java,v 3.8 2007-06-15 12:09:25 altheim Exp $
Author:
Murray Altheim
See Also:
GraphNode, GraphEdge

Field Summary
protected  boolean as_subgraph
          Display mode, either as single node or as a bounded subgraph.
 double BEZIER_DIST
          The ratio controlling the distance from the quadratic bezier control point to the bisecting line connecting the outermost points of the enclosing angle.
 double BOUNDARY_DIST
          Boundary separation distance, the distance between the bounding node and the drawn line.
static Color COLOR_SUBGRAPH
          The default color of the subgraph boundary.
static Color COLOR_SUBGRAPH_AXIS
          The default color of the subgraph axes.
static Color COLOR_SUBGRAPH_NODE
          The default color of the subgraph node.
static Color COLOR_SUBGRAPH_TEXT
          The default color of the subgraph text.
static BasicStroke STROKE_DASHED
          The stroke used to draw the subgraph axis.
static BasicStroke STROKE_SUBGRAPH
          The stroke used to draw the subgraph boundary.
static int STYLE_CURVE
          A constant indicating the SubGraph is to be draw using curved forms.
static int STYLE_RECTANGLE
          A constant indicating the SubGraph is to be draw using a rectangle.
 
Fields inherited from class org.ceryle.graph.GraphNode
COLOR_BORDER_DRAG, COLOR_BORDER_FIXED, COLOR_BORDER_INACTIVE, COLOR_BORDER_MOUSE_OVER, COLOR_DEFAULT_NODE, COLOR_FIXED_NODE, COLOR_HILIGHTED_NODE, COLOR_NEW_LOCAL_NODE, COLOR_NODE_DOWNSTREAM, COLOR_NODE_REMOVAL, COLOR_NODE_TEXT, COLOR_NODE_UPSTREAM, COLOR_PROVISIONAL, COLOR_SELECT_NODE, COLOR_SELECT_NODE_B, COLOR_SELECT_NODE_D, COLOR_SMALL_TAG, COLOR_TRANSLUCENT_GRAY, defaultMargin, Ellipsis, fontMetrics, h, hidden, hilight, hMargin, m_listener, maxHeight, maxLabelLength, maxWidth, minHeight, minWidth, outlined, provisional, rel_angle, sortCaseSensitive, STROKE_OUTLINE, STROKE_PROVISIONAL, use3D, vMargin, w
 
Fields inherited from class com.touchgraph.graphlayout.Node
BACK_DEFAULT_COLOR, BACK_FIXED_COLOR, BACK_HILIGHT_COLOR, BACK_SELECT_COLOR, backColor, BORDER_DRAG_COLOR, BORDER_INACTIVE_COLOR, BORDER_MOUSE_OVER_COLOR, DEFAULT_TYPE, drawx, drawy, dx, dy, edges, fixed, font, justMadeLocal, lbl, markedForRemoval, massfade, repulsion, simpleDraw, SMALL_TAG_FONT, TEXT_COLOR, TEXT_FONT, textColor, typ, TYPE_CIRCLE, TYPE_ELLIPSE, TYPE_RECTANGLE, TYPE_ROUNDRECT, visible, visibleEdgeCnt, x, y
 
Constructor Summary
SubGraph(int type, String id, String label, Color color, Set members, GraphLayoutPanel glpanel)
          Constructor for a SubGraph of int type, with Strings for ID id and label, and optional Color and Set of member GraphNodes.
SubGraph(int type, String id, String label, GraphLayoutPanel glpanel)
          Constructor for a SubGraph of int type with Strings for ID id and label, using default for Color.
SubGraph(String id, String label, GraphLayoutPanel glpanel)
          Constructor for a curved SubGraph with Strings for ID id and label, using default for Color.
 
Method Summary
 void addMember(GraphNode member)
          Add a new member to the set of GraphNodes within this SubGraph.
 void addMembers(Set members)
          Add a Set of new members to the set of GraphNodes within this SubGraph.
protected  void drawMemberPoints(Graphics g)
          Paints points at each member node, to better identify set membership.
protected  void extendPoint(Point2D.Double p1, Point2D.Double p2, double ratio)
          Extends the Point2D p2 from Point2D p1 by a ratio based on BOUNDARY_DIST.
 Iterator getMembers()
          Returns an Iterator over the GraphNodes within this SubGraph.
 Color getPaintBackColor(TGPanel graphpanel)
          Returns the background color of the SubGraph node, dependent on context.
 Color getPaintBorderColor(TGPanel graphpanel)
          Returns the border color of the SubGraph node, which is always transparent.
protected  void paintCurve1(Graphics g, TGPanel graphpanel)
          Paints a subgraph when there is one member.
protected  void paintCurve2(Graphics g, TGPanel graphpanel)
          Paints a subgraph when member count equals two.
protected  void paintCurveN(Graphics g, TGPanel graphpanel)
          Paints a subgraph when member count is greater than two.
 void paintNodeBody(Graphics g, TGPanel graphpanel)
          Overrides GraphNode's method when in subgraph mode.
protected  void paintRect(Graphics g, TGPanel graphpanel)
          Paints a subgraph using a rectangular form.
 void paintSmallTag(Graphics g, TGPanel graphpanel, int tagX, int tagY, Color backCol, Color textCol, char character)
          Overrides GraphNode's method to not paint the small tag when the subgraph is displayed.
 void removeMember(GraphNode member)
          Remove the node member from the set of GraphNodes within this SubGraph.
protected  double setControlPoint(Point2D.Double p1, Point2D.Double p2, Point2D.Double cp)
          Sets the (x,y) values of the bisector point bp based upon Points p1 and p2.
 void setFixed(boolean fixed)
          Overrides setFixed(boolean), disabling node fixation, since SubGraph nodes need to float free in order to display properly.
 void setMembers(Set members)
          Set the set of GraphNodes within this SubGraph to members.
 void setVisible(boolean visible)
          Overrides setVisible(boolean) to disable visibility setting.
 void showSubGraph(boolean asSubGraph)
          Sets the drawing mode to subgraph when true, normal node when not.
 
Methods inherited from class org.ceryle.graph.GraphNode
compareTo, getDefaultNodeFont, getHeight, getHilight, getID, getLabel, getMouseListener, getNodeFont, getVerticalTweak, getVerticalTweak, getWidth, isHidden, isProvisional, jubble, paint, paintProvisional, paintSimple, setAlternateFont, setFixed, setHidden, setHilight, setMargin, setMaximumLabelLength, setMouseListener, setNodeTagFont, setNodeTextFont, setProvisional, setSize, setVerticalTweak, toString
 
Methods inherited from class com.touchgraph.graphlayout.Node
addEdge, containsPoint, containsPoint, deleteEdges, edgeAt, edgeCount, edgeNum, getBackColor, getEdges, getFixed, getFont, getLocation, getPaintTextColor, getTextColor, getType, hasEdge, intersects, isFixed, isVisible, removeEdge, setBackColor, setFont, setID, setLabel, setLocation, setLocation, setNodeBackDefaultColor, setNodeBackFixedColor, setNodeBackHilightColor, setNodeBackSelectColor, setNodeBorderDragColor, setNodeBorderInactiveColor, setNodeBorderMouseOverColor, setNodeTextColor, setNodeType, setTextColor, setType, visibleEdgeCount
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

STYLE_CURVE

public static final int STYLE_CURVE
A constant indicating the SubGraph is to be draw using curved forms.

See Also:
Constant Field Values

STYLE_RECTANGLE

public static final int STYLE_RECTANGLE
A constant indicating the SubGraph is to be draw using a rectangle.

See Also:
Constant Field Values

as_subgraph

protected boolean as_subgraph
Display mode, either as single node or as a bounded subgraph.


COLOR_SUBGRAPH

public static Color COLOR_SUBGRAPH
The default color of the subgraph boundary. Ceryle property: http://purl.org/ceryle/prop/graph/color/#subgraph.


COLOR_SUBGRAPH_AXIS

public static Color COLOR_SUBGRAPH_AXIS
The default color of the subgraph axes.


COLOR_SUBGRAPH_NODE

public static Color COLOR_SUBGRAPH_NODE
The default color of the subgraph node.


COLOR_SUBGRAPH_TEXT

public static Color COLOR_SUBGRAPH_TEXT
The default color of the subgraph text.


BOUNDARY_DIST

public double BOUNDARY_DIST
Boundary separation distance, the distance between the bounding node and the drawn line. This affects how far the bounding bezier is from the Nodes it encloses. Default is 50.0. This is also affected by the current zoom value of the GraphLayoutPanel by up to +100%.


BEZIER_DIST

public double BEZIER_DIST
The ratio controlling the distance from the quadratic bezier control point to the bisecting line connecting the outermost points of the enclosing angle. This affects the roundness of the overall curve. Default is 1.6.

It may serve to alter this based on the number of connected nodes. Smaller numbers on larger sets should produce rounder curves. (This value is not used on cubic curves, used when there are only two members.)


STROKE_DASHED

public static final BasicStroke STROKE_DASHED
The stroke used to draw the subgraph axis.


STROKE_SUBGRAPH

public static final BasicStroke STROKE_SUBGRAPH
The stroke used to draw the subgraph boundary.

Constructor Detail

SubGraph

public SubGraph(String id,
                String label,
                GraphLayoutPanel glpanel)
         throws GraphException
Constructor for a curved SubGraph with Strings for ID id and label, using default for Color. Members are to be specified using setMembers(Set).

Throws:
GraphException

SubGraph

public SubGraph(int type,
                String id,
                String label,
                GraphLayoutPanel glpanel)
         throws GraphException
Constructor for a SubGraph of int type with Strings for ID id and label, using default for Color. Members are to be specified using setMembers(Set).

Throws:
GraphException

SubGraph

public SubGraph(int type,
                String id,
                String label,
                Color color,
                Set members,
                GraphLayoutPanel glpanel)
         throws GraphException
Constructor for a SubGraph of int type, with Strings for ID id and label, and optional Color and Set of member GraphNodes. The GraphLayoutPanel glpanel is required, in order for the SubGraph to manage its own Edges. Values for type include STYLE_CURVE and STYLE_RECTANGLE.

Throws:
GraphException
Method Detail

setMembers

public void setMembers(Set members)
                throws GraphException
Set the set of GraphNodes within this SubGraph to members.

Throws:
GraphException

addMember

public void addMember(GraphNode member)
Add a new member to the set of GraphNodes within this SubGraph.


addMembers

public void addMembers(Set members)
Add a Set of new members to the set of GraphNodes within this SubGraph.


removeMember

public void removeMember(GraphNode member)
Remove the node member from the set of GraphNodes within this SubGraph. If the provided GraphNode is not a member, nothing happens.


setVisible

public void setVisible(boolean visible)
Overrides setVisible(boolean) to disable visibility setting.

Overrides:
setVisible in class Node

getMembers

public Iterator getMembers()
Returns an Iterator over the GraphNodes within this SubGraph. This will return an empty Iterator if there are no members, not null.


showSubGraph

public void showSubGraph(boolean asSubGraph)
Sets the drawing mode to subgraph when true, normal node when not.


getPaintBorderColor

public Color getPaintBorderColor(TGPanel graphpanel)
Returns the border color of the SubGraph node, which is always transparent. This overrides the method in org.ceryle.graph.GraphNode.

Overrides:
getPaintBorderColor in class GraphNode

getPaintBackColor

public Color getPaintBackColor(TGPanel graphpanel)
Returns the background color of the SubGraph node, dependent on context. This overrides the method in org.ceryle.graph.GraphNode.

Overrides:
getPaintBackColor in class GraphNode

setFixed

public void setFixed(boolean fixed)
Overrides setFixed(boolean), disabling node fixation, since SubGraph nodes need to float free in order to display properly.

Overrides:
setFixed in class Node

paintNodeBody

public void paintNodeBody(Graphics g,
                          TGPanel graphpanel)
Overrides GraphNode's method when in subgraph mode.

Overrides:
paintNodeBody in class GraphNode

paintCurveN

protected void paintCurveN(Graphics g,
                           TGPanel graphpanel)
Paints a subgraph when member count is greater than two. This uses quadratic bezier curves. Called by paintNodeBody(Graphics,TGPanel) when in subgraph drawing mode.


paintCurve2

protected void paintCurve2(Graphics g,
                           TGPanel graphpanel)
Paints a subgraph when member count equals two. This uses cubic bezier curves. Called by paintNodeBody(Graphics,TGPanel) when in subgraph drawing mode.


paintCurve1

protected void paintCurve1(Graphics g,
                           TGPanel graphpanel)
Paints a subgraph when there is one member. This draws an oval. Called by paintNodeBody(Graphics,TGPanel) when in subgraph drawing mode.


extendPoint

protected void extendPoint(Point2D.Double p1,
                           Point2D.Double p2,
                           double ratio)
Extends the Point2D p2 from Point2D p1 by a ratio based on BOUNDARY_DIST. Point p1's position does not change.


setControlPoint

protected double setControlPoint(Point2D.Double p1,
                                 Point2D.Double p2,
                                 Point2D.Double cp)
Sets the (x,y) values of the bisector point bp based upon Points p1 and p2.

Returns:
the angle of the line connecting Point A with the bisector of the line connecting Points p1 and p2.

drawMemberPoints

protected void drawMemberPoints(Graphics g)
Paints points at each member node, to better identify set membership.


paintRect

protected void paintRect(Graphics g,
                         TGPanel graphpanel)
Paints a subgraph using a rectangular form. Called by paintNodeBody(Graphics,TGPanel) when in subgraph drawing mode.


paintSmallTag

public void paintSmallTag(Graphics g,
                          TGPanel graphpanel,
                          int tagX,
                          int tagY,
                          Color backCol,
                          Color textCol,
                          char character)
Overrides GraphNode's method to not paint the small tag when the subgraph is displayed.

Overrides:
paintSmallTag in class GraphNode


The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.