Class OtsAnimationPanel

All Implemented Interfaces:
ActionListener, WindowListener, ImageObserver, MenuContainer, Serializable, Remote, EventListener, Accessible, org.djutils.event.EventListener

public class OtsAnimationPanel extends OtsSimulationPanel implements ActionListener, WindowListener, org.djutils.event.EventListener
Animation panel with various controls.

Copyright (c) 2013-2024 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
See Also:
  • Field Details

    • closeHandlerRegistered

      protected boolean closeHandlerRegistered
      Has the window close handler been registered?
    • windowExited

      protected boolean windowExited
      Indicate the window has been closed and the timer thread can stop.
  • Constructor Details

    • OtsAnimationPanel

      public OtsAnimationPanel(Rectangle2D extent, Dimension size, org.opentrafficsim.core.dsol.OtsAnimator simulator, org.opentrafficsim.core.dsol.OtsModelInterface otsModel, GtuColorer gtuColorer, org.opentrafficsim.core.network.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 - Rectangle2D; bottom left corner, length and width of the area (world) to animate.
      size - Dimension; the size to be used for the animation.
      simulator - OTSAnimator; the simulator or animator of the model.
      otsModel - OtsModelInterface; the builder and rebuilder of the simulation, based on properties.
      gtuColorer - GtuColorer; the colorer to use for the GTUs.
      network - Network; network
      Throws:
      RemoteException - when notification of the animation panel fails
      nl.tudelft.simulation.language.DsolException - when simulator does not implement AnimatorInterface
  • Method Details

    • setAutoPan

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

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

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

      public final void addToggleText(String text)
      Add a text to explain animatable classes.
      Parameters:
      text - String; the text to show
    • addAllToggleGISButtonText

      public final void addAllToggleGISButtonText(String header, nl.tudelft.simulation.dsol.animation.gis.GisRenderable2d gisMap, String toolTipText)
      Add buttons for toggling all GIS layers on or off.
      Parameters:
      header - String; the name of the group of layers
      gisMap - GisRenderable2d; the GIS map for which the toggles have to be added
      toolTipText - String; the tool tip text to show when hovering over the button
    • addToggleGISButtonText

      public final void addToggleGISButtonText(String layerName, String displayName, nl.tudelft.simulation.dsol.animation.gis.GisRenderable2d gisMap, String toolTipText)
      Add a button to toggle a GIS Layer on or off.
      Parameters:
      layerName - String; the name of the layer
      displayName - String; the name to display next to the tick box
      gisMap - GisRenderable2d; the map
      toolTipText - String; the tool tip text
    • showGISLayer

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

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

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

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

      public final nl.tudelft.simulation.dsol.swing.animation.d2.AnimationPanel getAnimationPanel()
      Easy access to the AnimationPanel.
      Returns:
      AnimationPanel
    • createDemoPanel

      public void createDemoPanel(OtsAnimationPanel.DemoPanelPosition position)
      Creates a demo panel within the animation area.
      Parameters:
      position - String; any string from BorderLayout indicating the position of the demo panel, except CENTER.
      Throws:
      IllegalStateException - if the panel was already created
    • getDemoPanel

      public JPanel getDemoPanel()
      Return a panel for on-screen demo controls. The panel is create on first call.
      Returns:
      JPanel; panel
    • updateAnimationClassCheckBox

      public final void updateAnimationClassCheckBox(Class<? extends nl.tudelft.simulation.dsol.animation.Locatable> locatableClass)
      Update the checkmark related to a programmatically changed animation state.
      Parameters:
      locatableClass - Class<? extends Locatable>; class to show the checkmark for
    • updateWorldCoordinate

      protected final void updateWorldCoordinate()
      Display the latest world coordinate based on the mouse position on the screen.
    • getGtuColorer

      public final GtuColorer getGtuColorer()
      Access the GtuColorer of this animation ControlPanel.
      Returns:
      GtuColorer the colorer used. If it is a SwitchableGtuColorer, the wrapper with the list will be returned, not the actual colorer in use.
    • getColorControlPanel

      public final ColorControlPanel getColorControlPanel()
      Access the ColorControlPanel of this ControlPanel. If the simulator is not a SimpleAnimator, no ColorControlPanel was constructed and this method will return null.
      Returns:
      ColorControlPanel
    • installWindowCloseHandler

      public final void installWindowCloseHandler()
      Install a handler for the window closed event that stops the simulator (if it is running).
    • windowOpened

      public void windowOpened(WindowEvent e)
      Specified by:
      windowOpened in interface WindowListener
    • windowClosing

      public final void windowClosing(WindowEvent e)
      Specified by:
      windowClosing in interface WindowListener
    • windowClosed

      public final void windowClosed(WindowEvent e)
      Specified by:
      windowClosed in interface WindowListener
    • windowIconified

      public final void windowIconified(WindowEvent e)
      Specified by:
      windowIconified in interface WindowListener
    • windowDeiconified

      public final void windowDeiconified(WindowEvent e)
      Specified by:
      windowDeiconified in interface WindowListener
    • windowActivated

      public final void windowActivated(WindowEvent e)
      Specified by:
      windowActivated in interface WindowListener
    • windowDeactivated

      public final void windowDeactivated(WindowEvent e)
      Specified by:
      windowDeactivated in interface WindowListener
    • notify

      public void notify(org.djutils.event.Event event) throws RemoteException
      Specified by:
      notify in interface org.djutils.event.EventListener
      Throws:
      RemoteException