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