View Javadoc
1   package org.opentrafficsim.gui;
2   
3   import java.awt.BorderLayout;
4   import java.rmi.RemoteException;
5   import java.util.ArrayList;
6   
7   import javax.swing.JLabel;
8   import javax.swing.JPanel;
9   import javax.swing.JScrollPane;
10  import javax.swing.SwingConstants;
11  
12  import nl.tudelft.simulation.dsol.gui.swing.Console;
13  import nl.tudelft.simulation.dsol.gui.swing.StatusBar;
14  import nl.tudelft.simulation.dsol.gui.swing.TabbedContentPane;
15  
16  import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
17  import org.opentrafficsim.simulationengine.WrappableAnimation;
18  import org.opentrafficsim.simulationengine.properties.AbstractProperty;
19  import org.opentrafficsim.simulationengine.properties.CompoundProperty;
20  
21  /**
22   * GUI with simulator, console, control panel, status bar, etc.
23   * <p>
24   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
25   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
26   * <p>
27   * $LastChangedDate: 2016-04-05 21:30:47 +0200 (Tue, 05 Apr 2016) $, @version $Revision: 1889 $, by $Author: pknoppers $,
28   * initial version Jun 18, 2015 <br>
29   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
30   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
31   */
32  public class OTSSimulationPanel extends JPanel
33  {
34      /** */
35      private static final long serialVersionUID = 20150617L;
36  
37      /** The simulator. */
38      private final OTSDEVSSimulatorInterface simulator;
39  
40      /** The console to log messages. */
41      private final Console console = new Console();
42  
43      /** The control panel to control start/stop, speed of the simulation. */
44      private final OTSControlPanel otsControlPanel;
45  
46      /** The tabbed pane that contains the different (default) screens. */
47      private final TabbedContentPane tabbedPane = new TabbedContentPane(SwingConstants.BOTTOM);
48  
49      /** The status bar at the bottom to indicate wall clock time and simulation time. */
50      private final StatusBar statusBar;
51  
52      /**
53       * Construct a panel that looks like the DSOLPanel for quick building of OTS applications.
54       * @param simulator the simulator or animator of the model.
55       * @param wrappableAnimation the builder and rebuilder of the simulation, based on properties.
56       * @throws RemoteException when communications to a remote machine fails
57       */
58      public OTSSimulationPanel(final OTSDEVSSimulatorInterface simulator, final WrappableAnimation wrappableAnimation)
59          throws RemoteException
60      {
61          this.simulator = simulator;
62  
63          this.setLayout(new BorderLayout());
64  
65          // Let's add our simulationControl
66          this.otsControlPanel = new OTSControlPanel(simulator, wrappableAnimation);
67          this.add(this.otsControlPanel, BorderLayout.NORTH);
68  
69          // Let's add our console to our tabbed pane
70          this.tabbedPane.addTab("console", new JScrollPane(this.console));
71  
72          // Let's add the properties of the simulation model as a tab
73          ArrayList<AbstractProperty<?>> propertyList =
74              new CompoundProperty("", "", wrappableAnimation.getUserModifiedProperties(), true, 0).displayOrderedValue();
75          StringBuilder html = new StringBuilder();
76          html.append("<html><table border=\"1\"><tr><th colspan=\"" + propertyList.size() + "\">Settings</th></tr><tr>");
77  
78          for (AbstractProperty<?> ap : propertyList)
79          {
80              html.append("<td valign=\"top\">" + ap.htmlStateDescription() + "</td>");
81          }
82          html.append("</table></html>");
83          JLabel propertySettings = new JLabel(html.toString());
84          this.tabbedPane.addTab("settings", new JScrollPane(propertySettings));
85  
86          // Let's display our tabbed contentPane
87          this.add(this.tabbedPane, BorderLayout.CENTER);
88  
89          // put a status bar at the bottom
90          this.statusBar = new StatusBar(this.simulator);
91          this.add(this.statusBar, BorderLayout.SOUTH);
92      }
93  
94      /**
95       * @return tabbedPane
96       */
97      public final TabbedContentPane getTabbedPane()
98      {
99          return this.tabbedPane;
100     }
101 
102     /**
103      * @return simulator.
104      */
105     public final OTSDEVSSimulatorInterface getSimulator()
106     {
107         return this.simulator;
108     }
109 
110     /**
111      * @return statusBar.
112      */
113     public final StatusBar getStatusBar()
114     {
115         return this.statusBar;
116     }
117 
118 }