All Packages  This Package  Class Hierarchy  Class Search  Index

Class Graphomat.Graph
java.lang.Object
   |
   +----Graphomat.Graph

  Summary

public class  Graph
     extends java.lang.Object
{
          // Constructors 1
     public Graph();

          // Methods 11
     public void addNode(Node);
     public void deleteNode(Node);
     public Edge getEdge(Node, Node);
     public int getEdgeCount();
     public Enumeration getEdgeEnum();
     public Node getFirstNodeAt(double, double);
     public int getNodeCount();
     public Enumeration getNodeEnum();
     public String toString();
     public void traversEdges(EdgeTraverser);
     public void traversNodes(NodeTraverser);
}

This class provides the possiblity to store nodes and their connections. The edges and the nodelist can be traversed with the Enumeration given by getNodeEnum() and getEdgeEnum().There is a second posibility with the TraversNodes() and the equivalent TraversEdges() method.




  Constructors

· Graph

Summary  |  Top

   public Graph() 


  Methods

· addNode

Summary  |  Top
   public void addNode(Node n) 

All nodes added to the Graph have to be initallized first with the new operator, as shown below:

Graph g = new Graph();
g.addNode(new Node(4,1));
Uninitalized nodes will be ignored.



· deleteNode

Summary  |  Top
   public void deleteNode(Node n) 

Nodes deleted from the Graph will be disconnected first. Uninitalized nodes will be ignored.

Graph g = new Graph();
Node n1 = new Node();

g.addNode(n1);
g.deleteNode(n1);
Uninitalized nodes will be ignored.



· getFirstNodeAt

Summary  |  Top
   public Node getFirstNodeAt(double x, 
                              double y) 

Returns the node with a given location. Is usefull if u forgot the handle of a specific node. If there are several nodes at this location, the oldest will be returned. Warning: getFirstNodeAt() returns null if there was no Node at this location.

Graph g = new Graph();
Node n;

g.addNode(new Node(4,1));
n = g.getFirstNodeAt(4,1));



· getEdge

Summary  |  Top
   public Edge getEdge(Node n1, 
                       Node n2) 

Returns the Edges connecting the two Nodes.



· traversNodes

Summary  |  Top
   public void traversNodes(NodeTraverser t) 

Traverses all nodes and processes it with the given NodeTraverser.

class MoveTraverser extends NodeTraverser {
public void processNode(Node n) {
n.move(-1,2);
}
}

Graph g = new Graph();
MoveTraverser trav = new MoveTraverser();

g.addNode(new Node(2,3));
g.addNode(new Node(1,0));
g.traversNodes(trav);
There is also the possibility to define a NodeTraverser on-the-fly with a anonymous class.
Graph g = new Graph();
g.addNode(new Node(2,3));
g.addNode(new Node(1,0));
g.traversNodes(new NodeTraverser() {
public void processNode(Node n) {
n.move(-1,2);
}
});



· traversEdges

Summary  |  Top
   public void traversEdges(EdgeTraverser t) 

Traverses all edges and processes it with the given EdgeTraverser.

See Also: traversNodes



· getNodeEnum

Summary  |  Top
   public Enumeration getNodeEnum() 

Returns a Enumeration containing the nodes of the Graph.

Graph g = new Graph();
Enumertaion enum;

g.addNode(new Node(2,3));
g.addNode(new Node(1,0));
enum = g.getEnum();
while(enum.hasMoreElements()) {
((Node)enum.nextElement()).move(-1,2);
}



· getEdgeEnum

Summary  |  Top
   public Enumeration getEdgeEnum() 

Returns a Enumeration containing the edges of the Graph.

See Also: getNodeEnum



· getNodeCount

Summary  |  Top
   public int getNodeCount() 

Returns the number of nodes in the Graph.



· getEdgeCount

Summary  |  Top
   public int getEdgeCount() 

Returns the number of edges in the Graph.



· toString

Summary  |  Top
   public String toString() 

Returns a String discribing the whole Graph.

Overrides:
toString in class Object


All Packages  This Package  Class Hierarchy  Class Search  Index
Freshly brewed Java API Documentation automatically generated with polardoc Version 1.0.7