1 package org.opentrafficsim.swing.gui;
2
3 import java.util.Map;
4
5 import org.opentrafficsim.animation.DefaultAnimationFactory;
6 import org.opentrafficsim.core.dsol.OtsModelInterface;
7 import org.opentrafficsim.core.gtu.GtuType;
8 import org.opentrafficsim.draw.gtu.DefaultCarAnimation.GtuData.GtuMarker;
9
10 /**
11 * Extension of a swing application with standard preparation.
12 * <p>
13 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
15 * </p>
16 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
17 * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
18 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
19 * @param <T> model type
20 */
21 public class OtsSimulationApplication<T extends OtsModelInterface> extends OtsSwingApplication<T>
22 {
23
24 /** */
25 private static final long serialVersionUID = 20190118L;
26
27 /** Animation panel. */
28 private final OtsAnimationPanel animationPanel;
29
30 /** GTU type markers. */
31 private final Map<GtuType, GtuMarker> markers;
32
33 /**
34 * Constructor.
35 * @param model model
36 * @param panel animation panel
37 * @param markers GTU type markers
38 */
39 public OtsSimulationApplication(final T model, final OtsAnimationPanel panel, final Map<GtuType, GtuMarker> markers)
40 {
41 super(model, panel);
42 this.animationPanel = panel;
43 this.markers = markers;
44 setAnimationToggles();
45 animateNetwork();
46 addTabs();
47 setAppearance(getAppearance()); // update appearance of added objects
48 }
49
50 /**
51 * Creates the animation objects. This method is overridable. The default uses {@code DefaultAnimationFactory}.
52 */
53 private void animateNetwork()
54 {
55 DefaultAnimationFactory.animateNetwork(getModel().getNetwork(), getModel().getNetwork().getSimulator(),
56 this.animationPanel.getColorControlPanel().getGtuColorerManager(), this.markers);
57 }
58
59 /**
60 * Returns the GTU type markers.
61 * @return GTU type markers
62 */
63 protected Map<GtuType, GtuMarker> getMarkers()
64 {
65 return this.markers;
66 }
67
68 /**
69 * Set animation toggles. This method is overridable. The default sets standard text toggles.
70 */
71 protected void setAnimationToggles()
72 {
73 AnimationToggles.setTextAnimationTogglesStandard(getAnimationPanel());
74 }
75
76 /**
77 * Adds tabs. This method is overridable. The default does nothing.
78 */
79 protected void addTabs()
80 {
81 //
82 }
83
84 /**
85 * Returns the animation panel.
86 * @return animation panel
87 */
88 public OtsAnimationPanel getAnimationPanel()
89 {
90 return this.animationPanel;
91 }
92
93 }