| 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 java.io.IOException; |
|---|
| 9 | import java.util.Observable; |
|---|
| 10 | import java.util.Properties; |
|---|
| 11 | import java.util.logging.Level; |
|---|
| 12 | import java.util.logging.Logger; |
|---|
| 13 | import javax.swing.JFrame; |
|---|
| 14 | import javax.swing.JMenu; |
|---|
| 15 | import javax.swing.JMenuBar; |
|---|
| 16 | import javax.swing.JMenuItem; |
|---|
| 17 | import javax.swing.JOptionPane; |
|---|
| 18 | import javax.swing.JTabbedPane; |
|---|
| 19 | import javax.swing.KeyStroke; |
|---|
| 20 | import tmcsim.cadsimulator.managers.TrafficModelManager; |
|---|
| 21 | import tmcsim.cadsimulator.viewer.actions.ExitAction; |
|---|
| 22 | import tmcsim.cadsimulator.viewer.model.CADMediaStatus; |
|---|
| 23 | import tmcsim.cadsimulator.viewer.model.CADSimulatorStatus; |
|---|
| 24 | import tmcsim.interfaces.CADViewer; |
|---|
| 25 | import tmcsim.common.RevisionNumber; |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * This class provides a GUI to view current status information for the CAD |
|---|
| 29 | * Server. |
|---|
| 30 | * |
|---|
| 31 | * @see SimulationStatusPanel |
|---|
| 32 | * @see MediaStatusPanel |
|---|
| 33 | * @author Matthew Cechini |
|---|
| 34 | * @version $Revision: 1.3 $ $Date: 2006/06/06 20:46:41 $ |
|---|
| 35 | */ |
|---|
| 36 | @SuppressWarnings("serial") |
|---|
| 37 | public class CADServerViewer extends JFrame implements CADViewer |
|---|
| 38 | { |
|---|
| 39 | private JTabbedPane cadSimTabbedPane; |
|---|
| 40 | private JMenuBar menubar; |
|---|
| 41 | private JMenu fileMenu; |
|---|
| 42 | private JMenuItem exitMenuItem; |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * Panel to display simulation information. |
|---|
| 46 | */ |
|---|
| 47 | private SimulationStatusPanel simulationPanel; |
|---|
| 48 | /** |
|---|
| 49 | * Panel to display media control information. |
|---|
| 50 | */ |
|---|
| 51 | private MediaStatusPanel mediaPanel; |
|---|
| 52 | /** |
|---|
| 53 | * Panel to display configuration files. |
|---|
| 54 | */ |
|---|
| 55 | private ConfigStatusTab configPanel; |
|---|
| 56 | /* |
|---|
| 57 | * Panel to display Traffic Model Event Queue |
|---|
| 58 | */ |
|---|
| 59 | private TrafficModelViewPanel trafficPanel; |
|---|
| 60 | /* |
|---|
| 61 | * Name of propertes file for this run of CAD Server. |
|---|
| 62 | */ |
|---|
| 63 | private String propertiesFile; |
|---|
| 64 | |
|---|
| 65 | /** |
|---|
| 66 | * Constructor. |
|---|
| 67 | */ |
|---|
| 68 | public CADServerViewer(String propertiesFile) |
|---|
| 69 | { |
|---|
| 70 | super(); |
|---|
| 71 | this.propertiesFile = propertiesFile; |
|---|
| 72 | setTitle("CAD Server " + RevisionNumber.getAppVersion()); |
|---|
| 73 | |
|---|
| 74 | initComponents(); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | /** |
|---|
| 80 | * Method calls the processEvent() method with a WINDOW_CLOSING WindowEvent |
|---|
| 81 | * to start the application closing process. |
|---|
| 82 | */ |
|---|
| 83 | public void closeViewer() |
|---|
| 84 | { |
|---|
| 85 | processEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | /** |
|---|
| 89 | * Overloads the processEvent method. If the AWTEvent is a WINDOW_CLOSING |
|---|
| 90 | * event, prompt the user to confirm the action. If confirmed, close the |
|---|
| 91 | * application. |
|---|
| 92 | */ |
|---|
| 93 | protected void processEvent(AWTEvent evt) |
|---|
| 94 | { |
|---|
| 95 | |
|---|
| 96 | if (evt.getID() == WindowEvent.WINDOW_CLOSING) |
|---|
| 97 | { |
|---|
| 98 | // int option = JOptionPane.showConfirmDialog(null, |
|---|
| 99 | // "Closing the CAD Simulator will stop the current " |
|---|
| 100 | // + "simulation. Do you wish to continue exiting?", |
|---|
| 101 | // "Confirm Exit", |
|---|
| 102 | // JOptionPane.YES_NO_OPTION); |
|---|
| 103 | // |
|---|
| 104 | // if (option != JOptionPane.NO_OPTION) |
|---|
| 105 | // { |
|---|
| 106 | System.exit(0); |
|---|
| 107 | // } |
|---|
| 108 | } |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /** |
|---|
| 112 | * Initialize GUI Components |
|---|
| 113 | */ |
|---|
| 114 | private void initComponents() |
|---|
| 115 | { |
|---|
| 116 | simulationPanel = new SimulationStatusPanel(); |
|---|
| 117 | mediaPanel = new MediaStatusPanel(); |
|---|
| 118 | configPanel = new ConfigStatusTab(propertiesFile); |
|---|
| 119 | trafficPanel = new TrafficModelViewPanel(); |
|---|
| 120 | |
|---|
| 121 | cadSimTabbedPane = new JTabbedPane(); |
|---|
| 122 | cadSimTabbedPane.addTab("Status", simulationPanel); |
|---|
| 123 | cadSimTabbedPane.addTab("Media", mediaPanel); |
|---|
| 124 | cadSimTabbedPane.addTab("Config", configPanel); |
|---|
| 125 | cadSimTabbedPane.addTab("Traffic", trafficPanel); |
|---|
| 126 | |
|---|
| 127 | add(cadSimTabbedPane); |
|---|
| 128 | |
|---|
| 129 | menubar = new JMenuBar(); |
|---|
| 130 | |
|---|
| 131 | fileMenu = new JMenu("File"); |
|---|
| 132 | fileMenu.setMnemonic(KeyEvent.VK_F); |
|---|
| 133 | menubar.add(fileMenu); |
|---|
| 134 | |
|---|
| 135 | exitMenuItem = new JMenuItem(new ExitAction(this)); |
|---|
| 136 | exitMenuItem.setAccelerator(KeyStroke.getKeyStroke( |
|---|
| 137 | KeyEvent.VK_X, ActionEvent.ALT_MASK)); |
|---|
| 138 | fileMenu.add(exitMenuItem); |
|---|
| 139 | |
|---|
| 140 | javax.swing.JMenu helpMenu = new javax.swing.JMenu("Help"); |
|---|
| 141 | |
|---|
| 142 | menubar.add(helpMenu); |
|---|
| 143 | |
|---|
| 144 | setJMenuBar(menubar); |
|---|
| 145 | |
|---|
| 146 | setPreferredSize(new Dimension(500, 575)); |
|---|
| 147 | pack(); |
|---|
| 148 | setResizable(true); |
|---|
| 149 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | @Override |
|---|
| 153 | public void update(Observable obs, Object obj) |
|---|
| 154 | { |
|---|
| 155 | if (obs instanceof CADSimulatorStatus) |
|---|
| 156 | { |
|---|
| 157 | simulationPanel.refresh(obs); |
|---|
| 158 | } |
|---|
| 159 | if (obs instanceof CADMediaStatus) |
|---|
| 160 | { |
|---|
| 161 | mediaPanel.refresh(obs); |
|---|
| 162 | } |
|---|
| 163 | if (obs instanceof TrafficModelManager) |
|---|
| 164 | { |
|---|
| 165 | trafficPanel.update(obs, obj); |
|---|
| 166 | } |
|---|
| 167 | } |
|---|
| 168 | } |
|---|