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