org.jgraph.layout
Class SpringEmbeddedLayoutAlgorithm

java.lang.Object
  extended byorg.jgraph.layout.JGraphLayoutAlgorithm
      extended byorg.jgraph.layout.SpringEmbeddedLayoutAlgorithm

public class SpringEmbeddedLayoutAlgorithm
extends JGraphLayoutAlgorithm

Arranges the nodes with the Spring Embedded Layout Algorithm.
The algorithm takes O(|V|^2 * |E|) time. Jeremy Jedynak NetCentric Technology Inc www.NetCentricInc.com
This layout algorithm is derived from the one written by Sven Luzar. It fixes a bug in how the "u" and "v" vectors were stored and retrieved, which frequently caused IllegalArgumentExceptions and NullPointerExceptions, depending upon your luck.
Also, the original run method has been broken into several methods. Two new constructors and methods were added to support two constraints: the graph rendering frame and maxIterations. Most variable names have been modified for readability.
It now properly lays out the graph according to the algorithm. Work still needs to be done to better space vertices so that they do not overlap and so that edges do not pass through vertices. The new "step" parameter of the run method is currently not used. All that being said, this is a good starting point to understand the algorithm and make those changes.

Since:
1.2.2

Field Summary
static java.lang.String SPRING_EMBEDDED_DISP
          Key for an attribute.
static java.lang.String SPRING_EMBEDDED_POS
          Key for an attribute.
 
Fields inherited from class org.jgraph.layout.JGraphLayoutAlgorithm
LAYOUT_ATTRIBUTES
 
Constructor Summary
SpringEmbeddedLayoutAlgorithm()
           
SpringEmbeddedLayoutAlgorithm(java.awt.Rectangle frame, int maxIterations)
           
 
Method Summary
protected  double fa(double x, double k)
          calculates the attractive forces
protected  double fr(double x, double k)
          calculates the repulsive forces
protected  double norm(java.awt.geom.Rectangle2D p)
          Calculates the euklidische Norm for the point p.
 void run(JGraph graph, java.lang.Object[] dynamic_cells, java.lang.Object[] static_cells)
          The implementation of the layout algorithm.
 void setFrame(java.awt.Rectangle frame)
           
 void setMaxIterations(int maxIterations)
           
 java.lang.String toString()
          Returns the name of this algorithm in human readable form.
 
Methods inherited from class org.jgraph.layout.JGraphLayoutAlgorithm
applyLayout, applyLayout, createDialog, createDialog, createSettings, getHint, getMaximumProgress, getProgress, isAllowedToRun, populateDialog, run, setAllowedToRun, setMaximumProgress, setProgress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SPRING_EMBEDDED_DISP

public static final java.lang.String SPRING_EMBEDDED_DISP
Key for an attribute. The value for this key is a Rectangle object and specifies the disposement.

See Also:
Constant Field Values

SPRING_EMBEDDED_POS

public static final java.lang.String SPRING_EMBEDDED_POS
Key for an attribute. The value for this key is a Rectangle object and specifies the calculated position.

See Also:
Constant Field Values
Constructor Detail

SpringEmbeddedLayoutAlgorithm

public SpringEmbeddedLayoutAlgorithm()

SpringEmbeddedLayoutAlgorithm

public SpringEmbeddedLayoutAlgorithm(java.awt.Rectangle frame,
                                     int maxIterations)
Method Detail

setFrame

public void setFrame(java.awt.Rectangle frame)

toString

public java.lang.String toString()
Returns the name of this algorithm in human readable form.


setMaxIterations

public void setMaxIterations(int maxIterations)

run

public void run(JGraph graph,
                java.lang.Object[] dynamic_cells,
                java.lang.Object[] static_cells)
The implementation of the layout algorithm.

Specified by:
run in class JGraphLayoutAlgorithm
Parameters:
graph - : JGraph instance
dynamic_cells - : List of all nodes the layout should move
static_cells - : List of node the layout should not move but allow for
See Also:
LayoutAlgorithm

fa

protected double fa(double x,
                    double k)
calculates the attractive forces


fr

protected double fr(double x,
                    double k)
calculates the repulsive forces


norm

protected double norm(java.awt.geom.Rectangle2D p)
Calculates the euklidische Norm for the point p.