Warning: Can't use blame annotator:
svn blame failed on trunk/src/tmcsim/cadsimulator/viewer/SimulationStatusPanel.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/src/tmcsim/cadsimulator/viewer/SimulationStatusPanel.java @ 44

Revision 44, 14.1 KB checked in by jdalbey, 10 years ago (diff)

MultiFile? commit: Add CADViewer Interface and change CADSimulator to Observer Pattern.

RevLine 
1package tmcsim.cadsimulator.viewer;
2
3import java.awt.BorderLayout;
4import java.awt.Color;
5import java.awt.Dimension;
6import java.awt.Font;
7import java.util.Observable;
8import javax.swing.BorderFactory;
9import javax.swing.Box;
10import javax.swing.BoxLayout;
11import javax.swing.JLabel;
12import javax.swing.JPanel;
13import javax.swing.JScrollPane;
14import javax.swing.JTextArea;
15import javax.swing.JTextField;
16import javax.swing.border.EtchedBorder;
17import javax.swing.border.TitledBorder;
18import tmcsim.cadsimulator.viewer.model.CADSimulatorStatus;
19import tmcsim.common.CADEnums.PARAMICS_STATUS;
20import tmcsim.common.CADEnums.SCRIPT_STATUS;
21
22/**
23 * SimulationStatusPanel is a GUI object used for displaying information for the
24 * current simulation. This information includes:
25 *
26 * <ul>
27 * <li>Current simulation time.</li>
28 * <li>Current simulation status.</li>
29 * <li>Number of remote CAD Clients connected.</li>
30 * <li>Status of Simulation Manager connection.</li>
31 * <li>Status of Paramics connection.</li>
32 * <li>Paramics Network Loaded</li>
33 * <li>Information log messages.</li>
34 * <li>Error log messages</li>
35 * </ul>
36 *
37 * @author Matthew Cechini, jdalbey
38 * @version
39 */
40@SuppressWarnings("serial")
41public class SimulationStatusPanel extends JPanel
42{
43
44    /**
45     * Refresh this view
46     *
47     * @param obs the Observable we are watching
48     */
49    public void refresh(Observable obs)
50    {
51        CADSimulatorStatus status = (CADSimulatorStatus) obs;
52        termConnectedTF.setText(String.valueOf(status.getNumClients()));
53        String yesno = "No";
54        // Should we show yes or no?
55        if (status.isSimManagerConnected())
56        {
57            yesno = "Yes";
58        }
59        managerConnectedTF.setText(yesno);
60        simulationClockLabel.setText(status.getCurrentTime());
61        setScriptStatus(status.getScriptStatus());
62        setParamicsStatus(status.getParamicsStatus());
63
64        String netText = status.getParmicsNetworkID();
65        if (netText.length() == 0)
66        {
67            netText = "None";
68        }
69        setParamicsNetworkLoaded(netText);
70
71        String msgOut = status.getInfoMessages();
72        infoMessagesTA.setText(msgOut);
73        errorMessagesTA.setText(status.getErrorMessages());
74    }
75    /**
76     * Count of how many CAD clients have connected.
77     */
78    private int numClientsConnected = 0;
79
80    /**
81     * Constructor. Initialize GUI Objects. Register the logging handler to
82     * listen for log records from all loggers that exist in the
83     * "tmcsim.cadsimulator" package structure.
84     */
85    public SimulationStatusPanel()
86    {
87
88        initTimeAndStatus();
89        initAdditionalInfo();
90        initMessagesPanes();
91
92        //  errorHandler = new SimulatorErrorHandler();
93        //  Logger.getLogger("tmcsim.cadsimulator").addHandler(errorHandler);
94
95        cadSimulatorViewerBox = Box.createVerticalBox();
96        cadSimulatorViewerBox.add(simulationTimeAndStatusBox);
97        cadSimulatorViewerBox.add(additionalInfoBox);
98        cadSimulatorViewerBox.add(infoMessagesPane);
99        cadSimulatorViewerBox.add(errorMessagesPane);
100
101        add(cadSimulatorViewerBox);
102    }
103
104    /**
105     * This method is called within the CADSimulator whenever an error occurs.
106     * The message is then displayed to the user in the "Error Messages" portion
107     * of the CAD Simulator Viewer. Invoke method with null parameter to clear
108     * messages.
109     *
110     * @param errorMessage String message that will be displayed
111     */
112    protected void displayError(String errorMessage)
113    {
114        // Do we clear or append?
115        if (errorMessage == null)
116        {
117            errorMessagesTA.setText("");
118        }
119        else
120        {
121            errorMessagesTA.append(errorMessage + "\n");
122        }
123    }
124
125    /**
126     * Method is called to display the current status of the simulation.
127     *
128     * @param newStatus Current status of simulation. The following table
129     * describes each possible status and what is displayed. Each status code is
130     * found as a public static int in the Coordinator Class.
131     *
132     * <table cellpadding="2" cellspacing="2" border="1" style="text-align:
133     * left; width: 250px;">
134     * <tbody>
135     * <tr>
136     * <th>Status<br></th>
137     * <th>Actions Taken<br></th>
138     * </tr>
139     * <tr>
140     * <td>NO_SCRIPT<br></td>
141     * <td>Set the simulation status text to a black "No Script". <br></td>
142     * </tr>
143     * <tr>
144     * <td>SCRIPT_STOPPED_NOT_STARTED<br></td>
145     * <td>Set the simulation status text to a red "Ready". <br></td>
146     * </tr>
147     * <tr>
148     * <td>SCRIPT_PAUSED_STARTED<br></td>
149     * <td>Set the simulation status text to a red "Paused". <br></td>
150     * </tr>
151     * <tr>
152     * <td>SCRIPT_RUNNING<br></td>
153     * <td>Set the simulation status text to a green "Running". <br></td>
154     * </tr>
155     * <tr>
156     * <td>ATMS_SYNCHRONIZATION<br></td>
157     * <td>Set the simulation status text to an orange "Synchronizing".
158     * <br></td>
159     * </tr>
160     * </tbody>
161     * </table>
162     */
163    private void setScriptStatus(SCRIPT_STATUS newStatus)
164    {
165        // Display text based on status value
166        switch (newStatus)
167        {
168            case NO_SCRIPT:
169                simulationStatusText.setText("No Script");
170                simulationStatusText.setForeground(Color.BLACK);
171                break;
172
173            case SCRIPT_STOPPED_NOT_STARTED:
174                simulationStatusText.setText("Ready");
175                simulationStatusText.setForeground(Color.RED);
176                break;
177
178            case SCRIPT_PAUSED_STARTED:
179                simulationStatusText.setText("Paused");
180                simulationStatusText.setForeground(Color.RED);
181                break;
182
183            case SCRIPT_RUNNING:
184                simulationStatusText.setText("Running");
185                simulationStatusText.setForeground(Color.GREEN);
186                break;
187            case ATMS_SYNCHRONIZATION:
188                simulationStatusText.setText("Synchronizing");
189                simulationStatusText.setForeground(Color.ORANGE);
190                break;
191
192        }
193    }
194
195    /**
196     * Method is called when a connection to paramics is made or dropped.
197     *
198     * @param newStatus The status denoting whether a connection has been made
199     * or dropped.
200     */
201    private void setParamicsStatus(PARAMICS_STATUS newStatus)
202    {
203        // Display text based on status value
204        switch (newStatus)
205        {
206            case CONNECTED:
207                paramicsConnectedTF.setText("Yes");
208                break;
209            case DISCONNECTED:
210                paramicsConnectedTF.setText("No");
211                break;
212        }
213    }
214
215    /**
216     * Method is called when a paramics network is loaded.
217     *
218     * @param networkID Unique ID for Paramics network that has been loaded.
219     */
220    private void setParamicsNetworkLoaded(String networkID)
221    {
222        networkLoadedTF.setText(networkID);
223    }
224
225    /**
226     * Initialize Time and Status GUI Components
227     */
228    private void initTimeAndStatus()
229    {
230
231        simulationTime = new JPanel();
232        simulationClock = new JPanel();
233        simulationStatus = new JLabel("Simulation Status");
234        simulationStatusText = new JLabel("No Script");
235        simulationStatusText.setName("simulationStatusText");
236
237        simulationTime.setLayout(new BorderLayout());
238        simulationClock.setPreferredSize(new Dimension(100, 60));
239        simulationTimeAndStatusBox = new Box(BoxLayout.X_AXIS);
240        simulationStatusBox = new Box(BoxLayout.Y_AXIS);
241        simulationTimeBox = new Box(BoxLayout.Y_AXIS);
242        simulationClockBox = new Box(BoxLayout.X_AXIS);
243
244        simulationStatus.setAlignmentX(Box.CENTER_ALIGNMENT);
245        simulationStatusText.setAlignmentX(Box.CENTER_ALIGNMENT);
246        simulationStatusText.setName("simulationStatusText");
247
248        TitledBorder title = BorderFactory.createTitledBorder(
249                BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Status");
250        title.setTitleJustification(TitledBorder.LEFT);
251        simulationStatusBox.setBorder(title);
252
253        simulationStatusBox.setMaximumSize(new Dimension(140, 60));
254        simulationStatusBox.setAlignmentX(Box.CENTER_ALIGNMENT);
255
256        simulationStatusBox.add(Box.createHorizontalStrut(120));
257        simulationStatusBox.add(Box.createVerticalGlue());
258        simulationStatusBox.add(simulationStatusText);
259        simulationStatusBox.add(Box.createVerticalGlue());
260
261        simulationClockLabel = new JLabel("0:00:00");
262        simulationClockLabel.setFont(new Font("Geneva", Font.BOLD, 70));
263        simulationClockLabel.setName("simulationClockLabel");
264        simulationClockLabel.setForeground(Color.BLACK);
265        simulationClockLabel.setBackground(Color.BLACK);
266        simulationClockBox.setForeground(Color.BLACK);
267        simulationClockBox.setBackground(Color.BLACK);
268        simulationClockBox.add(simulationClockLabel);
269        simulationClockBox.setAlignmentX(Box.CENTER_ALIGNMENT);
270        simulationTimeBox.add(simulationClockBox);
271
272        simulationTimeAndStatusBox.add(Box.createHorizontalStrut(20));
273        simulationTimeAndStatusBox.add(simulationTimeBox);
274        simulationTimeAndStatusBox.add(Box.createHorizontalStrut(20));
275        simulationTimeAndStatusBox.add(simulationStatusBox);
276        simulationTimeAndStatusBox.add(Box.createHorizontalStrut(20));
277    }
278
279    /**
280     * Initialize Additional Info Label GUI Components
281     */
282    private void initAdditionalInfo()
283    {
284
285        terminalsConnectedLabel = new JLabel("Connected CAD Terminals: ");
286        termConnectedTF = new JTextField("   " + String.valueOf(numClientsConnected));
287        termConnectedTF.setEditable(false);
288        termConnectedTF.setName("termConnectedTF");
289
290        termConnectedBox = new Box(BoxLayout.X_AXIS);
291        termConnectedBox.add(terminalsConnectedLabel);
292        termConnectedBox.add(Box.createHorizontalGlue());
293        termConnectedBox.add(termConnectedTF);
294
295
296        managerConnectedLabel = new JLabel("Simulation Manager Connected: ");
297        managerConnectedTF = new JTextField("  No");
298        managerConnectedTF.setEditable(false);
299        managerConnectedTF.setName("managerConnectedTF");
300
301        managerConnectedBox = new Box(BoxLayout.X_AXIS);
302        managerConnectedBox.add(managerConnectedLabel);
303        managerConnectedBox.add(Box.createHorizontalGlue());
304        managerConnectedBox.add(managerConnectedTF);
305
306
307        paramicsConnectedLabel = new JLabel("Connected to Paramics: ");
308        paramicsConnectedTF = new JTextField("  No");
309        paramicsConnectedTF.setEditable(false);
310        paramicsConnectedTF.setName("paramicsConnectedTF");
311
312        paramicsConnectedBox = new Box(BoxLayout.X_AXIS);
313        paramicsConnectedBox.add(paramicsConnectedLabel);
314        paramicsConnectedBox.add(Box.createHorizontalGlue());
315        paramicsConnectedBox.add(paramicsConnectedTF);
316
317
318        networkLoadedLabel = new JLabel("Network Loaded: ");
319        networkLoadedTF = new JTextField("None");
320        networkLoadedTF.setEditable(false);
321        networkLoadedTF.setName("networkLoadedTF");
322
323        networkLoadedBox = new Box(BoxLayout.X_AXIS);
324        networkLoadedBox.add(networkLoadedLabel);
325        networkLoadedBox.add(Box.createHorizontalGlue());
326        networkLoadedBox.add(networkLoadedTF);
327
328
329        additionalInfoBox = new Box(BoxLayout.Y_AXIS);
330        additionalInfoBox.setMinimumSize(new Dimension(300, 150));
331
332        additionalInfoBox.add(Box.createVerticalStrut(10));
333        additionalInfoBox.add(termConnectedBox);
334        additionalInfoBox.add(Box.createVerticalStrut(10));
335        additionalInfoBox.add(managerConnectedBox);
336        additionalInfoBox.add(Box.createVerticalStrut(10));
337        additionalInfoBox.add(paramicsConnectedBox);
338        additionalInfoBox.add(Box.createVerticalStrut(10));
339        additionalInfoBox.add(networkLoadedBox);
340        additionalInfoBox.add(Box.createVerticalStrut(20));
341
342
343    }
344
345    /**
346     * Initialize Info & Error Messages GUI Components
347     */
348    private void initMessagesPanes()
349    {
350
351        infoMessagesTA = new JTextArea(6, 30);
352        infoMessagesTA.setEditable(false);
353        infoMessagesTA.setName("infoMessagesTA");
354        infoMessagesTA.setLineWrap(true);
355        infoMessagesTA.setWrapStyleWord(true);
356        infoMessagesPane = new JScrollPane(infoMessagesTA);
357        infoMessagesPane.setPreferredSize(new Dimension(300, 100));
358        infoMessagesPane.setName("infoMessagesPane");
359        infoMessagesPane.setBorder(BorderFactory.createTitledBorder(
360                BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Info Messages"));
361        infoMessagesPane.setName("infoMessagesPane");
362
363        errorMessagesTA = new JTextArea(6, 30);
364        errorMessagesTA.setForeground(Color.RED);
365        errorMessagesTA.setEditable(false);
366        errorMessagesTA.setName("errorMessagesTA");
367        errorMessagesTA.setLineWrap(true);
368        errorMessagesTA.setWrapStyleWord(true);
369        errorMessagesPane = new JScrollPane(errorMessagesTA);
370        errorMessagesPane.setPreferredSize(new Dimension(300, 150));
371        errorMessagesPane.setName("errorMessagesPane");
372        errorMessagesPane.setBorder(BorderFactory.createTitledBorder(
373                BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Error Messages"));
374
375    }
376    private Box additionalInfoBox;
377    private Box termConnectedBox;
378    private Box managerConnectedBox;
379    private Box paramicsConnectedBox;
380    private Box networkLoadedBox;
381    private Box cadSimulatorViewerBox;
382    private Box simulationTimeAndStatusBox;
383    private Box simulationStatusBox;
384    private Box simulationTimeBox;
385    private Box simulationClockBox;
386    private JLabel managerConnectedLabel;
387    private JLabel paramicsConnectedLabel;
388    private JLabel simulationStatus;
389    private JLabel simulationClockLabel;
390    private JLabel simulationStatusText;
391    private JLabel terminalsConnectedLabel;
392    private JLabel networkLoadedLabel;
393    private JPanel simulationTime;
394    private JPanel simulationClock;
395    private JTextField managerConnectedTF;
396    private JTextField paramicsConnectedTF;
397    private JTextField termConnectedTF;
398    private JTextField networkLoadedTF;
399    private JScrollPane infoMessagesPane;
400    private JScrollPane errorMessagesPane;
401    private JTextArea infoMessagesTA;
402    private JTextArea errorMessagesTA;
403}
Note: See TracBrowser for help on using the repository browser.