org.ceryle.graph
Class GraphNode

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

public class GraphNode
extends Node
implements Comparable

An extension of Node acting as a graph node for display of an extended TouchGraph graph.

Since:
JDK1.3
Version:
$Id: GraphNode.java,v 3.14 2007-06-15 12:09:23 altheim Exp $
Author:
Murray Altheim

Field Summary
static Color COLOR_BORDER_DRAG
          The border color of a dragged node.
static Color COLOR_BORDER_FIXED
          The color of fixed generic nodes.
static Color COLOR_BORDER_INACTIVE
          The border color of inactive nodes.
static Color COLOR_BORDER_MOUSE_OVER
          The border color of a mouse-over'd node.
static Color COLOR_DEFAULT_NODE
          The color of generic nodes.
static Color COLOR_FIXED_NODE
          The color of fixed generic nodes.
static Color COLOR_HILIGHTED_NODE
          The color of hilighted nodes.
static Color COLOR_NEW_LOCAL_NODE
          The color of a node just made local.
static Color COLOR_NODE_DOWNSTREAM
          The border color of nodes downstream (following directed edges) from a specific node.
static Color COLOR_NODE_REMOVAL
          The color of a node just prior to removal.
static Color COLOR_NODE_TEXT
          The color of node text.
static Color COLOR_NODE_UPSTREAM
          The border color of nodes upstream (against directed edges) from a specific node.
static Color COLOR_PROVISIONAL
          The background color of provisional (i.e., temporary) nodes.
static Color COLOR_SELECT_NODE
          The color of the selected node.
static Color COLOR_SELECT_NODE_B
           
static Color COLOR_SELECT_NODE_D
           
static Color COLOR_SMALL_TAG
          The color of the small tag's background (the foreground text will be white).
static Color COLOR_TRANSLUCENT_GRAY
          The background color of pinned nodes' small tag.
static int defaultMargin
          Default margin, in pixels.
protected static String Ellipsis
           
protected  FontMetrics fontMetrics
           
protected  int h
           
protected  boolean hidden
          Hidden status of this GraphNode.
protected  Color hilight
           
static int hMargin
          Horizontal margin, in pixels.
protected  MouseListener m_listener
           
static int maxHeight
          Maximum height, in pixels (default is 80).
static int maxLabelLength
          An int acting as the character limit for node labels.
static int maxWidth
          Maximum width, in pixels (default is 2000).
static int minHeight
          Minimum height, in pixels (default is 10).
static int minWidth
          Minimum width, in pixels (default is 10).
 boolean outlined
          When true, the GraphNode is drawn with an extra outline border.
protected  boolean provisional
          Provisional status of this GraphNode.
 double rel_angle
          Relative angle, used in calculating the angle between nodes.
static boolean sortCaseSensitive
          A boolean controlling whether the compareTo(Object) implementation of the Comparable interface when sorting by Node label should be done in case sensitive (true) or insensitive (false) mode.
static BasicStroke STROKE_OUTLINE
          The stroke used to draw the outline hilight.
protected static BasicStroke STROKE_PROVISIONAL
          Stroke for drawing provisional (temporary) nodes.
static boolean use3D
          A boolean controlling use of 3D versus flat style nodes.
static int vMargin
          Vertical margin, in pixels.
protected  int 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
GraphNode()
          Minimal constructor which throws an Exception, given that unlike TouchGraph Nodes, all GraphNodes must have an ID.
GraphNode(int type, String id, String label, Color color)
          Constructor with Strings for ID id and label, using defaults for type (rectangle) and color (a static variable from TGPanel).
 
Method Summary
 int compareTo(Object o)
          Implements the Comparable interface to compare this GraphNode with another.
static Font getDefaultNodeFont()
          Returns the default font.
 int getHeight()
          Overrides Node's method by returning the calculated height of this GraphNode.
 Color getHilight()
          Returns the hilight Color of this GraphNode.
 String getID()
          Returns the ID of this GraphNode.
 String getLabel()
          Overrides com.touchgraph.graphlayout.Node's method to return the label of this Node as a String, substituting an ellipsis should the length of the label exceed maxLabelLength.
 MouseListener getMouseListener()
          Returns the single MouseListener, null if it has not been set.
 Font getNodeFont()
          Returns the currently-used font for this GraphNode.
 Color getPaintBackColor(TGPanel tgPanel)
          Returns the background color of the node, dependent on context.
 Color getPaintBorderColor(TGPanel tgPanel)
          Returns the border color of the node, dependent on context.
 int getVerticalTweak()
          Returns a vertical text descent tweaking value based on the supplied font.
static int getVerticalTweak(int fontsize)
          Returns a vertical text descent tweaking value based on the supplied font size.
 int getWidth()
          Overrides Node's method by returning the calculated width of this GraphNode.
 boolean isHidden()
          Returns the hidden status of this GraphNode.
 boolean isProvisional()
          Returns the provisional status of this GraphNode.
 void jubble(int distance)
          Randomly moves the GraphNode horizontally and vertically within the limits set by the int distance.
 void paint(Graphics g, TGPanel tgPanel)
          Overrides Node's method, paying attention to "hidden" status.
 void paintNodeBody(Graphics g, TGPanel tgPanel)
          Overrides Node's method, painting the background of the node, along with its label.
 void paintProvisional(Graphics g, TGPanel tgPanel)
          Paints the body of this node as an outline.
 void paintSimple(Graphics g, TGPanel tgPanel)
          Paints the body of this node as an simple square.
 void paintSmallTag(Graphics g, TGPanel tgPanel, int tagX, int tagY, Color backCol, Color textCol, char character)
          Overrides Node's method using a color property from GraphLayoutPanel.
 void setAlternateFont(Font font)
          Sets the optional alternate font for this Node to the supplied Font.
 void setFixed(boolean fixed, Point p)
          Sets the fixed status of this GraphNode to the boolean fixed, fixing it at the provided Point p.
 void setHidden(boolean hidden)
          Sets the hidden status of this GraphNode to the boolean hidden.
 void setHilight(Color hilight)
          Sets the hilight of this node to the Color hilight.
 void setMargin(int margin)
          Sets the horizontal and vertical margins of this GraphNode to the int margin.
static void setMaximumLabelLength(int max)
          Sets the maximum length of a Node label to the int max.
 void setMouseListener(MouseListener listener)
          Sets the single MouseListener to listener.
static void setNodeTagFont(Font font)
          Extends Node to allow setting of the small tag font to the Font font.
static void setNodeTextFont(Font font)
          Passes the font change on to the superclass, sets the vertical tweaking, and the big font size.
 void setProvisional(boolean provisional)
          Sets the provisional status of this GraphNode to the boolean provisional.
protected  void setSize(Graphics g)
          Sets the internal width and height variables based on current properties.
static void setVerticalTweak(int fontsize)
          Sets the vertical text descent tweaking based on the supplied font size.
 String toString()
          Returns the String representation of this GraphNode, ie., its label.
 
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, setFixed, setFont, setID, setLabel, setLocation, setLocation, setNodeBackDefaultColor, setNodeBackFixedColor, setNodeBackHilightColor, setNodeBackSelectColor, setNodeBorderDragColor, setNodeBorderInactiveColor, setNodeBorderMouseOverColor, setNodeTextColor, setNodeType, setTextColor, setType, setVisible, visibleEdgeCount
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COLOR_DEFAULT_NODE

public static Color COLOR_DEFAULT_NODE
The color of generic nodes. Ceryle property: http://purl.org/ceryle/prop/graph/color/#defaultNode.


COLOR_NODE_TEXT

public static Color COLOR_NODE_TEXT
The color of node text. Ceryle property: http://purl.org/ceryle/prop/graph/color/#nodeText.


COLOR_FIXED_NODE

public static Color COLOR_FIXED_NODE
The color of fixed generic nodes. Ceryle property: http://purl.org/ceryle/prop/graph/color/#nodeFixed.


COLOR_BORDER_FIXED

public static Color COLOR_BORDER_FIXED
The color of fixed generic nodes. Ceryle property: http://purl.org/ceryle/prop/graph/color/#nodeFixed.


COLOR_HILIGHTED_NODE

public static Color COLOR_HILIGHTED_NODE
The color of hilighted nodes. Ceryle property: http://purl.org/ceryle/prop/graph/color/#nodeHilighted.


COLOR_NEW_LOCAL_NODE

public static Color COLOR_NEW_LOCAL_NODE
The color of a node just made local. Ceryle property: http://purl.org/ceryle/prop/graph/color/#newLocalNode.


COLOR_BORDER_DRAG

public static Color COLOR_BORDER_DRAG
The border color of a dragged node. Ceryle property: http://purl.org/ceryle/prop/graph/color/#borderDrag.


COLOR_BORDER_MOUSE_OVER

public static Color COLOR_BORDER_MOUSE_OVER
The border color of a mouse-over'd node. Ceryle property: http://purl.org/ceryle/prop/graph/color/#borderMouseOver.


COLOR_NODE_REMOVAL

public static Color COLOR_NODE_REMOVAL
The color of a node just prior to removal. Ceryle property: http://purl.org/ceryle/prop/graph/color/#nodeRemoval.


COLOR_SELECT_NODE

public static Color COLOR_SELECT_NODE
The color of the selected node. Default is an apple green. Ceryle property: http://purl.org/ceryle/prop/graph/color/#selectNode.


COLOR_SELECT_NODE_D

public static Color COLOR_SELECT_NODE_D

COLOR_SELECT_NODE_B

public static Color COLOR_SELECT_NODE_B

