Class ViewerDefaultGUI

java.lang.Object
madkit.gui.DefaultAgentGUI
madkit.simulation.viewer.ViewerDefaultGUI
Direct Known Subclasses:
CanvasDrawerGUI

public abstract class ViewerDefaultGUI extends DefaultAgentGUI
This class provides a default GUI for a viewer agent. It creates a JavaFX stage with a menu bar, a toolbar, a central node and a right node.

The central node is created by the createCenterNode() method, which has to be implemented by the subclass.

The right node is created by the createRightNode() method, which can be overridden to provide a custom right node. By default, it creates a VBox containing the simulation properties using the PropertySheetFactory.

The toolbar is created by the createToolBar() method, which can be overridden to provide a custom toolbar. By default, it creates a toolbar with the viewer agent's actions and the scheduler's actions.

The rendering is managed by the requestRendering() method, which is called by the viewer agent when it wants to render the simulation state. This method triggers the Viewer.render() in the JavaFX thread, depending on the state of the GUI such as the synchronous painting mode.

The synchronous painting mode can be activated or deactivated by the user. When activated, the rendering is done for each simulation step and blocks the simulation process. When deactivated, the rendering is done without blocking the simulation process, at a rate corresponding to the complexity of the rendering.

  • Constructor Details

    • ViewerDefaultGUI

      protected ViewerDefaultGUI(Viewer viewer)
      Creates a new ViewerDefaultGUI for the given viewer.
      Parameters:
      viewer - the viewer agent
  • Method Details

    • onInitialize

      protected void onInitialize()
      Redefines to initialize the default rendering actions.
      Overrides:
      onInitialize in class DefaultAgentGUI
    • createTopNode

      protected Node createTopNode()
      Creates the top node of the viewer agent. By default, it creates a menu bar with the rendering actions and returns a VBox containing the menu bar.
      Overrides:
      createTopNode in class DefaultAgentGUI
      Returns:
      a VBox containing the menu bar
    • createBottomNode

      protected Node createBottomNode()
      Creates the bottom node.
      Overrides:
      createBottomNode in class DefaultAgentGUI
      Returns:
      the node
    • createRightNode

      protected Node createRightNode()
      Returns the VBox that will positioned on the right part of the main pane, which is a BorderPane. By default, it creates a VBox containing the simulation properties using the PropertySheetFactory.

      This method can be overridden to provide a custom right node.

      Default code is:

       
       protected VBox createRightNode() {
       	return PropertySheetFactory.getVBoxProperties(getViewer().getSimuEngine(), getViewer().getModel(),
       			getViewer().getEnvironment(), getViewer().getScheduler(), getViewer());
       }
       
          

      It will be positioned on the right of the main pane.

      Overrides:
      createRightNode in class DefaultAgentGUI
      Returns:
      a VBox that will be used as the right node of the main pane
    • createCenterNode

      protected abstract Node createCenterNode()
      Creates the central node of the viewer agent. This method has to be implemented by the subclass.
      Overrides:
      createCenterNode in class DefaultAgentGUI
      Returns:
      the central node of the main pane
    • createToolBar

      protected ToolBar createToolBar()
      Creates a toolbar for the viewer agent.
      Overrides:
      createToolBar in class DefaultAgentGUI
      Returns:
      a ToolBar with the viewer agent's actions
    • requestRendering

      public void requestRendering()
      Requests the rendering of the simulation state. The rendering is done in the JavaFX thread depending on the state of the GUI such as the synchronous painting mode.
    • getRenderingOffAction

      public FXActionCheck getRenderingOffAction()
      Returns the rendering off action.
      Returns:
      the renderingOff action
    • getSynchroPaintingAction

      public FXActionCheck getSynchroPaintingAction()
      Returns the synchronous painting action.
      Returns:
      the synchroPainting
    • isRendering

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

      public void setRenderingOff(boolean activated)
      Enable or disable the renderingOff activity
      Parameters:
      activated - if true, the renderingOff activity is activated
    • setSynchroPainting

      public void setSynchroPainting(boolean activated)
      Enable or disable the synchronous painting
      Parameters:
      activated - if true, the synchronous painting is activated
    • getViewer

      public Viewer getViewer()
      Returns the viewer agent associated with this GUI.
      Returns:
      the viewer agent