Package org.eclipse.zest.layouts.algorithms

# Class SpringLayoutAlgorithm

java.lang.Object
org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm
org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm

All Implemented Interfaces:
  `LayoutAlgorithm`

public class SpringLayoutAlgorithm extends AbstractLayoutAlgorithm
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.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`SpringLayoutAlgorithm.Zest1`
Deprecated, for removal: This API element is subject to removal in a future version.
Use `SpringLayoutAlgorithm` instead.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final double`
`DEFAULT_SPRING_GRAVITATION`
The default value for the spring layout gravitation-control.
`static final int`
`DEFAULT_SPRING_ITERATIONS`
The default value for the spring layout number of interations.
`static final double`
`DEFAULT_SPRING_LENGTH`
The default value for the spring layout length-control.
`static final double`
`DEFAULT_SPRING_MOVE`
The default value for the spring layout move-control.
`static final boolean`
`DEFAULT_SPRING_RANDOM`
The default value for positioning nodes randomly.
`static final double`
`DEFAULT_SPRING_STRAIN`
The default value for the spring layout strain-control.
`protected static final double`
`EPSILON`
An arbitrarily small value in mathematics.
`boolean`
`fitWithinBounds`
`static final long`
`MAX_SPRING_TIME`
the default value for the time algorithm runs.
`protected static final double`
`MIN_DISTANCE`
Minimum distance considered between nodes

### Fields inherited from class org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm

`context`

## Constructor Summary

Constructors
Constructor
Description
`SpringLayoutAlgorithm()`
`SpringLayoutAlgorithm(int style)`
Deprecated.
Since Zest 2.0, use `SpringLayoutAlgorithm()`.

## Method Summary

Modifier and Type
Method
Description
`void`
`applyLayout(boolean clean)`
Makes this algorithm perform layout computation and apply it to its context.
`protected void`
`computeForces()`
Computes the force for each node in this SpringLayoutAlgorithm.
`protected void`
`computeOneIteration()`
`protected void`
`computePositions()`
Computes the position for each node in this SpringLayoutAlgorithm.
`protected int`
`getCurrentLayoutStep()`
`int`
`getIterations()`
Returns the number of iterations to be used.
`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()`
`boolean`
`isResizing()`
`protected boolean`
`performAnotherNonContinuousIteration()`
`void`
`performNIteration(int n)`
`void`
`performOneIteration()`
`void`
`placeRandomly()`
Puts vertices in random places, all between (0,0) and (1,1).
`void`
`setIterations(int iterations)`
Sets the number of iterations to be used.
`void`
`setLayoutContext(LayoutContext context)`
Sets the layout context for this algorithm.
`void`
`setRandom(boolean random)`
Sets whether or not this SpringLayoutAlgorithm will layout the nodes randomly before beginning iterations.
`void`
`setResizing(boolean resizing)`
`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

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### 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_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

### fitWithinBounds

public boolean fitWithinBounds

Since:
  2.0

## Constructor Details

### SpringLayoutAlgorithm

@Deprecated public SpringLayoutAlgorithm(int style)
Deprecated.
Since Zest 2.0, use `SpringLayoutAlgorithm()`.

### SpringLayoutAlgorithm

public SpringLayoutAlgorithm()

## Method Details

### applyLayout

public void applyLayout(boolean clean)
Description copied from interface: `LayoutAlgorithm`
Makes this algorithm perform layout computation and apply it to its context.

Parameters:
  `clean` - if true the receiver should assume that the layout context has changed significantly and recompute the whole layout even if it keeps track of changes with listeners. False can be used after dynamic layout in a context is turned back on so that layout algorithm working in background can apply accumulated changes. Static layout algorithm can ignore this call entirely if clean is false.

### setLayoutContext

public void setLayoutContext(LayoutContext context)
Description copied from interface: `LayoutAlgorithm`
Sets the layout context for this algorithm. The receiver will unregister from its previous layout context and register to the new one (registration means for example adding listeners). After a call to this method, the receiving algorithm can compute and cache internal data related to given context and perform an initial layout.

Specified by:
  `setLayoutContext` in interface `LayoutAlgorithm`
Overrides:
  `setLayoutContext` in class `AbstractLayoutAlgorithm`
Parameters:
  `context` - a new layout context or null if this algorithm should not perform any layout

### performNIteration

public void performNIteration(int n)

Since:
  2.0

### performOneIteration

public void performOneIteration()

Since:
  2.0

### isResizing

public boolean isResizing()

Returns:
  true if this algorithm is set to resize elements
Since:
  2.0

### setResizing

public void setResizing(boolean resizing)

Parameters:
  `resizing` - true if this algorithm should resize elements (default is false)
Since:
  2.0

### 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

### 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:
  `iterations` - 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.

### performAnotherNonContinuousIteration

protected boolean performAnotherNonContinuousIteration()

### getCurrentLayoutStep

protected int getCurrentLayoutStep()

### getTotalNumberOfLayoutSteps

protected int getTotalNumberOfLayoutSteps()

### computeOneIteration

protected void computeOneIteration()

Since:
  2.0

### placeRandomly

public void placeRandomly()
Puts vertices in random places, all between (0,0) and (1,1).

Since:
  2.0

### computeForces

protected void computeForces()
Computes the force for each node in this SpringLayoutAlgorithm. The computed force will be stored in the data repository

Since:
  2.0

### computePositions

protected void computePositions()
Computes the position for each node in this SpringLayoutAlgorithm. The computed position will be stored in the data repository. position = position + sprMove * force

Since:
  2.0