com.nwoods.jgo.layout
Class JGoNetwork

java.lang.Object
  extended bycom.nwoods.jgo.layout.JGoNetwork

public class JGoNetwork
extends java.lang.Object

JGoNetwork provides an abstract view of a JGoObjectSimpleCollection as a network (graph) of nodes and directed links. These nodes and links correspond to top-level JGoObjects in the JGoObjectSimpleCollection. The JGoNetwork class provides a framework for manipulating the state of nodes and links without modifying the structure of the original document.

See Also:
JGoNetworkNode, JGoNetworkLink

Constructor Summary
JGoNetwork()
          Constructs an empty network.
JGoNetwork(JGoObjectSimpleCollection collection)
          Constructs a network from the JGoObjectSimpleCollection's top-level objects.
 
Method Summary
 JGoNetworkLink addLink(JGoLink link)
          This convenience method makes sure there is a JGoNetworkLink in this network corresponding to the given JGoLink.
 void addLink(JGoNetworkLink pLink)
          Adds a JGoNetworkLink to the JGoNetwork.
 void addNode(JGoNetworkNode pNode)
          Adds a node to the network.
 JGoNetworkNode addNode(JGoObject node)
          This convenience method makes sure there is a JGoNetworkNode in this network corresponding to a JGoObject.
 void addNodesAndLinksFromCollection(JGoObjectSimpleCollection collection)
          Adds a JGoObjectSimpleCollection to the network.
 void commitLinks()
          Commits the positions of all links in the network to their corresponding JGoObjects.
 void commitNodes()
          Commits the positions of all nodes in the network to their corresponding JGoObjects.
 void commitNodesAndLinks()
          Commits the positions of all nodes and links in the network to their corresponding JGoObjects.
 JGoNetworkLink createNetworkLink()
           
 JGoNetworkNode createNetworkNode()
           
 void deleteArtificialNodes()
          Delete all nodes and links that have no getJGoObject() associated with them.
 void deleteLink(JGoLink link)
          This convenience method removes any JGoNetworkLink associated with the given JGoLink.
 void deleteLink(JGoNetworkLink pLink)
          Deletes the input link from the network.
 void deleteNode(JGoNetworkNode pNode)
          Deletes the input node from the network.
 void deleteNode(JGoObject node)
          This convenience method removes any JGoNetworkNode that may be associated with the given JGoObject.
 void deleteSelfLinks()
          Deletes all links whose "to node" and "from node" are the same node.
 JGoNetworkLink findLink(JGoObject pGoObj)
          Returns the JGoNetworkLink which was constructed with the pGoObj.
 JGoNetworkNode findNode(JGoObject pGoObj)
          Returns the JGoNetworkNode which was constructed with the pGoObj.
protected  java.util.HashMap getGoObjToLinkMap()
          Returns the hash table mapping JGoObjects to JGoNetworkLinks
protected  java.util.HashMap getGoObjToNodeMap()
          Returns the hash table mapping JGoObjects to JGoNetworkNodes
 JGoNetworkLink[] getLinkArray()
          Returns an array of the JGoNetworkLinks list.
 int getLinkCount()
          Returns the number of links in the network.
 java.util.Iterator getLinkIterator()
          Returns the Iterator for the first link in the network.
 java.util.Iterator getLinkIterator(int index)
          Returns an Iterator for myNetworkLinks, which points to the item at index as the first item.
protected  java.util.LinkedList getNetworkLinks()
          Returns the list of JGoNetworkLinks
protected  java.util.LinkedList getNetworkNodes()
          Returns the list of JGoNetworkNodes
 JGoNetworkNode[] getNodeArray()
          Returns an array of the JGoNetworkNodes list.
 int getNodeCount()
          Returns the number of nodes in the network.
 java.util.Iterator getNodeIterator()
          Returns the Iterator for the first node in the network.
 java.util.Iterator getNodeIterator(int index)
          Returns an Iterator for myNetworkNodes, which points to the item at index as the first item.
 JGoSelection getNodesAndLinks(JGoSelection sel)
          Retrieve all of the JGoObject nodes and links from the JGoNetworkNodes and JGoNetworkLinks that are in this network, by adding them to the given selection.
 JGoNetworkLink linkNodes(JGoNetworkNode pFromNode, JGoNetworkNode pToNode, JGoObject pGoObj)
          Links two nodes already in the network and returns the created link.
 void removeAllNodesAndLinks()
          Removes all nodes and links from the network, resulting in an empty network.
 void reverseLink(JGoNetworkLink pLink)
          Reverses the direction of a link in the network.
 JGoNetwork[] splitIntoSubNetworks()
          Modify this network by splitting it up into separate subnetworks, each of which has all of its nodes connected to each other, perhaps indirectly and in mixed directions, but not to any nodes in any other subnetworks.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JGoNetwork

public JGoNetwork()
Constructs an empty network.


JGoNetwork

public JGoNetwork(JGoObjectSimpleCollection collection)
Constructs a network from the JGoObjectSimpleCollection's top-level objects.

Parameters:
collection - the JGoObjectSimpleCollection containing the JGoObjects to add to the network.
Method Detail

addNodesAndLinksFromCollection

public void addNodesAndLinksFromCollection(JGoObjectSimpleCollection collection)
Adds a JGoObjectSimpleCollection to the network. Note that a JGoNetworkLink corresponding to a JGoLink will not be added to this network unless both nodes connected by the link are part of the network, either already present or part of the argument collection.


removeAllNodesAndLinks

public void removeAllNodesAndLinks()
Removes all nodes and links from the network, resulting in an empty network.


createNetworkNode

public JGoNetworkNode createNetworkNode()

addNode

public void addNode(JGoNetworkNode pNode)
Adds a node to the network.


