Package visualization

Class VisualizationEngine

  • All Implemented Interfaces:
    java.lang.Runnable

    public class VisualizationEngine
    extends java.util.TimerTask
    Responsible for visualizing States on a GraphStream graph.
    • Constructor Summary

      Constructors 
      Constructor Description
      VisualizationEngine​(org.graphstream.graph.Graph graph, java.util.List<State> states)
      Initializes the visualization engine with the given graph and states
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private org.graphstream.ui.spriteManager.Sprite createSpriteIfDoesNotExist​(UserState userState)
      Creates a sprite on the graph if it does not already exist.
      private static <T> java.util.function.Predicate<T> distinctByKey​(java.util.function.Function<? super T,​?> keyExtractor)  
      private void drawCurrentState()
      Statelessly draws the current state based on the States array and the current tick.
      private void drawUserState​(UserState userState)
      Draws a given UserState on the graph
      int getCurrentTick()
      Returns the current tick in the visualization.
      OnTickListener getOnTickListener()
      Returns the listener for Visualization state changes.
      java.util.List<State> getStates()  
      double getTotalNumberOfUsersWithData()  
      org.graphstream.ui.swingViewer.ViewPanel getViewPanel()
      Gets the ViewPanel for display
      boolean isRunning()
      Returns whether the simulation is running.
      private void removeOldSpritesFromGraph​(java.util.List<UserState> userStates)
      Removes sprites that are currently visible on the graph.
      void restart()
      Restarts the simulation from tick 0.
      void run()
      Starts the visualization loop
      void setCurrentTick​(int currentTick)
      Sets the current tick and forces a re-draw of the simulation.
      void setOnTickListener​(OnTickListener onTickListener)
      Sets the listener for visualization state changes.
      void setRunning​(boolean running)
      Sets the simulation to run or not.
      void setStates​(java.util.List<State> states)
      Sets the states to visualize.
      void toggleSimulation()
      Turns the simulation on or off.
      • Methods inherited from class java.util.TimerTask

        cancel, scheduledExecutionTime
      • Methods inherited from class java.lang.Object

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

      • currentTick

        private int currentTick
      • isRunning

        private boolean isRunning
      • graph

        private org.graphstream.graph.Graph graph
      • viewPanel

        private org.graphstream.ui.swingViewer.ViewPanel viewPanel
      • spriteManager

        private org.graphstream.ui.spriteManager.SpriteManager spriteManager
      • states

        private java.util.List<State> states
    • Constructor Detail

      • VisualizationEngine

        public VisualizationEngine​(org.graphstream.graph.Graph graph,
                                   java.util.List<State> states)
        Initializes the visualization engine with the given graph and states
        Parameters:
        graph - The graph to show
        states - The states to visualize
    • Method Detail

      • getViewPanel

        public org.graphstream.ui.swingViewer.ViewPanel getViewPanel()
        Gets the ViewPanel for display
        Returns:
        The ViewPanel object
      • run

        public void run()
        Starts the visualization loop
        Specified by:
        run in interface java.lang.Runnable
        Specified by:
        run in class java.util.TimerTask
      • drawCurrentState

        private void drawCurrentState()
        Statelessly draws the current state based on the States array and the current tick.
      • removeOldSpritesFromGraph

        private void removeOldSpritesFromGraph​(java.util.List<UserState> userStates)
        Removes sprites that are currently visible on the graph.
        Parameters:
        userStates - Current UserStates in the State
      • drawUserState

        private void drawUserState​(UserState userState)
        Draws a given UserState on the graph
        Parameters:
        userState - The UserState to visualize on the map
      • createSpriteIfDoesNotExist

        private org.graphstream.ui.spriteManager.Sprite createSpriteIfDoesNotExist​(UserState userState)
        Creates a sprite on the graph if it does not already exist.
        Parameters:
        userState - The UserState which the sprite will be created of.
        Returns:
        The found or created sprite
      • toggleSimulation

        public void toggleSimulation()
        Turns the simulation on or off.
      • restart

        public void restart()
        Restarts the simulation from tick 0.
      • getCurrentTick

        public int getCurrentTick()
        Returns the current tick in the visualization.
      • setCurrentTick

        public void setCurrentTick​(int currentTick)
        Sets the current tick and forces a re-draw of the simulation.
        Parameters:
        currentTick - The tick to set.
      • isRunning

        public boolean isRunning()
        Returns whether the simulation is running.
      • setRunning

        public void setRunning​(boolean running)
        Sets the simulation to run or not.
      • getOnTickListener

        public OnTickListener getOnTickListener()
        Returns the listener for Visualization state changes.
      • setOnTickListener

        public void setOnTickListener​(OnTickListener onTickListener)
        Sets the listener for visualization state changes.
        Parameters:
        onTickListener - The listener interface.
      • setStates

        public void setStates​(java.util.List<State> states)
        Sets the states to visualize.
      • getTotalNumberOfUsersWithData

        public double getTotalNumberOfUsersWithData()
      • distinctByKey

        private static <T> java.util.function.Predicate<T> distinctByKey​(java.util.function.Function<? super T,​?> keyExtractor)
      • getStates

        public java.util.List<State> getStates()