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