addNode

public JGoNetworkNode addNode(JGoObject node)
This convenience method makes sure there is a JGoNetworkNode in this network corresponding to a JGoObject.


deleteNode

public void deleteNode(JGoNetworkNode pNode)
Deletes the input node from the network. This function also deletes all links to or from the node. Performs a no-op if the node is not in the network.


deleteNode

public void deleteNode(JGoObject node)
This convenience method removes any JGoNetworkNode that may be associated with the given JGoObject. Any JGoNetworkLinks connected to the JGoNetworkNode will also be removed from this network.


findNode

public JGoNetworkNode findNode(JGoObject pGoObj)
Returns the JGoNetworkNode which was constructed with the pGoObj. Returns null if no such node exists.


createNetworkLink

public JGoNetworkLink createNetworkLink()

addLink

public void addLink(JGoNetworkLink pLink)
Adds a JGoNetworkLink to the JGoNetwork. Although this method is provided for completeness, the LinkNodes method provides a more efficient manner of linking nodes already in the network.


addLink

public JGoNetworkLink addLink(JGoLink link)
This convenience method makes sure there is a JGoNetworkLink in this network corresponding to the given JGoLink. This method first makes sure the nodes that contain the FromPort and the ToPort are added to this network as JGoNetworkNodes, and then calls linkNodes to create and initialize the JGoNetworkLink and add the link to the respective nodes.


deleteLink

public void deleteLink(JGoNetworkLink pLink)
Deletes the input link from the network. Also removes the link from its to node's predecessor list and from its from node's successor list. Performs a no-op if the link is not in the network.


deleteLink

public void deleteLink(JGoLink link)
This convenience method removes any JGoNetworkLink associated with the given JGoLink.


findLink

public JGoNetworkLink findLink(JGoObject pGoObj)
Returns the JGoNetworkLink which was constructed with the pGoObj. Returns null if no such link exists.


linkNodes

public JGoNetworkLink linkNodes(JGoNetworkNode pFromNode,
                                JGoNetworkNode pToNode,
                                JGoObject pGoObj)
Links two nodes already in the network and returns the created link.

Parameters:
pGoObj - the JGoObject to which the created link should correspond

reverseLink

public void reverseLink(JGoNetworkLink pLink)
Reverses the direction of a link in the network.


deleteSelfLinks

public void deleteSelfLinks()
Deletes all links whose "to node" and "from node" are the same node.


deleteArtificialNodes

public void deleteArtificialNodes()
Delete all nodes and links that have no getJGoObject() associated with them.


splitIntoSubNetworks

public JGoNetwork[] splitIntoSubNetworks()
Modify this network by splitting it up into separate subnetworks, each of which has all of its nodes connected to each other, perhaps indirectly and in mixed directions, but not to any nodes in any other subnetworks.

This method will first delete from this network all artificial nodes and all links that do not connect two different nodes. Afterwards, this original network may be empty or may contain all of the singleton JGoNetworkNodes, each of which had no JGoNetworkLinks connecting it to any other nodes.

Returns:
an array of JGoNetwork, sorted in order of decreasing getNodeCount().

getNodesAndLinks

public JGoSelection getNodesAndLinks(JGoSelection sel)
Retrieve all of the JGoObject nodes and links from the JGoNetworkNodes and JGoNetworkLinks that are in this network, by adding them to the given selection.

You can determine the bounding rectangle for a collection of nodes and links by calling the JGoDocument.computeBounds method. You can also call JGoView.moveSelection on this result to move the subnetwork where you would like them to be.

Parameters:
sel - a JGoSelection; if null, the method allocates and returns a new JGoSelection.
Returns:
a JGoSelection of all of the JGoObjects that correspond to JGoNetworkNodes and JGoNetworkLinks

getNodeCount

public int getNodeCount()
Returns the number of nodes in the network.


getNodeIterator

public java.util.Iterator getNodeIterator()
Returns the Iterator for the first node in the network. Use to iterate all nodes in the network.


getNodeIterator

public java.util.Iterator getNodeIterator(int index)
Returns an Iterator for myNetworkNodes, which points to the item at index as the first item. Use to iterate through part of the list, starting with the index-th item.


getLinkCount

public int getLinkCount()
Returns the number of links in the network.


getLinkIterator

public java.util.Iterator getLinkIterator()
Returns the Iterator for the first link in the network. Use to iterate all links in the network.


getLinkIterator

public java.util.Iterator getLinkIterator(int index)
Returns an Iterator for myNetworkLinks, which points to the item at index as the first item. Use to iterate through part of the list, starting with the index-th item.


commitNodes

public void commitNodes()
Commits the positions of all nodes in the network to their corresponding JGoObjects.


commitLinks

public void commitLinks()
Commits the positions of all links in the network to their corresponding JGoObjects.


commitNodesAndLinks

public void commitNodesAndLinks()
Commits the positions of all nodes and links in the network to their corresponding JGoObjects.


getLinkArray

public JGoNetworkLink[] getLinkArray()
Returns an array of the JGoNetworkLinks list.


getNodeArray

public JGoNetworkNode[] getNodeArray()
Returns an array of the JGoNetworkNodes list.


getNetworkLinks

protected java.util.LinkedList getNetworkLinks()
Returns the list of JGoNetworkLinks


getNetworkNodes

protected java.util.LinkedList getNetworkNodes()
Returns the list of JGoNetworkNodes


getGoObjToNodeMap

protected java.util.HashMap getGoObjToNodeMap()
Returns the hash table mapping JGoObjects to JGoNetworkNodes


getGoObjToLinkMap

protected java.util.HashMap getGoObjToLinkMap()
Returns the hash table mapping JGoObjects to JGoNetworkLinks