View Javadoc
1   package org.opentrafficsim.gui;
2   
3   import java.awt.BorderLayout;
4   import java.awt.Dimension;
5   import java.awt.geom.Rectangle2D;
6   import java.rmi.RemoteException;
7   
8   import javax.swing.JPanel;
9   
10  import nl.tudelft.simulation.dsol.animation.D2.AnimationPanel;
11  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
12  import nl.tudelft.simulation.event.Event;
13  
14  import org.opentrafficsim.core.gtu.animation.GTUColorer;
15  import org.opentrafficsim.simulationengine.SimpleAnimator;
16  import org.opentrafficsim.simulationengine.WrappableSimulation;
17  
18  /**
19   * <p>
20   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
22   * <p>
23   * $LastChangedDate: 2015-07-26 01:01:13 +0200 (Sun, 26 Jul 2015) $, @version $Revision: 1155 $, by $Author: averbraeck $,
24   * initial version Jun 18, 2015 <br>
25   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
26   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
27   */
28  public class OTSAnimationPanel extends OTSSimulationPanel
29  {
30      /** */
31      private static final long serialVersionUID = 20150617L;
32  
33      /** the animation panel on tab position 0. */
34      private final AnimationPanel animationPanel;
35  
36      /** Border panel in which the animation is shown. */
37      private final JPanel borderPanel;
38  
39      /** The switchableGTUColorer used to color the GTUs. */
40      private GTUColorer gtuColorer = null;
41  
42      /** The ColorControlPanel that allows the user to operate the SwitchableGTUColorer. */
43      private ColorControlPanel colorControlPanel = null;
44  
45      /**
46       * Construct a panel that looks like the DSOLPanel for quick building of OTS applications.
47       * @param extent Rectangle2D; bottom left corner, length and width of the area (world) to animate.
48       * @param size the size to be used for the animation.
49       * @param simulator the simulator or animator of the model.
50       * @param wrappableSimulation the builder and rebuilder of the simulation, based on properties.
51       * @param gtuColorer the colorer to use for the GTUs.
52       * @throws RemoteException when notification to the animation panel fails.
53       */
54      public OTSAnimationPanel(final Rectangle2D extent, final Dimension size, final SimpleAnimator simulator,
55          final WrappableSimulation wrappableSimulation, final GTUColorer gtuColorer) throws RemoteException
56      {
57          super(simulator, wrappableSimulation);
58  
59          // Add the animation panel as a tab.
60          this.animationPanel = new AnimationPanel(extent, size, simulator);
61          this.borderPanel = new JPanel(new BorderLayout());
62          this.borderPanel.add(this.animationPanel, BorderLayout.CENTER);
63          getTabbedPane().addTab(0, "animation", this.borderPanel);
64          getTabbedPane().setSelectedIndex(0); // Show the animation panel as the default tab
65  
66          // Include the GTU colorer control panel NORTH of the animation.
67          this.gtuColorer = gtuColorer;
68          this.colorControlPanel = new ColorControlPanel(this.gtuColorer);
69          this.borderPanel.add(this.colorControlPanel, BorderLayout.NORTH);
70  
71          // Tell the animation to build the list of animation objects.
72          this.animationPanel.notify(new Event(SimulatorInterface.START_REPLICATION_EVENT, simulator, null));
73      }
74  
75      /**
76       * Easy access to the AnimationPanel.
77       * @return AnimationPanel
78       */
79      public final AnimationPanel getAnimationPanel()
80      {
81          return this.animationPanel;
82      }
83  
84      /**
85       * Access the GTUColorer of this animation ControlPanel.
86       * @return GTUColorer the colorer used. If it is a SwitchableGTUColorer, the wrapper with the list will be returned, not the
87       *         actual colorer in use.
88       */
89      public final GTUColorer getGTUColorer()
90      {
91          return this.gtuColorer;
92      }
93  
94      /**
95       * Access the ColorControlPanel of this ControlPanel. If the simulator is not a SimpleAnimator, no ColorControlPanel was
96       * constructed and this method will return null.
97       * @return ColorControlPanel
98       */
99      public final ColorControlPanel getColorControlPanel()
100     {
101         return this.colorControlPanel;
102     }
103 
104 }