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

Revision 365, 4.5 KB checked in by jdalbey, 7 years ago (diff)

RevisionNumber?.java, SimulationManagerView?.java : Fix defect #119

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    /**
62     * Constructor.
63     */
64    public CADServerViewer()
65    {
66        super();
67        setTitle("CAD Server " + RevisionNumber.getAppVersion());
68
69        initComponents();
70    }
71
72
73
74    /**
75     * Method calls the processEvent() method with a WINDOW_CLOSING WindowEvent
76     * to start the application closing process.
77     */
78    public void closeViewer()
79    {
80        processEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
81    }
82
83    /**
84     * Overloads the processEvent method. If the AWTEvent is a WINDOW_CLOSING
85     * event, prompt the user to confirm the action. If confirmed, close the
86     * application.
87     */
88    protected void processEvent(AWTEvent evt)
89    {
90
91        if (evt.getID() == WindowEvent.WINDOW_CLOSING)
92        {
93//            int option = JOptionPane.showConfirmDialog(null,
94//                    "Closing the CAD Simulator will stop the current "
95//                    + "simulation.  Do you wish to continue exiting?",
96//                    "Confirm Exit",
97//                    JOptionPane.YES_NO_OPTION);
98//
99//            if (option != JOptionPane.NO_OPTION)
100//            {
101            System.exit(0);
102//            }
103        }
104    }
105
106    /**
107     * Initialize GUI Components
108     */
109    private void initComponents()
110    {
111        simulationPanel = new SimulationStatusPanel();
112        mediaPanel = new MediaStatusPanel();
113        configPanel = new ConfigStatusTab();
114        trafficPanel = new TrafficModelViewPanel();
115
116        cadSimTabbedPane = new JTabbedPane();
117        cadSimTabbedPane.addTab("Status", simulationPanel);
118        cadSimTabbedPane.addTab("Media", mediaPanel);
119        cadSimTabbedPane.addTab("Config", configPanel);
120        cadSimTabbedPane.addTab("Traffic", trafficPanel);
121
122        add(cadSimTabbedPane);
123
124        menubar = new JMenuBar();
125
126        fileMenu = new JMenu("File");
127        fileMenu.setMnemonic(KeyEvent.VK_F);
128        menubar.add(fileMenu);
129
130        exitMenuItem = new JMenuItem(new ExitAction(this));
131        exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(
132                KeyEvent.VK_X, ActionEvent.ALT_MASK));
133        fileMenu.add(exitMenuItem);
134
135        javax.swing.JMenu helpMenu = new javax.swing.JMenu("Help");
136
137        menubar.add(helpMenu);
138
139        setJMenuBar(menubar);
140
141        setPreferredSize(new Dimension(500, 575));
142        pack();
143        setResizable(true);
144        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
145    }
146
147    @Override
148    public void update(Observable obs, Object obj)
149    {
150        if (obs instanceof CADSimulatorStatus)
151        {
152            simulationPanel.refresh(obs);
153        }
154        if (obs instanceof CADMediaStatus)
155        {
156            mediaPanel.refresh(obs);
157        }
158        if (obs instanceof TrafficModelManager)
159        {
160            trafficPanel.update(obs, obj);
161        }
162    }
163}
Note: See TracBrowser for help on using the repository browser.