Class OtsSimulationPanel

All Implemented Interfaces:
ActionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, EventListener

public class OtsSimulationPanel extends JPanel implements ActionListener, EventListener
Simulation panel with various controls and animation.

Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
See Also:
  • Field Details

  • Constructor Details

    • OtsSimulationPanel

      public OtsSimulationPanel(Network network) throws RemoteException, nl.tudelft.simulation.language.DsolException
      Construct a panel that looks like the DSOLPanel for quick building of OTS applications.
      Parameters:
      network - network
      Throws:
      RemoteException - when notification of the animation panel fails
      nl.tudelft.simulation.language.DsolException - when simulator does not implement AnimatorInterface
    • OtsSimulationPanel

      public OtsSimulationPanel(Rectangle2D extent, Network network) throws RemoteException, nl.tudelft.simulation.language.DsolException
      Construct a panel that looks like the DSOLPanel for quick building of OTS applications.
      Parameters:
      extent - bottom left corner, length and width of the area (world) to animate
      network - network
      Throws:
      RemoteException - when notification of the animation panel fails
      nl.tudelft.simulation.language.DsolException - when simulator does not implement AnimatorInterface
    • OtsSimulationPanel

      public OtsSimulationPanel(Network network, OtsSimulationPanelDecorator decorator) throws RemoteException, nl.tudelft.simulation.language.DsolException
      Construct a panel that looks like the DSOLPanel for quick building of OTS applications.
      Parameters:
      network - network
      decorator - decorator for the animation panel
      Throws:
      RemoteException - when notification of the animation panel fails
      nl.tudelft.simulation.language.DsolException - when simulator does not implement AnimatorInterface
      NullPointerException - when any input is null
    • OtsSimulationPanel

      public OtsSimulationPanel(Rectangle2D extent, Network network, OtsSimulationPanelDecorator decorator) throws RemoteException, nl.tudelft.simulation.language.DsolException
      Construct a panel that looks like the DSOLPanel for quick building of OTS applications.
      Parameters:
      extent - bottom left corner, length and width of the area (world) to animate
      network - network
      decorator - decorator for the animation panel
      Throws:
      RemoteException - when notification of the animation panel fails
      nl.tudelft.simulation.language.DsolException - when simulator does not implement AnimatorInterface
      NullPointerException - when any input is null
  • Method Details

    • addConsoleTab

      public void addConsoleTab()
      Adds the console tab.
    • getTabbedPane

      public TabbedContentPane getTabbedPane()
      Return tabbed pane.
      Returns:
      tabbed pane
    • getSimulator

      public OtsSimulatorInterface getSimulator()
      Return simulator.
      Returns:
      simulator
    • enableSimulationControlButtons

      public void enableSimulationControlButtons()
      Enable the simulation or animation buttons in the GUI. This method HAS TO BE CALLED in order for the buttons to be enabled, because the initial state is DISABLED. Typically, this is done after all tabs, statistics, and other user interface and model components have been constructed and initialized.
    • disableSimulationControlButtons

      public void disableSimulationControlButtons()
      Disable the simulation or animation buttons in the GUI.
    • setAutoPan

      public void setAutoPan(String newAutoPanId, org.opentrafficsim.swing.gui.OtsSearchPanel.ObjectKind<?> newAutoPanKind, boolean newAutoPanTrack)
      Change auto pan target.
      Parameters:
      newAutoPanId - id of object to track
      newAutoPanKind - kind of object to track
      newAutoPanTrack - if true; tracking is continuously; if false; tracking is once
    • startToggleSection

      public void startToggleSection(String name, boolean visibleDefault)
      Adds a button that can hide all toggles in a section. The section is defined as laying between two section buttons.
      Parameters:
      name - name of the section that can be hidden
      visibleDefault - whether the section is visible by default
    • addToggleAnimationButtonIcon

      public void addToggleAnimationButtonIcon(String name, Class<? extends Locatable> locatableClass, String iconPath, String toolTipText, boolean initiallyVisible, boolean nextToPrevious)
      Add a button for toggling an animation class on or off. Button icons for which 'nextToPrevious' is true will be placed to the right of the previous button, which should be the corresponding button for id buttons. An example is an icon for showing/hiding the class 'Lane' followed by the button to show/hide the Lane ids. Other buttons can be placed next to the previous too.
      Parameters:
      name - the name of the button
      locatableClass - the class for which the button holds (e.g., GTU.class)
      iconPath - the path to the 24x24 icon to display
      toolTipText - the tool tip text to show when hovering over the button
      initiallyVisible - whether the class is initially shown or not
      nextToPrevious - button that needs to be placed next to the previous button
    • addToggleAnimationButtonText

      public void addToggleAnimationButtonText(String name, Class<? extends Locatable> locatableClass, String toolTipText, boolean initiallyVisible)
      Add a button for toggling an animation class on or off.
      Parameters:
      name - the name of the button
      locatableClass - the class for which the button holds (e.g., GTU.class)
      toolTipText - the tool tip text to show when hovering over the button
      initiallyVisible - whether the class is initially shown or not
    • addToggleText

      public void addToggleText(String text)
      Add a text to explain animation classes.
      Parameters:
      text - the text to show
    • addAllToggleGisButtonText

      public void addAllToggleGisButtonText(String header, GisRenderable2d gisMap, String toolTipText)
      Add buttons for toggling all GIS layers on or off.
      Parameters:
      header - the name of the group of layers
      gisMap - the GIS map for which the toggles have to be added
      toolTipText - the tool tip text to show when hovering over the button
    • addToggleGisButtonText

      public void addToggleGisButtonText(String layerName, String displayName, GisRenderable2d gisMap, String toolTipText, boolean initiallyVisible)
      Add a button to toggle a GIS Layer on or off.
      Parameters:
      layerName - the name of the layer
      displayName - the name to display next to the tick box
      gisMap - the map
      toolTipText - the tool tip text
      initiallyVisible - whether the layer is initially shown or not
    • showGisLayer

      public void showGisLayer(String layerName)
      Set a GIS layer to be shown in the animation to true.
      Parameters:
      layerName - the name of the GIS-layer that has to be shown
    • hideGisLayer

      public void hideGisLayer(String layerName)
      Set a GIS layer to be hidden in the animation to true.
      Parameters:
      layerName - the name of the GIS-layer that has to be hidden
    • toggleGisLayer

      public void toggleGisLayer(String layerName)
      Toggle a GIS layer to be displayed in the animation to its reverse value.
      Parameters:
      layerName - the name of the GIS-layer that has to be turned off or vice versa
    • actionPerformed

      public void actionPerformed(ActionEvent actionEvent)
      Specified by:
      actionPerformed in interface ActionListener
    • getAnimationPanel

      public AnimationPanel getAnimationPanel()
      Easy access to the AnimationPanel.
      Returns:
      animation panel
    • createDemoPanel

      public void createDemoPanel(OtsSimulationPanel.DemoPanelPosition position)
      Creates a demo panel within the animation area.
      Parameters:
      position - position within the animation panel
      Throws:
      IllegalStateException - if the panel was already created
    • getDemoPanel

      public JPanel getDemoPanel()
      Return a panel for on-screen demo controls. The panel is created on the right of the screen on first call, unless createDemoPanel(org.opentrafficsim.swing.gui.OtsSimulationPanel.DemoPanelPosition) was already called.
      Returns:
      demo panel
    • updateAnimationClassCheckBox

      public void updateAnimationClassCheckBox(Class<? extends Locatable> locatableClass)
      Update the check-mark related to a programmatically changed animation state.
      Parameters:
      locatableClass - class to show the check-mark for
    • getGtuColorerManager

      public GtuColorerManager getGtuColorerManager()
      GTU colorer manager from the GTU color panel.
      Returns:
      GTU colorer manager from the GTU color panel
    • notify

      public void notify(Event event)
      Specified by:
      notify in interface EventListener
    • separatedName

      public static String separatedName(String name)
      Adds a thin space before each capital character in a String, except the first.
      Parameters:
      name - name of node
      Returns:
      input string but with a thin space before each capital character, except the first