COLOR_BORDER_INACTIVE

public static Color COLOR_BORDER_INACTIVE
The border color of inactive nodes. Ceryle property: http://purl.org/ceryle/prop/graph/color/#nodeBorder.


COLOR_NODE_DOWNSTREAM

public static Color COLOR_NODE_DOWNSTREAM
The border color of nodes downstream (following directed edges) from a specific node. Ceryle property: http://purl.org/ceryle/prop/graph/color/#nodeDownstream.


COLOR_NODE_UPSTREAM

public static Color COLOR_NODE_UPSTREAM
The border color of nodes upstream (against directed edges) from a specific node. Ceryle property: http://purl.org/ceryle/prop/graph/color/#nodeUpstream.


COLOR_SMALL_TAG

public static Color COLOR_SMALL_TAG
The color of the small tag's background (the foreground text will be white). Ceryle property: http://purl.org/ceryle/prop/graph/color/#smallTag.


COLOR_PROVISIONAL

public static Color COLOR_PROVISIONAL
The background color of provisional (i.e., temporary) nodes. This is used during the creation of nodes to indicate their unfinished state. The default is a milky, translucent white.


COLOR_TRANSLUCENT_GRAY

public static Color COLOR_TRANSLUCENT_GRAY
The background color of pinned nodes' small tag. This is a translucent gray.


sortCaseSensitive

public static boolean sortCaseSensitive
A boolean controlling whether the compareTo(Object) implementation of the Comparable interface when sorting by Node label should be done in case sensitive (true) or insensitive (false) mode. The default is false.


use3D

public static boolean use3D
A boolean controlling use of 3D versus flat style nodes. This should be set 'false' if performance on large graphs is suffering. Default is true.


maxLabelLength

public static int maxLabelLength
An int acting as the character limit for node labels. Labels exceeding this limit will be truncated, with an ellipsis substituting for the missing characters. The default is 16 characters.


rel_angle

public double rel_angle
Relative angle, used in calculating the angle between nodes.


hidden

protected boolean hidden
Hidden status of this GraphNode. When true, drawing is suppressed.


provisional

protected boolean provisional
Provisional status of this GraphNode. When true, drawing is shown as an outline.


defaultMargin

public static int defaultMargin
Default margin, in pixels.


hMargin

public static int hMargin
Horizontal margin, in pixels.


vMargin

public static int vMargin
Vertical margin, in pixels.


minHeight

public static int minHeight
Minimum height, in pixels (default is 10).


minWidth

public static int minWidth
Minimum width, in pixels (default is 10).


maxWidth

public static int maxWidth
Maximum width, in pixels (default is 2000).


maxHeight

public static int maxHeight
Maximum height, in pixels (default is 80).


STROKE_PROVISIONAL

protected static final BasicStroke STROKE_PROVISIONAL
Stroke for drawing provisional (temporary) nodes.


STROKE_OUTLINE

public static final BasicStroke STROKE_OUTLINE
The stroke used to draw the outline hilight.


outlined

public boolean outlined
When true, the GraphNode is drawn with an extra outline border. (This is implemented in only certain classes.)


fontMetrics

protected FontMetrics fontMetrics

Ellipsis

protected static String Ellipsis

h

protected int h

w

protected int w

hilight

protected Color hilight

m_listener

protected MouseListener m_listener
Constructor Detail

GraphNode

public GraphNode()
          throws GraphException
Minimal constructor which throws an Exception, given that unlike TouchGraph Nodes, all GraphNodes must have an ID.

Throws:
GraphException

GraphNode

public GraphNode(int type,
                 String id,
                 String label,
                 Color color)
          throws GraphException
Constructor with Strings for ID id and label, using defaults for type (rectangle) and color (a static variable from TGPanel). If the label is null, it will be taken from the ID value.

Throws:
GraphException
Method Detail

setMouseListener

public void setMouseListener(MouseListener listener)
Sets the single MouseListener to listener. Setting this to null effectively removes the listener.


getMouseListener

public MouseListener getMouseListener()
Returns the single MouseListener, null if it has not been set.


setMaximumLabelLength

public static void setMaximumLabelLength(int max)
Sets the maximum length of a Node label to the int max. The provided value must be greater than 7, or it will be ignored (i.e., the shortest sensible limit: 7 = 1 character + "..." + 3 characters ).


setNodeTextFont

public static void setNodeTextFont(Font font)
Passes the font change on to the superclass, sets the vertical tweaking, and the big font size.


getVerticalTweak

public int getVerticalTweak()
Returns a vertical text descent tweaking value based on the supplied font. If the alternate font is set, this returns the tweak value for that font, otherwise for the default font.


getVerticalTweak

public static int getVerticalTweak(int fontsize)
Returns a vertical text descent tweaking value based on the supplied font size.


setVerticalTweak

