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
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 Summary
Modifier and TypeFieldDescriptionstatic final double
the margin factor 'around' the extent.Fields inherited from class nl.tudelft.simulation.dsol.web.animation.d2.HtmlGridPanel
DOWN, extent, formatter, GRIDCOLOR, gridSizeX, gridSizeY, homeExtent, htmlGraphics2D, lastDimension, LEFT, preferredSize, renderableScale, RIGHT, showGrid, showToolTip, size, UP, worldCoordinate, ZOOMFACTOR
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorDescriptionHtmlAnimationPanel
(org.djutils.draw.bounds.Bounds2d homeExtent, org.opentrafficsim.core.dsol.OtsSimulatorInterface simulator) constructs a new AnimationPanel. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addAllToggleGISButtonText
(String header, nl.tudelft.simulation.dsol.animation.gis.GisRenderable2d gisMap, String toolTipText) Add buttons for toggling all GIS layers on or off.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.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.final void
addToggleText
(String text) Add a text to explain animatable classes.org.djutils.draw.bounds.Bounds2d
Calculate the full extent based on the current positions of the objects.final int[]
final SortedSet<nl.tudelft.simulation.dsol.animation.d2.Renderable2dInterface<? extends nl.tudelft.simulation.dsol.animation.Locatable>>
final List<ToggleButtonInfo>
void
Set a class to be hidden in the animation to true.final void
Hide a Locatable class based on the name.final void
hideGISLayer
(String layerName) Set a GIS layer to be hidden in the animation to true.final boolean
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.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.void
notify
(org.djutils.event.Event event) void
objectAdded
(nl.tudelft.simulation.dsol.animation.d2.Renderable2dInterface<? extends nl.tudelft.simulation.dsol.animation.Locatable> element) Add a locatable object to the animation.void
objectRemoved
(nl.tudelft.simulation.dsol.animation.d2.Renderable2dInterface<? extends nl.tudelft.simulation.dsol.animation.Locatable> element) Remove a locatable object from the animation.void
Draw the grid.final void
setDragLineEnabled
(boolean dragLineEnabled) void
Set a class to be shown in the animation to true.final void
Show a Locatable class based on the name.final void
showGISLayer
(String layerName) Set a GIS layer to be shown in the animation to true.void
toggleClass
(Class<? extends nl.tudelft.simulation.dsol.animation.Locatable> locatableClass) Toggle a class to be displayed in the animation to its reverse value.final void
toggleGISLayer
(String layerName) Toggle a GIS layer to be displayed in the animation to its reverse value.void
zoomAll()
resets the panel to its an extent that covers all displayed objects.Methods inherited from class nl.tudelft.simulation.dsol.web.animation.d2.HtmlGridPanel
displayWorldCoordinateToolTip, drawGrid, getBackground, getDrawingCommands, getExtent, getFont, getFontMetrics, getHeight, getPreferredSize, getRenderableScale, getSize, getToolTipText, getWidth, getWorldCoordinate, home, imageUpdate, isDirty, isShowGrid, isShowing, isShowToolTip, pan, repaint, setBackground, setExtent, setFont, setPreferredSize, setRenderableScale, setShowGrid, setShowing, setShowToolTip, setSize, setToolTipText, setWorldCoordinate, showGrid, zoom, zoom
-
Field Details
-
EXTENT_MARGIN_FACTOR
public static final double EXTENT_MARGIN_FACTORthe 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 panelsimulator
- 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
Draw the grid.- Overrides:
paintComponent
in classHtmlGridPanel
- 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
- Specified by:
notify
in interfaceorg.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 buttonlocatableClass
- 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 buttoninitiallyVisible
- boolean; whether the class is initially shown or not
-
showClass
Show a Locatable class based on the name.- Parameters:
name
- String; the name of the class to show
-
hideClass
Hide a Locatable class based on the name.- Parameters:
name
- String; the name of the class to hide
-
addToggleText
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 layersgisMap
- GisRenderable2d; the GIS map for which the toggles have to be addedtoolTipText
- 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 layerdisplayName
- String; the name to display next to the tick boxgisMap
- GisRenderable2d; the maptoolTipText
- String; the tool tip text
-
showGISLayer
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
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
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
- Returns:
- toggleButtons
-