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

Revision 59, 37.7 KB checked in by jdalbey, 9 years ago (diff)

Merge CAD Client updates for multiple incident view windows.

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