Class AbstractLayout<V,E>

java.lang.Object
edu.uci.ics.jung.algorithms.layout.AbstractLayout<V,E>
Type Parameters:
V - the vertex type
E - the edge type
All Implemented Interfaces:
com.google.common.base.Function<V,Point2D>, Layout<V,E>, Function<V,Point2D>
Direct Known Subclasses:
CircleLayout, FRLayout, FRLayout2, ISOMLayout, KKLayout, SpringLayout, StaticLayout

public abstract class AbstractLayout<V,E> extends Object implements Layout<V,E>
Abstract class for implementations of Layout. It handles some of the basic functions: storing coordinates, maintaining the dimensions, initializing the locations, maintaining locked vertices.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Set<V>
    A set of vertices that are fixed in place and not affected by the layout algorithm
    protected Graph<V,E>
     
    protected boolean
     
    protected com.google.common.cache.LoadingCache<V,Point2D>
     
    protected Dimension
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates an instance for graph which does not initialize the vertex locations.
    protected
    AbstractLayout(Graph<V,E> graph, com.google.common.base.Function<V,Point2D> initializer)
    Creates an instance for graph which initializes the vertex locations using initializer.
    protected
    AbstractLayout(Graph<V,E> graph, com.google.common.base.Function<V,Point2D> initializer, Dimension size)
    Creates an instance for graph which initializes the vertex locations using initializer and sets the size of the layout to size.
    protected
    AbstractLayout(Graph<V,E> graph, Dimension size)
    Creates an instance for graph which sets the size of the layout to size.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
     
    apply(V v)
     
    private Point2D
    Returns the Coordinates object that stores the vertex' x and y location.
     
    Returns the current size of the visualization space, accoring to the last call to resize().
    double
    getX(V v)
    Returns the x coordinate of the vertex from the Coordinates object.
    double
    getY(V v)
    Returns the y coordinate of the vertex from the Coordinates object.
    boolean
     
    void
    lock(boolean lock)
     
    void
    lock(V v, boolean state)
    Locks v in place if state is true, otherwise unlocks it.
    protected void
    offsetVertex(V v, double xOffset, double yOffset)
     
    void
    setGraph(Graph<V,E> graph)
     
    void
    setInitializer(com.google.common.base.Function<V,Point2D> initializer)
     
    void
    setLocation(V picked, double x, double y)
    Forcibly moves a vertex to the (x,y) location by setting its x and y locations to the specified location.
    void
    setLocation(V picked, Point2D p)
    Changes the layout coordinates of v to location.
    void
    When a visualization is resized, it presumably wants to fix the locations of the vertices and possibly to reinitialize its data.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface com.google.common.base.Function

    equals

    Methods inherited from interface java.util.function.Function

    andThen, compose

    Methods inherited from interface edu.uci.ics.jung.algorithms.layout.Layout

    initialize, reset
  • Field Details

    • dontmove

      private Set<V> dontmove
      A set of vertices that are fixed in place and not affected by the layout algorithm
    • size

      protected Dimension size
    • graph

      protected Graph<V,E> graph
    • initialized

      protected boolean initialized
    • locations

      protected com.google.common.cache.LoadingCache<V,Point2D> locations
  • Constructor Details

    • AbstractLayout

      protected AbstractLayout(Graph<V,E> graph)
      Creates an instance for graph which does not initialize the vertex locations.
      Parameters:
      graph - the graph on which the layout algorithm is to operate
    • AbstractLayout

      protected AbstractLayout(Graph<V,E> graph, com.google.common.base.Function<V,Point2D> initializer)
      Creates an instance for graph which initializes the vertex locations using initializer.
      Parameters:
      graph - the graph on which the layout algorithm is to operate
      initializer - specifies the starting positions of the vertices
    • AbstractLayout

      protected AbstractLayout(Graph<V,E> graph, Dimension size)
      Creates an instance for graph which sets the size of the layout to size.
      Parameters:
      graph - the graph on which the layout algorithm is to operate
      size - the dimensions of the region in which the layout algorithm will place vertices
    • AbstractLayout

      protected AbstractLayout(Graph<V,E> graph, com.google.common.base.Function<V,Point2D> initializer, Dimension size)
      Creates an instance for graph which initializes the vertex locations using initializer and sets the size of the layout to size.
      Parameters:
      graph - the graph on which the layout algorithm is to operate
      initializer - specifies the starting positions of the vertices
      size - the dimensions of the region in which the layout algorithm will place vertices
  • Method Details

    • setGraph

      public void setGraph(Graph<V,E> graph)
      Specified by:
      setGraph in interface Layout<V,E>
      Parameters:
      graph - the graph that this algorithm is to operate on
    • setSize

      public void setSize(Dimension size)
      When a visualization is resized, it presumably wants to fix the locations of the vertices and possibly to reinitialize its data. The current method calls initializeLocations followed by initialize_local.
      Specified by:
      setSize in interface Layout<V,E>
      Parameters:
      size - the space to use to lay out this graph
    • adjustLocations

      private void adjustLocations(Dimension oldSize, Dimension size)
    • isLocked

      public boolean isLocked(V v)
      Specified by:
      isLocked in interface Layout<V,E>
      Parameters:
      v - the vertex whose locked state is being queried
      Returns:
      true if the position of vertex v is locked
    • setInitializer

      public void setInitializer(com.google.common.base.Function<V,Point2D> initializer)
      Specified by:
      setInitializer in interface Layout<V,E>
      Parameters:
      initializer - a function that specifies initial locations for all vertices
    • getSize

      public Dimension getSize()
      Returns the current size of the visualization space, accoring to the last call to resize().
      Specified by:
      getSize in interface Layout<V,E>
      Returns:
      the current size of the screen
    • getCoordinates

      private Point2D getCoordinates(V v)
      Returns the Coordinates object that stores the vertex' x and y location.
      Parameters:
      v - A Vertex that is a part of the Graph being visualized.
      Returns:
      A Coordinates object with x and y locations.
    • apply

      public Point2D apply(V v)
      Specified by:
      apply in interface com.google.common.base.Function<V,E>
      Specified by:
      apply in interface Function<V,E>
    • getX

      public double getX(V v)
      Returns the x coordinate of the vertex from the Coordinates object. in most cases you will be better off calling transform(v).
      Parameters:
      v - the vertex whose x coordinate is to be returned
      Returns:
      the x coordinate of v
    • getY

      public double getY(V v)
      Returns the y coordinate of the vertex from the Coordinates object. In most cases you will be better off calling transform(v).
      Parameters:
      v - the vertex whose y coordinate is to be returned
      Returns:
      the y coordinate of v
    • offsetVertex

      protected void offsetVertex(V v, double xOffset, double yOffset)
      Parameters:
      v - the vertex whose coordinates are to be offset
      xOffset - the change to apply to this vertex's x coordinate
      yOffset - the change to apply to this vertex's y coordinate
    • getGraph

      public Graph<V,E> getGraph()
      Specified by:
      getGraph in interface Layout<V,E>
      Returns:
      the graph that this layout operates on
    • setLocation

      public void setLocation(V picked, double x, double y)
      Forcibly moves a vertex to the (x,y) location by setting its x and y locations to the specified location. Does not add the vertex to the "dontmove" list, and (in the default implementation) does not make any adjustments to the rest of the graph.
      Parameters:
      picked - the vertex whose location is being set
      x - the x coordinate of the location to set
      y - the y coordinate of the location to set
    • setLocation

      public void setLocation(V picked, Point2D p)
      Description copied from interface: Layout
      Changes the layout coordinates of v to location.
      Specified by:
      setLocation in interface Layout<V,E>
      Parameters:
      picked - the vertex whose location is to be specified
      p - the coordinates of the specified location
    • lock

      public void lock(V v, boolean state)
      Locks v in place if state is true, otherwise unlocks it.
      Specified by:
      lock in interface Layout<V,E>
      Parameters:
      v - the vertex whose position is to be (un)locked
      state - true if the vertex is to be locked, false if to be unlocked
    • lock

      public void lock(boolean lock)
      Parameters:
      lock - true to lock all vertices in place, false to unlock all vertices