Class HtmlAnimationPanel

java.lang.Object
nl.tudelft.simulation.dsol.web.animation.d2.HtmlGridPanel
nl.tudelft.simulation.dsol.web.animation.d2.HtmlAnimationPanel
All Implemented Interfaces:
ImageObserver, Serializable, Remote, EventListener, org.djutils.event.EventListener

public class HtmlAnimationPanel extends HtmlGridPanel implements org.djutils.event.EventListener
The AnimationPanel to display animated (Locatable) objects. Added the possibility to witch layers on and off. By default all layers will be drawn, so no changes to existing software need to be made.

Copyright (c) 2003-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck
See Also:
  • Field Details

    • EXTENT_MARGIN_FACTOR

      public static final double EXTENT_MARGIN_FACTOR
      the margin factor 'around' the extent.
      See Also:
  • Constructor Details

    • HtmlAnimationPanel

      public HtmlAnimationPanel(org.djutils.draw.bounds.Bounds2d homeExtent, org.opentrafficsim.core.dsol.OtsSimulatorInterface simulator) throws RemoteException
      constructs a new AnimationPanel.
      Parameters:
      homeExtent - Bounds2d; the extent of the panel
      simulator - SimulatorInterface<?,?,?>; the simulator of which we want to know the events for animation
      Throws:
      RemoteException - on network error for one of the listeners
  • Method Details

    • paintComponent

      public void paintComponent(HtmlGraphics2d g2)
      Draw the grid.
      Overrides:
      paintComponent in class HtmlGridPanel
      Parameters:
      g2 - HTMLGraphics2D; the virtual Graphics2D canvas to enable writing to the browser
    • isShowElement

      public boolean isShowElement(nl.tudelft.simulation.dsol.animation.d2.Renderable2dInterface<? extends nl.tudelft.simulation.dsol.animation.Locatable> element)
      Test whether the element needs to be shown on the screen or not.
      Parameters:
      element - Renderable2dInterface<? extends Locatable>; the renderable element to test
      Returns:
      whether the element needs to be shown or not
    • isShowClass

      public boolean isShowClass(Class<? extends nl.tudelft.simulation.dsol.animation.Locatable> locatableClass)
      Test whether a certain class needs to be shown on the screen or not. The class needs to implement Locatable, otherwise it cannot be shown at all.
      Parameters:
      locatableClass - Class<? extends Locatable>; the class to test
      Returns:
      whether the class needs to be shown or not
    • notify

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

      public void objectAdded(nl.tudelft.simulation.dsol.animation.d2.Renderable2dInterface<? extends nl.tudelft.simulation.dsol.animation.Locatable> element)
      Add a locatable object to the animation.
      Parameters:
      element - Renderable2dInterface<? extends Locatable>; the element to add to the animation
    • objectRemoved

      public void objectRemoved(nl.tudelft.simulation.dsol.animation.d2.Renderable2dInterface<? extends nl.tudelft.simulation.dsol.animation.Locatable> element)
      Remove a locatable object from the animation.
      Parameters:
      element - Renderable2dInterface<? extends Locatable>; the element to add to the animation
    • fullExtent

      public org.djutils.draw.bounds.Bounds2d fullExtent()
      Calculate the full extent based on the current positions of the objects.
      Returns:
      Bounds2d; the full extent of the animation.
    • zoomAll

      public void zoomAll()
      resets the panel to its an extent that covers all displayed objects.
    • showClass

      public void showClass(Class<? extends nl.tudelft.simulation.dsol.animation.Locatable> locatableClass)
      Set a class to be shown in the animation to true.
      Parameters:
      locatableClass - Class<? extends Locatable>; the class for which the animation has to be shown.
    • hideClass

      public void hideClass(Class<? extends nl.tudelft.simulation.dsol.animation.Locatable> locatableClass)
      Set a class to be hidden in the animation to true.
      Parameters:
      locatableClass - Class<? extends Locatable>; the class for which the animation has to be hidden.
    • toggleClass

      public void toggleClass(Class<? extends nl.tudelft.simulation.dsol.animation.Locatable> locatableClass)
      Toggle a class to be displayed in the animation to its reverse value.
      Parameters:
      locatableClass - Class<? extends Locatable>; the class for which a visible animation has to be turned off or vice versa.
    • getElements

      public final SortedSet<nl.tudelft.simulation.dsol.animation.d2.Renderable2dInterface<? extends nl.tudelft.simulation.dsol.animation.Locatable>> getElements()
      Returns:
      the set of animation elements.
    • getDragLine

      public final int[] getDragLine()
      Returns:
      returns the dragLine.
    • isDragLineEnabled

      public final boolean isDragLineEnabled()
      Returns:
      returns the dragLineEnabled.
    • setDragLineEnabled

      public final void setDragLineEnabled(boolean dragLineEnabled)
      Parameters:
      dragLineEnabled - boolean; the dragLineEnabled to set.
    • 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
    • showClass

      public final void showClass(String name)
      Show a Locatable class based on the name.
      Parameters:
      name - String; the name of the class to show
    • hideClass

      public final void hideClass(String name)
      Hide a Locatable class based on the name.
      Parameters:
      name - String; the name of the class to hide
    • 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.
    • getToggleButtons

      public final List<ToggleButtonInfo> getToggleButtons()
      Returns:
      toggleButtons