Class SwingViewer

All Implemented Interfaces:
Comparable<AbstractAgent>

public abstract class SwingViewer extends Watcher
A very basic simulation viewer agent. This class defines a panel for the simulation rendering and two modes of rendering: Synchronous and asynchronous. The synchronous mode ensures that each simulation frame is displayed. That means that the scheduler will wait the end of the rendering activity to proceed to the next activator, waiting for the swing thread to ends. this is not the case with the asynchronous mode so that the whole simulation process goes faster because some simulation states will not be displayed. An observe method is already defined and is intended to be called by scheduler agents to trigger the rendering. This class could be thus extended to reuse the rendering call mechanism which is defined in here.
Since:
MaDKit 5.0.0.17
Version:
1.1
Author:
Fabien Michel
  • Constructor Details

    • SwingViewer

      public SwingViewer()
      Creates a new agent with a default panel for rendering purposes
  • Method Details

    • isRendering

      public boolean isRendering()
      Returns:
      true if the rendering activity is activated.
    • setRendering

      public void setRendering(boolean activated)
      Enable or disable the rendering activity
    • getDisplayPane

      public JComponent getDisplayPane()
      Returns:
      the current panel which is used for display
    • setDisplayPane

      public void setDisplayPane(JComponent displayPane)
      Could be used to define a customized panel instead of the default pane
      Parameters:
      displayPane - the displayPane to set
    • observe

      protected void observe()
      Intended to be invoked by a scheduler's activator for triggering the rendering. This method activate the rendering either synchronously or asynchronously depending on isSynchronousPainting().
    • render

      protected abstract void render(Graphics g)
      Override this method to do the rendering in the agent's panel. This method is automatically called when the observe method is triggered by a Scheduler
      Parameters:
      g -
    • isSynchronousPainting

      public boolean isSynchronousPainting()
      Tells if the rendering should be done synchronously or asynchronously with respect to simulation steps.
      Returns:
      the synchronousPainting
    • setSynchronousPainting

      public void setSynchronousPainting(boolean synchronousPainting)
      Set the rendering mode to synchronous or asynchronous. Synchronous painting is done for each time step and the simulation does not advance until all the rendering is done for a step: The simulation is slower but more smoothly rendered, making the visualization of the simulation dynamics more precise. In asynchronous mode, the rendering is done in parallel with the simulation steps and thus only display snapshot of the simulation's state:
      Parameters:
      synchronousPainting - the synchronousPainting mode to set
    • setupFrame

      public void setupFrame(AgentFrame frame)
      Provides a default implementation that assigns the default panel to the default frame
      Overrides:
      setupFrame in class AbstractAgent
      Parameters:
      frame - the default frame which has been created by MaDKit for this agent.
      See Also:
    • getDisplayMenu

      public JMenu getDisplayMenu()
      Returns a menu which could be used in any viewer GUI.
      Returns:
      a menu controlling the viewer's options
    • getFrame

      public JFrame getFrame()
      By default, get the default frame provided by MaDKit in setupFrame(AgentFrame) and set using setupFrame(AgentFrame). It can be any JFrame if setupFrame(AgentFrame) has been overridden.
      Returns:
      the working frame
    • getSynchroPaintingAction

      public Action getSynchroPaintingAction()
    • setRenderingInterval

      public void setRenderingInterval(int interval)
      Set the number of states between display updates. If set to 1, every simulation states will be displayed
      Parameters:
      interval - an int > 0
    • getToolBar

      public JToolBar getToolBar()
      Returns the viewer's toolbar.
      Returns:
      a toolBar controlling the viewer's actions