com.horstmann.violet.framework
Class Graph

java.lang.Object
  extended by com.horstmann.violet.framework.Graph
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ClassDiagramGraph, ObjectDiagramGraph, SequenceDiagramGraph, StateDiagramGraph, UseCaseDiagramGraph

public abstract class Graph
extends java.lang.Object
implements java.io.Serializable

A graph consisting of selectable nodes and edges.

See Also:
Serialized Form

Constructor Summary
Graph()
          Constructs a graph with no nodes or edges.
 
Method Summary
 boolean add(Node n, java.awt.geom.Point2D p)
          Adds a node to the graph so that the top left corner of the bounding rectangle is at the given point.
 void addNode(Node n, java.awt.geom.Point2D p)
          Adds a node to this graph.
 void connect(Edge e, Node start, Node end)
          Adds an edge to this graph.
 boolean connect(Edge e, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
          Adds an edge to the graph that joins the nodes containing the given points.
 void draw(java.awt.Graphics2D g2, Grid g)
          Draws the graph
 Edge findEdge(java.awt.geom.Point2D p)
          Finds an edge containing the given point.
 Node findNode(java.awt.geom.Point2D p)
          Finds a node containing the given point.
 java.awt.geom.Rectangle2D getBounds(java.awt.Graphics2D g2)
          Gets the smallest rectangle enclosing the graph
abstract  Edge[] getEdgePrototypes()
          Gets the edge types of a particular graph type.
 java.util.Collection getEdges()
          Gets the edges of this graph.
 java.awt.geom.Rectangle2D getMinBounds()
           
abstract  Node[] getNodePrototypes()
          Gets the node types of a particular graph type.
 java.util.Collection getNodes()
          Gets the nodes of this graph.
 void layout()
          Causes the layout of the graph to be recomputed.
 void removeEdge(Edge e)
          Removes an edge from the graph.
 void removeNode(Node n)
          Removes a node and all edges that start or end with that node
 void setMinBounds(java.awt.geom.Rectangle2D newValue)
           
static void setPersistenceDelegate(java.beans.Encoder encoder)
          Adds a persistence delegate to a given encoder that encodes the child nodes of this node.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Graph

public Graph()
Constructs a graph with no nodes or edges.

Method Detail

connect

public boolean connect(Edge e,
                       java.awt.geom.Point2D p1,
                       java.awt.geom.Point2D p2)
Adds an edge to the graph that joins the nodes containing the given points. If the points aren't both inside nodes, then no edge is added.

Parameters:
e - the edge to add
p1 - a point in the starting node
p2 - a point in the ending node

add

public boolean add(Node n,
                   java.awt.geom.Point2D p)
Adds a node to the graph so that the top left corner of the bounding rectangle is at the given point.

Parameters:
n - the node to add
p - the desired location

findNode

public Node findNode(java.awt.geom.Point2D p)
Finds a node containing the given point.

Parameters:
p - a point
Returns:
a node containing p or null if no nodes contain p

findEdge

public Edge findEdge(java.awt.geom.Point2D p)
Finds an edge containing the given point.

Parameters:
p - a point
Returns:
an edge containing p or null if no edges contain p

draw

public void draw(java.awt.Graphics2D g2,
                 Grid g)
Draws the graph

Parameters:
g2 - the graphics context

removeNode

public void removeNode(Node n)
Removes a node and all edges that start or end with that node

Parameters:
n - the node to remove

removeEdge

public void removeEdge(Edge e)
Removes an edge from the graph.

Parameters:
e - the edge to remove

layout

public void layout()
Causes the layout of the graph to be recomputed.


getBounds

public java.awt.geom.Rectangle2D getBounds(java.awt.Graphics2D g2)
Gets the smallest rectangle enclosing the graph

Parameters:
g2 - the graphics context
Returns:
the bounding rectangle

getMinBounds

public java.awt.geom.Rectangle2D getMinBounds()

setMinBounds

public void setMinBounds(java.awt.geom.Rectangle2D newValue)

getNodePrototypes

public abstract Node[] getNodePrototypes()
Gets the node types of a particular graph type.

Returns:
an array of node prototypes

getEdgePrototypes

public abstract Edge[] getEdgePrototypes()
Gets the edge types of a particular graph type.

Returns:
an array of edge prototypes

setPersistenceDelegate

public static void setPersistenceDelegate(java.beans.Encoder encoder)
Adds a persistence delegate to a given encoder that encodes the child nodes of this node.

Parameters:
encoder - the encoder to which to add the delegate

getNodes

public java.util.Collection getNodes()
Gets the nodes of this graph.

Returns:
an unmodifiable collection of the nodes

getEdges

public java.util.Collection getEdges()
Gets the edges of this graph.

Returns:
an unmodifiable collection of the edges

addNode

public void addNode(Node n,
                    java.awt.geom.Point2D p)
Adds a node to this graph. This method should only be called by a decoder when reading a data file.

Parameters:
n - the node to add
p - the desired location

connect

public void connect(Edge e,
                    Node start,
                    Node end)
Adds an edge to this graph. This method should only be called by a decoder when reading a data file.

Parameters:
e - the edge to add
start - the start node of the edge
end - the end node of the edge