att.grappa
Class Graph

java.lang.Object
  extended by att.grappa.Element
      extended by att.grappa.Subgraph
          extended by att.grappa.Graph
All Implemented Interfaces:
GrappaConstants, java.util.Comparator

public class Graph
extends Subgraph

This class is the root of the overall graph and provides methods for working with the entire graph (for example, printing the graph). It is an extension of the Subgraph class.

Version:
1.2, ; Copyright 1996 - 2010 by AT&T Corp.
Author:
John Mocenigo, Research @ AT&T Labs

Field Summary
 boolean filterMode
          When filtering a graph (see GrappaSupport.filterGraph) or whenever edge names are desired as part of the output of a printGraph call, set this value to true.
static java.lang.String INDENT_STRING
          The string used for indentation when printing out the graph.
 java.awt.font.FontRenderContext REFCNTXT
          Reference FontRenderContext
 
Fields inherited from class att.grappa.Subgraph
currentSelection, defaultNamePrefix
 
Fields inherited from class att.grappa.Element
counter, highlight, linewidth, object, printAllAttributes, printDefaultAttributes, usePrintList, visible
 
Fields inherited from interface att.grappa.GrappaConstants
_NO_TYPE, ANONYMOUS_PREFIX, BBOX_ATTR, BBOX_HASH, BOX_SHAPE, BOX_TYPE, CLUSTERRANK_ATTR, COLOR_ATTR, COLOR_HASH, COLOR_TYPE, CUSTOM_ATTR, CUSTOM_HASH, CUSTOM_SHAPE, DELETION_MASK, DIAMOND_SHAPE, DIR_ATTR, DIR_HASH, DIR_TYPE, DISTORTION_ATTR, DISTORTION_HASH, DOUBLE_TYPE, DOUBLECIRCLE_SHAPE, DOUBLEOCTAGON_SHAPE, EDGE, EGG_SHAPE, FILLCOLOR_ATTR, FILLCOLOR_HASH, FONTCOLOR_ATTR, FONTCOLOR_HASH, FONTNAME_ATTR, FONTNAME_HASH, FONTSIZE_ATTR, FONTSIZE_HASH, FONTSTYLE_ATTR, FONTSTYLE_HASH, FONTSTYLE_TYPE, GRAPPA_BACKGROUND_COLOR_ATTR, GRAPPA_BACKGROUND_COLOR_HASH, GRAPPA_DELETION_STYLE_ATTR, GRAPPA_DELETION_STYLE_HASH, GRAPPA_FONTSIZE_ADJUSTMENT_ATTR, GRAPPA_FONTSIZE_ADJUSTMENT_HASH, GRAPPA_SELECTION_STYLE_ATTR, GRAPPA_SELECTION_STYLE_HASH, GRAPPA_SHAPE, HASHMAP_TYPE, HEADLABEL_ATTR, HEADLABEL_HASH, HEADLP_ATTR, HEADLP_HASH, HEIGHT_ATTR, HEIGHT_HASH, HEXAGON_SHAPE, HIGHLIGHT_MASK, HIGHLIGHT_OFF, HIGHLIGHT_ON, HIGHLIGHT_TOGGLE, HOUSE_SHAPE, IDENTXFRM, IMAGE_ATTR, IMAGE_HASH, INTEGER_TYPE, INVERTEDHOUSE_SHAPE, INVERTEDTRAPEZIUM_SHAPE, INVERTEDTRIANGLE_SHAPE, LABEL_ATTR, LABEL_HASH, LINE_SHAPE, LINE_TYPE, LOG10, LP_ATTR, LP_HASH, MARGIN_ATTR, MARGIN_HASH, MCIRCLE_SHAPE, MCLIMIT_ATTR, MCLIMIT_HASH, MDIAMOND_SHAPE, MINBOX_ATTR, MINBOX_HASH, MINLEN_ATTR, MINLEN_HASH, MINSIZE_ATTR, MINSIZE_HASH, MRECORD_SHAPE, MSQUARE_SHAPE, NBSP, NEW_LINE, NO_SHAPE, NODE, NODESEP_ATTR, NODESEP_HASH, OCTAGON_SHAPE, ORIENTATION_ATTR, ORIENTATION_HASH, OVAL_SHAPE, PACKAGE_PREFIX, PARALLELOGRAM_SHAPE, PATCH_ATTR, PATCH_HASH, PENTAGON_SHAPE, PERIPHERIES_ATTR, PERIPHERIES_HASH, PERIPHERY_GAP, PKG_LOWER, PKG_UPLOW, PKG_UPPER, PLAINTEXT_SHAPE, POINT_SHAPE, POINT_TYPE, PointsPerInch, POLYGON_SHAPE, POS_ATTR, POS_HASH, PRINTLIST_ATTR, PRINTLIST_HASH, RANKDIR_ATTR, RANKDIR_HASH, RANKSEP_ATTR, RANKSEP_HASH, RECORD_SHAPE, RECTS_ATTR, RECTS_HASH, ROTATION_ATTR, ROTATION_HASH, ROUNDEDBOX_SHAPE, SELECTION_MASK, SHAPE_ATTR, SHAPE_HASH, SHAPE_MASK, SHAPE_TYPE, SIDES_ATTR, SIDES_HASH, SIZE_ATTR, SIZE_HASH, SIZE_TYPE, SKEW_ATTR, SKEW_HASH, STRING_TYPE, STYLE_ATTR, STYLE_HASH, STYLE_TYPE, SUBGRAPH, SYSTEM, TAG_ATTR, TAG_HASH, TAILLABEL_ATTR, TAILLABEL_HASH, TAILLP_ATTR, TAILLP_HASH, TIP_ATTR, TIP_HASH, TRAPEZIUM_SHAPE, TRIANGLE_SHAPE, TRIPLEOCTAGON_SHAPE, TYPES_SHIFT, WEIGHT_ATTR, WEIGHT_HASH, WIDTH_ATTR, WIDTH_HASH
 
