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 * @param model model
35 * @param panel animation panel
36 * @param markers GTU type markers
37 */
38 public OtsSimulationApplication(final T model, final OtsAnimationPanel panel, final Map<GtuType, GtuMarker> markers)
39 {
40 super(model, panel);
41 this.animationPanel = panel;
42 this.markers = markers;
43 setAnimationToggles();
44 animateNetwork();
45 addTabs();
46 setAppearance(getAppearance()); // update appearance of added objects
47 }
48
49 /**
50 * Creates the animation objects. This method is overridable. The default uses {@code DefaultAnimationFactory}.
51 */
52 private void animateNetwork()
53 {
54 DefaultAnimationFactory.animateNetwork(getModel().getNetwork(), getModel().getNetwork().getSimulator(),
55 this.animationPanel.getColorControlPanel().getGtuColorerManager(), this.markers);
56 }
57
58 /**
59 * Returns the GTU type markers.
60 * @return GTU type markers
61 */
62 protected Map<GtuType, GtuMarker> getMarkers()
63 {
64 return this.markers;
65 }
66
67 /**
68 * Set animation toggles. This method is overridable. The default sets standard text toggles.
69 */
70 protected void setAnimationToggles()
71 {
72 AnimationToggles.setTextAnimationTogglesStandard(getAnimationPanel());
73 }
74
75 /**
76 * Adds tabs. This method is overridable. The default does nothing.
77 */
78 protected void addTabs()
79 {
80 //
81 }
82
83 /**
84 * Returns the animation panel.
85 * @return animation panel
86 */
87 public OtsAnimationPanel getAnimationPanel()
88 {
89 return this.animationPanel;
90 }
91
92 }