Class ListenableLayoutModel2D<V>

  • Type Parameters:
    V - the vertex type
    All Implemented Interfaces:
    java.lang.Iterable<java.util.Map.Entry<V,​Point2D>>, LayoutModel2D<V>

    public class ListenableLayoutModel2D<V>
    extends java.lang.Object
    implements LayoutModel2D<V>
    A layout model wrapper which adds support for listeners.
    Author:
    Dimitrios Michail
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.function.BiConsumer<V,​Point2D> addListener​(java.util.function.BiConsumer<V,​Point2D> listener)
      Add a new listener.
      Point2D get​(V vertex)
      Get the last location of a particular vertex in the model.
      Box2D getDrawableArea()
      Get the drawable area of the model.
      boolean isFixed​(V vertex)
      Check whether a vertex is a fixed point.
      java.util.Iterator<java.util.Map.Entry<V,​Point2D>> iterator()
      Get an iterator with all vertices' locations.
      protected void notifyListeners​(V vertex, Point2D point)
      Notify all registered listeners.
      Point2D put​(V vertex, Point2D point)
      Set the location of a vertex.
      boolean removeListener​(java.util.function.BiConsumer<V,​Point2D> listener)
      Remove a listener.
      void setDrawableArea​(Box2D drawableArea)
      Set the drawable area of the model.
      void setFixed​(V vertex, boolean fixed)
      Set a point as being a "fixed-point" or not.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • listeners

        protected java.util.List<java.util.function.BiConsumer<V,​Point2D>> listeners
    • Constructor Detail

      • ListenableLayoutModel2D

        public ListenableLayoutModel2D​(LayoutModel2D<V> model)
        Create a new model
        Parameters:
        model - the underlying layout model
    • Method Detail

      • getDrawableArea

        public Box2D getDrawableArea()
        Description copied from interface: LayoutModel2D
        Get the drawable area of the model.
        Specified by:
        getDrawableArea in interface LayoutModel2D<V>
        Returns:
        the drawable area of the model
      • setDrawableArea

        public void setDrawableArea​(Box2D drawableArea)
        Description copied from interface: LayoutModel2D
        Set the drawable area of the model.
        Specified by:
        setDrawableArea in interface LayoutModel2D<V>
        Parameters:
        drawableArea - the drawable area to use
      • iterator

        public java.util.Iterator<java.util.Map.Entry<V,​Point2D>> iterator()
        Description copied from interface: LayoutModel2D
        Get an iterator with all vertices' locations. May return an empty iterator if the model does not store locations.
        Specified by:
        iterator in interface java.lang.Iterable<V>
        Specified by:
        iterator in interface LayoutModel2D<V>
        Returns:
        an iterator which returns all vertices with their locations. May return an empty iterator if the model does not store locations.
      • get

        public Point2D get​(V vertex)
        Description copied from interface: LayoutModel2D
        Get the last location of a particular vertex in the model. May return null if the vertex has not been assigned a location or if the particular implementation does not store the coordinates.
        Specified by:
        get in interface LayoutModel2D<V>
        Parameters:
        vertex - the graph vertex
        Returns:
        the last location of the vertex
      • put

        public Point2D put​(V vertex,
                           Point2D point)
        Description copied from interface: LayoutModel2D
        Set the location of a vertex.
        Specified by:
        put in interface LayoutModel2D<V>
        Parameters:
        vertex - the graph vertex
        point - the location
        Returns:
        the previous location or null if the vertex did not have a previous location or if the model does not store locations
      • setFixed

        public void setFixed​(V vertex,
                             boolean fixed)
        Description copied from interface: LayoutModel2D
        Set a point as being a "fixed-point" or not. It is the model's responsibility to make sure that changing the coordinates of a fixed point by calling LayoutModel2D.put(Object, Point2D) has no effect.
        Specified by:
        setFixed in interface LayoutModel2D<V>
        Parameters:
        vertex - a vertex
        fixed - whether it is a fixed point or not.
      • isFixed

        public boolean isFixed​(V vertex)
        Description copied from interface: LayoutModel2D
        Check whether a vertex is a fixed point. It is the model's responsibility to make sure that changing the coordinates of a fixed point by calling LayoutModel2D.put(Object, Point2D) has no effect.
        Specified by:
        isFixed in interface LayoutModel2D<V>
        Parameters:
        vertex - the vertex
        Returns:
        true if a fixed point, false otherwise
      • addListener

        public java.util.function.BiConsumer<V,​Point2D> addListener​(java.util.function.BiConsumer<V,​Point2D> listener)
        Add a new listener.
        Parameters:
        listener - the listener to add
        Returns:
        the newly added listener
      • removeListener

        public boolean removeListener​(java.util.function.BiConsumer<V,​Point2D> listener)
        Remove a listener.
        Parameters:
        listener - the listener to remove
        Returns:
        true if the listener was removed, false otherwise
      • notifyListeners

        protected void notifyListeners​(V vertex,
                                       Point2D point)
        Notify all registered listeners.
        Parameters:
        vertex - the vertex
        point - the vertex location