| 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 | * Panel to display configuration files. |
|---|
| 45 | */ |
|---|
| 46 | private ConfigStatusPanel configPanel; |
|---|
| 47 | /** |
|---|
| 48 | * Constructor. |
|---|
| 49 | */ |
|---|
| 50 | |
|---|
| 51 | public CADSimulatorViewer() |
|---|
| 52 | { |
|---|
| 53 | super("CAD Simulator"); |
|---|
| 54 | |
|---|
| 55 | initComponents(); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | /** |
|---|
| 59 | * @see SimulationStatusPanel |
|---|
| 60 | */ |
|---|
| 61 | public void connectClient() |
|---|
| 62 | { |
|---|
| 63 | simulationPanel.connectClient(); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | /** |
|---|
| 67 | * @see SimulationStatusPanel |
|---|
| 68 | */ |
|---|
| 69 | public void disconnectClient() |
|---|
| 70 | { |
|---|
| 71 | simulationPanel.disconnectClient(); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * @see SimulationStatusPanel |
|---|
| 76 | */ |
|---|
| 77 | public void setSimManagerStatus(boolean connection) |
|---|
| 78 | { |
|---|
| 79 | simulationPanel.setSimManagerStatus(connection); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | /** |
|---|
| 83 | * @see SimulationStatusPanel |
|---|
| 84 | */ |
|---|
| 85 | public void setTime(long seconds) |
|---|
| 86 | { |
|---|
| 87 | simulationPanel.setTime(seconds); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | /** |
|---|
| 91 | * @see SimulationStatusPanel |
|---|
| 92 | */ |
|---|
| 93 | public void setScriptStatus(SCRIPT_STATUS newStatus) |
|---|
| 94 | { |
|---|
| 95 | simulationPanel.setScriptStatus(newStatus); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | /** |
|---|
| 99 | * @see SimulationStatusPanel |
|---|
| 100 | */ |
|---|
| 101 | public void setParamicsStatus(PARAMICS_STATUS newStatus) |
|---|
| 102 | { |
|---|
| 103 | simulationPanel.setParamicsStatus(newStatus); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | /** |
|---|
| 107 | * @see SimulationStatusPanel |
|---|
| 108 | */ |
|---|
| 109 | public void setParamicsNetworkLoaded(String networkID) |
|---|
| 110 | { |
|---|
| 111 | simulationPanel.setParamicsNetworkLoaded(networkID); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | /** |
|---|
| 115 | * @see MediaStatusPanel |
|---|
| 116 | */ |
|---|
| 117 | public void updateDVDStatus(DVDStatusUpdate update) |
|---|
| 118 | { |
|---|
| 119 | mediaPanel.updateDVDStatus(update); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | /** |
|---|
| 123 | * @see MediaStatusPanel |
|---|
| 124 | */ |
|---|
| 125 | public void updateDVDTitle(DVDTitleUpdate update) |
|---|
| 126 | { |
|---|
| 127 | mediaPanel.updateDVDTitle(update); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | /** |
|---|
| 131 | * Method calls the processEvent() method with a WINDOW_CLOSING WindowEvent |
|---|
| 132 | * to start the application closing process. |
|---|
| 133 | */ |
|---|
| 134 | public void closeViewer() |
|---|
| 135 | { |
|---|
| 136 | processEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | /** |
|---|
| 140 | * Overloads the processEvent method. If the AWTEvent is a WINDOW_CLOSING |
|---|
| 141 | * event, prompt the user to confirm the action. If confirmed, close the |
|---|
| 142 | * application. |
|---|
| 143 | */ |
|---|
| 144 | protected void processEvent(AWTEvent evt) |
|---|
| 145 | { |
|---|
| 146 | |
|---|
| 147 | if (evt.getID() == WindowEvent.WINDOW_CLOSING) |
|---|
| 148 | { |
|---|
| 149 | int option = JOptionPane.showConfirmDialog(null, |
|---|
| 150 | "Closing the CAD Simulator will stop the current " |
|---|
| 151 | + "simulation. Do you wish to continue exiting?", |
|---|
| 152 | "Confirm Exit", |
|---|
| 153 | JOptionPane.YES_NO_OPTION); |
|---|
| 154 | |
|---|
| 155 | if (option != JOptionPane.NO_OPTION) |
|---|
| 156 | { |
|---|
| 157 | System.exit(0); |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | /** |
|---|
| 163 | * Initialize GUI Components |
|---|
| 164 | */ |
|---|
| 165 | private void initComponents() |
|---|
| 166 | { |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | simulationPanel = new SimulationStatusPanel(); |
|---|
| 170 | mediaPanel = new MediaStatusPanel(); |
|---|
| 171 | configPanel = new ConfigStatusPanel(); |
|---|
| 172 | |
|---|
| 173 | cadSimTabbedPane = new JTabbedPane(); |
|---|
| 174 | cadSimTabbedPane.addTab("Status", simulationPanel); |
|---|
| 175 | cadSimTabbedPane.addTab("Media", mediaPanel); |
|---|
| 176 | cadSimTabbedPane.addTab("Config", configPanel); |
|---|
| 177 | |
|---|
| 178 | add(cadSimTabbedPane); |
|---|
| 179 | |
|---|
| 180 | menubar = new JMenuBar(); |
|---|
| 181 | |
|---|
| 182 | fileMenu = new JMenu("File"); |
|---|
| 183 | fileMenu.setMnemonic(KeyEvent.VK_F); |
|---|
| 184 | menubar.add(fileMenu); |
|---|
| 185 | |
|---|
| 186 | exitMenuItem = new JMenuItem(new ExitAction(this)); |
|---|
| 187 | exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( |
|---|
| 188 | KeyEvent.VK_X, ActionEvent.ALT_MASK)); |
|---|
| 189 | fileMenu.add(exitMenuItem); |
|---|
| 190 | |
|---|
| 191 | javax.swing.JMenu helpMenu = new javax.swing.JMenu("Help"); |
|---|
| 192 | javax.swing.JMenuItem aboutItem = new javax.swing.JMenuItem("About"); |
|---|
| 193 | |
|---|
| 194 | aboutItem.addActionListener(new java.awt.event.ActionListener() |
|---|
| 195 | { |
|---|
| 196 | public void actionPerformed(java.awt.event.ActionEvent evt) |
|---|
| 197 | { |
|---|
| 198 | String ver = RevisionNumber.getString(); |
|---|
| 199 | JOptionPane.showMessageDialog(rootPane, "Version: " + ver, "About", JOptionPane.INFORMATION_MESSAGE); |
|---|
| 200 | } |
|---|
| 201 | }); |
|---|
| 202 | helpMenu.add(aboutItem); |
|---|
| 203 | menubar.add(helpMenu); |
|---|
| 204 | |
|---|
| 205 | setJMenuBar(menubar); |
|---|
| 206 | |
|---|
| 207 | setPreferredSize(new Dimension(500, 575)); |
|---|
| 208 | pack(); |
|---|
| 209 | setResizable(true); |
|---|
| 210 | } |
|---|
| 211 | private JTabbedPane cadSimTabbedPane; |
|---|
| 212 | private JMenuBar menubar; |
|---|
| 213 | private JMenu fileMenu; |
|---|
| 214 | private JMenuItem exitMenuItem; |
|---|
| 215 | } |
|---|