View Javadoc
1   package org.opentrafficsim.swing.gui;
2   
3   import java.awt.BorderLayout;
4   import java.awt.Insets;
5   import java.rmi.RemoteException;
6   
7   import javax.swing.JPanel;
8   import javax.swing.JScrollPane;
9   import javax.swing.SwingConstants;
10  import javax.swing.UIManager;
11  
12  import org.opentrafficsim.core.dsol.OTSModelInterface;
13  
14  import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterException;
15  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
16  import nl.tudelft.simulation.dsol.swing.gui.Console;
17  import nl.tudelft.simulation.dsol.swing.gui.StatusBar;
18  import nl.tudelft.simulation.dsol.swing.gui.TabbedContentPane;
19  
20  /**
21   * GUI with simulator, console, control panel, status bar, etc.
22   * <p>
23   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
25   * <p>
26   * $LastChangedDate: 2018-10-11 22:54:04 +0200 (Thu, 11 Oct 2018) $, @version $Revision: 4696 $, by $Author: averbraeck $,
27   * initial version Jun 18, 2015 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
30   */
31  public class OTSSimulationPanel extends JPanel
32  {
33      /** */
34      private static final long serialVersionUID = 20150617L;
35  
36      /** The simulator. */
37      private final DEVSSimulatorInterface.TimeDoubleUnit simulator;
38  
39      /** The console to log messages. */
40      private final Console console = new Console();
41  
42      /** The control panel to control start/stop, speed of the simulation. */
43      private final OTSControlPanel otsControlPanel;
44  
45      /** Animation, required to add properties tab. */
46      private final OTSModelInterface otsModel;
47  
48      static
49      {
50          // use narrow border for TabbedPane, which cannot be changed afterwards
51          UIManager.put("TabbedPane.contentBorderInsets", new Insets(1, 1, 1, 1));
52      }
53  
54      /** The tabbed pane that contains the different (default) screens. */
55      private final TabbedContentPane tabbedPane = new AppearanceControlTabbedContentPane(SwingConstants.BOTTOM);
56  
57      /** The status bar at the bottom to indicate wall clock time and simulation time. */
58      private final StatusBar statusBar = null;
59  
60      /**
61       * Construct a panel that looks like the DSOLPanel for quick building of OTS applications.
62       * @param simulator DEVSSimulatorInterface.TimeDoubleUnit; the simulator or animator of the model.
63       * @param otsModel OTSModelInterface; the model with its properties.
64       * @throws RemoteException when communications to a remote machine fails
65       */
66      public OTSSimulationPanel(final DEVSSimulatorInterface.TimeDoubleUnit simulator, final OTSModelInterface otsModel)
67              throws RemoteException
68      {
69          this.simulator = simulator;
70          this.otsModel = otsModel;
71  
72          this.setLayout(new BorderLayout());
73  
74          // Let's add our simulationControl
75          this.otsControlPanel = new OTSControlPanel(simulator, otsModel, (OTSAnimationPanel) this);
76          this.add(this.otsControlPanel, BorderLayout.NORTH);
77  
78          // Let's display our tabbed contentPane
79          this.add(this.tabbedPane, BorderLayout.CENTER);
80  
81          // put a status bar at the bottom
82          // this.statusBar = new StatusBar(this.simulator);
83          // this.add(this.statusBar, BorderLayout.SOUTH);
84      }
85  
86      /**
87       * Adds the console tab.
88       */
89      public final void addConsoleTab()
90      {
91          // Let's add our console to our tabbed pane
92          JScrollPane cons = new JScrollPane(this.console);
93          cons.setBorder(null);
94          this.tabbedPane.addTab("console", cons);
95      }
96  
97      /**
98       * Adds the properties tab.
99       * @throws InputParameterException on exception with properties
100      */
101     public final void addPropertiesTab() throws InputParameterException
102     {
103         // TODO: make a tab with the InputParameters
104     }
105 
106     /**
107      * @return tabbedPane
108      */
109     public final TabbedContentPane getTabbedPane()
110     {
111         return this.tabbedPane;
112     }
113 
114     /**
115      * @return simulator.
116      */
117     public final DEVSSimulatorInterface.TimeDoubleUnit getSimulator()
118     {
119         return this.simulator;
120     }
121 
122     /**
123      * @return statusBar.
124      */
125     public final StatusBar getStatusBar()
126     {
127         return this.statusBar;
128     }
129 
130     /**
131      * Return the OTSControlPanel of this OTSSimulationPanel.
132      * @return OTSControlPanel; the OTS control panel
133      */
134     public final OTSControlPanel getOtsControlPanel()
135     {
136         return this.otsControlPanel;
137     }
138 
139     /**
140      * @return console
141      */
142     public final Console getConsole()
143     {
144         return this.console;
145     }
146 
147     /**
148      * @return otsModel
149      */
150     public final OTSModelInterface getOtsModel()
151     {
152         return this.otsModel;
153     }
154 
155     /**
156      * Enable the simulation or animation buttons in the GUI. This method HAS TO BE CALLED in order for the buttons to be
157      * enabled, because the initial state is DISABLED. Typically, this is done after all tabs, statistics, and other user
158      * interface and model components have been constructed and initialized.
159      */
160     public void enableSimulationControlButtons()
161     {
162         getOtsControlPanel().setSimulationControlButtons(true);
163     }
164 
165     /**
166      * Disable the simulation or animation buttons in the GUI.
167      */
168     public void disableSimulationControlButtons()
169     {
170         getOtsControlPanel().setSimulationControlButtons(false);
171     }
172 
173     /** {@inheritDoc} */
174     @Override
175     public final String toString()
176     {
177         return "OTSSimulationPanel [simulatorTime=" + this.simulator.getSimulatorTime() + "]";
178     }
179 
180     /**
181      * TabbedContentPane which ignores appearance (it has too much colors looking ugly / becoming unreadable).
182      * <p>
183      * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
184      * <br>
185      * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
186      * <p>
187      * @version $Revision: 4696 $, $LastChangedDate: 2018-10-11 22:54:04 +0200 (Thu, 11 Oct 2018) $, by $Author: averbraeck $,
188      *          initial version 6 feb. 2018 <br>
189      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
190      * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
191      * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
192      */
193     static class AppearanceControlTabbedContentPane extends TabbedContentPane implements AppearanceControl
194     {
195         /** */
196         private static final long serialVersionUID = 20180206L;
197 
198         /**
199          * @param tabPlacement int; tabPlacement
200          */
201         AppearanceControlTabbedContentPane(final int tabPlacement)
202         {
203             super(tabPlacement);
204         }
205 
206         /** {@inheritDoc} */
207         @Override
208         public String toString()
209         {
210             return "AppearanceControlTabbedContentPane []";
211         }
212 
213     }
214 
215 }