Zest
1.5.0.201305060205

org.eclipse.zest.layouts.algorithms
Class SpringLayoutAlgorithm

java.lang.Object
  extended by org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm
      extended by org.eclipse.zest.layouts.algorithms.ContinuousLayoutAlgorithm
          extended by org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm
All Implemented Interfaces:
LayoutAlgorithm, Stoppable

public class SpringLayoutAlgorithm
extends ContinuousLayoutAlgorithm

The SpringLayoutAlgorithm has its own data repository and relation repository. A user can populate the repository, specify the layout conditions, do the computation and query the computed results.

Instructions for using SpringLayoutAlgorithm:
1. Instantiate a SpringLayout object;
2. Populate the data repository using add(...);
3. Populate the relation repository using addRelation(...);
4. Execute compute();
5. Execute fitWithinBounds(...);
6. Query the computed results(node size and node position).


Field Summary
static double DEFAULT_SPRING_GRAVITATION
          The default value for the spring layout gravitation-control.
static boolean DEFAULT_SPRING_IGNORE_UNCON
          The default value for ignoring unconnected nodes.
static int DEFAULT_SPRING_ITERATIONS
          The default value for the spring layout number of interations.
static double DEFAULT_SPRING_LENGTH
          The default value for the spring layout length-control.
static double DEFAULT_SPRING_MOVE
          The default value for the spring layout move-control.
static boolean DEFAULT_SPRING_RANDOM
          The default value for positioning nodes randomly.
static boolean DEFAULT_SPRING_SEPARATE_COMPONENTS
          The default value for separating connected components.
static double DEFAULT_SPRING_STRAIN
          The default value for the spring layout strain-control.
protected static double EPSILON
          An arbitrarily small value in mathematics.
static long MAX_SPRING_TIME
          the default value for the time algorithm runs.
protected static double MIN_DISTANCE
          Minimum distance considered between nodes
 
Fields inherited from class org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm
comparator, filter, internalAsynchronous, internalContinuous, layout_styles, layoutStopped, MIN_ENTITY_SIZE, resizeEntitiesAfterLayout
 
Constructor Summary
SpringLayoutAlgorithm()
          Creates a sprint layout algoirthm with no style
SpringLayoutAlgorithm(int styles)
          Constructor.
 
Method Summary
protected  void computeForces(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout)
          Computes the force for each node in this SpringLayoutAlgorithm.
protected  void computeOneIteration(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout, org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider, double x, double y, double width, double height)
          Computes a single iteration of the layout algorithm
protected  void computePositions(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout)
          Computes the position for each node in this SpringLayoutAlgorithm.
protected  void convertNodePositionsBack(int i, org.eclipse.zest.layouts.dataStructures.InternalNode entityToConvert, double px, double py, double screenWidth, double screenHeight, org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle layoutBounds)
           
protected  void convertToUnitCoordinates(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout)
          Converts the position for each node in this SpringLayoutAlgorithm to unit coordinates in double precision.
protected  int getCurrentLayoutStep()
          Gets the current layout step
 int getIterations()
          Returns the number of iterations to be used.
protected  org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle getLayoutBoundsTemp(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout, boolean includeNodeSize)
           
 boolean getRandom()
          Returns whether or not this SpringLayoutAlgorithm will layout the nodes randomly before beginning iterations.
 double getSpringGravitation()
          Returns the gravitation-control value of this SpringLayoutAlgorithm in double presion.
 double getSpringLength()
          Returns the length-control value of this SpringLayoutAlgorithm in double presion.
 double getSpringMove()
          Returns the move-control value of this SpringLayoutAlgorithm in double presion.
 double getSpringStrain()
          Returns the strain-control value of this SpringLayoutAlgorithm in double presion.
 long getSpringTimeout()
          Gets the max time this algorithm will run for
protected  int getTotalNumberOfLayoutSteps()
          Gets the total number of steps in this layout
 double getWeight(java.lang.String relType)
           
protected  boolean isValidConfiguration(boolean asynchronous, boolean continueous)
          Determines if the configuration is valid for this layout
protected  boolean performAnotherNonContinuousIteration()
          The logic to determine if a layout should continue running or not
 void placeRandomly(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout)
          Puts vertices in random places, all between (0,0) and (1,1).
protected  void postLayoutAlgorithm(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout, org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider)
          Code called after the layout algorithm ends
