1 package org.opentrafficsim.gui;
2
3 import java.awt.BorderLayout;
4 import java.awt.Insets;
5 import java.rmi.RemoteException;
6 import java.util.List;
7
8 import javax.swing.JLabel;
9 import javax.swing.JPanel;
10 import javax.swing.JScrollPane;
11 import javax.swing.SwingConstants;
12 import javax.swing.UIManager;
13
14 import org.opentrafficsim.base.modelproperties.CompoundProperty;
15 import org.opentrafficsim.base.modelproperties.Property;
16 import org.opentrafficsim.base.modelproperties.PropertyException;
17 import org.opentrafficsim.simulationengine.WrappableAnimation;
18
19 import nl.tudelft.simulation.dsol.gui.swing.Console;
20 import nl.tudelft.simulation.dsol.gui.swing.StatusBar;
21 import nl.tudelft.simulation.dsol.gui.swing.TabbedContentPane;
22 import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
23
24
25
26
27
28
29
30
31
32
33
34
35 public class OTSSimulationPanel extends JPanel
36 {
37
38 private static final long serialVersionUID = 20150617L;
39
40
41 private final DEVSSimulatorInterface.TimeDoubleUnit simulator;
42
43
44 private final Console console = new Console();
45
46
47 private final OTSControlPanel otsControlPanel;
48
49
50 private final WrappableAnimation wrappableAnimation;
51
52 static
53 {
54
55 UIManager.put("TabbedPane.contentBorderInsets", new Insets(1, 1, 1, 1));
56 }
57
58
59 private final TabbedContentPane tabbedPane = new AppearanceControlTabbedContentPane(SwingConstants.BOTTOM);
60
61
62 private final StatusBar statusBar = null;
63
64
65
66
67
68
69
70
71 public OTSSimulationPanel(final DEVSSimulatorInterface.TimeDoubleUnit simulator,
72 final WrappableAnimation wrappableAnimation) throws RemoteException, PropertyException
73 {
74
75 this.simulator = simulator;
76 this.wrappableAnimation = wrappableAnimation;
77
78 this.setLayout(new BorderLayout());
79
80
81 this.otsControlPanel = new OTSControlPanel(simulator, wrappableAnimation);
82 this.add(this.otsControlPanel, BorderLayout.NORTH);
83
84
85 this.add(this.tabbedPane, BorderLayout.CENTER);
86
87
88
89
90 }
91
92
93
94
95 public final void addConsoleTab()
96 {
97
98 JScrollPane cons = new JScrollPane(this.console);
99 cons.setBorder(null);
100 this.tabbedPane.addTab("console", cons);
101 }
102
103
104
105
106
107 public final void addPropertiesTab() throws PropertyException
108 {
109
110 List<Property<?>> propertyList =
111 new CompoundProperty("", "", "", this.wrappableAnimation.getUserModifiedProperties(), true, 0)
112 .displayOrderedValue();
113 StringBuilder html = new StringBuilder();
114 html.append("<html><table border=\"1\"><tr><th colspan=\"" + propertyList.size() + "\">Settings</th></tr><tr>");
115
116 for (Property<?> ap : propertyList)
117 {
118 html.append("<td valign=\"top\">" + ap.htmlStateDescription() + "</td>");
119 }
120 html.append("</table></html>");
121 JLabel propertySettings = new JLabel(html.toString());
122 JScrollPane settings = new JScrollPane(propertySettings);
123 settings.setBorder(null);
124 this.tabbedPane.addTab("settings", settings);
125 }
126
127
128
129
130 public final TabbedContentPane getTabbedPane()
131 {
132 return this.tabbedPane;
133 }
134
135
136
137
138 public final DEVSSimulatorInterface.TimeDoubleUnit getSimulator()
139 {
140 return this.simulator;
141 }
142
143
144
145
146 public final StatusBar getStatusBar()
147 {
148 return this.statusBar;
149 }
150
151
152
153
154
155 public final OTSControlPanel getOtsControlPanel()
156 {
157 return this.otsControlPanel;
158 }
159
160
161 @Override
162 public final String toString()
163 {
164 return "OTSSimulationPanel [simulatorTime=" + this.simulator.getSimulatorTime() + "]";
165 }
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180 static class AppearanceControlTabbedContentPane extends TabbedContentPane implements AppearanceControl
181 {
182
183 private static final long serialVersionUID = 20180206L;
184
185
186
187
188 public AppearanceControlTabbedContentPane(int tabPlacement)
189 {
190 super(tabPlacement);
191 }
192
193
194 @Override
195 public String toString()
196 {
197 return "AppearanceControlTabbedContentPane []";
198 }
199 }
200
201 }