source: tmcsimulator/trunk/src/tmcsim/client/CADClockView.java @ 54

Revision 54, 4.5 KB checked in by jdalbey, 9 years ago (diff)

Coordinator.java: updates with error checking for bad input parameters, add CADicon.png, mp3 jar

Line 
1package tmcsim.client;
2
3import java.awt.Color;
4import java.awt.Dimension;
5import java.awt.event.KeyEvent;
6import java.awt.event.KeyListener;
7import java.util.Observable;
8import java.util.Observer;
9import java.util.TreeMap;
10import java.util.logging.Level;
11import java.util.logging.Logger;
12
13import javax.swing.BorderFactory;
14import javax.swing.Box;
15import javax.swing.BoxLayout;
16import javax.swing.JFrame;
17import javax.swing.JOptionPane;
18import javax.swing.JPanel;
19import javax.swing.JTextPane;
20import javax.xml.parsers.DocumentBuilderFactory;
21
22import org.w3c.dom.Document;
23import org.w3c.dom.Element;
24
25import tmcsim.cadmodels.BlankScreenModel;
26import tmcsim.cadmodels.CADScreenModel;
27import tmcsim.cadmodels.IncidentBoardModel;
28import tmcsim.cadmodels.IncidentInquiryModel;
29import tmcsim.cadmodels.IncidentSummaryModel;
30import tmcsim.cadmodels.RoutedMessageModel;
31import tmcsim.client.cadscreens.IB_IncidentBoard;
32import tmcsim.client.cadscreens.II_IncidentInquiry;
33import tmcsim.client.cadscreens.SA_IncidentSummary;
34import tmcsim.client.cadscreens.TO_RoutedMessage;
35import tmcsim.client.cadscreens.view.CADCommandLineView;
36import tmcsim.client.cadscreens.view.CADFooterView;
37import tmcsim.client.cadscreens.view.CADMainView;
38import tmcsim.common.ObserverMessage;
39import tmcsim.common.CADEnums.ARROW;
40import tmcsim.common.CADEnums.CADScreenNum;
41import tmcsim.common.CADEnums.CAD_ERROR;
42import tmcsim.common.CADEnums.CAD_KEYS;
43import 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")
52public 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}   
Note: See TracBrowser for help on using the repository browser.