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