source: tmcsimulator/trunk/src/tmcsim/cadsimulator/viewer/CADSimulatorViewer.java @ 44

Revision 44, 5.5 KB checked in by jdalbey, 10 years ago (diff)

MultiFile? commit: Add CADViewer Interface and change CADSimulator to Observer Pattern.

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 * Simulator.
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 CADSimulatorViewer 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 CADSimulatorViewer()
55    {
56        super();
57        setTitle("CAD Simulator " + 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        }
85        return "revision: " + version;
86    }
87
88    /**
89     * Method calls the processEvent() method with a WINDOW_CLOSING WindowEvent
90     * to start the application closing process.
91     */
92    public void closeViewer()
93    {
94        processEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
95    }
96
97    /**
98     * Overloads the processEvent method. If the AWTEvent is a WINDOW_CLOSING
99     * event, prompt the user to confirm the action. If confirmed, close the
100     * application.
101     */
102    protected void processEvent(AWTEvent evt)
103    {
104
105        if (evt.getID() == WindowEvent.WINDOW_CLOSING)
106        {
107//            int option = JOptionPane.showConfirmDialog(null,
108//                    "Closing the CAD Simulator will stop the current "
109//                    + "simulation.  Do you wish to continue exiting?",
110//                    "Confirm Exit",
111//                    JOptionPane.YES_NO_OPTION);
112//
113//            if (option != JOptionPane.NO_OPTION)
114//            {
115            System.exit(0);
116//            }
117        }
118    }
119
120    /**
121     * Initialize GUI Components
122     */
123    private void initComponents()
124    {
125
126
127        simulationPanel = new SimulationStatusPanel();
128        mediaPanel = new MediaStatusPanel();
129        configPanel = new ConfigStatusPanel();
130
131        cadSimTabbedPane = new JTabbedPane();
132        cadSimTabbedPane.addTab("Status", simulationPanel);
133        cadSimTabbedPane.addTab("Media", mediaPanel);
134        cadSimTabbedPane.addTab("Config", configPanel);
135
136        add(cadSimTabbedPane);
137
138        menubar = new JMenuBar();
139
140        fileMenu = new JMenu("File");
141        fileMenu.setMnemonic(KeyEvent.VK_F);
142        menubar.add(fileMenu);
143
144        exitMenuItem = new JMenuItem(new ExitAction(this));
145        exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(
146                KeyEvent.VK_X, ActionEvent.ALT_MASK));
147        fileMenu.add(exitMenuItem);
148
149        javax.swing.JMenu helpMenu = new javax.swing.JMenu("Help");
150        javax.swing.JMenuItem aboutItem = new javax.swing.JMenuItem("About");
151
152        aboutItem.addActionListener(new java.awt.event.ActionListener()
153        {
154            public void actionPerformed(java.awt.event.ActionEvent evt)
155            {
156                String ver = "";//RevisionNumber.getString();
157                JOptionPane.showMessageDialog(rootPane, "Version: " + ver, "About", JOptionPane.INFORMATION_MESSAGE);
158            }
159        });
160        helpMenu.add(aboutItem);
161        menubar.add(helpMenu);
162
163        setJMenuBar(menubar);
164
165        setPreferredSize(new Dimension(500, 575));
166        pack();
167        setResizable(true);
168        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
169    }
170    private JTabbedPane cadSimTabbedPane;
171    private JMenuBar menubar;
172    private JMenu fileMenu;
173    private JMenuItem exitMenuItem;
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    }
187}
Note: See TracBrowser for help on using the repository browser.