Package org.opentrafficsim.swing.gui
Class OtsSimulationPanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.opentrafficsim.swing.gui.OtsSimulationPanel
- All Implemented Interfaces:
ActionListener,ImageObserver,MenuContainer,Serializable,EventListener,Accessible,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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnum for demo panel position.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT -
Constructor Summary
ConstructorsConstructorDescriptionOtsSimulationPanel(Rectangle2D extent, Network network) Construct a panel that looks like the DSOLPanel for quick building of OTS applications.OtsSimulationPanel(Rectangle2D extent, Network network, OtsSimulationPanelDecorator decorator) Construct a panel that looks like the DSOLPanel for quick building of OTS applications.OtsSimulationPanel(Network network) Construct a panel that looks like the DSOLPanel for quick building of OTS applications.OtsSimulationPanel(Network network, OtsSimulationPanelDecorator decorator) Construct a panel that looks like the DSOLPanel for quick building of OTS applications. -
Method Summary
Modifier and TypeMethodDescriptionvoidactionPerformed(ActionEvent actionEvent) voidaddAllToggleGisButtonText(String header, GisRenderable2d gisMap, String toolTipText) Add buttons for toggling all GIS layers on or off.voidAdds the console tab.voidaddToggleAnimationButtonIcon(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.voidaddToggleAnimationButtonText(String name, Class<? extends Locatable> locatableClass, String toolTipText, boolean initiallyVisible) Add a button for toggling an animation class on or off.voidaddToggleGisButtonText(String layerName, String displayName, GisRenderable2d gisMap, String toolTipText, boolean initiallyVisible) Add a button to toggle a GIS Layer on or off.voidaddToggleText(String text) Add a text to explain animation classes.voidCreates a demo panel within the animation area.voidDisable the simulation or animation buttons in the GUI.voidEnable the simulation or animation buttons in the GUI.Easy access to the AnimationPanel.Return a panel for on-screen demo controls.GTU colorer manager from the GTU color panel.Return simulator.Return tabbed pane.voidhideGisLayer(String layerName) Set a GIS layer to be hidden in the animation to true.voidstatic StringseparatedName(String name) Adds a thin space before each capital character in aString, except the first.voidsetAutoPan(String newAutoPanId, org.opentrafficsim.swing.gui.OtsSearchPanel.ObjectKind<?> newAutoPanKind, boolean newAutoPanTrack) Change auto pan target.voidshowGisLayer(String layerName) Set a GIS layer to be shown in the animation to true.voidstartToggleSection(String name, boolean visibleDefault) Adds a button that can hide all toggles in a section.voidtoggleGisLayer(String layerName) Toggle a GIS layer to be displayed in the animation to its reverse value.voidupdateAnimationClassCheckBox(Class<? extends Locatable> locatableClass) Update the check-mark related to a programmatically changed animation state.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
PROPERTIES
Properties.
-
-
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 failsnl.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 animatenetwork- network- Throws:
RemoteException- when notification of the animation panel failsnl.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- networkdecorator- decorator for the animation panel- Throws:
RemoteException- when notification of the animation panel failsnl.tudelft.simulation.language.DsolException- when simulator does not implement AnimatorInterfaceNullPointerException- when any input isnull
-
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 animatenetwork- networkdecorator- decorator for the animation panel- Throws:
RemoteException- when notification of the animation panel failsnl.tudelft.simulation.language.DsolException- when simulator does not implement AnimatorInterfaceNullPointerException- when any input isnull
-
-
Method Details
-
addConsoleTab
public void addConsoleTab()Adds the console tab. -
getTabbedPane
Return tabbed pane.- Returns:
- tabbed pane
-
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 tracknewAutoPanKind- kind of object to tracknewAutoPanTrack- if true; tracking is continuously; if false; tracking is once
-
startToggleSection
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 hiddenvisibleDefault- 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 buttonlocatableClass- the class for which the button holds (e.g., GTU.class)iconPath- the path to the 24x24 icon to displaytoolTipText- the tool tip text to show when hovering over the buttoninitiallyVisible- whether the class is initially shown or notnextToPrevious- 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 buttonlocatableClass- the class for which the button holds (e.g.,GTU.class)toolTipText- the tool tip text to show when hovering over the buttoninitiallyVisible- whether the class is initially shown or not
-
addToggleText
Add a text to explain animation classes.- Parameters:
text- the text to show
-
addAllToggleGisButtonText
Add buttons for toggling all GIS layers on or off.- Parameters:
header- the name of the group of layersgisMap- the GIS map for which the toggles have to be addedtoolTipText- 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 layerdisplayName- the name to display next to the tick boxgisMap- the maptoolTipText- the tool tip textinitiallyVisible- whether the layer is initially shown or not
-
showGisLayer
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
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
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
- Specified by:
actionPerformedin interfaceActionListener
-
getAnimationPanel
Easy access to the AnimationPanel.- Returns:
- animation panel
-
createDemoPanel
Creates a demo panel within the animation area.- Parameters:
position- position within the animation panel- Throws:
IllegalStateException- if the panel was already created
-
getDemoPanel
Return a panel for on-screen demo controls. The panel is created on the right of the screen on first call, unlesscreateDemoPanel(org.opentrafficsim.swing.gui.OtsSimulationPanel.DemoPanelPosition)was already called.- Returns:
- demo panel
-
updateAnimationClassCheckBox
Update the check-mark related to a programmatically changed animation state.- Parameters:
locatableClass- class to show the check-mark for
-
getGtuColorerManager
GTU colorer manager from the GTU color panel.- Returns:
- GTU colorer manager from the GTU color panel
-
notify
- Specified by:
notifyin interfaceEventListener
-
separatedName
Adds a thin space before each capital character in aString, except the first.- Parameters:
name- name of node- Returns:
- input string but with a thin space before each capital character, except the first
-