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

Revision 230, 5.6 KB checked in by jdalbey, 8 years ago (diff)

ConfigStatusTab?.java Improved display and fixed defect so it now uses the correct config directory.

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;
25
26/**
27 * This class provides a GUI to view current status information for the CAD
28 * Server.
29 *
30 * @see SimulationStatusPanel
31 * @see MediaStatusPanel
32 * @author Matthew Cechini
33 * @version $Revision: 1.3 $ $Date: 2006/06/06 20:46:41 $
34 */
35@SuppressWarnings("serial")
36public class CADServerViewer extends JFrame implements CADViewer
37{
38    private JTabbedPane cadSimTabbedPane;
39    private JMenuBar menubar;
40    private JMenu fileMenu;
41    private JMenuItem exitMenuItem;
42
43    /**
44     * Panel to display simulation information.
45     */
46    private SimulationStatusPanel simulationPanel;
47    /**
48     * Panel to display media control information.
49     */
50    private MediaStatusPanel mediaPanel;
51    /**
52     * Panel to display configuration files.
53     */
54    private ConfigStatusTab configPanel;
55    /*
56     * Panel to display Traffic Model Event Queue
57    */
58    private TrafficModelViewPanel trafficPanel;
59   
60    /**
61     * Constructor.
62     */
63    public CADServerViewer()
64    {
65        super();
66        setTitle("CAD Server " + getAppVersion());
67
68        initComponents();
69    }
70
71    /**
72     * Read the version number from the application properties. The file
73     * 'application.properties' is generated by build.xml.
74     *
75     * @return a version string obtained from application.properties file, or
76     * "Version: unknown" if an IOerror prevents us from reading the file.
77     */
78    private String getAppVersion()
79    {
80        String propfilename = "/tmcsim/application.properties";
81        String propKey = "Application.revision";
82        String version = "unknown";
83        try
84        {
85            Properties props = new Properties();
86            props.load(this.getClass().getResourceAsStream(propfilename));
87            version = (String) props.get(propKey);
88        } catch (IOException ex)
89        {
90            Logger.getLogger("tmcsim/cadsimulator").log(Level.SEVERE,
91                    "CADSimulatorView.getAppVersion()."
92                    + " IOError reading " + propfilename);
93        } catch (NullPointerException npe)
94        {
95            Logger.getLogger("tmcsim/cadsimulator").log(Level.SEVERE,
96                    "CADSimulatorView.getAppVersion().load."
97                    + " Missing file: " + propfilename);
98        }
99        return "revision: " + version;
100    }
101
102    /**
103     * Method calls the processEvent() method with a WINDOW_CLOSING WindowEvent
104     * to start the application closing process.
105     */
106    public void closeViewer()
107    {
108        processEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
109    }
110
111    /**
112     * Overloads the processEvent method. If the AWTEvent is a WINDOW_CLOSING
113     * event, prompt the user to confirm the action. If confirmed, close the
114     * application.
115     */
116    protected void processEvent(AWTEvent evt)
117    {
118
119        if (evt.getID() == WindowEvent.WINDOW_CLOSING)
120        {
121//            int option = JOptionPane.showConfirmDialog(null,
122//                    "Closing the CAD Simulator will stop the current "
123//                    + "simulation.  Do you wish to continue exiting?",
124//                    "Confirm Exit",
125//                    JOptionPane.YES_NO_OPTION);
126//
127//            if (option != JOptionPane.NO_OPTION)
128//            {
129            System.exit(0);
130//            }
131        }
132    }
133
134    /**
135     * Initialize GUI Components
136     */
137    private void initComponents()
138    {
139        simulationPanel = new SimulationStatusPanel();
140        mediaPanel = new MediaStatusPanel();
141        configPanel = new ConfigStatusTab();
142        trafficPanel = new TrafficModelViewPanel();
143
144        cadSimTabbedPane = new JTabbedPane();
145        cadSimTabbedPane.addTab("Status", simulationPanel);
146        cadSimTabbedPane.addTab("Media", mediaPanel);
147        cadSimTabbedPane.addTab("Config", configPanel);
148        cadSimTabbedPane.addTab("Traffic", trafficPanel);
149
150        add(cadSimTabbedPane);
151
152        menubar = new JMenuBar();
153
154        fileMenu = new JMenu("File");
155        fileMenu.setMnemonic(KeyEvent.VK_F);
156        menubar.add(fileMenu);
157
158        exitMenuItem = new JMenuItem(new ExitAction(this));
159        exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(
160                KeyEvent.VK_X, ActionEvent.ALT_MASK));
161        fileMenu.add(exitMenuItem);
162
163        javax.swing.JMenu helpMenu = new javax.swing.JMenu("Help");
164
165        menubar.add(helpMenu);
166
167        setJMenuBar(menubar);
168
169        setPreferredSize(new Dimension(500, 575));
170        pack();
171        setResizable(true);
172        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
173    }
174
175    @Override
176    public void update(Observable obs, Object obj)
177    {
178        if (obs instanceof CADSimulatorStatus)
179        {
180            simulationPanel.refresh(obs);
181        }
182        if (obs instanceof CADMediaStatus)
183        {
184            mediaPanel.refresh(obs);
185        }
186        if (obs instanceof TrafficModelManager)
187        {
188            trafficPanel.update(obs, obj);
189        }
190    }
191}
Note: See TracBrowser for help on using the repository browser.