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

Revision 445, 30.6 KB checked in by jdalbey, 7 years ago (diff)

Changed restart dialog in CADClientView to a non-modal one to fix #159. Shortened exception log messages in other client modules.

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