| 1 | package tmcsim.client; |
|---|
| 2 | |
|---|
| 3 | import java.awt.BorderLayout; |
|---|
| 4 | import java.awt.Color; |
|---|
| 5 | import java.awt.Dimension; |
|---|
| 6 | import java.awt.Font; |
|---|
| 7 | import java.awt.event.KeyEvent; |
|---|
| 8 | import java.awt.event.KeyListener; |
|---|
| 9 | import java.util.Observable; |
|---|
| 10 | import java.util.Observer; |
|---|
| 11 | import java.util.TreeMap; |
|---|
| 12 | import java.util.logging.Level; |
|---|
| 13 | import java.util.logging.Logger; |
|---|
| 14 | |
|---|
| 15 | import javax.swing.BorderFactory; |
|---|
| 16 | import javax.swing.Box; |
|---|
| 17 | import javax.swing.BoxLayout; |
|---|
| 18 | import javax.swing.JFrame; |
|---|
| 19 | import javax.swing.JLabel; |
|---|
| 20 | import javax.swing.JOptionPane; |
|---|
| 21 | import javax.swing.JPanel; |
|---|
| 22 | import javax.swing.JTextPane; |
|---|
| 23 | import javax.swing.WindowConstants; |
|---|
| 24 | import javax.xml.parsers.DocumentBuilderFactory; |
|---|
| 25 | |
|---|
| 26 | import org.w3c.dom.Document; |
|---|
| 27 | import org.w3c.dom.Element; |
|---|
| 28 | |
|---|
| 29 | import tmcsim.cadmodels.BlankScreenModel; |
|---|
| 30 | import tmcsim.cadmodels.CADScreenModel; |
|---|
| 31 | import tmcsim.cadmodels.IncidentBoardModel; |
|---|
| 32 | import tmcsim.cadmodels.IncidentInquiryModel; |
|---|
| 33 | import tmcsim.cadmodels.IncidentSummaryModel; |
|---|
| 34 | import tmcsim.cadmodels.RoutedMessageModel; |
|---|
| 35 | import tmcsim.client.cadscreens.IB_IncidentBoard; |
|---|
| 36 | import tmcsim.client.cadscreens.II_IncidentInquiry; |
|---|
| 37 | import tmcsim.client.cadscreens.SA_IncidentSummary; |
|---|
| 38 | import tmcsim.client.cadscreens.TO_RoutedMessage; |
|---|
| 39 | import tmcsim.client.cadscreens.view.CADCommandLineView; |
|---|
| 40 | import tmcsim.client.cadscreens.view.CADFooterView; |
|---|
| 41 | import tmcsim.client.cadscreens.view.CADMainView; |
|---|
| 42 | import tmcsim.common.ObserverMessage; |
|---|
| 43 | import tmcsim.common.CADEnums.ARROW; |
|---|
| 44 | import tmcsim.common.CADEnums.CADScreenNum; |
|---|
| 45 | import tmcsim.common.CADEnums.CAD_ERROR; |
|---|
| 46 | import tmcsim.common.CADEnums.CAD_KEYS; |
|---|
| 47 | import tmcsim.common.CADProtocol.CAD_CLIENT_CMD; |
|---|
| 48 | import tmcsim.cadsimulator.viewer.model.CADSimulatorStatus; |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * The CADClientView class is the view component to the CAD Client application. |
|---|
| 52 | * |
|---|
| 53 | * This view class observers the CADClientModel, listening for updates |
|---|
| 54 | * from the CAD Simulator. Updates includes the current |
|---|
| 55 | * CAD time */ |
|---|
| 56 | @SuppressWarnings("serial") |
|---|
| 57 | public class CADClockView extends JFrame implements KeyListener, Observer { |
|---|
| 58 | |
|---|
| 59 | /** Error Logger. */ |
|---|
| 60 | private static Logger cadLogger = Logger.getLogger("tmcsim.client"); |
|---|
| 61 | |
|---|
| 62 | /** Reference to the CADClient model object. */ |
|---|
| 63 | private CADClientModel theModel = null; |
|---|
| 64 | |
|---|
| 65 | /** Current CAD Screen number. */ |
|---|
| 66 | private CADScreenNum currentScreenNum = null; |
|---|
| 67 | private JPanel mainPane; |
|---|
| 68 | private JLabel currentTime; |
|---|
| 69 | |
|---|
| 70 | /** |
|---|
| 71 | * Constructor. Build panes, add key listeners, and set up observer |
|---|
| 72 | * relationship between the footer and main panes. |
|---|
| 73 | * |
|---|
| 74 | * @param position |
|---|
| 75 | * The CAD position for this client terminal. |
|---|
| 76 | */ |
|---|
| 77 | public CADClockView(CADClientModel mod) { |
|---|
| 78 | super("CAD Client"); |
|---|
| 79 | this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|---|
| 80 | theModel = mod; |
|---|
| 81 | currentTime = new JLabel("0:00:00"); |
|---|
| 82 | CADSimulatorStatus status = new CADSimulatorStatus(); |
|---|
| 83 | String simtime = status.getCurrentTime(); |
|---|
| 84 | currentTime.setText(simtime); |
|---|
| 85 | currentTime.setAlignmentX(Box.CENTER_ALIGNMENT); |
|---|
| 86 | currentTime.setFont(new Font("Geneva", Font.BOLD, 70)); |
|---|
| 87 | mainPane = new JPanel(); |
|---|
| 88 | setSize(new Dimension(730, 455)); |
|---|
| 89 | setMaximumSize(new Dimension(730, 455)); |
|---|
| 90 | setMinimumSize(new Dimension(730, 455)); |
|---|
| 91 | mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
|---|
| 92 | mainPane.setBorder(BorderFactory.createLineBorder(Color.black)); |
|---|
| 93 | mainPane.setBackground(Color.LIGHT_GRAY); |
|---|
| 94 | mainPane.add(currentTime); |
|---|
| 95 | add(mainPane); |
|---|
| 96 | pack(); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | /** |
|---|
| 100 | * Observable update method. The CADClientView class is an observer of the |
|---|
| 101 | * CADClientModel. If the model sends a null object, it is signifying that |
|---|
| 102 | * it has shut down. In this case, an error message should be shown to prompt |
|---|
| 103 | * the user to restart the CAD Client. If the update object is an |
|---|
| 104 | * ObserverMessage object, the following actions are to be taken: |
|---|
| 105 | * |
|---|
| 106 | *<table cellpadding="2" cellspacing="2" border="1" |
|---|
| 107 | * style="text-align: left; width: 250px;"> |
|---|
| 108 | * <tbody> |
|---|
| 109 | * <tr> |
|---|
| 110 | * <th>Message Type</th> |
|---|
| 111 | * <th>Message Data</th> |
|---|
| 112 | * <th>Action Taken</th> |
|---|
| 113 | * </tr> |
|---|
| 114 | * <tr> |
|---|
| 115 | * <td>TIME_UPDATE<br></td> |
|---|
| 116 | * <td>Time String<br></td> |
|---|
| 117 | * <td>Update the footer pane with the new time.</td> |
|---|
| 118 | * </tr> |
|---|
| 119 | * </tbody> |
|---|
| 120 | *</table> |
|---|
| 121 | */ |
|---|
| 122 | public void update(Observable o, Object arg) { |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | if(arg == null) |
|---|
| 126 | { |
|---|
| 127 | JOptionPane.showMessageDialog(this, |
|---|
| 128 | "Connection to the CAD Simulator has been lost. " + |
|---|
| 129 | "Restart the CAD Client.", "Connection Error", |
|---|
| 130 | JOptionPane.ERROR_MESSAGE); |
|---|
| 131 | return; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | ObserverMessage oMessage = (ObserverMessage)arg; |
|---|
| 135 | |
|---|
| 136 | switch(oMessage.type) { |
|---|
| 137 | // Time updates occur once a minute |
|---|
| 138 | case TIME_UPDATE: |
|---|
| 139 | currentTime.setText("" + (String)oMessage.value); |
|---|
| 140 | break; |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | @Override |
|---|
| 145 | public void keyTyped(KeyEvent e) |
|---|
| 146 | { |
|---|
| 147 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | @Override |
|---|
| 151 | public void keyPressed(KeyEvent e) |
|---|
| 152 | { |
|---|
| 153 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | @Override |
|---|
| 157 | public void keyReleased(KeyEvent e) |
|---|
| 158 | { |
|---|
| 159 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | } |
|---|