Constructor Summary
Graph(java.lang.String graphName)
          Creates a directed graph that is not strict A convenience method equivalent to Graph(graphName,true,false).
Graph(java.lang.String graphName, boolean directed, boolean strict)
          Creates a new, empty Graph object.
 
Method Summary
 void addPanel(GrappaPanel panel)
          Adds a panel to the list of GrappaPanels that are displaying this graph.
static int attributeType(java.lang.String attrname)
          Returns the attribute conversion type for the supplied attribute name.
 void buildShapes()
          Builds any GrappaNexus object not already built for elements in this graph.
 void decrementIndent()
          Decrease the indent string by removing one INDENT_STRING.
 boolean dropcloth(boolean block, boolean auto)
          Sets and unsets a flag in a synchronized manner so that during the period that the flag is set, painting will not occur.
 java.io.PrintWriter getErrorWriter()
          Get the current PrintWriter used for error messages.
static Attribute getGlobalAttribute(int type, java.lang.String key)
          Gets a graph default attribute.
static java.util.Iterator<java.lang.String> getGlobalAttributeKeys(int type)
          Gets an Iterator of the specified graph default attribute keys
static java.util.Iterator<Attribute> getGlobalAttributePairs(int type)
          Gets an iterator of the specified graph default attributes
static int getGlobalAttributeSize(int type)
          Get a count of the graph default attributes of a particular type.
 Attribute getGrappaAttribute(java.lang.String key)
          Gets Grappa default attribute.
 java.util.Iterator<java.lang.String> getGrappaAttributeKeys()
          Get an Iterator of the Grappa package attribute keys.
 java.lang.Object getGrappaAttributeValue(java.lang.String key)
          Gets Grappa default attribute value.
 int getId(int type)
          Get the next id number for the specified type, but do not increment the counter.
 java.lang.String getIndent()
          Get the current indent string.
 boolean getSynchronizePaint()
          Get the current paint synchronization indicator value.
 java.lang.String getToolTipText()
          Get the tooltip text displayed when outside the graph area.
 void incrementIndent()
          Increase the indent string by appending INDENT_STRING.
 boolean isDirected()
          Check if the graph is directed.
 boolean isEditable()
          Check if this graph is interactively editable (i.e., through mouse events).
 boolean isMenuable()
          Check if an element-specific menu is available interactively (i.e., through mouse events).
 boolean isSelectable()
          Check if graph elements are interactively selectable (i.e., through mouse events).
 boolean isStrict()
          Check if the graph is strict (i.e., no self-loops).
 void paintImmediately()
          Makes a paintImmediately request of all GrappaPanels that are displaying this graph.
 void printError(java.lang.String msg)
          Print the supplied message to the error output.
 void printError(java.lang.String msg, java.lang.Exception ex)
          Print the supplied message and exception information to the error output.
 void printGraph(java.io.OutputStream output)
          Output graph to specified OutputStream.
 void printGraph(java.io.Writer output)
          Output graph to specified Writer.
 void removePanel(GrappaPanel panel)
          Removes a panel to the list of GrappaPanels that are displaying this graph.
 void repaint()
          Makes a repaint request of all GrappaPanels that are displaying this graph.
 void reset()
          Reset this graph by removing all its elements and re-initiailizing its internal variables.
 void reset(java.lang.String graphName, boolean directed, boolean strict)
          Reset this graph by removing all its elements and re-initiailizing its internal variables and possibly changing its name, directedness and strictness.
 void resync()
          Builds any GrappaNexus object not already built and rebuilds those that already exist for all elements in this graph.
 boolean setEditable(boolean mode)
          Set the editability of the graph.
 java.io.PrintWriter setErrorWriter(java.io.PrintWriter errWriter)
          Set the PrintWriter for error messages.
 java.lang.Object setGrappaAttribute(java.lang.String key, java.lang.String value)
          Sets a Grappa package attribute.
 boolean setMenuable(boolean mode)
          Set whether element-specific menus are to be available interactively.
 boolean setSelectable(boolean mode)
          Set the selectability of the graph.
 boolean setSynchronizePaint(boolean sync)
          Sets or unsets indication that paint requests should be done within a synchronized wrapper that prevents concurrent paints and any paints between calls to the dropcloth method.
 java.lang.String setToolTipText(java.lang.String text)
          Set the tooltip text displayed when outside the graph area.
