Changeset 59 in tmcsimulator for trunk/src/tmcsim/client/cadclientgui/screens/AssignedIncidents.java
- Timestamp:
- 03/15/2017 10:20:21 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/client/cadclientgui/screens/AssignedIncidents.java
r3 r59 4 4 import java.awt.Component; 5 5 import java.awt.Dimension; 6 import java.awt.Point; 6 7 import java.awt.Toolkit; 7 8 import java.awt.datatransfer.DataFlavor; … … 14 15 import java.rmi.RemoteException; 15 16 import java.util.List; 16 17 17 import javax.swing.Box; 18 18 import javax.swing.BoxLayout; … … 23 23 import javax.swing.JTable; 24 24 import javax.swing.ListSelectionModel; 25 import javax.swing.RowSorter.SortKey; 25 26 import javax.swing.SwingUtilities; 26 27 import javax.swing.TransferHandler; 27 import javax.swing.RowSorter.SortKey;28 28 import javax.swing.table.DefaultTableModel; 29 29 import javax.swing.table.TableCellRenderer; 30 31 30 import tmcsim.client.cadclientgui.enums.CADDataEnums; 32 31 import tmcsim.client.cadclientgui.enums.CADScriptTags.UNIT_TAGS; … … 36 35 37 36 /** 38 * This class contains the view and controller for the AssignedIncidents screen. The view was not built using a GUI builder plug-in 39 * (but may want to consider doing so in the future), and the controller uses listeners to control how the view and data act. 40 * 37 * This class contains the view and controller for the AssignedIncidents screen. 38 * The view was not built using a GUI builder plug-in (but may want to consider 39 * doing so in the future), and the controller uses listeners to control how the 40 * view and data act. 41 * 41 42 * @author Vincent 42 43 */ 43 44 public class AssignedIncidents extends JFrame { 45 44 public class AssignedIncidents extends JFrame 45 { 46 46 private final String SCREEN_TITLE = "(Shift + F3) Assigned Incidents"; 47 48 47 private final Dimension SCREEN_DIMENSIONS = new Dimension(1400, 250); 49 50 48 private final Dimension DROP_DOWN_MENU_LABEL_DIMENSIONS = new Dimension( 51 49 170, 20); 52 53 50 private final Dimension DROP_DOWN_MENU_DIMENSIONS = new Dimension(170, 230); 54 55 51 private final int COLUMN_WIDTH = 120; 56 57 private final String[] LABELS = { "Add Resources...", "Greater Alarm...", 58 "Reconfigure", "Open", "Recall Incident", "Cancel", "Reassign", 59 "Link/Append", "Map", "Recall Linked Incidents", "Read Notes", 60 "Page...", "Mail...", "Fax..." }; 61 52 private final String[] LABELS = 53 { 54 "Add Resources...", "Greater Alarm...", 55 "Reconfigure", "Open", "Recall Incident", "Cancel", "Reassign", 56 "Link/Append", "Map", "Recall Linked Incidents", "Read Notes", 57 "Page...", "Mail...", "Fax..." 58 }; 62 59 private final String LABEL_SPACING = " "; 63 64 60 private JTable assignedIncidentsTable; 65 61 private JFrame assignedIncidentsMenu; 66 67 62 // labels for the drop down menu 68 63 private JLabel[] dropDownLabels = new JLabel[LABELS.length]; 69 70 64 private long lastLeftClick;// used for double clicking feature 71 65 72 public AssignedIncidents() { 66 public AssignedIncidents() 67 { 73 68 initComponents(); 74 69 } 75 70 76 private void initComponents() { 71 private void initComponents() 72 { 77 73 initializeTable(); 78 74 initController(); … … 98 94 * drop feature. 99 95 */ 100 private void initializeTable() { 101 assignedIncidentsTable = new JTable(){ 96 private void initializeTable() 97 { 98 assignedIncidentsTable = new JTable() 99 { 102 100 /* 103 101 * Custom renderer to set different background/foreground colors 104 102 * @see javax.swing.JTable#prepareRenderer(javax.swing.table.TableCellRenderer, int, int) 105 103 */ 106 public Component prepareRenderer(TableCellRenderer renderer, int row, int column){ 104 public Component prepareRenderer(TableCellRenderer renderer, int row, int column) 105 { 107 106 Component comp = super.prepareRenderer(renderer, row, column); 108 107 109 108 comp.setForeground(Color.BLACK); 110 109 comp.setBackground(Color.CYAN); 111 if(assignedIncidentsTable.getModel().getColumnName(column).equals("Unit/s")){//4 is the column for "Unit/s" 112 System.out.println("Commenting this line breaks the client"); 110 if (assignedIncidentsTable.getModel().getColumnName(column).equals("Unit/s")) 111 {//4 is the column for "Unit/s" 112 //System.out.println("Diagnostic: in AssignedIncidents.prepareRenderer()"); //Commenting this line breaks the client 113 113 comp.setBackground(Color.BLACK); 114 114 int primaryColumn = 3; 115 try { 116 switch(ScreenManager.theCoordinator.getCadDataUnitStatus( 117 (String) assignedIncidentsTable.getValueAt(row,primaryColumn))){ 118 case Assignable: 119 comp.setForeground(Color.GREEN); 120 break; 121 case Arrived: 122 comp.setForeground(Color.YELLOW); 123 break; 124 case Enroute: 125 comp.setForeground(Color.CYAN); 126 break; 127 } 128 }catch (RemoteException e){ 129 e.printStackTrace(); 115 try 116 { 117 // get the unit name from the table JD 118 String unitname = (String) assignedIncidentsTable.getValueAt(row, primaryColumn); 119 // Validate that unitname isn't blank 120 if (!unitname.equals("")) 121 { 122 // Fetch the unit's current status from server 123 UnitStatusEnums ustatus = ScreenManager.theCoordinator.getCadDataUnitStatus(unitname); 124 // Decide which color to use for displaying the status 125 switch (ustatus) 126 { 127 case Assignable: 128 comp.setForeground(Color.GREEN); 129 break; 130 case Arrived: 131 comp.setForeground(Color.YELLOW); 132 break; 133 case Enroute: 134 comp.setForeground(Color.CYAN); 135 break; 136 } 137 } 138 } catch (RemoteException e) 139 { 140 e.printStackTrace(); 130 141 } 131 142 } 132 133 if (getSelectedRow() == row){ 143 144 if (getSelectedRow() == row) 145 { 134 146 comp.setForeground(Color.WHITE); 135 147 comp.setBackground(Color.BLUE); 136 148 } 137 149 138 150 return comp; 139 151 } 140 141 public Class getColumnClass(int c) { 152 153 public Class getColumnClass(int c) 154 { 142 155 return getValueAt(0, c).getClass(); 143 156 } 144 145 157 }; 146 158 147 159 assignedIncidentsTable.setOpaque(true); 148 160 assignedIncidentsTable.setIntercellSpacing(new Dimension(1, 0)); … … 153 165 assignedIncidentsTable.setAutoCreateRowSorter(true); 154 166 assignedIncidentsTable.setModel(new DefaultTableModel()); 155 167 156 168 ((DefaultTableModel) assignedIncidentsTable.getModel()).setColumnIdentifiers(TableHeaders.ASSIGNED_INCIDENTS_HEADERS); 157 158 assignedIncidentsTable.setTransferHandler(new TransferHandler(){ 159 160 public boolean canImport(TransferHandler.TransferSupport info) { 169 170 assignedIncidentsTable.setTransferHandler(new TransferHandler() 171 { 172 public boolean canImport(TransferHandler.TransferSupport info) 173 { 161 174 // Check for String flavor 162 if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { 175 if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) 176 { 163 177 return false; 164 178 } 165 179 return true; 166 } 167 168 public boolean importData(TransferHandler.TransferSupport info) { 169 if (!info.isDrop()) { 180 } 181 182 public boolean importData(TransferHandler.TransferSupport info) 183 { 184 if (!info.isDrop()) 185 { 170 186 return false; 171 187 } 172 173 DefaultTableModel tableModel = (DefaultTableModel) assignedIncidentsTable.getModel();174 JTable.DropLocation dl = (JTable.DropLocation) info.getDropLocation();188 189 DefaultTableModel tableModel = (DefaultTableModel) assignedIncidentsTable.getModel(); 190 JTable.DropLocation dl = (JTable.DropLocation) info.getDropLocation(); 175 191 int index = dl.getRow(); 176 192 177 193 // Get the string that is being dropped. 178 194 Transferable t = info.getTransferable(); 179 195 String data; 180 try { 181 data = (String)t.getTransferData(DataFlavor.stringFlavor); 182 } 183 catch (Exception e) { return false; } 184 196 try 197 { 198 data = (String) t.getTransferData(DataFlavor.stringFlavor); 199 } catch (Exception e) 200 { 201 return false; 202 } 203 185 204 // Perform the actual import 186 int incidentId = (Integer)assignedIncidentsTable.getValueAt(dl.getRow(), 0); 187 try { 188 ScreenManager.theCoordinator.setCadDataUnitAssignedId(data, incidentId); 189 ScreenManager.theCoordinator.setCadDataUnitValue(data, 190 UNIT_TAGS.UNIT_STATUS, UnitStatusEnums.Arrived); 191 ScreenManager.theCoordinator.addCadDataIncidentAssignedUnitNum(incidentId, data); 192 ScreenManager.theCoordinator.setCadDataIncidentStatus(incidentId, IncidentEnums.Assigned); 193 } catch (RemoteException e) { 194 e.printStackTrace(); 195 } 205 int incidentId = (Integer) assignedIncidentsTable.getValueAt(dl.getRow(), 0); 206 try 207 { 208 ScreenManager.theCoordinator.setCadDataUnitAssignedId(data, incidentId); 209 ScreenManager.theCoordinator.setCadDataUnitValue(data, 210 UNIT_TAGS.UNIT_STATUS, UnitStatusEnums.Arrived); 211 ScreenManager.theCoordinator.addCadDataIncidentAssignedUnitNum(incidentId, data); 212 ScreenManager.theCoordinator.setCadDataIncidentStatus(incidentId, IncidentEnums.Assigned); 213 } catch (RemoteException e) 214 { 215 e.printStackTrace(); 216 } 196 217 ScreenManager.refreshScreens(); 197 218 return true; 198 219 } 199 220 }); 200 201 for(int i = 0; i < assignedIncidentsTable.getColumnCount(); i++){ 221 222 for (int i = 0; i < assignedIncidentsTable.getColumnCount(); i++) 223 { 202 224 assignedIncidentsTable.getColumnModel().getColumn(i).setPreferredWidth(120); 203 225 } 204 226 } 205 227 206 228 /* 207 229 * Adds the key and mouse listeners for the table and component listener for 208 230 * screen. 209 231 */ 210 private void initController() { 211 assignedIncidentsTable.addMouseListener(new MouseListener() { 212 public void mouseClicked(MouseEvent e) { 213 if (SwingUtilities.isLeftMouseButton(e)) { 214 if (System.currentTimeMillis() - lastLeftClick < 1000) { 232 private void initController() 233 { 234 assignedIncidentsTable.addMouseListener(new MouseListener() 235 { 236 public void mouseClicked(MouseEvent e) 237 { 238 if (SwingUtilities.isLeftMouseButton(e)) 239 { 240 // TODO: Use e.getClickCount() == 2 241 if (System.currentTimeMillis() - lastLeftClick < 1000) 242 { 215 243 int idColumn = 0; 216 ScreenManager 217 .openIncidentViewer((Integer) assignedIncidentsTable 218 .getValueAt(assignedIncidentsTable 219 .getSelectedRow(), idColumn)); 220 } else { 244 int selectedRow = assignedIncidentsTable.getSelectedRow(); 245 try 246 { 247 int selectedValue = (Integer) assignedIncidentsTable.getValueAt(selectedRow, idColumn); 248 ScreenManager.openIncidentViewer(selectedValue); 249 } catch (IndexOutOfBoundsException ex) 250 { 251 ex.printStackTrace(); 252 } 253 } 254 else 255 { 221 256 lastLeftClick = System.currentTimeMillis(); 222 257 } 223 258 } 224 if (SwingUtilities.isRightMouseButton(e)) { 259 if (SwingUtilities.isRightMouseButton(e)) 260 { 261 // Fixed to force right click to cause the row to be selected. JD 262 // get the coordinates of the mouse click 263 Point p = e.getPoint(); 264 // get the row index that contains that coordinate 265 int rowNumber = assignedIncidentsTable.rowAtPoint(p); 266 // Get the ListSelectionModel of the JTable 267 ListSelectionModel model = assignedIncidentsTable.getSelectionModel(); 268 // set the selected interval of rows. Using the "rowNumber" 269 // variable for the beginning and end selects only that one row. 270 model.setSelectionInterval(rowNumber, rowNumber); 271 // go open the drop down menu 225 272 openDropDownMenu(e); 226 } else { 273 } 274 else 275 { 227 276 closeDropDownMenu(); 228 277 } 229 278 } 230 279 231 public void mouseEntered(MouseEvent e) { 232 } 233 234 public void mouseExited(MouseEvent e) { 235 } 236 237 public void mousePressed(MouseEvent e) { 238 } 239 240 public void mouseReleased(MouseEvent e) { 280 public void mouseEntered(MouseEvent e) 281 { 282 } 283 284 public void mouseExited(MouseEvent e) 285 { 286 } 287 288 public void mousePressed(MouseEvent e) 289 { 290 } 291 292 public void mouseReleased(MouseEvent e) 293 { 241 294 } 242 295 }); 243 296 244 addComponentListener(new ComponentListener() { 245 public void componentHidden(ComponentEvent e) { 246 } 247 248 public void componentMoved(ComponentEvent e) { 297 addComponentListener(new ComponentListener() 298 { 299 public void componentHidden(ComponentEvent e) 300 { 301 } 302 303 public void componentMoved(ComponentEvent e) 304 { 249 305 closeDropDownMenu(); 250 306 } 251 307 252 public void componentResized(ComponentEvent e) { 253 } 254 255 public void componentShown(ComponentEvent e) { 308 public void componentResized(ComponentEvent e) 309 { 310 } 311 312 public void componentShown(ComponentEvent e) 313 { 256 314 } 257 315 }); … … 262 320 * on the table. 263 321 */ 264 private void initializeDropDownMenu() { 322 private void initializeDropDownMenu() 323 { 265 324 Box menu = new Box(BoxLayout.Y_AXIS); 266 325 initializeDropDownLabels(); … … 282 341 * Sets the text and size and adds a listener to each activated label. 283 342 */ 284 private void initializeDropDownLabels() { 285 for (int i = 0; i < dropDownLabels.length; i++) { 343 private void initializeDropDownLabels() 344 { 345 for (int i = 0; i < dropDownLabels.length; i++) 346 { 286 347 dropDownLabels[i] = new JLabel(LABEL_SPACING + LABELS[i]); 287 348 dropDownLabels[i].setMaximumSize(DROP_DOWN_MENU_LABEL_DIMENSIONS); … … 298 359 * between. 299 360 */ 300 private void addLabelsToBox(Box menu) { 361 private void addLabelsToBox(Box menu) 362 { 301 363 menu.add(dropDownLabels[0]); 302 364 menu.add(dropDownLabels[1]); … … 335 397 * Sets the highlighted color(when the mouse is over it) of the JLabels. 336 398 * Note: the color is not shown until .setOpaque(true) is called. 337 * 399 * 338 400 * @param color the highlighted color 339 401 */ 340 public void setMenuHighlightedBackground(Color color) { 341 for (int i = 0; i < dropDownLabels.length; i++) { 402 public void setMenuHighlightedBackground(Color color) 403 { 404 for (int i = 0; i < dropDownLabels.length; i++) 405 { 342 406 dropDownLabels[i].setBackground(color); 343 407 } … … 347 411 * Sets all JLabels to not display a highlighted background 348 412 */ 349 public void unSelectAllLabels() { 350 for (int i = 0; i < dropDownLabels.length; i++) { 413 public void unSelectAllLabels() 414 { 415 for (int i = 0; i < dropDownLabels.length; i++) 416 { 351 417 dropDownLabels[i].setOpaque(false); 352 418 } … … 355 421 /* 356 422 * Sets the label to have a highlighted background. 357 * 423 * 358 424 * @param label the label that is selected/highlighted 359 425 */ 360 public void selectLabel(Object label) { 426 public void selectLabel(Object label) 427 { 361 428 ((JLabel) label).setOpaque(true); 362 429 } … … 365 432 * Performs the label action depending on which label was clicked. 366 433 */ 367 public void performLabelAction(Object label) { 368 if (label.equals(dropDownLabels[0])) {// Add Resources 369 370 } else if (label.equals(dropDownLabels[1])) {// Greater Alarm 371 372 } else if (label.equals(dropDownLabels[2])) {// Reconfigure 373 374 } else if (label.equals(dropDownLabels[3])) {// Open 434 public void performLabelAction(Object label) 435 { 436 if (label.equals(dropDownLabels[0])) 437 {// Add Resources 438 } 439 else if (label.equals(dropDownLabels[1])) 440 {// Greater Alarm 441 } 442 else if (label.equals(dropDownLabels[2])) 443 {// Reconfigure 444 } 445 else if (label.equals(dropDownLabels[3])) 446 {// Open 447 int idColumn = 0; 448 int selectedRow = assignedIncidentsTable.getSelectedRow(); 449 try 450 { 451 int selectedValue = (Integer) assignedIncidentsTable.getValueAt(selectedRow, idColumn); 452 ScreenManager.openIncidentViewer(selectedValue); 453 } catch (IndexOutOfBoundsException ex) 454 { 455 ex.printStackTrace(); 456 } 457 } 458 else if (label.equals(dropDownLabels[4])) 459 {// Recall Incident 460 } 461 else if (label.equals(dropDownLabels[5])) 462 {// Cancel 463 } 464 else if (label.equals(dropDownLabels[6])) 465 {// Reassign 466 } 467 else if (label.equals(dropDownLabels[7])) 468 {// Link append 469 } 470 else if (label.equals(dropDownLabels[8])) 471 {// Map 472 } 473 else if (label.equals(dropDownLabels[9])) 474 {// Recall Linked Incidents 475 } 476 else if (label.equals(dropDownLabels[10])) 477 {// Read Notes 375 478 int idColumn = 0; 376 479 ScreenManager.openIncidentViewer((Integer) assignedIncidentsTable 377 480 .getValueAt(assignedIncidentsTable.getSelectedRow(), 378 idColumn)); 379 } else if (label.equals(dropDownLabels[4])) {// Recall Incident 380 381 } else if (label.equals(dropDownLabels[5])) {// Cancel 382 383 } else if (label.equals(dropDownLabels[6])) {// Reassign 384 385 } else if (label.equals(dropDownLabels[7])) {// Link append 386 387 } else if (label.equals(dropDownLabels[8])) {// Map 388 389 } else if (label.equals(dropDownLabels[9])) {// Recall Linked Incidents 390 391 } else if (label.equals(dropDownLabels[10])) {// Read Notes 392 int idColumn = 0; 393 ScreenManager.openIncidentViewer((Integer) assignedIncidentsTable 394 .getValueAt(assignedIncidentsTable.getSelectedRow(), 395 idColumn)); 396 } else if (label.equals(dropDownLabels[11])) {// Page 397 398 } else if (label.equals(dropDownLabels[12])) {// Mail 399 400 } else if (label.equals(dropDownLabels[13])) {// Fax 401 481 idColumn)); 482 } 483 else if (label.equals(dropDownLabels[11])) 484 {// Page 485 } 486 else if (label.equals(dropDownLabels[12])) 487 {// Mail 488 } 489 else if (label.equals(dropDownLabels[13])) 490 {// Fax 402 491 } 403 492 } … … 409 498 * designates. 410 499 */ 411 public void addMouseListenersToLabel(JLabel label) { 412 label.addMouseMotionListener(new MouseMotionListener() { 413 public void mouseDragged(MouseEvent e) { 414 } 415 416 public void mouseMoved(MouseEvent e) { 500 public void addMouseListenersToLabel(JLabel label) 501 { 502 label.addMouseMotionListener(new MouseMotionListener() 503 { 504 public void mouseDragged(MouseEvent e) 505 { 506 } 507 508 public void mouseMoved(MouseEvent e) 509 { 417 510 unSelectAllLabels(); 418 511 selectLabel(e.getSource()); … … 421 514 } 422 515 }); 423 label.addMouseListener(new MouseListener() { 424 public void mouseClicked(MouseEvent e) { 516 label.addMouseListener(new MouseListener() 517 { 518 public void mouseClicked(MouseEvent e) 519 { 425 520 performLabelAction(e.getSource()); 426 521 unSelectAllLabels(); … … 430 525 } 431 526 432 public void mouseEntered(MouseEvent e) { 433 } 434 435 public void mouseExited(MouseEvent e) { 436 } 437 438 public void mousePressed(MouseEvent e) { 439 } 440 441 public void mouseReleased(MouseEvent e) { 527 public void mouseEntered(MouseEvent e) 528 { 529 } 530 531 public void mouseExited(MouseEvent e) 532 { 533 } 534 535 public void mousePressed(MouseEvent e) 536 { 537 } 538 539 public void mouseReleased(MouseEvent e) 540 { 442 541 } 443 542 }); … … 447 546 * Displays the menu where the right click occurred. 448 547 */ 449 public void openDropDownMenu(MouseEvent e) { 548 public void openDropDownMenu(MouseEvent e) 549 { 450 550 assignedIncidentsMenu.setLocation(e.getX() + this.getX(), e.getY() 451 551 + this.getY()); … … 456 556 * Hides the menu. 457 557 */ 458 public void closeDropDownMenu() { 558 public void closeDropDownMenu() 559 { 459 560 unSelectAllLabels(); 460 561 assignedIncidentsMenu.revalidate(); … … 465 566 /* 466 567 * Refreshes the data in the table by updating all data and repainting the 467 * screen. It saves user preferences(like column sizes, selected row, sorted preferences) 568 * screen. It saves user preferences(like column sizes, selected row, sorted preferences) 468 569 * and applies them to the updated model it receives from the server. 469 570 */ 470 public void refreshTable() { 471 472 if(assignedIncidentsTable.getTableHeader().getResizingColumn() == null){//only update info if resize not in progress 473 try { 571 public void refreshTable() 572 { 573 574 if (assignedIncidentsTable.getTableHeader().getResizingColumn() == null) 575 {//only update info if resize not in progress 576 try 577 { 474 578 int index = assignedIncidentsTable.getSelectedRow(); 475 579 int[] columnWidths = new int[20]; 476 580 List<? extends SortKey> keys = assignedIncidentsTable.getRowSorter().getSortKeys(); 477 for(int i = 0; i < assignedIncidentsTable.getColumnCount(); i++){ 581 for (int i = 0; i < assignedIncidentsTable.getColumnCount(); i++) 582 { 478 583 columnWidths[i] = assignedIncidentsTable.getColumnModel().getColumn(i).getWidth(); 479 584 } 480 585 481 586 assignedIncidentsTable.setModel(ScreenManager.theCoordinator.getCadDataTable(CADDataEnums.TABLE.ASSIGNED_INCIDENTS)); 482 483 for(int i = 0; i < assignedIncidentsTable.getColumnCount(); i++){ 587 588 for (int i = 0; i < assignedIncidentsTable.getColumnCount(); i++) 589 { 484 590 assignedIncidentsTable.getColumnModel().getColumn(i).setPreferredWidth(columnWidths[i]); 485 591 } 486 592 assignedIncidentsTable.getRowSorter().setSortKeys(keys); 487 593 assignedIncidentsTable.getSelectionModel().setSelectionInterval(index, index); 488 } catch (RemoteException e) { 489 e.printStackTrace(); 490 } 491 revalidate(); 492 repaint(); 493 } 594 } catch (RemoteException e) 595 { 596 e.printStackTrace(); 597 } 598 revalidate(); 599 repaint(); 600 } 494 601 } 495 602 … … 497 604 * Makes screen visible. 498 605 */ 499 public void open() { 606 public void open() 607 { 500 608 setVisible(true); 501 609 } … … 504 612 * Hides screen. 505 613 */ 506 public void close() { 614 public void close() 615 { 507 616 setVisible(false); 508 617 } 509 510 618 }
Note: See TracChangeset
for help on using the changeset viewer.
