OTSSimulationPanel.java

  1. package org.opentrafficsim.gui;

  2. import java.awt.BorderLayout;
  3. import java.rmi.RemoteException;
  4. import java.util.List;

  5. import javax.swing.JLabel;
  6. import javax.swing.JPanel;
  7. import javax.swing.JScrollPane;
  8. import javax.swing.SwingConstants;

  9. import nl.tudelft.simulation.dsol.gui.swing.Console;
  10. import nl.tudelft.simulation.dsol.gui.swing.StatusBar;
  11. import nl.tudelft.simulation.dsol.gui.swing.TabbedContentPane;

  12. import org.opentrafficsim.base.modelproperties.CompoundProperty;
  13. import org.opentrafficsim.base.modelproperties.Property;
  14. import org.opentrafficsim.base.modelproperties.PropertyException;
  15. import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
  16. import org.opentrafficsim.simulationengine.WrappableAnimation;

  17. /**
  18.  * GUI with simulator, console, control panel, status bar, etc.
  19.  * <p>
  20.  * Copyright (c) 2013-2016 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: 2016-10-28 16:34:11 +0200 (Fri, 28 Oct 2016) $, @version $Revision: 2429 $, by $Author: pknoppers $,
  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 OTSSimulationPanel extends JPanel
  29. {
  30.     /** */
  31.     private static final long serialVersionUID = 20150617L;

  32.     /** The simulator. */
  33.     private final OTSDEVSSimulatorInterface simulator;

  34.     /** The console to log messages. */
  35.     private final Console console = new Console();

  36.     /** The control panel to control start/stop, speed of the simulation. */
  37.     private final OTSControlPanel otsControlPanel;

  38.     /** The tabbed pane that contains the different (default) screens. */
  39.     private final TabbedContentPane tabbedPane = new TabbedContentPane(SwingConstants.BOTTOM);

  40.     /** The status bar at the bottom to indicate wall clock time and simulation time. */
  41.     private final StatusBar statusBar;

  42.     /**
  43.      * Construct a panel that looks like the DSOLPanel for quick building of OTS applications.
  44.      * @param simulator the simulator or animator of the model.
  45.      * @param wrappableAnimation the builder and rebuilder of the simulation, based on properties.
  46.      * @throws RemoteException when communications to a remote machine fails
  47.      * @throws PropertyException when one of the user modified properties has the empty string as key
  48.      */
  49.     public OTSSimulationPanel(final OTSDEVSSimulatorInterface simulator, final WrappableAnimation wrappableAnimation)
  50.             throws RemoteException, PropertyException
  51.     {
  52.         this.simulator = simulator;

  53.         this.setLayout(new BorderLayout());

  54.         // Let's add our simulationControl
  55.         this.otsControlPanel = new OTSControlPanel(simulator, wrappableAnimation);
  56.         this.add(this.otsControlPanel, BorderLayout.NORTH);

  57.         // Let's add our console to our tabbed pane
  58.         this.tabbedPane.addTab("console", new JScrollPane(this.console));

  59.         // Let's add the properties of the simulation model as a tab
  60.         List<Property<?>> propertyList =
  61.                 new CompoundProperty("", "", "", wrappableAnimation.getUserModifiedProperties(), true, 0).displayOrderedValue();
  62.         StringBuilder html = new StringBuilder();
  63.         html.append("<html><table border=\"1\"><tr><th colspan=\"" + propertyList.size() + "\">Settings</th></tr><tr>");

  64.         for (Property<?> ap : propertyList)
  65.         {
  66.             html.append("<td valign=\"top\">" + ap.htmlStateDescription() + "</td>");
  67.         }
  68.         html.append("</table></html>");
  69.         JLabel propertySettings = new JLabel(html.toString());
  70.         this.tabbedPane.addTab("settings", new JScrollPane(propertySettings));

  71.         // Let's display our tabbed contentPane
  72.         this.add(this.tabbedPane, BorderLayout.CENTER);

  73.         // put a status bar at the bottom
  74.         this.statusBar = new StatusBar(this.simulator);
  75.         this.add(this.statusBar, BorderLayout.SOUTH);
  76.     }

  77.     /**
  78.      * @return tabbedPane
  79.      */
  80.     public final TabbedContentPane getTabbedPane()
  81.     {
  82.         return this.tabbedPane;
  83.     }

  84.     /**
  85.      * @return simulator.
  86.      */
  87.     public final OTSDEVSSimulatorInterface getSimulator()
  88.     {
  89.         return this.simulator;
  90.     }

  91.     /**
  92.      * @return statusBar.
  93.      */
  94.     public final StatusBar getStatusBar()
  95.     {
  96.         return this.statusBar;
  97.     }

  98.     /**
  99.      * Return the OTSControlPanel of this OTSSimulationPanel.
  100.      * @return OTSControlPanel; the OTS control panel
  101.      */
  102.     public final OTSControlPanel getOtsControlPanel()
  103.     {
  104.         return this.otsControlPanel;
  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     public final String toString()
  109.     {
  110.         return "OTSSimulationPanel [simulatorTime=" + this.simulator.getSimulatorTime().getTime() + "]";
  111.     }

  112. }