static boolean validGrappaAttributeKey(java.lang.String key)
          Check if the given key has a format consistent with Grappa package attribute keys.
 
Methods inherited from class att.grappa.Subgraph
addEdge, addNode, addSubgraph, addTypeTag, clearPatchWork, compare, computePatchWork, countOfElements, countOfLocalElements, createElement, edgeElements, edgeElementsAsArray, elements, elements, equals, findEdgeByName, findNodeByName, findSubgraphByName, getBoundingBox, getEdgeAttribute, getEdgeAttributeKeys, getEdgeAttributePairs, getEdgeAttributeValue, getNodeAttribute, getNodeAttributeKeys, getNodeAttributePairs, getNodeAttributeValue, getShowEdgeLabels, getShowNodeLabels, getShowSubgraphLabels, getType, hasEmptySubgraphs, hasTypeTag, hasTypeTags, isCluster, isLR, isRoot, isSubgraph, listOfElements, nodeElements, nodeElementsAsArray, patchWork, preparePatchWork, printSubgraph, removeEdge, removeEmptySubgraphs, removeNode, removeSubgraph, removeTypeTag, removeTypeTags, resetBoundingBox, setAttribute, setAttribute, setEdgeAttribute, setEdgeAttribute, setName, setNodeAttribute, setNodeAttribute, setShowEdgeLabels, setShowNodeLabels, setShowSubgraphLabels, subgraphElements, subgraphElementsAsArray
 