protected  void preLayoutAlgorithm(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout, org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider, double x, double y, double width, double height)
          Code called before the layout algorithm starts
 void setDefaultConditions()
          Sets the default conditions.
 void setIterations(int iterations)
          Sets the number of iterations to be used.
 void setLayoutArea(double x, double y, double width, double height)
           
 void setRandom(boolean random)
          Sets whether or not this SpringLayoutAlgorithm will layout the nodes randomly before beginning iterations.
 void setSpringGravitation(double gravitation)
          Sets the spring layout gravitation-control.
 void setSpringLength(double length)
          Sets the spring layout length-control.
 void setSpringMove(double move)
          Sets the spring layout move-control.
 void setSpringStrain(double strain)
          Sets the spring layout strain-control.
 void setSpringTimeout(long timeout)
          Sets the spring timeout
 void setWeight(java.lang.String relType, double weight)
           
 
Methods inherited from class org.eclipse.zest.layouts.algorithms.ContinuousLayoutAlgorithm
applyLayoutInternal, getBounds, setBounds
 
Methods inherited from class org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm
addEntity, addProgressListener, addRelationship, applyLayout, defaultFitWithinBounds, defaultFitWithinBounds, fireProgressEnded, fireProgressEvent, fireProgressStarted, getEntityAspectRatio, getLayoutBounds, getLocalLocation, getNumberOfProgressListeners, getStyle, isRunning, removeEntity, removeProgressListener, removeRelationship, removeRelationships, removeRelationships, setComparator, setEntityAspectRatio, setFilter, setStyle, stop, updateBendPoints, updateEntities, updateLayoutLocations, updateRelationships, verifyInput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SPRING_ITERATIONS

public static final int DEFAULT_SPRING_ITERATIONS
The default value for the spring layout number of interations.

See Also:
Constant Field Values

MAX_SPRING_TIME

public static final long MAX_SPRING_TIME
the default value for the time algorithm runs.

See Also:
Constant Field Values

DEFAULT_SPRING_RANDOM

public static final boolean DEFAULT_SPRING_RANDOM
The default value for positioning nodes randomly.

See Also:
Constant Field Values

DEFAULT_SPRING_IGNORE_UNCON

public static final boolean DEFAULT_SPRING_IGNORE_UNCON
The default value for ignoring unconnected nodes.

See Also:
Constant Field Values

DEFAULT_SPRING_SEPARATE_COMPONENTS

public static final boolean DEFAULT_SPRING_SEPARATE_COMPONENTS
The default value for separating connected components.

See Also:
Constant Field Values

DEFAULT_SPRING_MOVE

public static final double DEFAULT_SPRING_MOVE
The default value for the spring layout move-control.

See Also:
Constant Field Values

DEFAULT_SPRING_STRAIN

public static final double DEFAULT_SPRING_STRAIN
The default value for the spring layout strain-control.

See Also:
Constant Field Values

DEFAULT_SPRING_LENGTH

public static final double DEFAULT_SPRING_LENGTH
The default value for the spring layout length-control.

See Also:
Constant Field Values

DEFAULT_SPRING_GRAVITATION

public static final double DEFAULT_SPRING_GRAVITATION
The default value for the spring layout gravitation-control.

See Also:
Constant Field Values

MIN_DISTANCE

protected static final double MIN_DISTANCE
Minimum distance considered between nodes

See Also:
Constant Field Values

EPSILON

protected static final double EPSILON
An arbitrarily small value in mathematics.

See Also:
Constant Field Values
Constructor Detail

SpringLayoutAlgorithm

public SpringLayoutAlgorithm(int styles)
Constructor.


SpringLayoutAlgorithm

public SpringLayoutAlgorithm()
Creates a sprint layout algoirthm with no style

Method Detail

setLayoutArea

public void setLayoutArea(double x,
                          double y,
                          double width,
                          double height)
Overrides:
setLayoutArea in class ContinuousLayoutAlgorithm

setSpringMove

public void setSpringMove(double move)
Sets the spring layout move-control.

Parameters:
move - The move-control value.

getSpringMove

public double getSpringMove()
Returns the move-control value of this SpringLayoutAlgorithm in double presion.

Returns:
The move-control value.

setSpringStrain

public void setSpringStrain(double strain)
Sets the spring layout strain-control.

Parameters:
strain - The strain-control value.

getSpringStrain

public double getSpringStrain()
Returns the strain-control value of this SpringLayoutAlgorithm in double presion.

Returns:
The strain-control value.

setSpringLength

public void setSpringLength(double length)
Sets the spring layout length-control.

Parameters:
length - The length-control value.

getSpringTimeout

public long getSpringTimeout()
Gets the max time this algorithm will run for

Returns:

setSpringTimeout

