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-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
23 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
24 * <p>
25 * $LastChangedDate: 2018-10-11 22:54:04 +0200 (Thu, 11 Oct 2018) $, @version $Revision: 4696 $, by $Author: averbraeck $,
26 * initial version Jun 18, 2015 <br>
27 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
28 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
29 */
30 public class OTSSimulationPanel extends JPanel
31 {
32 /** */
33 private static final long serialVersionUID = 20150617L;
34
35 /** The simulator. */
36 private final OTSSimulatorInterface simulator;
37
38 /** The console to log messages. */
39 private final ConsoleOutput console = new ConsoleOutput();
40
41 /** The control panel to control start/stop, speed of the simulation. */
42 private final OTSControlPanel otsControlPanel;
43
44 /** Animation, required to add properties tab. */
45 private final OTSModelInterface otsModel;
46
47 static
48 {
49 // use narrow border for TabbedPane, which cannot be changed afterwards
50 UIManager.put("TabbedPane.contentBorderInsets", new Insets(1, 1, 1, 1));
51 }
52
53 /** The tabbed pane that contains the different (default) screens. */
54 private final TabbedContentPane tabbedPane = new AppearanceControlTabbedContentPane(SwingConstants.BOTTOM);
55
56 /**
57 * Construct a panel that looks like the DSOLPanel for quick building of OTS applications.
58 * @param simulator OTSSimulatorInterface; the simulator or animator of the model.
59 * @param otsModel OTSModelInterface; the model with its properties.
60 * @throws RemoteException when communications to a remote machine fails
61 */
62 public OTSSimulationPanel(final OTSSimulatorInterface simulator, final OTSModelInterface otsModel)
63 throws RemoteException
64 {
65 this.simulator = simulator;
66 this.otsModel = otsModel;
67
68 this.setLayout(new BorderLayout());
69
70 // Let's add our simulationControl
71 this.otsControlPanel = new OTSControlPanel(simulator, otsModel, (OTSAnimationPanel) this);
72 this.add(this.otsControlPanel, BorderLayout.NORTH);
73
74 // Let's display our tabbed contentPane
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 tabbedPane
104 */
105 public final TabbedContentPane getTabbedPane()
106 {
107 return this.tabbedPane;
108 }
109
110 /**
111 * @return simulator.
112 */
113 public final OTSSimulatorInterface getSimulator()
114 {
115 return this.simulator;
116 }
117
118 /**
119 * Return the OTSControlPanel of this OTSSimulationPanel.
120 * @return OTSControlPanel; the OTS control panel
121 */
122 public final OTSControlPanel getOtsControlPanel()
123 {
124 return this.otsControlPanel;
125 }
126
127 /**
128 * @return console
129 */
130 public final ConsoleOutput getConsole()
131 {
132 return this.console;
133 }
134
135 /**
136 * @return otsModel
137 */
138 public final OTSModelInterface getOtsModel()
139 {
140 return this.otsModel;
141 }
142
143 /**
144 * Enable the simulation or animation buttons in the GUI. This method HAS TO BE CALLED in order for the buttons to be
145 * enabled, because the initial state is DISABLED. Typically, this is done after all tabs, statistics, and other user
146 * interface and model components have been constructed and initialized.
147 */
148 public void enableSimulationControlButtons()
149 {
150 getOtsControlPanel().setSimulationControlButtons(true);
151 }
152
153 /**
154 * Disable the simulation or animation buttons in the GUI.
155 */
156 public void disableSimulationControlButtons()
157 {
158 getOtsControlPanel().setSimulationControlButtons(false);
159 }
160
161 /** {@inheritDoc} */
162 @Override
163 public final String toString()
164 {
165 return "OTSSimulationPanel [simulatorTime=" + this.simulator.getSimulatorTime() + "]";
166 }
167
168 /**
169 * TabbedContentPane which ignores appearance (it has too much colors looking ugly / becoming unreadable).
170 * <p>
171 * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
172 * <br>
173 * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
174 * <p>
175 * @version $Revision: 4696 $, $LastChangedDate: 2018-10-11 22:54:04 +0200 (Thu, 11 Oct 2018) $, by $Author: averbraeck $,
176 * initial version 6 feb. 2018 <br>
177 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
178 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
179 * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
180 */
181 static class AppearanceControlTabbedContentPane extends TabbedContentPane implements AppearanceControl
182 {
183 /** */
184 private static final long serialVersionUID = 20180206L;
185
186 /**
187 * @param tabPlacement int; tabPlacement
188 */
189 AppearanceControlTabbedContentPane(final int tabPlacement)
190 {
191 super(tabPlacement);
192 }
193
194 /** {@inheritDoc} */
195 @Override
196 public String toString()
197 {
198 return "AppearanceControlTabbedContentPane []";
199 }
200
201 }
202
203 }