View Javadoc
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-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
12   * <p>
13   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 18 jan. 2019 <br>
14   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
16   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
17   * @param <T> model type
18   */
19  public class OTSSimulationApplication<T extends OTSModelInterface> extends OTSSwingApplication<T>
20  {
21  
22      /** */
23      private static final long serialVersionUID = 20190118L;
24  
25      /** Animation panel. */
26      private final OTSAnimationPanel animationPanel;
27  
28      /**
29       * @param model T; model
30       * @param panel OTSAnimationPanel; animation panel
31       * @throws OTSDrawingException on animation error
32       */
33      public OTSSimulationApplication(final T model, final OTSAnimationPanel panel) throws OTSDrawingException
34      {
35          super(model, panel);
36          this.animationPanel = panel;
37          animateNetwork();
38          setAnimationToggles();
39          addTabs();
40          setAppearance(getAppearance()); // update appearance of added objects
41      }
42  
43      /**
44       * Creates the animation objects. This method is overridable. The default uses {@code DefaultAnimationFactory}.
45       * @throws OTSDrawingException on animation error
46       */
47      protected void animateNetwork() throws OTSDrawingException
48      {
49          DefaultAnimationFactory.animateNetwork(getModel().getNetwork(), getModel().getSimulator(),
50                  getAnimationPanel().getGTUColorer());
51      }
52  
53      /**
54       * Set animation toggles. This method is overridable. The default sets standard text toggles.
55       */
56      protected void setAnimationToggles()
57      {
58          AnimationToggles.setTextAnimationTogglesStandard(getAnimationPanel());
59      }
60  
61      /**
62       * Adds tabs. This method is overridable. The default does nothing.
63       */
64      protected void addTabs()
65      {
66          //
67      }
68  
69      /**
70       * Returns the animation panel.
71       * @return OTSAnimationPanel; animation panel
72       */
73      public OTSAnimationPanel getAnimationPanel()
74      {
75          return this.animationPanel;
76      }
77  
78  }