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