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

Revision 58, 5.6 KB checked in by jdalbey, 9 years ago (diff)

CADClockView.java: change font

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