org.wilmascope.graph
Class Cluster

java.lang.Object
  extended by org.wilmascope.graph.GraphElement
      extended by org.wilmascope.graph.Node
          extended by org.wilmascope.graph.Cluster

public class Cluster
extends Node

a Cluster is a set of Nodes (Node) and Edges (Edge) sharing the same (LayoutEngine). This class is the main interface to the graph package for adding GraphElements to a graph hierarchy.

Version:
$Id: Cluster.java,v 1.15 2004/11/16 01:47:11 tgdwyer Exp $
Author:
Tim Dwyer

Field Summary
 
Fields inherited from class org.wilmascope.graph.GraphElement
layout, owner, view, visible
 
Constructor Summary
Cluster()
          The default constructor - an empty cluster
Cluster(Cluster original)
          Creates a new cluster with duplicate nodes and edges to the argument.
Cluster(NodeView view)
          Create a new cluster with the specified NodeView
 
Method Summary
 void addBalancedEventListener(BalancedEventListener l)
           
 void addEdge(Edge e)
          Add an Edgeto the Cluster Note that the edge may not finish up being added to this cluster, it will be added to the lowest common ancestor of the two ends of the edge.
protected  void addInternalEdgeHere(Edge e)
          Add an internal edge to this cluster...
 float addMass(float newMass)
          On adding or removing a node from the cluster the mass of the cluster will change, and a positive or negative contribution to the mass will have to be added, not only to this cluster, but to parent clusters as well.
 void addNode(Node node)
          Add a Nodeto the Cluster
 void addNodes(NodeList startNodes)
          Add the specified nodes to this cluster
 boolean applyLayout()
          applies the layout changes calculated in calculateLayout()to the contents of this cluster and all subclusters
 void calculateLayout()
          Find a new layout for the nodes according to the current graph and layout engine
 void collapse()
           
 void delete()
          delete a cluster and its contents
 void draw()
          draw the element if it's visible
 void expand(GraphCanvas graphCanvas)
           
 EdgeList getAcyclicEdgeSet_EnhancedGreedy()
          Uses a tricky heuristic (Eades et al.
 EdgeList getAcyclicEdgeSet_Greedy()
          Finds an acyclic subset Ea of this cluster's edges E such that |Ea|>=|E|/2 using a simple greedy heuristic (Berger and Shor, 1990).
 NodeList getAllNodes()
           
 EdgeList getInternalEdges()
          Get the edges internal to this cluster, ie, only those edges connecting a pair of nodes that are both inside this cluster
 LayoutEngine getLayoutEngine()
          Get the LayoutEngineused by the cluster
 NodeList getNodes()
           
 Node getPortalNode(Edge edge)
          An external edge is one which has one end in this cluster and one end in another cluster that is not a child (or descendent) of this cluster.
 void hideChildren()
           
 boolean isAncestor(Node node)
          Check if the specified node is a child of this cluster or one of this cluster's child clusters etc recursively
 boolean isBalanced()
           
 boolean isExpanded()
           
 void moveToParent(Node n)
          shift a Node up from this Cluster to its parent cluster
protected  void remove(GraphElement e)
          remove a graph element (ie node or edge) from this cluster
protected  void removeEdge(Edge e)
          Remove an Edgefrom the Cluster.
protected  void removeExternalEdge(Edge e)
          remove an edge that is external to this cluster.
protected  void removeNode(Node n)
          remove a Node up from this Cluster
 void setLayoutEngine(LayoutEngine l)
          Set the LayoutEnginefor the cluster
 void setMass(float newMass)
          When the mass of this cluster changes, due to an addition or removal of a node from the cluster or by a user call to this method, the mass of the parent cluster must also be recalculated
 void showChildren(GraphCanvas gc)
           
 
Methods inherited from class org.wilmascope.graph.Node
getCommonAncestor, getCommonEdges, getDegree, getEdges, getInDegree, getInEdges, getLayout, getMass, getNeighbours, getOutDegree, getOutEdges, getPosition, getProperties, getView, isNeighbour, reposition, setEdges, setLayout, setPosition, setProperties, setView
 
Methods inherited from class org.wilmascope.graph.GraphElement
getOwner, getUserData, hide, isVisible, setOwner, show, storeUserData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cluster

public Cluster()
The default constructor - an empty cluster


Cluster

public Cluster(Cluster original)
Creates a new cluster with duplicate nodes and edges to the argument. References to the original graph elements are kept in userFacade. Does not recurse down clusters.

Parameters:
original -

Cluster

public Cluster(NodeView view)
Create a new cluster with the specified NodeView

Method Detail

getNodes

public NodeList getNodes()
Returns:
a list of the children in this cluster

addNode

public void addNode(Node node)
Add a Nodeto the Cluster

Parameters:
node - the Node to add

getInternalEdges

public EdgeList getInternalEdges()
Get the edges internal to this cluster, ie, only those edges connecting a pair of nodes that are both inside this cluster

Returns:
a list of edges
See Also:
Node.getEdges()

isAncestor

public boolean isAncestor(Node node)
Check if the specified node is a child of this cluster or one of this cluster's child clusters etc recursively

Parameters:
node - node ancestory of
Returns:
true if this cluster is an ancestor of node

moveToParent

public void moveToParent(Node n)
shift a Node up from this Cluster to its parent cluster

Parameters:
n - which Node to remove

removeNode

protected void removeNode(Node n)
remove a Node up from this Cluster

Parameters:
n - which Node to remove

addEdge

public void addEdge(Edge e)
Add an Edgeto the Cluster Note that the edge may not finish up being added to this cluster, it will be added to the lowest common ancestor of the two ends of the edge.

Overrides:
addEdge in class Node
Parameters:
e - the edge to add

getPortalNode

public Node getPortalNode(Edge edge)
An external edge is one which has one end in this cluster and one end in another cluster that is not a child (or descendent) of this cluster. A portal node is a node in this cluster which has an external edge This method looks up the portal node in this cluster for a specific external edge.

Parameters:
edge - an edge external to this cluster

addInternalEdgeHere

protected void addInternalEdgeHere(Edge e)
Add an internal edge to this cluster... If the edge is already a member of this cluster it will be removed and then added again. Nothing like brute force to get the job done.


remove

protected void remove(GraphElement e)
remove a graph element (ie node or edge) from this cluster


removeEdge

protected void removeEdge(Edge e)
Remove an Edgefrom the Cluster. Will work with either an internal or external edge.

Overrides:
removeEdge in class Node

removeExternalEdge

protected void removeExternalEdge(Edge e)
remove an edge that is external to this cluster. If the edge is actually internal nothing will happen. If in doubt call removeEdge(org.wilmascope.graph.Edge)

See Also:
removeEdge(org.wilmascope.graph.Edge)

isExpanded

public boolean isExpanded()

draw

public void draw()
Description copied from class: GraphElement
draw the element if it's visible

Overrides:
draw in class GraphElement

setLayoutEngine

public void setLayoutEngine(LayoutEngine l)
Set the LayoutEnginefor the cluster


getLayoutEngine

public LayoutEngine getLayoutEngine()
Get the LayoutEngineused by the cluster


hideChildren

public void hideChildren()

showChildren

public void showChildren(GraphCanvas gc)

getAllNodes

public NodeList getAllNodes()
Returns:
all children (recursive descendants) of this cluster

collapse

public void collapse()

expand

public void expand(GraphCanvas graphCanvas)

calculateLayout

public void calculateLayout()
Find a new layout for the nodes according to the current graph and layout engine


applyLayout

public boolean applyLayout()
applies the layout changes calculated in calculateLayout()to the contents of this cluster and all subclusters

Returns:
true if all are balanced

delete

public void delete()
delete a cluster and its contents

Overrides:
delete in class Node

addNodes

public void addNodes(NodeList startNodes)
Add the specified nodes to this cluster


addMass

public float addMass(float newMass)
On adding or removing a node from the cluster the mass of the cluster will change, and a positive or negative contribution to the mass will have to be added, not only to this cluster, but to parent clusters as well. The latter is handled by setMass(float)


setMass

public void setMass(float newMass)
When the mass of this cluster changes, due to an addition or removal of a node from the cluster or by a user call to this method, the mass of the parent cluster must also be recalculated

Overrides:
setMass in class Node

addBalancedEventListener

public void addBalancedEventListener(BalancedEventListener l)

isBalanced

public boolean isBalanced()
Returns:
Returns true if the cluster is balanced, meaning layout is not currently in progress.

getAcyclicEdgeSet_Greedy

public EdgeList getAcyclicEdgeSet_Greedy()
Finds an acyclic subset Ea of this cluster's edges E such that |Ea|>=|E|/2 using a simple greedy heuristic (Berger and Shor, 1990).

Returns:
acyclic subset of edges in this cluster

getAcyclicEdgeSet_EnhancedGreedy

public EdgeList getAcyclicEdgeSet_EnhancedGreedy()
Uses a tricky heuristic (Eades et al. 1993) to find an acyclic subset (Ea) of this cluster's edges (E) such that: |Ea|>=|E|/2+|V|/6

Returns:
acyclic subset of edges in this cluster