Warning: Can't use blame annotator:
svn blame failed on trunk/src/tmcsim/client/CADClientView.java: ("Can't find a temporary directory: Internal error", 20014)

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

Revision 2, 29.8 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files

RevLine 
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        setVisible(true);       
231               
232    }
233   
234    /**
235     * Method contructs a box out of the three CAD Screen components:
236     * CommandLine, MainTextArea, Footer.  The Command Line panel is placed
237     * above the main text area panel, which is above the footer panel.
238     *
239     * @return Box Box containing all three panels.
240     */
241    public Box initBox() {
242        Box theBox = new Box(BoxLayout.Y_AXIS);
243        theBox.add(cmdLinePanel);
244        theBox.add(mainPanel);
245        theBox.add(footerPanel);   
246        theBox.setBackground(Color.black);
247       
248        return theBox;
249    }
250
251    /** 
252     * This method is called by the implemented KeyListener whenever a key is pressed.  The following
253     * keystrokes are listened for in this method.  Each keystroke pressed is referenced by the keycode
254     * for the associated key.  These key codes are defined in the CADProtocol class.
255     *
256     *
257     *<table cellpadding="2" cellspacing="2" border="1"
258     * style="text-align: left; width: 250px;">
259     *  <tbody>
260     *    <tr>
261     *      <th>CAD Protocol Command<br></th>
262     *      <th>Action Taken<br></th>
263     *    </tr>
264     *    <tr>
265     *      <td>SHIFT_KEY<br></td>
266     *      <td>Set shiftKeyPressed flag to true.<br></td>
267     *    </tr>
268     *    <tr>
269     *      <td>COMMAND_LINE_CLEAR<br></td>
270     *      <td>If the shift key is pressed, clear the current CAD Screen's command line.<br></td>
271     *    </tr>
272     *    <tr>
273     *      <td>SCREEN_CLEAR<br></td>
274     *      <td>If the shift key is pressed, transmit the SCREEN_CLEAR
275     *          command as a TERMINAL_FUNCTION to the CAD Simulator<br></td>
276     *   </tr>
277     *  </tbody>
278     *</table>
279     *
280     * @param e KeyEvent
281     */
282    public void keyPressed(KeyEvent evt) { 
283       //System.out.println("keyPressed" + evt.getKeyCode());   
284       
285        switch(CAD_KEYS.fromValue(CAD_KEYS.keyboard_type, evt.getKeyCode())) { 
286            case  SHIFT_KEY: 
287                shiftKeyPressed = true;
288                break; 
289               
290            case COMMAND_LINE_CLEAR:       
291                if(shiftKeyPressed)  {
292                    CADCommandLinePane.clearCommandLine();
293                }
294                break;
295   
296            case SCREEN_CLEAR:     
297                if(shiftKeyPressed) {         
298                    try {
299                        Document cmdDoc = DocumentBuilderFactory.newInstance()
300                            .newDocumentBuilder().newDocument();
301                        Element cmdElem = cmdDoc.createElement(
302                                CAD_CLIENT_CMD.TERMINAL_FUNCTION.type);                 
303                        cmdElem.appendChild(cmdDoc.createTextNode(
304                                CAD_KEYS.keyboard_type + ":" + 
305                                String.valueOf(evt.getKeyCode())));                 
306                        cmdDoc.appendChild(cmdElem);           
307                        theModel.transmitCommand(cmdDoc);                           
308                    } catch (Exception e) {
309                        cadLogger.logp(Level.SEVERE, "CADClientView", "keyPressed()",
310                                "Exception in sending screen clear command.", e);
311                    }
312                }
313                break;     
314        }
315    }
316       
317    /**
318     * This method is called by the implemented KeyListener whenever a key is released.  The following
319     * keystrokes are listened for in this method.  Each keystroke released is referenced by the keycode
320     * for the associated key.  These key codes are defined in the CADProtocol class.
321     *
322     *<table cellpadding="2" cellspacing="2" border="1"
323     * style="text-align: left; width: 250px;">
324     *  <tbody>
325     *    <tr>
326     *      <th>CAD Protocol Command<br></th>
327     *      <th>Action Taken<br></th>
328     *    </tr>
329     *    <tr>
330     *      <td>SHIFT_KEY<br></td>
331     *      <td>Set the shiftKeyPressed flag to false.<br></td>
332     *    </tr>
333     *    <tr>
334     *      <td>CYCLE<br></td>
335     *      <td>Preserve the current page number to return the screen to the same location after
336     *          the cycle.  Transmit the current command line to the CAD Simulator with a
337     *          SAVE_COMMAND_LINE message type.  Transmit the CYCLE command as a
338     *          TERMINAL_FUNCTION to the CAD Simulator.<br></td>
339     *    </tr>
340     *    <tr>
341     *      <td>REFRESH<br></td>
342     *      <td>Preserve the current page number to return the screen to the same location after
343     *          the refresh.  Transmit the current command line to the CAD Simulator with a
344     *          SAVE_COMMAND_LINE message type.  Transmit the CYCLE command as a
345     *          TERMINAL_FUNCTION to the CAD Simulator.<br></td>
346     *    </tr>
347     *    <tr>
348     *      <td>PGDN</td>
349     *      <td>Notify the main pane object of the received page down command.<br></td>
350     *    </tr>
351     *    <tr>
352     *      <td>PGUP</td>
353     *      <td>Notify the main pane object of the received page up command.<br> </td>
354     *    </tr>
355     *    <tr>
356     *      <td>LEFT_ARROW</td>
357     *      <td>Notify the command line pane object of the received left arrow.<br> </td>
358     *    </tr>
359     *    <tr>
360     *      <td>UP_ARROW</td>
361     *      <td>Notify the command line pane object of the received up arrow.<br> </td>
362     *    </tr>
363     *    <tr>
364     *      <td>RIGHT_ARROW</td>
365     *      <td>Notify the command line pane object of the received right arrow.<br> </td>
366     *    </tr>
367     *    <tr>
368     *      <td>DOWN_ARROW</td>
369     *      <td>Notify the command line pane object of the received down arrow.<br> </td>
370     *    </tr>
371     *    <tr>
372     *      <td>COMMAND_LINE_TX<br> </td>
373     *      <td>Parse the current command line and create an XMLWriter with the
374     *          converted XML representation of the command line data.
375     *          Transmit the command line as a TERMINAL_CMD_LINE message to
376     *          the CAD Simulator.  Clear the current CAD screen's command line.
377     *          If there is an error in parsing, show the corresponding error
378     *          message and clear the command line.<br></td>
379     *    </tr>
380     *    <tr>
381     *      <td>NEXT_QUEUE<br></td>
382     *      <td>Transmit the NEXT_QUEUE command as a TERMINAL_FUNCTION to the CAD Simulator.<br></td>
383     *    </tr>
384     *    <tr>
385     *      <td>DELETE_QUEUE<br></td>
386     *      <td>Transmit the DELETE_QUEUE command as a TERMINAL_FUNCTION to the CAD Simulator.<br></td>
387     *    </tr>
388     *    <tr>
389     *      <td>PREV_QUEUE<br></td>
390     *      <td>Transmit the PREV_QUEUE command as a TERMINAL_FUNCTION to the CAD Simulator.<br></td>
391     *    </tr>
392     *    <tr>
393     *      <td>BACKSPACE<br></td>
394     *      <td>Notify the command line pane of the received backspace command.<br></td>
395     *    </tr>
396     *    <tr>
397     *      <td>ENTER<br></td>
398     *      <td>Currently, do nothing<br></td>
399     *    </tr>
400     *  </tbody>
401     *</table>
402     *
403     * @param e KeyEvent
404     */       
405    public void keyReleased(KeyEvent evt) {
406       //System.out.println("keyReleased" + evt.getKeyCode());       
407       
408        switch(CAD_KEYS.fromValue(CAD_KEYS.keyboard_type, evt.getKeyCode())) { 
409           
410            case  SHIFT_KEY: 
411                shiftKeyPressed = false;
412                break; 
413
414            case REFRESH:
415            case CYCLE: 
416
417                pageLocationSaved = true;
418                pageLocationMap.put(currentScreenNum, CADMainPane.getCurrentPage());
419
420                try {
421                    Document cmdDoc = DocumentBuilderFactory.newInstance()
422                            .newDocumentBuilder().newDocument();
423                    Element cmdElem = cmdDoc.createElement(
424                            CAD_CLIENT_CMD.SAVE_COMMAND_LINE.type);                 
425                    cmdElem.appendChild(cmdDoc.createTextNode(
426                            CADCommandLinePane.getCommandLine()));
427                    cmdDoc.appendChild(cmdElem);                                   
428                    theModel.transmitCommand(cmdDoc);
429                                       
430                    cmdDoc = DocumentBuilderFactory.newInstance()
431                            .newDocumentBuilder().newDocument();
432                    cmdElem = cmdDoc.createElement(
433                            CAD_CLIENT_CMD.TERMINAL_FUNCTION.type);                 
434                    cmdElem.appendChild(cmdDoc.createTextNode(
435                            CAD_KEYS.keyboard_type + ":" + 
436                            String.valueOf(evt.getKeyCode())));                 
437                    cmdDoc.appendChild(cmdElem);           
438                    theModel.transmitCommand(cmdDoc);           
439                   
440                } catch (Exception e) {
441                    cadLogger.logp(Level.SEVERE, "CADClientView", 
442                            "keyReleased()",
443                            "Exception in sending cycle command.", e);
444                }
445                break;                 
446           
447            case PGDN:
448               
449               CADMainPane.pageDown();
450               break;
451           
452            case PGUP: 
453           
454               CADMainPane.pageUp();
455               break; 
456               
457            case LEFT_ARROW: 
458           
459               CADCommandLinePane.receiveArrow(ARROW.LEFT);
460               break; 
461               
462            case UP_ARROW: 
463           
464               CADCommandLinePane.receiveArrow(ARROW.UP);
465               break; 
466   
467            case RIGHT_ARROW: 
468           
469               CADCommandLinePane.receiveArrow(ARROW.RIGHT);
470               break; 
471   
472            case DOWN_ARROW: 
473           
474               CADCommandLinePane.receiveArrow(ARROW.DOWN);
475               break;                                                 
476   
477            case COMMAND_LINE_TX:
478                   
479                try {
480                    Document cmdDoc = DocumentBuilderFactory.newInstance()
481                        .newDocumentBuilder().newDocument();
482                    Element cmdElem = cmdDoc.createElement(CAD_CLIENT_CMD.TERMINAL_CMD_LINE.type);
483                   
484                    cmdParser.parseCommand(cmdElem, CADCommandLinePane.getCommandLine());
485                    cmdDoc.appendChild(cmdElem);
486               
487                    theModel.transmitCommand(cmdDoc);
488           
489                    CADCommandLinePane.clearCommandLine();
490
491                    pageLocationSaved = false;
492                }
493                catch (Exception ex) {
494                    CADFooterPane.displayInfoMessage(CAD_ERROR.UNAUTH_CMD.message);
495                    CADCommandLinePane.clearCommandLine();
496                }
497                break; 
498   
499            case PREV_QUEUE:
500            case DELETE_QUEUE:
501            case NEXT_QUEUE:
502                try {
503                    Document cmdDoc = DocumentBuilderFactory.newInstance()
504                            .newDocumentBuilder().newDocument();
505                    Element cmdElem = cmdDoc.createElement(
506                            CAD_CLIENT_CMD.TERMINAL_FUNCTION.type);
507                                       
508                    cmdElem.appendChild(cmdDoc.createTextNode(
509                            CAD_KEYS.keyboard_type + ":" + 
510                            String.valueOf(evt.getKeyCode())));
511                    cmdDoc.appendChild(cmdElem);                   
512                    theModel.transmitCommand(cmdDoc);
513   
514                } catch (Exception e) {
515                    cadLogger.logp(Level.SEVERE, "CADClientView", "keyReleased()",
516                            "Exception in sending queue command.", e);
517                }
518                break;
519
520            case BACKSPACE:
521               CADCommandLinePane.backspace();
522               break;       
523            case ENTER:                   
524                break;
525            default: 
526        }
527               
528    }
529
530    /**
531     * This method implements the necessary KeyListener functionality, and is
532     * called whenever a key is typed.  Only letters, numbers, and standard
533     * keyboard symbols, whose ascii value is between 32(inclusive) and
534     * 127(exclusive).  Lower case character are in the range between 97 and
535     * 122, inclusive.  These characters are made uppercase by substracting
536     * 32 from their ascii value.  The ascii value for an upper case character
537     * is 32 less than its lower case representation.  The valid character
538     * is then sent to the CADCommandLinePane.
539     *
540     * @param e KeyEvent received.
541     */
542    public void keyTyped(KeyEvent e) {
543        //System.out.println("keyTyped" + e.getKeyCode());
544       
545        char key = e.getKeyChar();
546        //if valid character
547        if(key >= 32 && key < 127) {
548            //lower case letter
549            if(key >= 97 && key <= 122)
550                key -= 32; //make uppercase
551           
552            CADCommandLinePane.receiveKeyPress(key);               
553           
554        }
555    }
556
557    /**
558     * Observable update method.  The CADClientView class is an observer of the
559     * CADClientModel.  If the model sends a null object, it is signifying that
560     * it has shut down.  In this case, an error message should be shown to prompt
561     * the user to restart the CAD Client.  If the update object is an
562     * ObserverMessage object, the following actions are to be taken:
563     *
564     *<table cellpadding="2" cellspacing="2" border="1"
565     * style="text-align: left; width: 250px;">
566     *  <tbody>
567     *    <tr>
568     *      <th>Message Type</th>
569     *      <th>Message Data</th>
570     *      <th>Action Taken</th>
571     *    </tr>
572     *    <tr>
573     *      <td>INCIDENT_INQUIRY<br></td>
574     *      <td>IncidentInquiryModel<br></td>
575     *      <td>Construct a new II_IncidentInquiry view pane from the model data.
576     *          Reset the observer relationship between the footer and main pane.
577     *          Update the page location map and update the views with the model data.
578     *      </td>
579     *    </tr>
580     *    <tr>
581     *      <td>INCIDENT_SUMMARY<br></td>
582     *      <td>IncidentSummaryModel<br></td>
583     *      <td>Construct a new SA_IncidentSummary view pane from the model data.
584     *          Reset the observer relationship between the footer and main pane.
585     *          Update the page location map and update the views with the model data.
586     *      </td>
587     *    </tr>
588     *    <tr>
589     *      <td>INCIDENT_BOARD<br></td>
590     *      <td>IncidentBoardModel<br></td>
591     *      <td>Construct a new IB_IncidentBoard view pane from the model data.
592     *          Reset the observer relationship between the footer and main pane.
593     *          Update the page location map and update the views with the model data.
594     *      </td>
595     *    </tr>
596     *    <tr>
597     *      <td>ROUTED_MESSAGE<br></td>
598     *      <td>RoutedMessageModel<br></td>
599     *      <td>Construct a new TO_RoutedMessage view pane from the model data.
600     *          Reset the observer relationship between the footer and main pane.
601     *          Update the page location map and update the views with the model data.
602     *      </td>
603     *    </tr>
604     *    <tr>
605     *      <td>BLANK_SCREEN<br></td>
606     *      <td>BlankScreenModel<br></td>
607     *      <td>Construct a new empty view pane.
608     *          Reset the observer relationship between the footer and main pane.
609     *          Update the page location map and update the views with the model data.
610     *      </td>
611     *    </tr>
612     *    <tr>
613     *      <td>SCREEN_UPDATE<br></td>
614     *      <td>TreeMap<CADScreenNum, Boolean><br></td>
615     *      <td>Update the footer pane with the new screen updates map.</td>
616     *    </tr>
617     *    <tr>
618     *      <td>TIME_UPDATE<br></td>
619     *      <td>Time String<br></td>
620     *      <td>Update the footer pane with the new time.</td>
621     *    </tr>
622     *    <tr>
623     *      <td>ROUTED_MESSAGE_COUNT_UPDATE<br></td>
624     *      <td># Routed Messages<br></td>
625     *      <td>Update the footer pane with the new number of routed messages.</td>
626     *    </tr>
627     *    <tr>
628     *      <td>ROUTED_MESSAGE_UNREAD_UPDATE<br></td>
629     *      <td>Unread Routed Messages Boolean<br></td>
630     *      <td>Update the footer pane with the unread messages boolean.</td>
631     *    </tr>
632     *    <tr>
633     *      <td>CAD_INFO_MESSAGE<br></td>
634     *      <td>Information message<br></td>
635     *      <td>Update the footer pane with the new info message.</td>
636     *    </tr>
637     *  </tbody>
638     *</table>
639     */
640    public void update(Observable o, Object arg) {
641       
642       
643        if(arg == null) 
644        {
645            JOptionPane.showMessageDialog(this, 
646                    "Connection to the CAD Simulator has been lost.  " +
647                    "Restart the CAD Client.", "Connection Error", 
648                    JOptionPane.ERROR_MESSAGE); 
649            return;
650        }
651       
652        ObserverMessage oMessage = (ObserverMessage)arg;
653   
654        switch(oMessage.type) {
655            case INCIDENT_INQUIRY:
656                IncidentInquiryModel iiModel = (IncidentInquiryModel)oMessage.value;
657               
658                CADMainPane   = new II_IncidentInquiry(iiModel, mainTextPane.getDocument());
659                CADMainPane.addObserver(CADFooterPane);
660               
661                if(!pageLocationSaved)
662                    pageLocationMap.put(currentScreenNum, CADMainPane.getCurrentPage());
663               
664                updateViews(iiModel);               
665               
666                break;
667               
668            case INCIDENT_SUMMARY:
669                IncidentSummaryModel isModel = (IncidentSummaryModel)oMessage.value;
670               
671                CADMainPane   = new SA_IncidentSummary(isModel, mainTextPane.getDocument());
672                CADMainPane.addObserver(CADFooterPane);
673               
674                if(!pageLocationSaved)
675                    pageLocationMap.put(currentScreenNum, CADMainPane.getCurrentPage());
676               
677                updateViews(isModel);
678                break;
679               
680            case INCIDENT_BOARD:
681                IncidentBoardModel ibModel = (IncidentBoardModel)oMessage.value;
682           
683                CADMainPane   = new IB_IncidentBoard(ibModel, mainTextPane.getDocument());
684                CADMainPane.addObserver(CADFooterPane);     
685               
686                if(!pageLocationSaved)
687                    pageLocationMap.put(currentScreenNum, CADMainPane.getCurrentPage());
688               
689                updateViews(ibModel);
690                break;
691               
692            case ROUTED_MESSAGE:
693                RoutedMessageModel rmModel = (RoutedMessageModel)oMessage.value;
694           
695                CADMainPane = new TO_RoutedMessage(rmModel, mainTextPane.getDocument());
696                CADMainPane.addObserver(CADFooterPane);
697               
698                if(!pageLocationSaved)
699                    pageLocationMap.put(currentScreenNum, CADMainPane.getCurrentPage());
700               
701                updateViews(rmModel);
702                break;
703               
704            case BLANK_SCREEN:
705                BlankScreenModel bsModel = (BlankScreenModel)oMessage.value;
706               
707                CADMainPane = new CADMainView(mainTextPane.getDocument());
708                CADMainPane.addObserver(CADFooterPane); 
709
710                if(!pageLocationSaved)
711                    pageLocationMap.put(currentScreenNum, CADMainPane.getCurrentPage());
712               
713                updateViews(bsModel);
714                break;             
715               
716            case SCREEN_UPDATE:
717                CADFooterPane.updateStatus(CADScreenModel.updateStringToMap(
718                        (String)oMessage.value));
719                break;
720               
721            case TIME_UPDATE:
722                CADFooterPane.updateTime((String)oMessage.value);           
723                break;
724               
725            case ROUTED_MESSAGE_COUNT_UPDATE:
726                CADFooterPane.updateRoutedMessageCount((Integer)oMessage.value);
727                break;
728               
729            case ROUTED_MESSAGE_UNREAD_UPDATE:
730                CADFooterPane.updateUnreadMessages((Boolean)oMessage.value);
731                break;
732               
733            case CAD_INFO_MESSAGE:
734                CADFooterPane.displayInfoMessage((String)oMessage.value);
735                break;
736        }           
737    }
738   
739   
740    /**
741     * Update the command line and footer pane with model
742     * data.  Then refresh all of the views to repaint the screen.
743     *
744     * @param model CADScreenModel shown in main Pane.
745     */
746    private void updateViews(CADScreenModel model) {
747               
748        currentScreenNum = model.getScreenNum();
749       
750        CADCommandLinePane.setCommandLine(model.commandLine);
751
752        CADFooterPane.setCADScreenNum(model.getScreenNum());       
753        CADFooterPane.updateTime(CADScreenModel.theCADTime);
754        CADFooterPane.updateDate(CADScreenModel.theCADDate);       
755        CADFooterPane.updateStatus(model.screenUpdateMap);
756        CADFooterPane.updateRoutedMessageCount(model.numberRoutedMessages); 
757        CADFooterPane.updateUnreadMessages(model.unreadMessages);       
758       
759        CADCommandLinePane.refreshView();
760        CADMainPane.refreshView(pageLocationMap.get(currentScreenNum));
761        CADFooterPane.refreshView();
762       
763    }
764   
765    /* SWING OBJECTS */       
766   
767    private JTextPane cmdLineTextPane = null;
768    private JTextPane mainTextPane    = null;
769    private JTextPane footerTextPane  = null;
770   
771    private JPanel cmdLinePanel = null;
772    private JPanel mainPanel    = null;
773    private JPanel footerPanel  = null;
774   
775   
776}   
Note: See TracBrowser for help on using the repository browser.