Package visualization
Class VisualizationEngine
- java.lang.Object
-
- java.util.TimerTask
-
- visualization.VisualizationEngine
-
- All Implemented Interfaces:
java.lang.Runnable
public class VisualizationEngine extends java.util.TimerTaskResponsible for visualizing States on a GraphStream graph.
-
-
Field Summary
Fields Modifier and Type Field Description private intcurrentTickprivate org.graphstream.graph.Graphgraphprivate booleanisRunningprivate OnTickListeneronTickListenerprivate org.graphstream.ui.spriteManager.SpriteManagerspriteManagerprivate java.util.List<State>statesprivate org.graphstream.ui.swingViewer.ViewPanelviewPanel
-
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.SpritecreateSpriteIfDoesNotExist(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 voiddrawCurrentState()Statelessly draws the current state based on the States array and the current tick.private voiddrawUserState(UserState userState)Draws a given UserState on the graphintgetCurrentTick()Returns the current tick in the visualization.OnTickListenergetOnTickListener()Returns the listener for Visualization state changes.java.util.List<State>getStates()doublegetTotalNumberOfUsersWithData()org.graphstream.ui.swingViewer.ViewPanelgetViewPanel()Gets the ViewPanel for displaybooleanisRunning()Returns whether the simulation is running.private voidremoveOldSpritesFromGraph(java.util.List<UserState> userStates)Removes sprites that are currently visible on the graph.voidrestart()Restarts the simulation from tick 0.voidrun()Starts the visualization loopvoidsetCurrentTick(int currentTick)Sets the current tick and forces a re-draw of the simulation.voidsetOnTickListener(OnTickListener onTickListener)Sets the listener for visualization state changes.voidsetRunning(boolean running)Sets the simulation to run or not.voidsetStates(java.util.List<State> states)Sets the states to visualize.voidtoggleSimulation()Turns the simulation on or off.
-
-
-
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
-
onTickListener
private OnTickListener onTickListener
-
-
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 showstates- 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:
runin interfacejava.lang.Runnable- Specified by:
runin classjava.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()
-
-