Methods inherited from class att.grappa.Element
addTag, attrOfInterest, bdfs, buildShape, canonString, canonValue, clearBBox, delete, getAttribute, getAttributePairs, getAttributeValue, getDefaultAttribute, getDefaultAttribute, getGraph, getGrappaNexus, getId, getIdKey, getLocalAttribute, getLocalAttributeKeys, getLocalAttributePairs, getName, getSubgraph, getThisAttribute, getThisAttributeValue, hasAttributeForKey, hasDefaultTag, hasDefaultTags, hasLocalTag, hasLocalTags, hasTag, hasTags, isEdge, isNode, isOfInterest, listAttrsOfInterest, printElement, removeTag, removeTags, setDefaultAttribute, setDefaultAttribute, setDefaultAttribute, setDefaultAttribute, setIdKey, setSubgraph, setUserAttributeType, toString, typeString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INDENT_STRING

public static final java.lang.String INDENT_STRING
The string used for indentation when printing out the graph.

See Also:
Constant Field Values

filterMode

public boolean filterMode
When filtering a graph (see GrappaSupport.filterGraph) or whenever edge names are desired as part of the output of a printGraph call, set this value to true. The edge name will be included among edge attributes in the print output as '__nAmE__'. filterGraph automatically handles setting this variable, but users writing their own version of filterGraph will need it.


REFCNTXT

public final java.awt.font.FontRenderContext REFCNTXT
Reference FontRenderContext

Constructor Detail

Graph

public Graph(java.lang.String graphName,
             boolean directed,
             boolean strict)
Creates a new, empty Graph object.

Parameters:
graphName - the name of this graph.
directed - use true if graph is to be a directed graph
strict - use true if graph is a strict graph

Graph

public Graph(java.lang.String graphName)
Creates a directed graph that is not strict A convenience method equivalent to Graph(graphName,true,false).

Parameters:
graphName - the name of this graph.
See Also:
Graph(java.lang.String, boolean, boolean)
Method Detail

setSynchronizePaint

public boolean setSynchronizePaint(boolean sync)
Sets or unsets indication that paint requests should be done within a synchronized wrapper that prevents concurrent paints and any paints between calls to the dropcloth method.

Parameters:
sync - value to which indicator will be set
Returns:
the previous indicator value
See Also:
dropcloth(boolean, boolean)

getSynchronizePaint

public boolean getSynchronizePaint()
Get the current paint synchronization indicator value.

Returns:
the current paint synchronization indicator value
See Also:
setSynchronizePaint(boolean)

dropcloth

public boolean dropcloth(boolean block,
                         boolean auto)
Sets and unsets a flag in a synchronized manner so that during the period that the flag is set, painting will not occur.

Parameters:
block - value to which to set the indicator flag
auto - when block is false, setting this parameter true will request a repaint() if any paint requests arrived while the dropcloth was laid out.
Returns:
returns false only when block is true and a paint is pending or in progress.
See Also:
setSynchronizePaint(boolean)

getGrappaAttribute

public Attribute getGrappaAttribute(java.lang.String key)
                             throws java.lang.IllegalArgumentException
Gets Grappa default attribute.

Parameters:
key - the search key for the corresponding attribute.
Returns:
the value of the matching Grappa default attribute or null.
Throws:
java.lang.IllegalArgumentException - whenever the key is null

getGrappaAttributeValue

public java.lang.Object getGrappaAttributeValue(java.lang.String key)
                                         throws java.lang.IllegalArgumentException
Gets Grappa default attribute value.

Parameters:
key - the search key for the corresponding attribute.
Returns:
the value portion of the matching Grappa default attribute or null.
Throws:
java.lang.IllegalArgumentException - whenever the key is null

setGrappaAttribute

public java.lang.Object setGrappaAttribute(java.lang.String key,
                                           java.lang.String value)
                                    throws java.lang.IllegalArgumentException
Sets a Grappa package attribute. A Grappa package attribute is one specific to Grappa (for example, a display color) rather than an attribute that relates to a graph.

