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

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

Renamed to ClockClient?, added build target for it.

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