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-2019 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  
70          this.simulator = simulator;
71          this.otsModel = otsModel;
72  
73          this.setLayout(new BorderLayout());
74  
75          // Let's add our simulationControl
76          this.otsControlPanel = new OTSControlPanel(simulator, otsModel);
77          this.add(this.otsControlPanel, BorderLayout.NORTH);
78  
79          // Let's display our tabbed contentPane
80          this.add(this.tabbedPane, BorderLayout.CENTER);
81  
82          // put a status bar at the bottom
83          // this.statusBar = new StatusBar(this.simulator);
84          // this.add(this.statusBar, BorderLayout.SOUTH);
85      }
86  
87      /**
88       * Adds the console tab.
89       */
90      public final void addConsoleTab()
91      {
92          // Let's add our console to our tabbed pane
93          JScrollPane cons = new JScrollPane(this.console);
94          cons.setBorder(null);
95          this.tabbedPane.addTab("console", cons);
96      }
97  
98      /**
99       * Adds the properties tab.
100      * @throws InputParameterException on exception with properties
101      */
102     public final void addPropertiesTab() throws InputParameterException
103     {
104         // TODO: make a tab with the InputParameters
105     }
106 
107     /**
108      * @return tabbedPane
109      */
110     public final TabbedContentPane getTabbedPane()
111     {
112         return this.tabbedPane;
113     }
114 
115     /**
116      * @return simulator.
117      */
118     public final DEVSSimulatorInterface.TimeDoubleUnit getSimulator()
119     {
120         return this.simulator;
121     }
122 
123     /**
124      * @return statusBar.
125      */
126     public final StatusBar getStatusBar()
127     {
128         return this.statusBar;
129     }
130 
131     /**
132      * Return the OTSControlPanel of this OTSSimulationPanel.
133      * @return OTSControlPanel; the OTS control panel
134      */
135     public final OTSControlPanel getOtsControlPanel()
136     {
137         return this.otsControlPanel;
138     }
139 
140     /**
141      * @return console
142      */
143     public final Console getConsole()
144     {
145         return this.console;
146     }
147 
148     /**
149      * @return otsModel
150      */
151     public final OTSModelInterface getOtsModel()
152     {
153         return this.otsModel;
154     }
155 
156     /** {@inheritDoc} */
157     @Override
158     public final String toString()
159     {
160         return "OTSSimulationPanel [simulatorTime=" + this.simulator.getSimulatorTime() + "]";
161     }
162 
163     /**
164      * TabbedContentPane which ignores appearance (it has too much colors looking ugly / becoming unreadable).
165      * <p>
166      * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
167      * <br>
168      * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
169      * <p>
170      * @version $Revision: 4696 $, $LastChangedDate: 2018-10-11 22:54:04 +0200 (Thu, 11 Oct 2018) $, by $Author: averbraeck $,
171      *          initial version 6 feb. 2018 <br>
172      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
173      * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
174      * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
175      */
176     static class AppearanceControlTabbedContentPane extends TabbedContentPane implements AppearanceControl
177     {
178         /** */
179         private static final long serialVersionUID = 20180206L;
180 
181         /**
182          * @param tabPlacement int; tabPlacement
183          */
184         AppearanceControlTabbedContentPane(final int tabPlacement)
185         {
186             super(tabPlacement);
187         }
188 
189         /** {@inheritDoc} */
190         @Override
191         public String toString()
192         {
193             return "AppearanceControlTabbedContentPane []";
194         }
195 
196     }
197 
198 }