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

Revision 57, 5.2 KB checked in by jdalbey, 9 years ago (diff)

Clock Client first draft

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