public static void setVerticalTweak(int fontsize)
Sets the vertical text descent tweaking based on the supplied font size. This is universal across all GraphNodes and its subclasses if they include the vtweak value in text positioning in paintNodeBody().


getID

public String getID()
Returns the ID of this GraphNode. This produces the same result as getID().

Overrides:
getID in class Node

isHidden

public boolean isHidden()
Returns the hidden status of this GraphNode.


setHidden

public void setHidden(boolean hidden)
Sets the hidden status of this GraphNode to the boolean hidden.


isProvisional

public boolean isProvisional()
Returns the provisional status of this GraphNode.


jubble

public void jubble(int distance)
Randomly moves the GraphNode horizontally and vertically within the limits set by the int distance.


setProvisional

public void setProvisional(boolean provisional)
Sets the provisional status of this GraphNode to the boolean provisional.


getLabel

public String getLabel()
Overrides com.touchgraph.graphlayout.Node's method to return the label of this Node as a String, substituting an ellipsis should the length of the label exceed maxLabelLength.

Overrides:
getLabel in class Node

setMargin

public void setMargin(int margin)
Sets the horizontal and vertical margins of this GraphNode to the int margin.


setSize

protected void setSize(Graphics g)
Sets the internal width and height variables based on current properties.


getWidth

public int getWidth()
Overrides Node's method by returning the calculated width of this GraphNode.

Overrides:
getWidth in class Node

getHeight

public int getHeight()
Overrides Node's method by returning the calculated height of this GraphNode.

Overrides:
getHeight in class Node

setAlternateFont

public void setAlternateFont(Font font)
Sets the optional alternate font for this Node to the supplied Font. This can be reset by setting to null.


getNodeFont

public Font getNodeFont()
Returns the currently-used font for this GraphNode.


getDefaultNodeFont

public static Font getDefaultNodeFont()
Returns the default font.


setNodeTagFont

public static void setNodeTagFont(Font font)
Extends Node to allow setting of the small tag font to the Font font.


setFixed

public void setFixed(boolean fixed,
                     Point p)
Sets the fixed status of this GraphNode to the boolean fixed, fixing it at the provided Point p. If p is null, the Node is fixed at its current location. This includes adding an XML processing instruction to the Node of the form:
    <?ceryle_node_loc 233,-178 ?>
 
The PI target is specified by the constant NODE_LOC_INDICATOR. p is ignored if fixed is false.


setHilight

public void setHilight(Color hilight)
Sets the hilight of this node to the Color hilight. To turn off hilighting, set to null.


getHilight

public Color getHilight()
Returns the hilight Color of this GraphNode. The hilight is a temporary condition, used in key navigation.


paint

public void paint(Graphics g,
                  TGPanel tgPanel)
Overrides Node's method, paying attention to "hidden" status.

Overrides:
paint in class Node

paintNodeBody

public void paintNodeBody(Graphics g,
                          TGPanel tgPanel)
Overrides Node's method, painting the background of the node, along with its label.

Overrides:
paintNodeBody in class Node

paintSimple

public void paintSimple(Graphics g,
                        TGPanel tgPanel)
Paints the body of this node as an simple square.


paintProvisional

public void paintProvisional(Graphics g,
                             TGPanel tgPanel)
Paints the body of this node as an outline.


getPaintBorderColor

public Color getPaintBorderColor(TGPanel tgPanel)
Returns the border color of the node, dependent on context. This overrides the method in com.touchgraph.graphlayout.Node.

Overrides:
getPaintBorderColor in class Node

getPaintBackColor

public Color getPaintBackColor(TGPanel tgPanel)
Returns the background color of the node, dependent on context. This overrides the method in com.touchgraph.graphlayout.Node by ignoring the fixation state of the Node.

Overrides:
getPaintBackColor in class Node

paintSmallTag

public void paintSmallTag(Graphics g,
                          TGPanel tgPanel,
                          int tagX,
                          int tagY,
                          Color backCol,
                          Color textCol,
                          char character)
Overrides Node's method using a color property from GraphLayoutPanel. This also alters the background color on alone, pinned nodes.

Overrides:
paintSmallTag in class Node

compareTo

public int compareTo(Object o)
Implements the Comparable interface to compare this GraphNode with another. There are two modes. If the int rel_angle has not been set (its default value is Double.MIN_VALUE), the comparison is made based on node label (if not set, node ID is used).

If rel_angle has been set, This is based on relative position (in degrees) from another GraphNode (no other sorting methods have been seen necessary, yet). It's assumed that this comparison is only made when both nodes have a set angle (default is zero). If only one is set, returns 0.

Specified by:
compareTo in interface Comparable
Throws:
ClassCastException - if the supplied Object is not a GraphNode

toString

public String toString()
Returns the String representation of this GraphNode, ie., its label.

Overrides:
toString in class Object


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