## org.eclipse.amp.agf.zest
Class SpringPartitionLayoutAlgorithm

    java.lang.Object
      org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm
          org.eclipse.zest.layouts.algorithms.ContinuousLayoutAlgorithm
              org.eclipse.amp.agf.zest.SpringPartitionLayoutAlgorithm

All Implemented Interfaces:
  org.eclipse.zest.layouts.LayoutAlgorithm, org.eclipse.zest.layouts.Stoppable

    public class SpringPartitionLayoutAlgorithm

extends org.eclipse.zest.layouts.algorithms.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).

Version:
  2.0
Author:
  Ian Bull, Casey Best (version 1.0 by Jingwei Wu/Rob Lintern)

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
`SpringPartitionLayoutAlgorithm()` Creates a sprint layout algoirthm with no style
`SpringPartitionLayoutAlgorithm(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)`
`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()`
`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()`
`double` `getWeight(java.lang.String relType)`
`protected boolean` `isValidConfiguration(boolean asynchronous, boolean continueous)`
`protected boolean` `performAnotherNonContinuousIteration()`
`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)`
`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)`
`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

### SpringPartitionLayoutAlgorithm

    public SpringPartitionLayoutAlgorithm(int styles)

  Constructor.

### SpringPartitionLayoutAlgorithm

    public SpringPartitionLayoutAlgorithm()

  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 `org.eclipse.zest.layouts.algorithms.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)

  Specified by:
    `preLayoutAlgorithm` in class `org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm`

### postLayoutAlgorithm

    protected void postLayoutAlgorithm(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout,
                                       org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider)

  Specified by:
    `postLayoutAlgorithm` in class `org.eclipse.zest.layouts.algorithms.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()

  Specified by:
    `performAnotherNonContinuousIteration` in class `org.eclipse.zest.layouts.algorithms.ContinuousLayoutAlgorithm`

### getCurrentLayoutStep

    protected int getCurrentLayoutStep()

  Specified by:
    `getCurrentLayoutStep` in class `org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm`

### getTotalNumberOfLayoutSteps

    protected int getTotalNumberOfLayoutSteps()

  Specified by:
    `getTotalNumberOfLayoutSteps` in class `org.eclipse.zest.layouts.algorithms.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)

  Specified by:
    `computeOneIteration` in class `org.eclipse.zest.layouts.algorithms.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)

  Specified by:
    `isValidConfiguration` in class `org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm`