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

source: tmcsimulator/trunk/src/tmcsim/client/cadclientgui/screens/UnitStatus.java @ 201

Revision 201, 38.5 KB checked in by jdalbey, 9 years ago (diff)

UnitStatus?.java: Added explanatory comment.

RevLine 
1package tmcsim.client.cadclientgui.screens;
2
3import java.awt.Color;
4import java.awt.Component;
5import java.awt.Dimension;
6import java.awt.Point;
7import java.awt.Toolkit;
8import java.awt.datatransfer.DataFlavor;
9import java.awt.datatransfer.StringSelection;
10import java.awt.datatransfer.Transferable;
11import java.awt.event.ActionEvent;
12import java.awt.event.ActionListener;
13import java.awt.event.ComponentEvent;
14import java.awt.event.ComponentListener;
15import java.awt.event.MouseEvent;
16import java.awt.event.MouseListener;
17import java.awt.event.MouseMotionListener;
18import java.rmi.RemoteException;
19import java.util.List;
20import java.util.logging.Level;
21import java.util.logging.Logger;
22import javax.swing.Box;
23import javax.swing.BoxLayout;
24import javax.swing.JButton;
25import javax.swing.JComponent;
26import javax.swing.JFrame;
27import javax.swing.JLabel;
28import javax.swing.JScrollPane;
29import javax.swing.JSeparator;
30import javax.swing.JTable;
31import javax.swing.ListSelectionModel;
32import javax.swing.RowSorter.SortKey;
33import javax.swing.SwingUtilities;
34import javax.swing.TransferHandler;
35import javax.swing.table.DefaultTableModel;
36import javax.swing.table.TableCellRenderer;
37import tmcsim.client.cadclientgui.enums.CADDataEnums;
38import tmcsim.client.cadclientgui.enums.CADScriptTags.UNIT_TAGS;
39import tmcsim.client.cadclientgui.enums.TableHeaders;
40import tmcsim.client.cadclientgui.enums.UnitStatusEnums;
41
42/**
43 * This class contains the view and controller for the UnitStatus screen. The
44 * view was not built using a GUI builder plug-in (but may want to consider
45 * doing so in the future), and the controller uses listeners to control how the
46 * view and data act.
47 *
48 * @author Vincent
49 */
50public class UnitStatus extends JFrame
51{
52    private final static int ONE_SECOND = 1000;
53    private static Logger clientLogger = Logger.getLogger("tmcsim.client");
54    private final String SCREEN_TITLE = "(Shift + F4)  Unit Status";
55    private final Dimension SCREEN_DIMENSIONS = new Dimension(1400, 250);
56    private final Dimension DROP_DOWN_MENU_LABEL_DIMENSIONS = new Dimension(
57            170, 20);
58    private final Dimension DROP_DOWN_MENU_DIMENSIONS = new Dimension(170, 300);
59    private final Dimension BUTTON_DIMENSIONS = new Dimension(100, 25);
60    private final int COLUMN_WIDTH = 120;
61    private final String[] LABELS =
62    {
63        "10-8", "OFC", "OOS",
64        "Open Unit Details", "Open Unit Activity Log", "Map",
65        "Change Vehicle", "Unit Poll", "Quick Note...",
66        "Activate User Timer...", "Filters", "Page...", "Roster System",
67        "10-10"
68    };
69    private final String[] WITH_ASSIGNED_INC_LABELS =
70    {
71        "STAGE", "10-97",
72        "10-8", "ASSIGNED ALT...", "ENRT ALT...", "10-97 ALT...",
73        "Open Incident", "Recall Incident", "Open Unit Details",
74        "Open Unit Activity Log", "Map", "Recall Linked Incidents",
75        "Cancel", "Reassign", "Duplicate", "Unit Poll", "Quick Note...",
76        "Activate User Timer...", "Filters", "Page...", "Fax..."
77    };
78    private final String LABEL_SPACING = "     ";
79    // this box holds both the table and the buttons below
80    private Box unitStatusFrame;
81    private JTable unitStatusTable;
82    private JFrame unitStatusMenu;
83    private JFrame unitStatusWithAssignedIncMenu;
84    // labels for the drop down menu
85    private JLabel[] dropDownLabels = new JLabel[LABELS.length];
86    private JLabel[] dropDownWithAssignedIncLabels = new JLabel[WITH_ASSIGNED_INC_LABELS.length];
87    private JButton buttonEnrt;
88    private JButton buttonStage;
89    private JButton button1097;
90    private JButton buttonCode4;
91    private JButton buttonDash1;
92    private JButton buttonDash2;
93    private JButton buttonDash3;
94    private JButton button108;
95    private JButton buttonOFC;
96    private JButton buttonOOS;
97
98    public UnitStatus()
99    {
100        initComponents();
101    }
102
103    private void initComponents()
104    {
105        initializeTable();
106        initControllers();
107        initializeDropDownMenus();
108
109        JScrollPane scrollpane = new JScrollPane(unitStatusTable);
110        scrollpane.getViewport().setBackground(Color.WHITE);
111
112        Box bottomButtons = new Box(BoxLayout.X_AXIS);
113        initializeBottomButtons(bottomButtons);
114
115        unitStatusFrame = new Box(BoxLayout.Y_AXIS);
116        unitStatusFrame.add(bottomButtons);
117
118        unitStatusFrame.add(scrollpane);// holds the table
119        unitStatusFrame.add(bottomButtons);
120
121        setTitle(SCREEN_TITLE);
122        setPreferredSize(SCREEN_DIMENSIONS);
123        getContentPane().add(unitStatusFrame);
124        setResizable(true);
125        pack();
126        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
127        setLocation(0, (int) (dim.getHeight() * 2 / 4));
128        setDefaultCloseOperation(HIDE_ON_CLOSE);
129        setVisible(false);
130    }
131
132    /**
133     * Initializes the table and prepares the cell renderer for color
134     * management. It initializes the default settings and handles the drag and
135     * drop feature.
136     */
137    private void initializeTable()
138    {
139        unitStatusTable = new JTable()
140        {
141            /**
142             * Custom renderer to set different background/foreground colors
143             *
144             * @see
145             * javax.swing.JTable#prepareRenderer(javax.swing.table.TableCellRenderer,
146             * int, int)
147             */
148            public Component prepareRenderer(TableCellRenderer renderer,
149                    int row, int column)
150            {
151                Component comp;
152                // In a rare odd circumstance of timing, this exception is thrown:
153                // http://pastebin.com/f5wtSMHN or
154                // http://pastebin.com/DDJNLVac
155                try
156                {
157                    comp = super.prepareRenderer(renderer, row, column);
158                } catch (Exception ex)
159                {
160                    clientLogger.logp(Level.INFO, "UnitStatus",
161                            "prepareRenderer", "row=" + row + " col=" + column, ex);
162                    // Our workaround is to just return a dummy value.
163                    // It will be erased in the next one second refresh
164                    return new JLabel("?");
165                }
166
167                int unitNumColumn = 2;
168                try
169                {
170                    switch (ScreenManager.theCoordinator
171                            .getCadDataUnitStatus((String) unitStatusTable
172                            .getValueAt(row, unitNumColumn)))
173                    {
174                        case Assignable:
175                            comp.setForeground(Color.GREEN);
176                            comp.setBackground(Color.BLACK);
177                            break;
178                        case Arrived:
179                            comp.setForeground(Color.YELLOW);
180                            comp.setBackground(Color.BLACK);
181                            break;
182                        case NotAssignable:
183                            comp.setForeground(Color.BLACK);
184                            comp.setBackground(Color.GRAY);
185                            break;
186                        case Enroute:
187                            comp.setForeground(Color.CYAN);
188                            comp.setBackground(Color.BLACK);
189                            break;
190                    }
191                } catch (RemoteException e)
192                {
193                    e.printStackTrace();
194                }
195
196                if (getSelectedRow() == row)
197                {
198                    comp.setForeground(Color.WHITE);
199                    comp.setBackground(Color.BLUE);
200                }
201
202                return comp;
203            }
204        };
205
206        unitStatusTable.setOpaque(true);
207        unitStatusTable.setIntercellSpacing(new Dimension(1, 0));
208        unitStatusTable.setGridColor(Color.WHITE);
209        unitStatusTable.getTableHeader().setReorderingAllowed(false);
210        unitStatusTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
211        unitStatusTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
212        unitStatusTable.setAutoCreateRowSorter(true);
213        unitStatusTable.setDragEnabled(true);
214
215        unitStatusTable.setModel(new DefaultTableModel());
216        ((DefaultTableModel) unitStatusTable.getModel())
217                .setColumnIdentifiers(TableHeaders.UNIT_STATUS_HEADERS);
218
219        unitStatusTable.setTransferHandler(new TransferHandler()
220        {
221            public boolean canImport(TransferHandler.TransferSupport info)
222            {
223                if (!info.isDataFlavorSupported(DataFlavor.stringFlavor))
224                {
225                    return false;
226                }
227                return true;
228            }
229
230            public int getSourceActions(JComponent c)
231            {
232                return TransferHandler.COPY_OR_MOVE;
233            }
234
235            protected Transferable createTransferable(JComponent c)
236            {
237                return new StringSelection((String) unitStatusTable.getValueAt(
238                        unitStatusTable.getSelectedRow(), 2));
239            }
240        });
241
242        for (int i = 0; i < unitStatusTable.getColumnCount(); i++)
243        {
244            unitStatusTable.getColumnModel().getColumn(i)
245                    .setPreferredWidth(COLUMN_WIDTH);
246        }
247    }
248
249    /*
250     * Adds the key and mouse listeners for the table and component listener for
251     * screen.
252     */
253//TODO: JD    If one unit has been selected, but you right-click on a different one.
254//Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Invalid index
255//      at javax.swing.DefaultRowSorter.convertRowIndexToModel(DefaultRowSorter.java:514)
256//      at javax.swing.JTable.convertRowIndexToModel(JTable.java:2642)
257//      at javax.swing.JTable.getValueAt(JTable.java:2717)
258//      at tmcsim.client.cadclientgui.screens.UnitStatus$3.mouseClicked(UnitStatus.java:234)
259    private void initControllers()
260    {
261        unitStatusTable.addMouseListener(new MouseListener()
262        {
263            public void mouseClicked(MouseEvent e)
264            {
265                int unitColumn = 2;
266                // Fixed to force right click to cause the row to be selected. JD
267                // get the coordinates of the mouse click
268                Point p = e.getPoint();
269                // get the row index that contains that coordinate
270                int rowNumber = unitStatusTable.rowAtPoint(p);
271                // Get the ListSelectionModel of the JTable
272                ListSelectionModel model = unitStatusTable.getSelectionModel();
273                // set the selected interval of rows. Using the "rowNumber"
274                // variable for the beginning and end selects only that one row.
275                model.setSelectionInterval(rowNumber, rowNumber);
276
277                String unitNum = (String) unitStatusTable.getValueAt(
278                        rowNumber, unitColumn);
279                // Validity check for non-empty unit number
280                if (unitNum.equals(""))
281                {
282                    return;
283                }
284                if (SwingUtilities.isRightMouseButton(e))
285                {
286                    try
287                    {
288                        if (ScreenManager.theCoordinator
289                                .getCadDataUnitStatus(unitNum) == UnitStatusEnums.Enroute
290                                || ScreenManager.theCoordinator
291                                .getCadDataUnitStatus(unitNum) == UnitStatusEnums.Arrived)
292                        {
293                            openDropDownWithAssignedIncMenu(e);
294                        }
295                        else
296                        {
297                            openDropDownMenu(e);
298                        }
299                    } catch (RemoteException e1)
300                    {
301                        e1.printStackTrace();
302                    }
303                }
304                else
305                {
306                    closeDropDownMenu();
307                    closeDropDownWithAssignedIncMenu();
308                }
309            }
310
311            public void mouseEntered(MouseEvent e)
312            {
313            }
314
315            public void mouseExited(MouseEvent e)
316            {
317            }
318
319            public void mousePressed(MouseEvent e)
320            {
321            }
322
323            public void mouseReleased(MouseEvent e)
324            {
325            }
326        });
327
328        addComponentListener(new ComponentListener()
329        {
330            public void componentHidden(ComponentEvent e)
331            {
332            }
333
334            public void componentMoved(ComponentEvent e)
335            {
336                closeDropDownMenu();
337            }
338
339            public void componentResized(ComponentEvent e)
340            {
341            }
342
343            public void componentShown(ComponentEvent e)
344            {
345            }
346        });
347    }
348
349    /*
350     * Creates the drop down menu that appears when a right click is performed
351     * on the table.
352     */
353    private void initializeDropDownMenus()
354    {
355        Box menu = new Box(BoxLayout.Y_AXIS);
356        initializeDropDownLabels();
357        addLabelsToBox(menu);
358
359        setMenuHighlightedBackground(Color.BLUE);
360
361        unitStatusMenu = new JFrame();
362        unitStatusMenu.getContentPane().add(menu);
363        unitStatusMenu.setPreferredSize(DROP_DOWN_MENU_DIMENSIONS);
364        unitStatusMenu.setUndecorated(true);
365        unitStatusMenu.pack();
366        unitStatusMenu.setVisible(false);
367
368        menu = new Box(BoxLayout.Y_AXIS);
369        initializeDropDownWithAssignedIncLabels();
370        addWithAssignedIncLabelsToBox(menu);
371
372        setWithAssignedIncMenuHighlightedBackground(Color.BLUE);
373
374        unitStatusWithAssignedIncMenu = new JFrame();
375        unitStatusWithAssignedIncMenu.getContentPane().add(menu);
376        unitStatusWithAssignedIncMenu
377                .setPreferredSize(DROP_DOWN_MENU_DIMENSIONS);
378        unitStatusWithAssignedIncMenu.setUndecorated(true);
379        unitStatusWithAssignedIncMenu.pack();
380        unitStatusWithAssignedIncMenu.setVisible(false);
381    }
382
383    /*
384     * Sets the text and size and adds a listener to each label. Currently,
385     * labels are not implemented so no listeners are added.
386     */
387    private void initializeDropDownLabels()
388    {
389        for (int i = 0; i < dropDownLabels.length; i++)
390        {
391            dropDownLabels[i] = new JLabel(LABEL_SPACING + LABELS[i]);
392            dropDownLabels[i].setMaximumSize(DROP_DOWN_MENU_LABEL_DIMENSIONS);
393            dropDownLabels[i].setForeground(Color.GRAY);
394        }
395    }
396
397    /*
398     * Sets the text and size and adds a listener to each activated label.
399     */
400    private void initializeDropDownWithAssignedIncLabels()
401    {
402        for (int i = 0; i < dropDownWithAssignedIncLabels.length; i++)
403        {
404            dropDownWithAssignedIncLabels[i] = new JLabel(LABEL_SPACING
405                    + WITH_ASSIGNED_INC_LABELS[i]);
406            dropDownWithAssignedIncLabels[i]
407                    .setMaximumSize(DROP_DOWN_MENU_LABEL_DIMENSIONS);
408            dropDownWithAssignedIncLabels[i].setForeground(Color.GRAY);
409        }
410        dropDownWithAssignedIncLabels[6].setForeground(Color.BLACK);
411        addMouseListenersToWithAssignedIncLabel(dropDownWithAssignedIncLabels[6]);
412
413    }
414
415    /*
416     * Add the labels to the box in order with separators and spacings in
417     * between.
418     */
419    private void addLabelsToBox(Box menu)
420    {
421        menu.add(dropDownLabels[0]);
422        menu.add(dropDownLabels[1]);
423        menu.add(dropDownLabels[2]);
424
425        menu.add(Box.createVerticalStrut(5));
426        menu.add(new JSeparator());
427        menu.add(Box.createVerticalStrut(5));
428
429        menu.add(dropDownLabels[3]);
430        menu.add(dropDownLabels[4]);
431        menu.add(dropDownLabels[5]);
432
433        menu.add(Box.createVerticalStrut(5));
434        menu.add(new JSeparator());
435        menu.add(Box.createVerticalStrut(5));
436
437        menu.add(dropDownLabels[6]);
438        menu.add(dropDownLabels[7]);
439        menu.add(dropDownLabels[8]);
440
441        menu.add(Box.createVerticalStrut(5));
442        menu.add(new JSeparator());
443        menu.add(Box.createVerticalStrut(5));
444
445        menu.add(dropDownLabels[9]);
446        menu.add(dropDownLabels[10]);
447
448        menu.add(Box.createVerticalStrut(5));
449        menu.add(new JSeparator());
450        menu.add(Box.createVerticalStrut(5));
451
452        menu.add(dropDownLabels[11]);
453
454        menu.add(Box.createVerticalStrut(5));
455        menu.add(new JSeparator());
456        menu.add(Box.createVerticalStrut(5));
457
458        menu.add(dropDownLabels[12]);
459
460        menu.add(Box.createVerticalStrut(5));
461        menu.add(new JSeparator());
462        menu.add(Box.createVerticalStrut(5));
463
464        menu.add(dropDownLabels[13]);
465
466        menu.add(Box.createVerticalStrut(5));
467    }
468
469    /*
470     * Add the labels to the box in order with separators and spacings in
471     * between.
472     */
473    private void addWithAssignedIncLabelsToBox(Box menu)
474    {
475        menu.add(dropDownWithAssignedIncLabels[0]);
476        menu.add(dropDownWithAssignedIncLabels[1]);
477        menu.add(dropDownWithAssignedIncLabels[2]);
478        menu.add(dropDownWithAssignedIncLabels[3]);
479        menu.add(dropDownWithAssignedIncLabels[4]);
480        menu.add(dropDownWithAssignedIncLabels[5]);
481
482        menu.add(Box.createVerticalStrut(5));
483        menu.add(new JSeparator());
484        menu.add(Box.createVerticalStrut(5));
485
486        menu.add(dropDownWithAssignedIncLabels[6]);
487        menu.add(dropDownWithAssignedIncLabels[7]);
488        menu.add(dropDownWithAssignedIncLabels[8]);
489        menu.add(dropDownWithAssignedIncLabels[9]);
490        menu.add(dropDownWithAssignedIncLabels[10]);
491        menu.add(dropDownWithAssignedIncLabels[11]);
492
493        menu.add(Box.createVerticalStrut(5));
494        menu.add(new JSeparator());
495        menu.add(Box.createVerticalStrut(5));
496
497        menu.add(dropDownWithAssignedIncLabels[12]);
498        menu.add(dropDownWithAssignedIncLabels[13]);
499        menu.add(dropDownWithAssignedIncLabels[14]);
500
501        menu.add(Box.createVerticalStrut(5));
502        menu.add(new JSeparator());
503        menu.add(Box.createVerticalStrut(5));
504
505        menu.add(dropDownWithAssignedIncLabels[15]);
506        menu.add(dropDownWithAssignedIncLabels[16]);
507
508        menu.add(Box.createVerticalStrut(5));
509        menu.add(new JSeparator());
510        menu.add(Box.createVerticalStrut(5));
511
512        menu.add(dropDownWithAssignedIncLabels[17]);
513        menu.add(dropDownWithAssignedIncLabels[18]);
514
515        menu.add(Box.createVerticalStrut(5));
516        menu.add(new JSeparator());
517        menu.add(Box.createVerticalStrut(5));
518
519        menu.add(dropDownWithAssignedIncLabels[19]);
520        menu.add(dropDownWithAssignedIncLabels[20]);
521
522        menu.add(Box.createVerticalStrut(5));
523    }
524
525    /*
526     * Creates each button and handles the action performed by the button.
527     */
528    public void initializeBottomButtons(Box bottomButtons)
529    {
530        bottomButtons.add(buttonEnrt = makeButton("ENRT", new ActionListener()
531        {
532            public void actionPerformed(ActionEvent arg0)
533            {
534                try
535                {
536                    ScreenManager.theCoordinator.setCadDataUnitValue(
537                            (String) unitStatusTable.getValueAt(
538                            unitStatusTable.getSelectedRow(), 2),
539                            UNIT_TAGS.STATUS, "ENRT");
540                    ScreenManager.theCoordinator.setCadDataUnitValue(
541                            (String) unitStatusTable.getValueAt(
542                            unitStatusTable.getSelectedRow(), 2),
543                            UNIT_TAGS.UNIT_STATUS, UnitStatusEnums.Enroute);
544                } catch (RemoteException e)
545                {
546                    e.printStackTrace();
547                }
548                refreshTable();
549            }
550        }));
551        bottomButtons.add(buttonStage = makeButton("STAGE",
552                new ActionListener()
553        {
554            public void actionPerformed(ActionEvent arg0)
555            {
556                try
557                {
558                    ScreenManager.theCoordinator.setCadDataUnitValue(
559                            (String) unitStatusTable
560                            .getValueAt(unitStatusTable
561                            .getSelectedRow(), 2),
562                            UNIT_TAGS.STATUS, "STAGE");
563                } catch (RemoteException e)
564                {
565                    e.printStackTrace();
566                }
567                refreshTable();
568            }
569        }));
570        bottomButtons.add(button1097 = makeButton("10-97",
571                new ActionListener()
572        {
573            public void actionPerformed(ActionEvent arg0)
574            {
575                try
576                {
577                    ScreenManager.theCoordinator.setCadDataUnitValue(
578                            (String) unitStatusTable
579                            .getValueAt(unitStatusTable
580                            .getSelectedRow(), 2),
581                            UNIT_TAGS.STATUS, "10-97");
582                    ScreenManager.theCoordinator.setCadDataUnitValue(
583                            (String) unitStatusTable
584                            .getValueAt(unitStatusTable
585                            .getSelectedRow(), 2),
586                            UNIT_TAGS.UNIT_STATUS,
587                            UnitStatusEnums.Arrived);
588                } catch (RemoteException e)
589                {
590                    e.printStackTrace();
591                }
592                refreshTable();
593            }
594        }));
595        bottomButtons.add(buttonCode4 = makeButton("CODE 4",
596                new ActionListener()
597        {
598            public void actionPerformed(ActionEvent arg0)
599            {
600                try
601                {
602                    ScreenManager.theCoordinator.setCadDataUnitValue(
603                            (String) unitStatusTable
604                            .getValueAt(unitStatusTable
605                            .getSelectedRow(), 2),
606                            UNIT_TAGS.STATUS, "CODE 4");
607                } catch (RemoteException e)
608                {
609                    e.printStackTrace();
610                }
611                refreshTable();
612            }
613        }));
614        bottomButtons.add(buttonDash1 = makeButton("-", null));
615        bottomButtons.add(buttonDash2 = makeButton("-", null));
616        bottomButtons.add(buttonDash3 = makeButton("-", null));
617        bottomButtons.add(button108 = makeButton("10-8", new ActionListener()
618        {
619            public void actionPerformed(ActionEvent arg0)
620            {
621                try
622                {
623                    ScreenManager.theCoordinator.setCadDataUnitValue(
624                            (String) unitStatusTable.getValueAt(
625                            unitStatusTable.getSelectedRow(), 2),
626                            UNIT_TAGS.STATUS, "10-8");
627                    ScreenManager.theCoordinator.setCadDataUnitValue(
628                            (String) unitStatusTable.getValueAt(
629                            unitStatusTable.getSelectedRow(), 2),
630                            UNIT_TAGS.UNIT_STATUS, UnitStatusEnums.Assignable);
631                } catch (RemoteException e)
632                {
633                    e.printStackTrace();
634                }
635                refreshTable();
636            }
637        }));
638        bottomButtons.add(buttonOFC = makeButton("OFC", new ActionListener()
639        {
640            public void actionPerformed(ActionEvent arg0)
641            {
642                try
643                {
644                    ScreenManager.theCoordinator.setCadDataUnitValue(
645                            (String) unitStatusTable.getValueAt(
646                            unitStatusTable.getSelectedRow(), 2),
647                            UNIT_TAGS.STATUS, "OFC");
648                    ScreenManager.theCoordinator.setCadDataUnitValue(
649                            (String) unitStatusTable.getValueAt(
650                            unitStatusTable.getSelectedRow(), 2),
651                            UNIT_TAGS.UNIT_STATUS, UnitStatusEnums.Arrived);
652                } catch (RemoteException e)
653                {
654                    e.printStackTrace();
655                }
656                refreshTable();
657            }
658        }));
659        bottomButtons.add(buttonOOS = makeButton("OOS", new ActionListener()
660        {
661            public void actionPerformed(ActionEvent arg0)
662            {
663                try
664                {
665                    ScreenManager.theCoordinator.setCadDataUnitValue(
666                            (String) unitStatusTable.getValueAt(
667                            unitStatusTable.getSelectedRow(), 2),
668                            UNIT_TAGS.STATUS, "OOS");
669                    ScreenManager.theCoordinator.setCadDataUnitValue(
670                            (String) unitStatusTable.getValueAt(
671                            unitStatusTable.getSelectedRow(), 2),
672                            UNIT_TAGS.UNIT_STATUS,
673                            UnitStatusEnums.NotAssignable);
674                } catch (RemoteException e)
675                {
676                    e.printStackTrace();
677                }
678                refreshTable();
679            }
680        }));
681    }
682
683    /*
684     * Makes a JButton with an text and listener.
685     *
686     * @param text the text to be displayed
687     *
688     * @param listener the action listener for this button.
689     *
690     * @return the JButton.
691     */
692    public JButton makeButton(String text, ActionListener listener)
693    {
694        JButton button = new JButton(text);
695        button.setBackground(Color.GRAY);
696        button.setOpaque(false);
697        Dimension size = BUTTON_DIMENSIONS;
698        button.setPreferredSize(size);
699        button.setMinimumSize(size);
700        button.setMaximumSize(size);
701        button.addActionListener(listener);
702        button.setFocusable(false);
703
704        return button;
705    }
706
707    /*
708     * Sets the highlighted color(when the mouse is over it) of the JLabels.
709     * Note: the color is not shown until .setOpaque(true) is called.
710     *
711     * @param color the highlighted color
712     */
713    public void setMenuHighlightedBackground(Color color)
714    {
715        for (int i = 0; i < dropDownLabels.length; i++)
716        {
717            dropDownLabels[i].setBackground(color);
718        }
719    }
720
721    /*
722     * Sets the highlighted color(when the mouse is over it) of the JLabels.
723     * Note: the color is not shown until .setOpaque(true) is called.
724     *
725     * @param color the highlighted color
726     */
727    public void setWithAssignedIncMenuHighlightedBackground(Color color)
728    {
729        for (int i = 0; i < dropDownWithAssignedIncLabels.length; i++)
730        {
731            dropDownWithAssignedIncLabels[i].setBackground(color);
732        }
733    }
734
735    /*
736     * Sets all JLabels to not display a highlighted background
737     */
738    public void unSelectAllLabels()
739    {
740        for (int i = 0; i < dropDownLabels.length; i++)
741        {
742            dropDownLabels[i].setOpaque(false);
743        }
744    }
745
746    /*
747     * Sets all JLabels to not display a highlighted background
748     */
749    public void unSelectAllWithAssignedIncLabels()
750    {
751        for (int i = 0; i < dropDownWithAssignedIncLabels.length; i++)
752        {
753            dropDownWithAssignedIncLabels[i].setOpaque(false);
754        }
755    }
756
757    /*
758     * Sets the label to have a highlighted background.
759     *
760     * @param label the label that is selected/highlighted
761     */
762    public void selectLabel(Object label)
763    {
764        ((JLabel) label).setOpaque(true);
765    }
766
767    /*
768     * Performs the label action depending on which label was clicked.
769     */
770    public void performLabelAction(Object label)
771    {
772        if (label.equals(dropDownLabels[0]))
773        { // 10-8
774        }
775        else if (label.equals(dropDownLabels[1]))
776        { // OFC
777        }
778        else if (label.equals(dropDownLabels[2]))
779        { // OOS
780        }
781        else if (label.equals(dropDownLabels[3]))
782        { // Open Unit Details
783        }
784        else if (label.equals(dropDownLabels[4]))
785        { // Open Unit Activity Log
786        }
787        else if (label.equals(dropDownLabels[5]))
788        { // Map
789        }
790        else if (label.equals(dropDownLabels[6]))
791        { // Change Vehicle
792        }
793        else if (label.equals(dropDownLabels[7]))
794        { // Unit Poll
795        }
796        else if (label.equals(dropDownLabels[8]))
797        { // Quick Notes
798        }
799        else if (label.equals(dropDownLabels[9]))
800        { // Activate User Timer
801        }
802        else if (label.equals(dropDownLabels[10]))
803        { // Filters
804        }
805        else if (label.equals(dropDownLabels[11]))
806        { // Page
807        }
808        else if (label.equals(dropDownLabels[12]))
809        { // Roster System
810        }
811        else if (label.equals(dropDownLabels[13]))
812        { // 10-10
813        }
814    }
815
816    /*
817     * Performs the label action depending on which label was clicked.
818     */
819    public void performWithAssignedIncLabelAction(Object label)
820    {
821        if (label.equals(dropDownWithAssignedIncLabels[0]))
822        { // STAGE
823        }
824        else if (label.equals(dropDownWithAssignedIncLabels[1]))
825        { // 10-97
826        }
827        else if (label.equals(dropDownWithAssignedIncLabels[2]))
828        { // 10-8
829        }
830        else if (label.equals(dropDownWithAssignedIncLabels[3]))
831        { // ASSIGN
832            // ALT...
833        }
834        else if (label.equals(dropDownWithAssignedIncLabels[4]))
835        { // ENRT
836            // ALT...
837        }
838        else if (label.equals(dropDownWithAssignedIncLabels[5]))
839        { // 10-97
840            // ALT...
841        }
842        else if (label.equals(dropDownWithAssignedIncLabels[6]))
843        { // Open
844            // Incident
845            int idColumn = 0;
846            ScreenManager.openIncidentViewer(Integer
847                    .parseInt((String) unitStatusTable.getValueAt(
848                    unitStatusTable.getSelectedRow(), idColumn)));
849        }
850        else if (label.equals(dropDownWithAssignedIncLabels[7]))
851        { // Recall
852            // Incident
853        }
854        else if (label.equals(dropDownWithAssignedIncLabels[8]))
855        { // Open
856            // Unit
857            // Details
858        }
859        else if (label.equals(dropDownWithAssignedIncLabels[9]))
860        { // Open
861            // Unit
862            // Activity
863            // Log
864        }
865        else if (label.equals(dropDownWithAssignedIncLabels[10]))
866        { // Map
867        }
868        else if (label.equals(dropDownWithAssignedIncLabels[11]))
869        { // Recall
870            // Linked
871            // Incidents
872        }
873        else if (label.equals(dropDownWithAssignedIncLabels[12]))
874        { // Cancel
875        }
876        else if (label.equals(dropDownWithAssignedIncLabels[13]))
877        { // Reassign
878        }
879        else if (label.equals(dropDownWithAssignedIncLabels[14]))
880        { // Duplicate
881        }
882        else if (label.equals(dropDownWithAssignedIncLabels[15]))
883        { // Unit
884            // Poll
885        }
886        else if (label.equals(dropDownWithAssignedIncLabels[16]))
887        { // Quick
888            // Note...
889        }
890        else if (label.equals(dropDownWithAssignedIncLabels[17]))
891        { // Activate
892            // User
893            // Timer...
894        }
895        else if (label.equals(dropDownWithAssignedIncLabels[18]))
896        { // Filters
897        }
898        else if (label.equals(dropDownWithAssignedIncLabels[19]))
899        { // Page...
900        }
901        else if (label.equals(dropDownWithAssignedIncLabels[20]))
902        { // Fax...
903        }
904    }
905
906    /*
907     * Factory method. Adds a mouse listeners to the label. The
908     * MouseMotionListener detects the mouse's location to highlight the label.
909     * The MouseListener detects for clicks and performs the action of the label
910     * designates.
911     */
912    public void addMouseListenersToLabel(JLabel label)
913    {
914        label.addMouseMotionListener(new MouseMotionListener()
915        {
916            public void mouseDragged(MouseEvent e)
917            {
918            }
919
920            public void mouseMoved(MouseEvent e)
921            {
922                unSelectAllLabels();
923                selectLabel(e.getSource());
924                unitStatusMenu.revalidate();
925                unitStatusMenu.repaint();
926            }
927        });
928        label.addMouseListener(new MouseListener()
929        {
930            public void mouseClicked(MouseEvent e)
931            {
932                performLabelAction(e.getSource());
933                unSelectAllLabels();
934                unitStatusMenu.revalidate();
935                unitStatusMenu.repaint();
936                unitStatusMenu.setVisible(false);
937            }
938
939            public void mouseEntered(MouseEvent e)
940            {
941            }
942
943            public void mouseExited(MouseEvent e)
944            {
945            }
946
947            public void mousePressed(MouseEvent e)
948            {
949            }
950
951            public void mouseReleased(MouseEvent e)
952            {
953            }
954        });
955    }
956
957    /*
958     * Factory method. Adds a mouse listeners to the label. The
959     * MouseMotionListener detects the mouse's location to highlight the label.
960     * The MouseListener detects for clicks and performs the action of the label
961     * designates.
962     */
963    public void addMouseListenersToWithAssignedIncLabel(JLabel label)
964    {
965        label.addMouseMotionListener(new MouseMotionListener()
966        {
967            public void mouseDragged(MouseEvent e)
968            {
969            }
970
971            public void mouseMoved(MouseEvent e)
972            {
973                unSelectAllLabels();
974                selectLabel(e.getSource());
975                unitStatusWithAssignedIncMenu.revalidate();
976                unitStatusWithAssignedIncMenu.repaint();
977            }
978        });
979        label.addMouseListener(new MouseListener()
980        {
981            public void mouseClicked(MouseEvent e)
982            {
983                performWithAssignedIncLabelAction(e.getSource());
984                unSelectAllLabels();
985                unitStatusWithAssignedIncMenu.revalidate();
986                unitStatusWithAssignedIncMenu.repaint();
987                unitStatusWithAssignedIncMenu.setVisible(false);
988            }
989
990            public void mouseEntered(MouseEvent e)
991            {
992            }
993
994            public void mouseExited(MouseEvent e)
995            {
996            }
997
998            public void mousePressed(MouseEvent e)
999            {
1000            }
1001
1002            public void mouseReleased(MouseEvent e)
1003            {
1004            }
1005        });
1006    }
1007
1008    /*
1009     * Displays the menu where the right click occurred.
1010     */
1011    public void openDropDownMenu(MouseEvent e)
1012    {
1013        unitStatusMenu.setLocation(e.getX() + this.getX(),
1014                e.getY() + this.getY());
1015        unitStatusMenu.setVisible(true);
1016    }
1017
1018    /*
1019     * Displays the menu where the right click occurred.
1020     */
1021    public void openDropDownWithAssignedIncMenu(MouseEvent e)
1022    {
1023        unitStatusWithAssignedIncMenu.setLocation(e.getX() + this.getX(),
1024                e.getY() + this.getY());
1025        unitStatusWithAssignedIncMenu.setVisible(true);
1026    }
1027
1028    /*
1029     * Hides the menu.
1030     */
1031    public void closeDropDownMenu()
1032    {
1033        unSelectAllLabels();
1034        unitStatusMenu.revalidate();
1035        unitStatusMenu.repaint();
1036        unitStatusMenu.setVisible(false);
1037    }
1038
1039    /*
1040     * Hides the menu.
1041     */
1042    public void closeDropDownWithAssignedIncMenu()
1043    {
1044        unSelectAllLabels();
1045        unitStatusWithAssignedIncMenu.revalidate();
1046        unitStatusWithAssignedIncMenu.repaint();
1047        unitStatusWithAssignedIncMenu.setVisible(false);
1048    }
1049
1050    /*
1051     * Refreshes the data in the table by updating all data and repainting the
1052     * screen. It saves user preferences(like column sizes, selected row, sorted preferences)
1053     * and applies them to the updated model it receives from the server.
1054     */
1055    public void refreshTable()
1056    {
1057        if (unitStatusTable.getTableHeader().getResizingColumn() == null)
1058        {//only update info if resize not in progress
1059            try
1060            {
1061                int index = unitStatusTable.getSelectedRow();
1062                List<? extends SortKey> keys = unitStatusTable.getRowSorter().getSortKeys();
1063                int[] columnWidths = new int[20];
1064                for (int i = 0; i < unitStatusTable.getColumnCount(); i++)
1065                {
1066                    columnWidths[i] = unitStatusTable.getColumnModel().getColumn(i).getWidth();
1067                }
1068
1069                unitStatusTable.setModel(ScreenManager.theCoordinator.getCadDataTable(CADDataEnums.TABLE.UNIT_STATUS));
1070
1071                for (int i = 0; i < unitStatusTable.getColumnCount(); i++)
1072                {
1073                    unitStatusTable.getColumnModel().getColumn(i).setPreferredWidth(columnWidths[i]);
1074                }
1075                unitStatusTable.getRowSorter().setSortKeys(keys);
1076                unitStatusTable.getSelectionModel().setSelectionInterval(index, index);
1077            } catch (RemoteException e)
1078            {
1079                e.printStackTrace();
1080            }
1081            revalidate();
1082            repaint();
1083        }
1084    }
1085
1086    /*
1087     * Makes screen visible.
1088     */
1089    public void open()
1090    {
1091        setVisible(true);
1092    }
1093
1094    /*
1095     * Hides screen.
1096     */
1097    public void close()
1098    {
1099        setVisible(false);
1100    }
1101
1102    /**
1103     * This method is called every second in ScreenManger to update the display
1104     * time every second. Seems redundant: refreshTable already takes care of
1105     * it. JD
1106     */
1107//    public void handleUpdateTime()
1108//    {
1109//        int timerColumn = 13;
1110//        int unitColumn = 2;
1111//        for (int i = 0; i < unitStatusTable.getModel().getRowCount(); i++)
1112//        {
1113//            try
1114//            {
1115//                unitStatusTable.getModel().setValueAt(
1116//                        ScreenManager.theCoordinator.getCadDataUnitValue(
1117//                        (String) unitStatusTable.getModel().getValueAt(
1118//                        i, unitColumn), UNIT_TAGS.TIMER), i,
1119//                        timerColumn);
1120//            } catch (RemoteException e)
1121//            {
1122//                e.printStackTrace();
1123//            }
1124//        }
1125//    }
1126//
1127//    /**
1128//     * Replaces handleUpdateTime
1129//     */
1130//    public void updateTimeColumn()
1131//    {
1132//        int unitColumn = 2;
1133//        try
1134//        {
1135//            DefaultTableModel dm = ScreenManager.theCoordinator.getCadDataTable(CADDataEnums.TABLE.UNIT_STATUS);
1136//            int size = dm.getRowCount();
1137//            for (int i = 0; i < size; i++)
1138//            {
1139//                String cell = (String) dm.getValueAt(i, unitColumn);
1140//                String currTime = ScreenManager.theCoordinator.getCadDataUnitValue(cell, UNIT_TAGS.TIMER);
1141//            }
1142//        } catch (RemoteException e)
1143//        {
1144//            e.printStackTrace();
1145//        }
1146//    }
1147    /**
1148     * Removes drag and drop feature/button clicking.
1149     */
1150    public void removeDispatcherAuthority()
1151    {
1152        unitStatusTable.setTransferHandler(new TransferHandler(""));
1153        buttonEnrt.setEnabled(false);
1154        buttonStage.setEnabled(false);
1155        button1097.setEnabled(false);
1156        buttonCode4.setEnabled(false);
1157        buttonDash1.setEnabled(false);
1158        buttonDash2.setEnabled(false);
1159        buttonDash3.setEnabled(false);
1160        button108.setEnabled(false);
1161        buttonOFC.setEnabled(false);
1162        buttonOOS.setEnabled(false);
1163    }
1164}
Note: See TracBrowser for help on using the repository browser.