Parameters:
key - the search key for the corresponding attribute.
Returns:
the previous value of the matching Grappa default attribute or null.
Throws:
java.lang.IllegalArgumentException - whenever the key is not prefixed by Grappa.PKG_LOWER
See Also:
GrappaConstants.PKG_LOWER

attributeType

public static int attributeType(java.lang.String attrname)
Returns the attribute conversion type for the supplied attribute name. Only graph global specific attribute name/type mappings are checked.

Parameters:
attrname - the attribute name
Returns:
the currently associated attribute type

getGrappaAttributeKeys

public java.util.Iterator<java.lang.String> getGrappaAttributeKeys()
Get an Iterator of the Grappa package attribute keys.

Returns:
an Iterator of Attribute objects

validGrappaAttributeKey

public static boolean validGrappaAttributeKey(java.lang.String key)
Check if the given key has a format consistent with Grappa package attribute keys. A Grappa package key starts with Grappa.PKG_LOWER.

Parameters:
key - the key to validate
Returns:
true if the supplied key could serve as a Grappa package attribute key.
See Also:
GrappaConstants.PKG_LOWER

getGlobalAttribute

public static Attribute getGlobalAttribute(int type,
                                           java.lang.String key)
                                    throws java.lang.IllegalArgumentException
Gets a graph default attribute. A graph default attribute determines basic graph characteristics initially (e.g., node shape).

Parameters:
type - indicates attribute type.
key - the search key for the corresponding attribute.
Returns:
the value of the matching graph default attribute or null.
Throws:
java.lang.IllegalArgumentException - whenever the specified type is not valid
See Also:
GrappaConstants.NODE, GrappaConstants.EDGE, GrappaConstants.SUBGRAPH

getGlobalAttributeKeys

public static java.util.Iterator<java.lang.String> getGlobalAttributeKeys(int type)
                                                                   throws java.lang.IllegalArgumentException
Gets an Iterator of the specified graph default attribute keys

Parameters:
type - indicates attribute type.
Returns:
an Iterator of String objects
Throws:
java.lang.IllegalArgumentException - whenever the specified type is not valid
See Also:
GrappaConstants.NODE, GrappaConstants.EDGE, GrappaConstants.SUBGRAPH

getGlobalAttributePairs

public static java.util.Iterator<Attribute> getGlobalAttributePairs(int type)
                                                             throws java.lang.IllegalArgumentException
Gets an iterator of the specified graph default attributes

Parameters:
type - indicates attribute type.
Returns:
an Iterator of Attribute objects
Throws:
java.lang.IllegalArgumentException - whenever the specified type is not valid
See Also:
GrappaConstants.NODE, GrappaConstants.EDGE, GrappaConstants.SUBGRAPH

getGlobalAttributeSize

public static int getGlobalAttributeSize(int type)
                                  throws java.lang.IllegalArgumentException
Get a count of the graph default attributes of a particular type.

Parameters:
type - indicates attribute type.
Returns:
a count of the specified graph default attributes
Throws:
java.lang.IllegalArgumentException - whenever the specified type is not valid
See Also:
GrappaConstants.NODE, GrappaConstants.EDGE, GrappaConstants.SUBGRAPH

printGraph

public void printGraph(java.io.Writer output)
Output graph to specified Writer.

Parameters:
output - the Writer for writing

printGraph

public void printGraph(java.io.OutputStream output)
Output graph to specified OutputStream. A convenience method to accomodate the OuputStreams easily.

Parameters:
output - the OutputStream for writing

getId

public int getId(int type)
          throws java.lang.IllegalArgumentException
Get the next id number for the specified type, but do not increment the counter.

Parameters:
type - type of id number to return
Returns:
the next sequential id number (counter is not incremented).
Throws:
java.lang.IllegalArgumentException - whenever the specified type is not valid
See Also:
GrappaConstants.NODE, GrappaConstants.EDGE, GrappaConstants.SUBGRAPH

getIndent

public java.lang.String getIndent()
Get the current indent string.

Returns:
the current indent string.

incrementIndent

public void incrementIndent()
Increase the indent string by appending INDENT_STRING.

