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

Revision 210, 5.6 KB checked in by jdalbey, 9 years ago (diff)

Integrate TrafficModelViewer? into the CAD Server GUI as an additional tab. Eliminates the separate window for traffic mgr view.

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 ConfigStatusPanel 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
140
141        simulationPanel = new SimulationStatusPanel();
142        mediaPanel = new MediaStatusPanel();
143        configPanel = new ConfigStatusPanel();
144        trafficPanel = new TrafficModelViewPanel();
145
146        cadSimTabbedPane = new JTabbedPane();
147        cadSimTabbedPane.addTab("Status", simulationPanel);
148        cadSimTabbedPane.addTab("Media", mediaPanel);
149        cadSimTabbedPane.addTab("Config", configPanel);
150        cadSimTabbedPane.addTab("Traffic", trafficPanel);
151
152        add(cadSimTabbedPane);
153
154        menubar = new JMenuBar();
155
156        fileMenu = new JMenu("File");
157        fileMenu.setMnemonic(KeyEvent.VK_F);
158        menubar.add(fileMenu);
159
160        exitMenuItem = new JMenuItem(new ExitAction(this));
161        exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(
162                KeyEvent.VK_X, ActionEvent.ALT_MASK));
163        fileMenu.add(exitMenuItem);
164
165        javax.swing.JMenu helpMenu = new javax.swing.JMenu("Help");
166
167        menubar.add(helpMenu);
168
169        setJMenuBar(menubar);
170
171        setPreferredSize(new Dimension(500, 575));
172        pack();
173        setResizable(true);
174        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
175    }
176
177    @Override
178    public void update(Observable obs, Object obj)
179    {
180        if (obs instanceof CADSimulatorStatus)
181        {
182            simulationPanel.refresh(obs);
183        }
184        if (obs instanceof CADMediaStatus)
185        {
186            mediaPanel.refresh(obs);
187        }
188        if (obs instanceof TrafficModelManager)
189        {
190            trafficPanel.update(obs, obj);
191        }
192    }
193}
Note: See TracBrowser for help on using the repository browser.