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