public void setSpringTimeout(long timeout)
Sets the spring timeout

Parameters:
timeout -

getSpringLength

public double getSpringLength()
Returns the length-control value of this SpringLayoutAlgorithm in double presion.

Returns:
The length-control value.

setSpringGravitation

public void setSpringGravitation(double gravitation)
Sets the spring layout gravitation-control.

Parameters:
gravitation - The gravitation-control value.

getSpringGravitation

public double getSpringGravitation()
Returns the gravitation-control value of this SpringLayoutAlgorithm in double presion.

Returns:
The gravitation-control value.

setIterations

public void setIterations(int iterations)
Sets the number of iterations to be used.

Parameters:
gravitation - The number of iterations.

getIterations

public int getIterations()
Returns the number of iterations to be used.

Returns:
The number of iterations.

setRandom

public void setRandom(boolean random)
Sets whether or not this SpringLayoutAlgorithm will layout the nodes randomly before beginning iterations.

Parameters:
random - The random placement value.

getRandom

public boolean getRandom()
Returns whether or not this SpringLayoutAlgorithm will layout the nodes randomly before beginning iterations.


setWeight

public void setWeight(java.lang.String relType,
                      double weight)

getWeight

public double getWeight(java.lang.String relType)

setDefaultConditions

public void setDefaultConditions()
Sets the default conditions.


preLayoutAlgorithm

protected void preLayoutAlgorithm(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout,
                                  org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider,
                                  double x,
                                  double y,
                                  double width,
                                  double height)
Description copied from class: AbstractLayoutAlgorithm
Code called before the layout algorithm starts

Specified by:
preLayoutAlgorithm in class AbstractLayoutAlgorithm

postLayoutAlgorithm

protected void postLayoutAlgorithm(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout,
                                   org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider)
Description copied from class: AbstractLayoutAlgorithm
Code called after the layout algorithm ends

Specified by:
postLayoutAlgorithm in class AbstractLayoutAlgorithm

getLayoutBoundsTemp

protected org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle getLayoutBoundsTemp(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout,
                                                                                                  boolean includeNodeSize)

convertNodePositionsBack

protected void convertNodePositionsBack(int i,
                                        org.eclipse.zest.layouts.dataStructures.InternalNode entityToConvert,
                                        double px,
                                        double py,
                                        double screenWidth,
                                        double screenHeight,
                                        org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle layoutBounds)

performAnotherNonContinuousIteration

protected boolean performAnotherNonContinuousIteration()
Description copied from class: ContinuousLayoutAlgorithm
The logic to determine if a layout should continue running or not

Specified by:
performAnotherNonContinuousIteration in class ContinuousLayoutAlgorithm

getCurrentLayoutStep

protected int getCurrentLayoutStep()
Description copied from class: AbstractLayoutAlgorithm
Gets the current layout step

Specified by:
getCurrentLayoutStep in class AbstractLayoutAlgorithm
Returns:

getTotalNumberOfLayoutSteps

protected int getTotalNumberOfLayoutSteps()
Description copied from class: AbstractLayoutAlgorithm
Gets the total number of steps in this layout

Specified by:
getTotalNumberOfLayoutSteps in class AbstractLayoutAlgorithm

computeOneIteration

protected void computeOneIteration(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout,
                                   org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider,
                                   double x,
                                   double y,
                                   double width,
                                   double height)
Description copied from class: ContinuousLayoutAlgorithm
Computes a single iteration of the layout algorithm

Specified by:
computeOneIteration in class ContinuousLayoutAlgorithm

placeRandomly

public void placeRandomly(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout)
Puts vertices in random places, all between (0,0) and (1,1).


computeForces

protected void computeForces(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout)
Computes the force for each node in this SpringLayoutAlgorithm. The computed force will be stored in the data repository


computePositions

protected void computePositions(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout)
Computes the position for each node in this SpringLayoutAlgorithm. The computed position will be stored in the data repository. position = position + sprMove * force


convertToUnitCoordinates

protected void convertToUnitCoordinates(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout)
Converts the position for each node in this SpringLayoutAlgorithm to unit coordinates in double precision. The computed positions will be still stored in the data repository.


isValidConfiguration

protected boolean isValidConfiguration(boolean asynchronous,
                                       boolean continueous)
Description copied from class: AbstractLayoutAlgorithm
Determines if the configuration is valid for this layout

Specified by:
isValidConfiguration in class AbstractLayoutAlgorithm

Zest
1.5.0.201305060205

Copyright (c) IBM Corp. and others 2000, 2011. All Rights Reserved.