source: tmcsimulator/trunk/src/tmcsim/cadsimulator/viewer/CADServerViewer.java @ 455

Revision 455, 4.7 KB checked in by jdalbey, 7 years ago (diff)

ConfigStatusTab? updated to fix @169.

Line 
1package tmcsim.cadsimulator.viewer;
2
3import java.awt.AWTEvent;
4import java.awt.Dimension;
5import java.awt.event.ActionEvent;
6import java.awt.event.KeyEvent;
7import java.awt.event.WindowEvent;
8import java.io.IOException;
9import java.util.Observable;
10import java.util.Properties;
11import java.util.logging.Level;
12import java.util.logging.Logger;
13import javax.swing.JFrame;
14import javax.swing.JMenu;
15import javax.swing.JMenuBar;
16import javax.swing.JMenuItem;
17import javax.swing.JOptionPane;
18import javax.swing.JTabbedPane;
19import javax.swing.KeyStroke;
20import tmcsim.cadsimulator.managers.TrafficModelManager;
21import tmcsim.cadsimulator.viewer.actions.ExitAction;
22import tmcsim.cadsimulator.viewer.model.CADMediaStatus;
23import tmcsim.cadsimulator.viewer.model.CADSimulatorStatus;
24import tmcsim.interfaces.CADViewer;
25import tmcsim.common.RevisionNumber;
26
27/**
28 * This class provides a GUI to view current status information for the CAD
29 * Server.
30 *
31 * @see SimulationStatusPanel
32 * @see MediaStatusPanel
33 * @author Matthew Cechini
34 * @version $Revision: 1.3 $ $Date: 2006/06/06 20:46:41 $
35 */
36@SuppressWarnings("serial")
37public class CADServerViewer extends JFrame implements CADViewer
38{
39    private JTabbedPane cadSimTabbedPane;
40    private JMenuBar menubar;
41    private JMenu fileMenu;
42    private JMenuItem exitMenuItem;
43
44    /**
45     * Panel to display simulation information.
46     */
47    private SimulationStatusPanel simulationPanel;
48    /**
49     * Panel to display media control information.
50     */
51    private MediaStatusPanel mediaPanel;
52    /**
53     * Panel to display configuration files.
54     */
55    private ConfigStatusTab configPanel;
56    /*
57     * Panel to display Traffic Model Event Queue
58    */
59    private TrafficModelViewPanel trafficPanel;
60    /*
61     * Name of propertes file for this run of CAD Server.
62    */
63    private String propertiesFile;
64   
65    /**
66     * Constructor.
67     */
68    public CADServerViewer(String propertiesFile)
69    {
70        super();
71        this.propertiesFile = propertiesFile;
72        setTitle("CAD Server " + RevisionNumber.getAppVersion());
73
74        initComponents();
75    }
76
77
78
79    /**
80     * Method calls the processEvent() method with a WINDOW_CLOSING WindowEvent
81     * to start the application closing process.
82     */
83    public void closeViewer()
84    {
85        processEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
86    }
87
88    /**
89     * Overloads the processEvent method. If the AWTEvent is a WINDOW_CLOSING
90     * event, prompt the user to confirm the action. If confirmed, close the
91     * application.
92     */
93    protected void processEvent(AWTEvent evt)
94    {
95
96        if (evt.getID() == WindowEvent.WINDOW_CLOSING)
97        {
98//            int option = JOptionPane.showConfirmDialog(null,
99//                    "Closing the CAD Simulator will stop the current "
100//                    + "simulation.  Do you wish to continue exiting?",
101//                    "Confirm Exit",
102//                    JOptionPane.YES_NO_OPTION);
103//
104//            if (option != JOptionPane.NO_OPTION)
105//            {
106            System.exit(0);
107//            }
108        }
109    }
110
111    /**
112     * Initialize GUI Components
113     */
114    private void initComponents()
115    {
116        simulationPanel = new SimulationStatusPanel();
117        mediaPanel = new MediaStatusPanel();
118        configPanel = new ConfigStatusTab(propertiesFile);
119        trafficPanel = new TrafficModelViewPanel();
120
121        cadSimTabbedPane = new JTabbedPane();
122        cadSimTabbedPane.addTab("Status", simulationPanel);
123        cadSimTabbedPane.addTab("Media", mediaPanel);
124        cadSimTabbedPane.addTab("Config", configPanel);
125        cadSimTabbedPane.addTab("Traffic", trafficPanel);
126
127        add(cadSimTabbedPane);
128
129        menubar = new JMenuBar();
130
131        fileMenu = new JMenu("File");
132        fileMenu.setMnemonic(KeyEvent.VK_F);
133        menubar.add(fileMenu);
134
135        exitMenuItem = new JMenuItem(new ExitAction(this));
136        exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(
137                KeyEvent.VK_X, ActionEvent.ALT_MASK));
138        fileMenu.add(exitMenuItem);
139
140        javax.swing.JMenu helpMenu = new javax.swing.JMenu("Help");
141
142        menubar.add(helpMenu);
143
144        setJMenuBar(menubar);
145
146        setPreferredSize(new Dimension(500, 575));
147        pack();
148        setResizable(true);
149        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
150    }
151
152    @Override
153    public void update(Observable obs, Object obj)
154    {
155        if (obs instanceof CADSimulatorStatus)
156        {
157            simulationPanel.refresh(obs);
158        }
159        if (obs instanceof CADMediaStatus)
160        {
161            mediaPanel.refresh(obs);
162        }
163        if (obs instanceof TrafficModelManager)
164        {
165            trafficPanel.update(obs, obj);
166        }
167    }
168}
Note: See TracBrowser for help on using the repository browser.