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