See Also:
INDENT_STRING

decrementIndent

public void decrementIndent()
Decrease the indent string by removing one INDENT_STRING.

See Also:
INDENT_STRING

isDirected

public boolean isDirected()
Check if the graph is directed.

Returns:
true if graph is a directed graph

isStrict

public boolean isStrict()
Check if the graph is strict (i.e., no self-loops).

Returns:
true if the graph is strict

setToolTipText

public java.lang.String setToolTipText(java.lang.String text)
Set the tooltip text displayed when outside the graph area.

Parameters:
text - out-of-graph tooltip text
Returns:
previous out-of-graph tooltip text

getToolTipText

public java.lang.String getToolTipText()
Get the tooltip text displayed when outside the graph area.

Returns:
out-of-graph tooltip text

reset

public void reset()
Reset this graph by removing all its elements and re-initiailizing its internal variables.


reset

public void reset(java.lang.String graphName,
                  boolean directed,
                  boolean strict)
Reset this graph by removing all its elements and re-initiailizing its internal variables and possibly changing its name, directedness and strictness.


isEditable

public boolean isEditable()
Check if this graph is interactively editable (i.e., through mouse events).

Returns:
true if the graph can be edited interactively.

setEditable

public boolean setEditable(boolean mode)
Set the editability of the graph.

Parameters:
mode - true to turn on editability.
Returns:
previous value
See Also:
isEditable()

isSelectable

public boolean isSelectable()
Check if graph elements are interactively selectable (i.e., through mouse events).

Returns:
true if graph elements can be selected interactively.

setSelectable

public boolean setSelectable(boolean mode)
Set the selectability of the graph.

Parameters:
mode - true to turn on selectability.
Returns:
previous value
See Also:
isSelectable()

isMenuable

public boolean isMenuable()
Check if an element-specific menu is available interactively (i.e., through mouse events).

Returns:
true if an element-specific menu is available

setMenuable

public boolean setMenuable(boolean mode)
Set whether element-specific menus are to be available interactively.

Parameters:
mode - true to turn on element-specific-menus.
Returns:
previous value
See Also:
isMenuable()

setErrorWriter

public java.io.PrintWriter setErrorWriter(java.io.PrintWriter errWriter)
Set the PrintWriter for error messages.

Parameters:
errWriter - the PrintWriter to use for error messages.
Returns:
the previous PrintWriter used for error messages.
See Also:
PrintWriter

getErrorWriter

public java.io.PrintWriter getErrorWriter()
Get the current PrintWriter used for error messages.

Returns:
the current PrintWriter used for error messages.
See Also:
PrintWriter

printError

public void printError(java.lang.String msg)
Print the supplied message to the error output. Nothing happens if the error output is set to null.

Parameters:
msg - the message to print on the error output.
See Also:
setErrorWriter(java.io.PrintWriter)

printError

public void printError(java.lang.String msg,
                       java.lang.Exception ex)
Print the supplied message and exception information to the error output. Nothing happens if the error output is set to null.

Parameters:
msg - the message to print on the error output.
ex - if supplied, the stack trace associated with this exception is also printed.
See Also:
setErrorWriter(java.io.PrintWriter)

buildShapes

public void buildShapes()
Builds any GrappaNexus object not already built for elements in this graph.


resync

public void resync()
Builds any GrappaNexus object not already built and rebuilds those that already exist for all elements in this graph.


repaint

public void repaint()
Makes a repaint request of all GrappaPanels that are displaying this graph.


paintImmediately

public void paintImmediately()
Makes a paintImmediately request of all GrappaPanels that are displaying this graph.


addPanel

public void addPanel(GrappaPanel panel)
Adds a panel to the list of GrappaPanels that are displaying this graph.

Parameters:
panel - the GrappaPanel to be added to the list

removePanel

public void removePanel(GrappaPanel panel)
Removes a panel to the list of GrappaPanels that are displaying this graph.

Parameters:
panel - the GrappaPanel to be removed to the list


Grappa 1.2