edu.ksu.cis.bnj.gui.components
Class AutoLayouter

java.lang.Object
  extended byedu.ksu.cis.bnj.gui.components.AbstractLayouter
      extended byedu.ksu.cis.bnj.gui.components.AutoLayouter
All Implemented Interfaces:
salvo.jesus.graph.visual.layout.GraphLayoutManager, java.io.Serializable

public class AutoLayouter
extends AbstractLayouter

An implementation of a directed-force layout using logarithmic springs and electrical forces, as discussed in Chapter 10 of the book "Graph Drawing".

However, note that the implementation is a bit different to the equation 10.2 in the book such that:

I am not a mathematician, but the above adjustments to the equation greatly improved the force-directed layout.

Author:
Jesus M. Salvo Jr.

Adapted for BNJ auto-layouter by: Roby Joehanes

List of changes:

See Also:
Serialized Form

Field Summary
protected  double electricalRepulsion
           
protected  java.util.ArrayList fixedVertexList
           
protected  double increment
           
protected  boolean initialized
           
protected  double springLength
           
protected  double stiffness
           
 
Fields inherited from class edu.ksu.cis.bnj.gui.components.AbstractLayouter
vGraph
 
Constructor Summary
AutoLayouter(salvo.jesus.graph.visual.VisualGraph vGraph)
           
 
Method Summary
 void addEdge(salvo.jesus.graph.visual.VisualEdge vEdge)
           
 void addFixedVertex(salvo.jesus.graph.visual.VisualVertex vVertex)
          Adds a VisuaLVertex that will not be moved from its position during the layout operation of ForceDirectedLayout.
 void addVertex(salvo.jesus.graph.visual.VisualVertex vVertex)
           
 void drawLayout()
          This method is called to actually paint or draw the layout of the graph.
 double getEletricalRepulsion()
          Returns the eletrical repulsion between all vertices The default value is 400.
 double getIncrement()
          Returns the increment by which the vertices gets closer to the equilibrium or closer to the force.
 double getSpringLength()
          Returns the desired spring length for all edges.
 double getStiffness()
          Returns the stiffness for all edges.
 boolean isInitialized()
          Determines if the graph has been initially laid out.
 boolean isVertexFixed(salvo.jesus.graph.visual.VisualVertex vVertex)
          Returns true if the specified VisualVertex has a fixed position.
 void layout()
          This method is called to layout the vertices in the graph, running a thread to perform the layout if the thread is not running, or stopping the thread if the thread is running.
protected  double relax(salvo.jesus.graph.visual.VisualVertex vVertex)
          "Relax" the force on the VisualVertex.
 void removeEdge(salvo.jesus.graph.visual.VisualEdge vEdge)
           
 void removeFixedVertex(salvo.jesus.graph.visual.VisualVertex vVertex)
          Removes a VisualVertex from the list of VisualVertices that has a fixed position.
 void removeVertex(salvo.jesus.graph.visual.VisualVertex vVertex)
           
 void setEletricalRepulsion(double repulsion)
          Sets the value of the electrical repulsion between all vertices
 void setIncrement(double increment)
          Sets the increment by which the vertices gets close to the equilibrium or gets closer to the direction of the force.
 void setSpringLength(double length)
          Sets the desired length of the spring among all edges
 void setStiffness(double stiffness)
          Sets the value of stiffness among all edges
 
Methods inherited from class edu.ksu.cis.bnj.gui.components.AbstractLayouter
paintEdge, routeEdge
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

springLength

protected double springLength

stiffness

protected double stiffness

electricalRepulsion

protected double electricalRepulsion

increment

protected double increment

initialized

protected boolean initialized

fixedVertexList

protected java.util.ArrayList fixedVertexList
Constructor Detail

AutoLayouter

public AutoLayouter(salvo.jesus.graph.visual.VisualGraph vGraph)
Method Detail

getSpringLength

public double getSpringLength()
Returns the desired spring length for all edges. The default value is 50.


getStiffness

public double getStiffness()
Returns the stiffness for all edges. The default value is 50.


getEletricalRepulsion

