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