| 1 | package tmcsim.cadsimulator.viewer; |
|---|
| 2 | |
|---|
| 3 | import java.awt.AWTEvent; |
|---|
| 4 | import java.awt.Dimension; |
|---|
| 5 | import java.awt.event.ActionEvent; |
|---|
| 6 | import java.awt.event.KeyEvent; |
|---|
| 7 | import java.awt.event.WindowEvent; |
|---|
| 8 | import javax.swing.JFrame; |
|---|
| 9 | import javax.swing.JMenu; |
|---|
| 10 | import javax.swing.JMenuBar; |
|---|
| 11 | import javax.swing.JMenuItem; |
|---|
| 12 | import javax.swing.JOptionPane; |
|---|
| 13 | import javax.swing.JTabbedPane; |
|---|
| 14 | import javax.swing.KeyStroke; |
|---|
| 15 | import tmcsim.cadsimulator.videocontrol.DVDStatusUpdate; |
|---|
| 16 | import tmcsim.cadsimulator.videocontrol.DVDTitleUpdate; |
|---|
| 17 | import tmcsim.cadsimulator.viewer.actions.ExitAction; |
|---|
| 18 | import tmcsim.common.CADEnums.PARAMICS_STATUS; |
|---|
| 19 | import tmcsim.common.CADEnums.SCRIPT_STATUS; |
|---|
| 20 | import tmcsim.common.RevisionNumber; |
|---|
| 21 | |
|---|
| 22 | /** |
|---|
| 23 | * This class provides a GUI to view current status information for the CAD |
|---|
| 24 | * Simulator. |
|---|
| 25 | * |
|---|
| 26 | * @see SimulationStatusPanel |
|---|
| 27 | * @see MediaStatusPanel |
|---|
| 28 | * @author Matthew Cechini |
|---|
| 29 | * @version $Revision: 1.3 $ $Date: 2006/06/06 20:46:41 $ |
|---|
| 30 | */ |
|---|
| 31 | @SuppressWarnings("serial") |
|---|
| 32 | public class CADSimulatorViewer extends JFrame |
|---|
| 33 | { |
|---|
| 34 | |
|---|
| 35 | /** |
|---|
| 36 | * Panel to display simulation information. |
|---|
| 37 | */ |
|---|
| 38 | private SimulationStatusPanel simulationPanel; |
|---|
| 39 | /** |
|---|
| 40 | * Panel to display media control information. |
|---|
| 41 | */ |
|---|
| 42 | private MediaStatusPanel mediaPanel; |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * Constructor. |
|---|
| 46 | */ |
|---|
| 47 | public CADSimulatorViewer() |
|---|
| 48 | { |
|---|
| 49 | super("CAD Simulator"); |
|---|
| 50 | |
|---|
| 51 | initComponents(); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | /** |
|---|
| 55 | * @see SimulationStatusPanel |
|---|
| 56 | */ |
|---|
| 57 | public void connectClient() |
|---|
| 58 | { |
|---|
| 59 | simulationPanel.connectClient(); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | /** |
|---|
| 63 | * @see SimulationStatusPanel |
|---|
| 64 | */ |
|---|
| 65 | public void disconnectClient() |
|---|
| 66 | { |
|---|
| 67 | simulationPanel.disconnectClient(); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | /** |
|---|
| 71 | * @see SimulationStatusPanel |
|---|
| 72 | */ |
|---|
| 73 | public void setSimManagerStatus(boolean connection) |
|---|
| 74 | { |
|---|
| 75 | simulationPanel.setSimManagerStatus(connection); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | /** |
|---|
| 79 | * @see SimulationStatusPanel |
|---|
| 80 | */ |
|---|
| 81 | public void setTime(long seconds) |
|---|
| 82 | { |
|---|
| 83 | simulationPanel.setTime(seconds); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | /** |
|---|
| 87 | * @see SimulationStatusPanel |
|---|
| 88 | */ |
|---|
| 89 | public void setScriptStatus(SCRIPT_STATUS newStatus) |
|---|
| 90 | { |
|---|
| 91 | simulationPanel.setScriptStatus(newStatus); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * @see SimulationStatusPanel |
|---|
| 96 | */ |
|---|
| 97 | public void setParamicsStatus(PARAMICS_STATUS newStatus) |
|---|
| 98 | { |
|---|
| 99 | simulationPanel.setParamicsStatus(newStatus); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | /** |
|---|
| 103 | * @see SimulationStatusPanel |
|---|
| 104 | */ |
|---|
| 105 | public void setParamicsNetworkLoaded(String networkID) |
|---|
| 106 | { |
|---|
| 107 | simulationPanel.setParamicsNetworkLoaded(networkID); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | /** |
|---|
| 111 | * @see MediaStatusPanel |
|---|
| 112 | */ |
|---|
| 113 | public void updateDVDStatus(DVDStatusUpdate update) |
|---|
| 114 | { |
|---|
| 115 | mediaPanel.updateDVDStatus(update); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | /** |
|---|
| 119 | * @see MediaStatusPanel |
|---|
| 120 | */ |
|---|
| 121 | public void updateDVDTitle(DVDTitleUpdate update) |
|---|
| 122 | { |
|---|
| 123 | mediaPanel.updateDVDTitle(update); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | /** |
|---|
| 127 | * Method calls the processEvent() method with a WINDOW_CLOSING WindowEvent |
|---|
| 128 | * to start the application closing process. |
|---|
| 129 | */ |
|---|
| 130 | public void closeViewer() |
|---|
| 131 | { |
|---|
| 132 | processEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | /** |
|---|
| 136 | * Overloads the processEvent method. If the AWTEvent is a WINDOW_CLOSING |
|---|
| 137 | * event, prompt the user to confirm the action. If confirmed, close the |
|---|
| 138 | * application. |
|---|
| 139 | */ |
|---|
| 140 | protected void processEvent(AWTEvent evt) |
|---|
| 141 | { |
|---|
| 142 | |
|---|
| 143 | if (evt.getID() == WindowEvent.WINDOW_CLOSING) |
|---|
| 144 | { |
|---|
| 145 | int option = JOptionPane.showConfirmDialog(null, |
|---|
| 146 | "Closing the CAD Simulator will stop the current " |
|---|
| 147 | + "simulation. Do you wish to continue exiting?", |
|---|
| 148 | "Confirm Exit", |
|---|
| 149 | JOptionPane.YES_NO_OPTION); |
|---|
| 150 | |
|---|
| 151 | if (option != JOptionPane.NO_OPTION) |
|---|
| 152 | { |
|---|
| 153 | System.exit(0); |
|---|
| 154 | } |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | /** |
|---|
| 159 | * Initialize GUI Components |
|---|
| 160 | */ |
|---|
| 161 | private void initComponents() |
|---|
| 162 | { |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | simulationPanel = new SimulationStatusPanel(); |
|---|
| 166 | mediaPanel = new MediaStatusPanel(); |
|---|
| 167 | |
|---|
| 168 | cadSimTabbedPane = new JTabbedPane(); |
|---|
| 169 | cadSimTabbedPane.addTab("Status", simulationPanel); |
|---|
| 170 | cadSimTabbedPane.addTab("Media", mediaPanel); |
|---|
| 171 | |
|---|
| 172 | add(cadSimTabbedPane); |
|---|
| 173 | |
|---|
| 174 | menubar = new JMenuBar(); |
|---|
| 175 | |
|---|
| 176 | fileMenu = new JMenu("File"); |
|---|
| 177 | fileMenu.setMnemonic(KeyEvent.VK_F); |
|---|
| 178 | menubar.add(fileMenu); |
|---|
| 179 | |
|---|
| 180 | exitMenuItem = new JMenuItem(new ExitAction(this)); |
|---|
| 181 | exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( |
|---|
| 182 | KeyEvent.VK_X, ActionEvent.ALT_MASK)); |
|---|
| 183 | fileMenu.add(exitMenuItem); |
|---|
| 184 | |
|---|
| 185 | javax.swing.JMenu helpMenu = new javax.swing.JMenu("Help"); |
|---|
| 186 | javax.swing.JMenuItem aboutItem = new javax.swing.JMenuItem("About"); |
|---|
| 187 | |
|---|
| 188 | aboutItem.addActionListener(new java.awt.event.ActionListener() |
|---|
| 189 | { |
|---|
| 190 | public void actionPerformed(java.awt.event.ActionEvent evt) |
|---|
| 191 | { |
|---|
| 192 | String ver = RevisionNumber.getString(); |
|---|
| 193 | JOptionPane.showMessageDialog(rootPane, "Version: " + ver, "About", JOptionPane.INFORMATION_MESSAGE); |
|---|
| 194 | } |
|---|
| 195 | }); |
|---|
| 196 | helpMenu.add(aboutItem); |
|---|
| 197 | menubar.add(helpMenu); |
|---|
| 198 | |
|---|
| 199 | setJMenuBar(menubar); |
|---|
| 200 | |
|---|
| 201 | setPreferredSize(new Dimension(500, 575)); |
|---|
| 202 | pack(); |
|---|
| 203 | setResizable(false); |
|---|
| 204 | } |
|---|
| 205 | private JTabbedPane cadSimTabbedPane; |
|---|
| 206 | private JMenuBar menubar; |
|---|
| 207 | private JMenu fileMenu; |
|---|
| 208 | private JMenuItem exitMenuItem; |
|---|
| 209 | } |
|---|