Class SpringLayoutAlgorithm

  • All Implemented Interfaces:
    ILayoutAlgorithm

    public class SpringLayoutAlgorithm
    extends java.lang.Object
    implements ILayoutAlgorithm
    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.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void applyLayout​(LayoutContext layoutContext, 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()
      Computes one iteration (forces, positions) and increases the iteration counter.
      protected void computePositions()
      Computes the position for each node in this SpringLayoutAlgorithm.
      protected int getCurrentLayoutStep()
      Returns the current iteration.
      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 precision.
      double getSpringLength()
      Returns the length-control value of this SpringLayoutAlgorithm in double precision.
      double getSpringMove()
      Returns the move-control value of this SpringLayoutAlgorithm in double precision.
      double getSpringStrain()
      Returns the strain-control value of this SpringLayoutAlgorithm in double precision.
      long getSpringTimeout()
      Gets the max time this algorithm will run for
      protected int getTotalNumberOfLayoutSteps()
      Returns the maximum number of iterations.
      boolean isResizing()  
      protected boolean performAnotherNonContinuousIteration()
      Performs one iteration based on time.
      void performNIteration​(int n)
      Performs the given number of iterations.
      void performOneIteration()
      Performs one single iteration.
      protected 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 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 to the given value (in millis).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SpringLayoutAlgorithm

        public SpringLayoutAlgorithm()
    • Method Detail

      • applyLayout

        public void applyLayout​(LayoutContext layoutContext,
                                boolean clean)
        Description copied from interface: ILayoutAlgorithm
        Makes this algorithm perform layout computation and apply it to its context.
        Specified by:
        applyLayout in interface ILayoutAlgorithm
        Parameters:
        layoutContext - The LayoutContext that provides all relevant information about what to layout.
        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.
      • performNIteration

        public void performNIteration​(int n)
        Performs the given number of iterations.
        Parameters:
        n - The number of iterations to perform.
      • performOneIteration

        public void performOneIteration()
        Performs one single iteration.
      • isResizing

        public boolean isResizing()
        Returns:
        true if this algorithm is set to resize elements
      • setResizing

        public void setResizing​(boolean resizing)
        Parameters:
        resizing - true if this algorithm should resize elements (default is false)
      • 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 precision.
        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 precision.
        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:
        the timeout up to which this algorithm may run
      • setSpringTimeout

        public void setSpringTimeout​(long timeout)
        Sets the spring timeout to the given value (in millis).
        Parameters:
        timeout - The new spring timeout (in millis).
      • getSpringLength

        public double getSpringLength()
        Returns the length-control value of this SpringLayoutAlgorithm in double precision.
        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 precision.
        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.
        Returns:
        true if this algorithm will layout the nodes randomly before iterating, otherwise false.
      • performAnotherNonContinuousIteration

        protected boolean performAnotherNonContinuousIteration()
        Performs one iteration based on time.
        Returns:
        true if the maximum number of iterations was not reached yet, otherwise false.
      • getCurrentLayoutStep

        protected int getCurrentLayoutStep()
        Returns the current iteration.
        Returns:
        The current iteration.
      • getTotalNumberOfLayoutSteps

        protected int getTotalNumberOfLayoutSteps()
        Returns the maximum number of iterations.
        Returns:
        The maximum number of iterations.
      • computeOneIteration

        protected void computeOneIteration()
        Computes one iteration (forces, positions) and increases the iteration counter.
      • placeRandomly

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

        protected void computeForces()
        Computes the force for each node in this SpringLayoutAlgorithm. The computed force will be stored in the data repository
      • 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