public double getEletricalRepulsion()
Returns the eletrical repulsion between all vertices The default value is 400.


getIncrement

public double getIncrement()
Returns the increment by which the vertices gets closer to the equilibrium or closer to the force. The default value is 0.50.


setSpringLength

public void setSpringLength(double length)
Sets the desired length of the spring among all edges


setStiffness

public void setStiffness(double stiffness)
Sets the value of stiffness among all edges


setEletricalRepulsion

public void setEletricalRepulsion(double repulsion)
Sets the value of the electrical repulsion between all vertices


setIncrement

public void setIncrement(double increment)
Sets the increment by which the vertices gets close to the equilibrium or gets closer to the direction of the force. This must be a number > 0 and <= 1. The higher the value, the faster the layout reaches equilibrium.


addFixedVertex

public void addFixedVertex(salvo.jesus.graph.visual.VisualVertex vVertex)
Adds a VisuaLVertex that will not be moved from its position during the layout operation of ForceDirectedLayout.


isVertexFixed

public boolean isVertexFixed(salvo.jesus.graph.visual.VisualVertex vVertex)
Returns true if the specified VisualVertex has a fixed position.


removeFixedVertex

public void removeFixedVertex(salvo.jesus.graph.visual.VisualVertex vVertex)
Removes a VisualVertex from the list of VisualVertices that has a fixed position.


isInitialized

public boolean isInitialized()
Determines if the graph has been initially laid out. This method should be called prior to any painting to be done by the graph layout manager, as most internal variables are only initialized during layout.

Specified by:
isInitialized in interface salvo.jesus.graph.visual.layout.GraphLayoutManager
Overrides:
isInitialized in class AbstractLayouter
Returns:
True if the graph has at least been laid out once.
See Also:
GraphLayoutManager.isInitialized()

layout

public void layout()

This method is called to layout the vertices in the graph, running a thread to perform the layout if the thread is not running, or stopping the thread if the thread is running.

Adapted by Roby Joehanes

Specified by:
layout in interface salvo.jesus.graph.visual.layout.GraphLayoutManager
Specified by:
layout in class AbstractLayouter
See Also:
GraphLayoutManager.layout()

relax

protected double relax(salvo.jesus.graph.visual.VisualVertex vVertex)
"Relax" the force on the VisualVertex. "Relax" here means to get closer to the equilibrium position.

This method will:


drawLayout

public void drawLayout()
This method is called to actually paint or draw the layout of the graph. This method should only be called after at least one call to layout().

Specified by:
drawLayout in interface salvo.jesus.graph.visual.layout.GraphLayoutManager
Overrides:
drawLayout in class AbstractLayouter
See Also:
GraphLayoutManager.drawLayout()

addVertex

public void addVertex(salvo.jesus.graph.visual.VisualVertex vVertex)
Specified by:
addVertex in interface salvo.jesus.graph.visual.layout.GraphLayoutManager
Overrides:
addVertex in class AbstractLayouter
See Also:
GraphLayoutManager.addVertex(salvo.jesus.graph.visual.VisualVertex)

removeEdge

public void removeEdge(salvo.jesus.graph.visual.VisualEdge vEdge)
Specified by:
removeEdge in interface salvo.jesus.graph.visual.layout.GraphLayoutManager
Overrides:
removeEdge in class AbstractLayouter
See Also:
GraphLayoutManager.removeEdge(salvo.jesus.graph.visual.VisualEdge)

removeVertex

public void removeVertex(salvo.jesus.graph.visual.VisualVertex vVertex)
Specified by:
removeVertex in interface salvo.jesus.graph.visual.layout.GraphLayoutManager
Overrides:
removeVertex in class AbstractLayouter
See Also:
GraphLayoutManager.removeVertex(salvo.jesus.graph.visual.VisualVertex)

addEdge

public void addEdge(salvo.jesus.graph.visual.VisualEdge vEdge)
Specified by:
addEdge in interface salvo.jesus.graph.visual.layout.GraphLayoutManager
Overrides:
addEdge in class AbstractLayouter
See Also:
GraphLayoutManager.addEdge(salvo.jesus.graph.visual.VisualEdge)