1 package nl.tudelft.simulation.dsol.swing.gui;
2
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.Dimension;
6 import java.awt.Insets;
7 import java.rmi.RemoteException;
8
9 import javax.swing.JPanel;
10 import javax.swing.SwingConstants;
11 import javax.swing.UIManager;
12
13 import org.pmw.tinylog.Level;
14
15 import nl.tudelft.simulation.dsol.model.DSOLModel;
16 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
17 import nl.tudelft.simulation.dsol.swing.gui.appearance.AppearanceControl;
18 import nl.tudelft.simulation.dsol.swing.gui.control.AbstractControlPanel;
19
20 /**
21 * Tabbed content panel for the simulation with a control bar on top.
22 * <p>
23 * Copyright (c) 2020-2023 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
24 * for project information <a href="https://simulation.tudelft.nl/dsol/manual/" target="_blank">DSOL Manual</a>. The DSOL
25 * project is distributed under a three-clause BSD-style license, which can be found at
26 * <a href="https://https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank">DSOL License</a>.
27 * </p>
28 * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
30 */
31 public class DSOLPanel extends JPanel implements AppearanceControl
32 {
33 /** */
34 private static final long serialVersionUID = 20150617L;
35
36 /** The control panel to control start/stop, speed of the simulation. */
37 private AbstractControlPanel<?, ?> controlPanel;
38
39 /** The tabbed pane that contains the different (default) screens. */
40 private final TabbedContentPane tabbedPane;
41
42 static
43 {
44 // use narrow border for TabbedPane, which cannot be changed afterwards
45 UIManager.put("TabbedPane.contentBorderInsets", new Insets(1, 1, 1, 1));
46 }
47
48 /**
49 * Construct a panel for an interactive simulation model.
50 * @param controlPanel AbstractControlPanel<?, ?>; the control panel to use (especially with relation to time
51 * control)
52 * @throws RemoteException when communications to a remote machine fails
53 */
54 public DSOLPanel(final AbstractControlPanel<?, ?> controlPanel) throws RemoteException
55 {
56 setPreferredSize(new Dimension(1024, 768));
57 this.tabbedPane = new AppearanceControlTabbedContentPane(SwingConstants.BOTTOM);
58 setLayout(new BorderLayout());
59
60 // add the simulationControl at the top
61 this.controlPanel = controlPanel;
62 add(this.controlPanel, BorderLayout.NORTH);
63
64 // add the tabbed contentPane in the center
65 add(this.tabbedPane, BorderLayout.CENTER);
66 }
67
68 /**
69 * Add a tab to the DSOLPanel as the last tab.
70 * @param tabTitle String; the title of the tab
71 * @param component Component; the swing component to add as this tab
72 */
73 public void addTab(final String tabTitle, final Component component)
74 {
75 this.tabbedPane.addTab(tabTitle, component);
76 }
77
78 /**
79 * Add a tab to the DSOLPanel at a given position.
80 * @param position int; the position to insert the tab at (0 is first)
81 * @param tabTitle String; the title of the tab
82 * @param component Component; the swing component to add as this tab
83 * @throws IndexOutOfBoundsException when position is less than zero or larger than the number of tabs
84 */
85 public void addTab(final int position, final String tabTitle, final Component component)
86 {
87 this.tabbedPane.addTab(position, tabTitle, component);
88 }
89
90 /**
91 * Adds a console tab for the Logger.
92 * @param logLevel Level the logLevel to use;
93 */
94 public void addConsoleLogger(final Level logLevel)
95 {
96 addTab("logger", new ConsoleLogger(logLevel));
97 }
98
99 /**
100 * Adds a console tab for stdout and stderr.
101 */
102 public void addConsoleOutput()
103 {
104 addTab("console", new ConsoleOutput());
105 }
106
107 /**
108 * Adds a properties tab.
109 */
110 public void addInputParametersTab()
111 {
112 addTab("parameters", new InputParametersTab(getModel()));
113 }
114
115 /**
116 * @return tabbedPane
117 */
118 public TabbedContentPane getTabbedPane()
119 {
120 return this.tabbedPane;
121 }
122
123 /**
124 * @return simulator.
125 */
126 public SimulatorInterface<?> getSimulator()
127 {
128 return this.controlPanel.getSimulator();
129 }
130
131 /**
132 * Return the control panel of this SimulationPanel.
133 * @return ControlPanel; the control panel
134 */
135 public AbstractControlPanel<?, ?> getControlPanel()
136 {
137 return this.controlPanel;
138 }
139
140 /**
141 * @return the Model
142 */
143 public DSOLModel<?, ?> getModel()
144 {
145 return this.controlPanel.getModel();
146 }
147
148 /**
149 * Enable the simulation or animation buttons in the GUI. This method HAS TO BE CALLED in order for the buttons to be
150 * enabled, because the initial state is DISABLED. Typically, this is done after all tabs, statistics, and other user
151 * interface and model components have been constructed and initialized.
152 */
153 public void enableSimulationControlButtons()
154 {
155 this.controlPanel.setControlButtonsState(true);
156 }
157
158 /**
159 * Disable the simulation or animation buttons in the GUI.
160 */
161 public void disableSimulationControlButtons()
162 {
163 this.controlPanel.setControlButtonsState(false);
164 }
165
166 /** {@inheritDoc} */
167 @Override
168 public String toString()
169 {
170 return "SimulationPanel";
171 }
172
173 /**
174 * TabbedContentPane which ignores appearance (it has too much colors looking ugly / becoming unreadable).
175 * <p>
176 * Copyright (c) 2020-2023 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved.
177 * See for project information <a href="https://simulation.tudelft.nl/dsol/manual/" target="_blank">DSOL Manual</a>. The
178 * DSOL project is distributed under a three-clause BSD-style license, which can be found at
179 * <a href="https://https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank">DSOL License</a>.
180 * </p>
181 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
182 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
183 * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
184 */
185 static class AppearanceControlTabbedContentPane extends TabbedContentPane implements AppearanceControl
186 {
187 /** */
188 private static final long serialVersionUID = 20180206L;
189
190 /**
191 * @param tabPlacement int; tabPlacement
192 */
193 AppearanceControlTabbedContentPane(final int tabPlacement)
194 {
195 super(tabPlacement);
196 }
197
198 /** {@inheritDoc} */
199 @Override
200 public String toString()
201 {
202 return "AppearanceControlTabbedContentPane []";
203 }
204
205 }
206 }