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

Revision 124, 5.7 KB checked in by jdalbey, 9 years ago (diff)

CADClientVew.java Changed to action when server drops to hard exit because Windows was just hanging the app. More renaming.

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