source: tmcsimulator/trunk/src/tmcsim/client/CADClientView.java @ 37

Revision 37, 29.8 KB checked in by bokumura, 10 years ago (diff)

Gets rid of the flashing black box when starting the client. (Legacy from the old CAD Client)

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 * The CADSCreen is displayed with three separate view components: Command Line,
48 * Main Text Area, and Footer.  User input is handled by the Command Line Pane.
49 * Any commands are sent to the model which are then transmitted to the
50 * CAD Simulator.  The view keeps track of current CAD Screen Number and the
51 * current page being displayed on each screen.  This allows for the screen
52 * refresh and cycle commands to return the screen to its previous page.
53 *
54 * This view class observers the CADClientModel, listening for updates
55 * from the CAD Simulator.  Updates include new CADScreenModel objects notifying
56 * that a new screen is to be displayed.  Other update data includes the current
57 * CAD time, number of routed messages, screen update map, and information messages. 
58 * These are all displayed in the CAD Footer.
59 *
60 * @author Matthew Cechini (mcechini@calpoly.edu)
61 * @version $Date: 2009/04/20 17:58:27 $ $Revision: 1.7 $
62 */
63@SuppressWarnings("serial")
64public class CADClientView extends JFrame implements KeyListener, Observer {
65   
66    /** Error Logger. */
67    private static Logger cadLogger = Logger.getLogger("tmcsim.client");
68   
69    /** Reference to the CADClient model object. */
70    private CADClientModel theModel = null;
71     
72    /** View pane for the CAD Screen command line area. */
73    private CADCommandLineView CADCommandLinePane = null;
74     
75    /** View pane for the CAD Screen main area. */
76    private CADMainView        CADMainPane        = null;
77     
78    /** View pane for the CAD Screen footer area. */
79    private CADFooterView      CADFooterPane      = null;   
80   
81    /** CAD Command Line Parser.  */
82    private CADCommandParser cmdParser;
83
84    /** Boolean flag to designate whether the shift key is being pressed. */
85    private boolean shiftKeyPressed = false;
86         
87    /** Current CAD Screen number. */
88    private CADScreenNum currentScreenNum = null;
89   
90    /** Map of CADScreen numbers and the current page displayed on that screen. */
91    private TreeMap<CADScreenNum, Integer> pageLocationMap = null;
92   
93    /** Flag designating whether the screen's page location has been saved. */
94    private boolean pageLocationSaved = false;
95
96    /**
97     * Constructor. Build panes, add key listeners, and set up observer
98     * relationship between the footer and main panes.
99     *
100     * @param position
101     *            The CAD position for this client terminal.
102     */
103    public CADClientView(CADClientModel mod) {
104        super("CAD Client");
105        theModel = mod;
106       
107       
108        cmdParser = new CADCommandParser();
109       
110        //Build and initialize all initial screens to the first page.
111        pageLocationMap = new TreeMap<CADScreenNum, Integer>();
112        for(CADScreenNum screen : CADScreenNum.values()) 
113        {
114            pageLocationMap.put(screen, 1);
115        }
116       
117        currentScreenNum = CADScreenNum.orderedList().get(0);
118       
119        buildPanes();       
120        buildPanels();
121
122        cmdLineTextPane.addKeyListener(this);
123        mainTextPane.addKeyListener(this);
124        footerTextPane.addKeyListener(this);
125   
126
127        CADMainPane.addObserver(CADFooterPane);
128       
129    }
130   
131    /**
132     * Build the command line, main, and footer text panes.
133     */
134    private void buildPanes() {
135
136        cmdLineTextPane    = new JTextPane();
137        cmdLineTextPane.setSize(new Dimension(730, 50)); 
138        cmdLineTextPane.setMinimumSize(new Dimension(730, 50));
139        cmdLineTextPane.setMaximumSize(new Dimension(730, 50));
140        cmdLineTextPane.setBorder(BorderFactory.createLineBorder(Color.black));
141
142        cmdLineTextPane.setBackground(Color.black);
143        cmdLineTextPane.setEditable(false);
144        CADCommandLinePane = new CADCommandLineView(cmdLineTextPane);
145       
146        mainTextPane = new JTextPane();
147        mainTextPane.setSize(new Dimension(730, 455));
148        mainTextPane.setMaximumSize(new Dimension(730, 455));
149        mainTextPane.setMinimumSize(new Dimension(730, 455));
150        mainTextPane.setBorder(BorderFactory.createLineBorder(Color.black));   
151        mainTextPane.setBackground(Color.black);
152        mainTextPane.setEditable(false); 
153        CADMainPane  = new CADMainView(mainTextPane.getDocument());     
154
155        footerTextPane = new JTextPane();
156        footerTextPane.setSize(new Dimension(730, 95)); 
157        footerTextPane.setMaximumSize(new Dimension(730, 95));
158        footerTextPane.setMinimumSize(new Dimension(730, 95));
159        footerTextPane.setBorder(BorderFactory.createLineBorder(Color.black));   
160        footerTextPane.setBackground(Color.black);
161        footerTextPane.setEditable(false);
162        CADFooterPane  = new CADFooterView(footerTextPane.getDocument());
163    }
164   
165   
166    /**
167     * Build the command line, main, and footer panels.
168     */
169    private void buildPanels() {
170       
171        cmdLinePanel = new JPanel();
172        cmdLinePanel.setSize(new Dimension(800, 50)); 
173        cmdLinePanel.setMinimumSize(new Dimension(800, 50));
174        cmdLinePanel.setMaximumSize(new Dimension(800, 50));
175        cmdLinePanel.setBackground(Color.black);
176       
177        Box cmdLineBox = new Box(BoxLayout.Y_AXIS);
178        cmdLineBox.add(Box.createHorizontalStrut(35));
179        cmdLineBox.add(cmdLineTextPane);
180        cmdLineBox.add(Box.createHorizontalStrut(35));
181       
182        cmdLinePanel.add(cmdLineBox);
183       
184        //***************************************************//
185       
186        mainPanel    = new JPanel();
187        mainPanel.setSize(new Dimension(800, 455)); 
188        mainPanel.setMaximumSize(new Dimension(800, 455));
189        mainPanel.setMinimumSize(new Dimension(800, 455));
190        mainPanel.setBackground(Color.black);
191       
192       
193        Box mainBox = new Box(BoxLayout.Y_AXIS);
194        mainBox.add(Box.createHorizontalStrut(35));
195        mainBox.add(mainTextPane);
196        mainBox.add(Box.createHorizontalStrut(35));
197       
198        mainPanel.add(mainBox);
199
200        //***************************************************//
201       
202        footerPanel  = new JPanel();       
203        footerPanel.setSize(new Dimension(800, 95)); 
204        footerPanel.setMaximumSize(new Dimension(800, 95));
205        footerPanel.setMinimumSize(new Dimension(800, 95));
206        footerPanel.setBackground(Color.black);
207       
208        Box footerBox = new Box(BoxLayout.Y_AXIS);
209        footerBox.add(Box.createHorizontalStrut(35));
210        footerBox.add(footerTextPane);
211        footerBox.add(Box.createHorizontalStrut(35));
212       
213        footerPanel.add(footerBox);
214       
215    }
216       
217   
218    /**
219     * Method adds the three CAD Screen components (CommandLine, MainTextArea,
220     * Footer) to this view class.  The background is set to black, resized
221     * to 800x600, and shown to the screen.
222     */
223    public void initWindow() {
224        add(initBox());
225
226        addKeyListener(this);
227        setBackground(Color.black);     
228        setSize(new Dimension(800, 600));
229        setUndecorated(true); 
230        setDefaultCloseOperation(EXIT_ON_CLOSE);
231        //setVisible(true);       
232               
233    }
234   
235    /**
236     * Method contructs a box out of the three CAD Screen components:
237     * CommandLine, MainTextArea, Footer.  The Command Line panel is placed
238     * above the main text area panel, which is above the footer panel.
239     *
240     * @return Box Box containing all three panels.
241     */
242    public Box initBox() {
243        Box theBox = new Box(BoxLayout.Y_AXIS);
244        theBox.add(cmdLinePanel);
245        theBox.add(mainPanel);
246        theBox.add(footerPanel);   
247        theBox.setBackground(Color.black);
248       
249        return theBox;
250    }
251
252    /** 
253     * This method is called by the implemented KeyListener whenever a key is pressed.  The following
254     * keystrokes are listened for in this method.  Each keystroke pressed is referenced by the keycode
255     * for the associated key.  These key codes are defined in the CADProtocol class.
256     *
257     *
258     *<table cellpadding="2" cellspacing="2" border="1"
259     * style="text-align: left; width: 250px;">
260     *  <tbody>
261     *    <tr>
262     *      <th>CAD Protocol Command<br></th>
263     *      <th>Action Taken<br></th>
264     *    </tr>
265     *    <tr>
266     *      <td>SHIFT_KEY<br></td>
267     *      <td>Set shiftKeyPressed flag to true.<br></td>
268     *    </tr>
269     *    <tr>
270     *      <td>COMMAND_LINE_CLEAR<br></td>
271     *      <td>If the shift key is pressed, clear the current CAD Screen's command line.<br></td>
272     *    </tr>
273     *    <tr>
274     *      <td>SCREEN_CLEAR<br></td>
275     *      <td>If the shift key is pressed, transmit the SCREEN_CLEAR
276     *          command as a TERMINAL_FUNCTION to the CAD Simulator<br></td>
277     *   </tr>
278     *  </tbody>
279     *</table>
280     *
281     * @param e KeyEvent
282     */
283    public void keyPressed(KeyEvent evt) { 
284       //System.out.println("keyPressed" + evt.getKeyCode());   
285       
286        switch(CAD_KEYS.fromValue(CAD_KEYS.keyboard_type, evt.getKeyCode())) { 
287            case  SHIFT_KEY: 
288                shiftKeyPressed = true;
289                break; 
290               
291            case COMMAND_LINE_CLEAR:       
292                if(shiftKeyPressed)  {
293                    CADCommandLinePane.clearCommandLine();
294                }
295                break;
296   
297            case SCREEN_CLEAR:     
298                if(shiftKeyPressed) {         
299                    try {
300                        Document cmdDoc = DocumentBuilderFactory.newInstance()
301                            .newDocumentBuilder().newDocument();
302                        Element cmdElem = cmdDoc.createElement(
303                                CAD_CLIENT_CMD.TERMINAL_FUNCTION.type);                 
304                        cmdElem.appendChild(cmdDoc.createTextNode(
305                                CAD_KEYS.keyboard_type + ":" + 
306                                String.valueOf(evt.getKeyCode())));                 
307                        cmdDoc.appendChild(cmdElem);           
308                        theModel.transmitCommand(cmdDoc);                           
309                    } catch (Exception e) {
310                        cadLogger.logp(Level.SEVERE, "CADClientView", "keyPressed()",
311                                "Exception in sending screen clear command.", e);
312                    }
313                }
314                break;     
315        }
316    }
317       
318    /**
319     * This method is called by the implemented KeyListener whenever a key is released.  The following
320     * keystrokes are listened for in this method.  Each keystroke released is referenced by the keycode
321     * for the associated key.  These key codes are defined in the CADProtocol class.
322     *
323     *<table cellpadding="2" cellspacing="2" border="1"
324     * style="text-align: left; width: 250px;">
325     *  <tbody>
326     *    <tr>
327     *      <th>CAD Protocol Command<br></th>
328     *      <th>Action Taken<br></th>
329     *    </tr>
330     *    <tr>
331     *      <td>SHIFT_KEY<br></td>
332     *      <td>Set the shiftKeyPressed flag to false.<br></td>
333     *    </tr>
334     *    <tr>
335     *      <td>CYCLE<br></td>
336     *      <td>Preserve the current page number to return the screen to the same location after
337     *          the cycle.  Transmit the current command line to the CAD Simulator with a
338     *          SAVE_COMMAND_LINE message type.  Transmit the CYCLE command as a
339     *          TERMINAL_FUNCTION to the CAD Simulator.<br></td>
340     *    </tr>
341     *    <tr>
342     *      <td>REFRESH<br></td>
343     *      <td>Preserve the current page number to return the screen to the same location after
344     *          the refresh.  Transmit the current command line to the CAD Simulator with a
345     *          SAVE_COMMAND_LINE message type.  Transmit the CYCLE command as a
346     *          TERMINAL_FUNCTION to the CAD Simulator.<br></td>
347     *    </tr>
348     *    <tr>
349     *      <td>PGDN</td>
350     *      <td>Notify the main pane object of the received page down command.<br></td>
351     *    </tr>
352     *    <tr>
353     *      <td>PGUP</td>
354     *      <td>Notify the main pane object of the received page up command.<br> </td>
355     *    </tr>
356     *    <tr>
357     *      <td>LEFT_ARROW</td>
358     *      <td>Notify the command line pane object of the received left arrow.<br> </td>
359     *    </tr>
360     *    <tr>
361     *      <td>UP_ARROW</td>
362     *      <td>Notify the command line pane object of the received up arrow.<br> </td>
363     *    </tr>
364     *    <tr>
365     *      <td>RIGHT_ARROW</td>
366     *      <td>Notify the command line pane object of the received right arrow.<br> </td>
367     *    </tr>
368     *    <tr>
369     *      <td>DOWN_ARROW</td>
370     *      <td>Notify the command line pane object of the received down arrow.<br> </td>
371     *    </tr>
372     *    <tr>
373     *      <td>COMMAND_LINE_TX<br> </td>
374     *      <td>Parse the current command line and create an XMLWriter with the
375     *          converted XML representation of the command line data.
376     *          Transmit the command line as a TERMINAL_CMD_LINE message to
377     *          the CAD Simulator.  Clear the current CAD screen's command line.
378     *          If there is an error in parsing, show the corresponding error
379     *          message and clear the command line.<br></td>
380     *    </tr>
381     *    <tr>
382     *      <td>NEXT_QUEUE<br></td>
383     *      <td>Transmit the NEXT_QUEUE command as a TERMINAL_FUNCTION to the CAD Simulator.<br></td>
384     *    </tr>
385     *    <tr>
386     *      <td>DELETE_QUEUE<br></td>
387     *      <td>Transmit the DELETE_QUEUE command as a TERMINAL_FUNCTION to the CAD Simulator.<br></td>
388     *    </tr>
389     *    <tr>
390     *      <td>PREV_QUEUE<br></td>
391     *      <td>Transmit the PREV_QUEUE command as a TERMINAL_FUNCTION to the CAD Simulator.<br></td>
392     *    </tr>
393     *    <tr>
394     *      <td>BACKSPACE<br></td>
395     *      <td>Notify the command line pane of the received backspace command.<br></td>
396     *    </tr>
397     *    <tr>
398     *      <td>ENTER<br></td>
399     *      <td>Currently, do nothing<br></td>
400     *    </tr>
401     *  </tbody>
402     *</table>
403     *
404     * @param e KeyEvent
405     */       
406    public void keyReleased(KeyEvent evt) {
407       //System.out.println("keyReleased" + evt.getKeyCode());       
408       
409        switch(CAD_KEYS.fromValue(CAD_KEYS.keyboard_type, evt.getKeyCode())) { 
410           
411            case  SHIFT_KEY: 
412                shiftKeyPressed = false;
413                break; 
414
415            case REFRESH:
416            case CYCLE: 
417
418                pageLocationSaved = true;
419                pageLocationMap.put(currentScreenNum, CADMainPane.getCurrentPage());
420
421                try {
422                    Document cmdDoc = DocumentBuilderFactory.newInstance()
423                            .newDocumentBuilder().newDocument();
424                    Element cmdElem = cmdDoc.createElement(
425                            CAD_CLIENT_CMD.SAVE_COMMAND_LINE.type);                 
426                    cmdElem.appendChild(cmdDoc.createTextNode(
427                            CADCommandLinePane.getCommandLine()));
428                    cmdDoc.appendChild(cmdElem);                                   
429                    theModel.transmitCommand(cmdDoc);
430                                       
431                    cmdDoc = DocumentBuilderFactory.newInstance()
432                            .newDocumentBuilder().newDocument();
433                    cmdElem = cmdDoc.createElement(
434                            CAD_CLIENT_CMD.TERMINAL_FUNCTION.type);                 
435                    cmdElem.appendChild(cmdDoc.createTextNode(
436                            CAD_KEYS.keyboard_type + ":" + 
437                            String.valueOf(evt.getKeyCode())));                 
438                    cmdDoc.appendChild(cmdElem);           
439                    theModel.transmitCommand(cmdDoc);           
440                   
441                } catch (Exception e) {
442                    cadLogger.logp(Level.SEVERE, "CADClientView", 
443                            "keyReleased()",
444                            "Exception in sending cycle command.", e);
445                }
446                break;                 
447           
448            case PGDN:
449               
450               CADMainPane.pageDown();
451               break;
452           
453            case PGUP: 
454           
455               CADMainPane.pageUp();
456               break; 
457               
458            case LEFT_ARROW: 
459           
460               CADCommandLinePane.receiveArrow(ARROW.LEFT);
461               break; 
462               
463            case UP_ARROW: 
464           
465               CADCommandLinePane.receiveArrow(ARROW.UP);
466               break; 
467   
468            case RIGHT_ARROW: 
469           
470               CADCommandLinePane.receiveArrow(ARROW.RIGHT);
471               break; 
472   
473            case DOWN_ARROW: 
474           
475               CADCommandLinePane.receiveArrow(ARROW.DOWN);
476               break;                                                 
477   
478            case COMMAND_LINE_TX:
479                   
480                try {
481                    Document cmdDoc = DocumentBuilderFactory.newInstance()
482                        .newDocumentBuilder().newDocument();
483                    Element cmdElem = cmdDoc.createElement(CAD_CLIENT_CMD.TERMINAL_CMD_LINE.type);
484                   
485                    cmdParser.parseCommand(cmdElem, CADCommandLinePane.getCommandLine());
486                    cmdDoc.appendChild(cmdElem);
487               
488                    theModel.transmitCommand(cmdDoc);
489           
490                    CADCommandLinePane.clearCommandLine();
491
492                    pageLocationSaved = false;
493                }
494                catch (Exception ex) {
495                    CADFooterPane.displayInfoMessage(CAD_ERROR.UNAUTH_CMD.message);
496                    CADCommandLinePane.clearCommandLine();
497                }
498                break; 
499   
500            case PREV_QUEUE:
501            case DELETE_QUEUE:
502            case NEXT_QUEUE:
503                try {
504                    Document cmdDoc = DocumentBuilderFactory.newInstance()
505                            .newDocumentBuilder().newDocument();
506                    Element cmdElem = cmdDoc.createElement(
507                            CAD_CLIENT_CMD.TERMINAL_FUNCTION.type);
508                                       
509                    cmdElem.appendChild(cmdDoc.createTextNode(
510                            CAD_KEYS.keyboard_type + ":" + 
511                            String.valueOf(evt.getKeyCode())));
512                    cmdDoc.appendChild(cmdElem);                   
513                    theModel.transmitCommand(cmdDoc);
514   
515                } catch (Exception e) {
516                    cadLogger.logp(Level.SEVERE, "CADClientView", "keyReleased()",
517                            "Exception in sending queue command.", e);
518                }
519                break;
520
521            case BACKSPACE:
522               CADCommandLinePane.backspace();
523               break;       
524            case ENTER:                   
525                break;
526            default: 
527        }
528               
529    }
530
531    /**
532     * This method implements the necessary KeyListener functionality, and is
533     * called whenever a key is typed.  Only letters, numbers, and standard
534     * keyboard symbols, whose ascii value is between 32(inclusive) and
535     * 127(exclusive).  Lower case character are in the range between 97 and
536     * 122, inclusive.  These characters are made uppercase by substracting
537     * 32 from their ascii value.  The ascii value for an upper case character
538     * is 32 less than its lower case representation.  The valid character
539     * is then sent to the CADCommandLinePane.
540     *
541     * @param e KeyEvent received.
542     */
543    public void keyTyped(KeyEvent e) {
544        //System.out.println("keyTyped" + e.getKeyCode());
545       
546        char key = e.getKeyChar();
547        //if valid character
548        if(key >= 32 && key < 127) {
549            //lower case letter
550            if(key >= 97 && key <= 122)
551                key -= 32; //make uppercase
552           
553            CADCommandLinePane.receiveKeyPress(key);               
554           
555        }
556    }
557
558    /**
559     * Observable update method.  The CADClientView class is an observer of the
560     * CADClientModel.  If the model sends a null object, it is signifying that
561     * it has shut down.  In this case, an error message should be shown to prompt
562     * the user to restart the CAD Client.  If the update object is an
563     * ObserverMessage object, the following actions are to be taken:
564     *
565     *<table cellpadding="2" cellspacing="2" border="1"
566     * style="text-align: left; width: 250px;">
567     *  <tbody>
568     *    <tr>
569     *      <th>Message Type</th>
570     *      <th>Message Data</th>
571     *      <th>Action Taken</th>
572     *    </tr>
573     *    <tr>
574     *      <td>INCIDENT_INQUIRY<br></td>
575     *      <td>IncidentInquiryModel<br></td>
576     *      <td>Construct a new II_IncidentInquiry view pane from the model data.
577     *          Reset the observer relationship between the footer and main pane.
578     *          Update the page location map and update the views with the model data.
579     *      </td>
580     *    </tr>
581     *    <tr>
582     *      <td>INCIDENT_SUMMARY<br></td>
583     *      <td>IncidentSummaryModel<br></td>
584     *      <td>Construct a new SA_IncidentSummary view pane from the model data.
585     *          Reset the observer relationship between the footer and main pane.
586     *          Update the page location map and update the views with the model data.
587     *      </td>
588     *    </tr>
589     *    <tr>
590     *      <td>INCIDENT_BOARD<br></td>
591     *      <td>IncidentBoardModel<br></td>
592     *      <td>Construct a new IB_IncidentBoard view pane from the model data.
593     *          Reset the observer relationship between the footer and main pane.
594     *          Update the page location map and update the views with the model data.
595     *      </td>
596     *    </tr>
597     *    <tr>
598     *      <td>ROUTED_MESSAGE<br></td>
599     *      <td>RoutedMessageModel<br></td>
600     *      <td>Construct a new TO_RoutedMessage view pane from the model data.
601     *          Reset the observer relationship between the footer and main pane.
602     *          Update the page location map and update the views with the model data.
603     *      </td>
604     *    </tr>
605     *    <tr>
606     *      <td>BLANK_SCREEN<br></td>
607     *      <td>BlankScreenModel<br></td>
608     *      <td>Construct a new empty view pane.
609     *          Reset the observer relationship between the footer and main pane.
610     *          Update the page location map and update the views with the model data.
611     *      </td>
612     *    </tr>
613     *    <tr>
614     *      <td>SCREEN_UPDATE<br></td>
615     *      <td>TreeMap<CADScreenNum, Boolean><br></td>
616     *      <td>Update the footer pane with the new screen updates map.</td>
617     *    </tr>
618     *    <tr>
619     *      <td>TIME_UPDATE<br></td>
620     *      <td>Time String<br></td>
621     *      <td>Update the footer pane with the new time.</td>
622     *    </tr>
623     *    <tr>
624     *      <td>ROUTED_MESSAGE_COUNT_UPDATE<br></td>
625     *      <td># Routed Messages<br></td>
626     *      <td>Update the footer pane with the new number of routed messages.</td>
627     *    </tr>
628     *    <tr>
629     *      <td>ROUTED_MESSAGE_UNREAD_UPDATE<br></td>
630     *      <td>Unread Routed Messages Boolean<br></td>
631     *      <td>Update the footer pane with the unread messages boolean.</td>
632     *    </tr>
633     *    <tr>
634     *      <td>CAD_INFO_MESSAGE<br></td>
635     *      <td>Information message<br></td>
636     *      <td>Update the footer pane with the new info message.</td>
637     *    </tr>
638     *  </tbody>
639     *</table>
640     */
641    public void update(Observable o, Object arg) {
642       
643       
644        if(arg == null) 
645        {
646            JOptionPane.showMessageDialog(this, 
647                    "Connection to the CAD Simulator has been lost.  " +
648                    "Restart the CAD Client.", "Connection Error", 
649                    JOptionPane.ERROR_MESSAGE); 
650            return;
651        }
652       
653        ObserverMessage oMessage = (ObserverMessage)arg;
654   
655        switch(oMessage.type) {
656            case INCIDENT_INQUIRY:
657                IncidentInquiryModel iiModel = (IncidentInquiryModel)oMessage.value;
658               
659                CADMainPane   = new II_IncidentInquiry(iiModel, mainTextPane.getDocument());
660                CADMainPane.addObserver(CADFooterPane);
661               
662                if(!pageLocationSaved)
663                    pageLocationMap.put(currentScreenNum, CADMainPane.getCurrentPage());
664               
665                updateViews(iiModel);               
666               
667                break;
668               
669            case INCIDENT_SUMMARY:
670                IncidentSummaryModel isModel = (IncidentSummaryModel)oMessage.value;
671               
672                CADMainPane   = new SA_IncidentSummary(isModel, mainTextPane.getDocument());
673                CADMainPane.addObserver(CADFooterPane);
674               
675                if(!pageLocationSaved)
676                    pageLocationMap.put(currentScreenNum, CADMainPane.getCurrentPage());
677               
678                updateViews(isModel);
679                break;
680               
681            case INCIDENT_BOARD:
682                IncidentBoardModel ibModel = (IncidentBoardModel)oMessage.value;
683           
684                CADMainPane   = new IB_IncidentBoard(ibModel, mainTextPane.getDocument());
685                CADMainPane.addObserver(CADFooterPane);     
686               
687                if(!pageLocationSaved)
688                    pageLocationMap.put(currentScreenNum, CADMainPane.getCurrentPage());
689               
690                updateViews(ibModel);
691                break;
692               
693            case ROUTED_MESSAGE:
694                RoutedMessageModel rmModel = (RoutedMessageModel)oMessage.value;
695           
696                CADMainPane = new TO_RoutedMessage(rmModel, mainTextPane.getDocument());
697                CADMainPane.addObserver(CADFooterPane);
698               
699                if(!pageLocationSaved)
700                    pageLocationMap.put(currentScreenNum, CADMainPane.getCurrentPage());
701               
702                updateViews(rmModel);
703                break;
704               
705            case BLANK_SCREEN:
706                BlankScreenModel bsModel = (BlankScreenModel)oMessage.value;
707               
708                CADMainPane = new CADMainView(mainTextPane.getDocument());
709                CADMainPane.addObserver(CADFooterPane); 
710
711                if(!pageLocationSaved)
712                    pageLocationMap.put(currentScreenNum, CADMainPane.getCurrentPage());
713               
714                updateViews(bsModel);
715                break;             
716               
717            case SCREEN_UPDATE:
718                CADFooterPane.updateStatus(CADScreenModel.updateStringToMap(
719                        (String)oMessage.value));
720                break;
721               
722            case TIME_UPDATE:
723                CADFooterPane.updateTime((String)oMessage.value);           
724                break;
725               
726            case ROUTED_MESSAGE_COUNT_UPDATE:
727                CADFooterPane.updateRoutedMessageCount((Integer)oMessage.value);
728                break;
729               
730            case ROUTED_MESSAGE_UNREAD_UPDATE:
731                CADFooterPane.updateUnreadMessages((Boolean)oMessage.value);
732                break;
733               
734            case CAD_INFO_MESSAGE:
735                CADFooterPane.displayInfoMessage((String)oMessage.value);
736                break;
737        }           
738    }
739   
740   
741    /**
742     * Update the command line and footer pane with model
743     * data.  Then refresh all of the views to repaint the screen.
744     *
745     * @param model CADScreenModel shown in main Pane.
746     */
747    private void updateViews(CADScreenModel model) {
748               
749        currentScreenNum = model.getScreenNum();
750       
751        CADCommandLinePane.setCommandLine(model.commandLine);
752
753        CADFooterPane.setCADScreenNum(model.getScreenNum());       
754        CADFooterPane.updateTime(CADScreenModel.theCADTime);
755        CADFooterPane.updateDate(CADScreenModel.theCADDate);       
756        CADFooterPane.updateStatus(model.screenUpdateMap);
757        CADFooterPane.updateRoutedMessageCount(model.numberRoutedMessages); 
758        CADFooterPane.updateUnreadMessages(model.unreadMessages);       
759       
760        CADCommandLinePane.refreshView();
761        CADMainPane.refreshView(pageLocationMap.get(currentScreenNum));
762        CADFooterPane.refreshView();
763       
764    }
765   
766    /* SWING OBJECTS */       
767   
768    private JTextPane cmdLineTextPane = null;
769    private JTextPane mainTextPane    = null;
770    private JTextPane footerTextPane  = null;
771   
772    private JPanel cmdLinePanel = null;
773    private JPanel mainPanel    = null;
774    private JPanel footerPanel  = null;
775   
776   
777}   
Note: See TracBrowser for help on using the repository browser.