Changeset 288 in tmcsimulator for trunk/src


Ignore:
Timestamp:
03/02/2019 09:24:47 AM (7 years ago)
Author:
jdalbey
Message:

IncidentViewer?.java: Enable the upper comment box and save any text when Exit/Send? is clicked. Then clear the box so it appears empty when window is next opened. "Extract method" refactoring to encapsulate code common to both save comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/client/cadclientgui/screens/IncidentViewer.java

    r59 r288  
    296296            public void actionPerformed(ActionEvent arg0) 
    297297            { 
     298                String commentMsg = upperCommentBox.getText().trim(); 
     299                // If any text was entered in upper comment box 
     300                if (commentMsg.length() > 0) 
     301                { 
     302                    /*save text from comment box */ 
     303                    saveComment(commentMsg.toUpperCase()); 
     304                    // Clear the text before closing 
     305                    upperCommentBox.setText(""); 
     306                } 
    298307                close(); 
    299308            } 
     
    358367            public void actionPerformed(ActionEvent arg0) 
    359368            { 
    360                 DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); 
    361                 DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); 
    362                 String[] fields = 
    363                 { 
    364                     dateFormat.format(new Date()), 
    365                     timeFormat.format(new Date()), 
    366                     ScreenManager.getUserName(), // Put username in "Initials" column 
    367                     "", // "Block" is left blank for now  
    368                     commentsNotesField.getText().toUpperCase() // JD 
    369                 }; 
    370                 try 
    371                 { 
    372                     ScreenManager.theCoordinator.addCadDataIncidentTable( 
    373                             INC_TABLE.COMMENTS_NOTES, incidentId, fields); 
    374                     ((DefaultTableModel) commentsNotesTable.getModel()).insertRow(0, fields);//JD 
    375                     //((DefaultTableModel) commentsNotesTable.getModel()).addRow(fields); 
    376                 } catch (RemoteException e) 
    377                 { 
    378                     e.printStackTrace(); 
    379                 } 
     369                // pull the text from the text area and go save it 
     370                saveComment(commentsNotesField.getText().toUpperCase()); 
    380371 
    381372                commentsNotesField.setText(""); 
     
    388379        }; 
    389380    } 
    390  
     381     
     382    /** There are two comment fields on the form so this method performs 
     383     * the save actions that are common to both fields. 
     384     * @author jdalbey 
     385     * @param commentMsg the text of the comment to be saved. 
     386     */ 
     387    private void saveComment(String commentMsg) 
     388    { 
     389                DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); 
     390                DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); 
     391                // prepare fields to be added to comment table 
     392                String[] fields = 
     393                { 
     394                    dateFormat.format(new Date()), 
     395                    timeFormat.format(new Date()), 
     396                    ScreenManager.getUserName(), // Put username in "Initials" column 
     397                    "", // "Block" is left blank for now  
     398                    commentMsg 
     399                }; 
     400                try 
     401                { 
     402                    // insert a new row in the comment table 
     403                    ScreenManager.theCoordinator.addCadDataIncidentTable( 
     404                            INC_TABLE.COMMENTS_NOTES, incidentId, fields); 
     405                    ((DefaultTableModel) commentsNotesTable.getModel()).insertRow(0, fields); 
     406                } catch (RemoteException e) 
     407                { 
     408                    e.printStackTrace(); 
     409                } 
     410         
     411    } 
    391412    // JD Add a mouselistener to the comments table to display a single cell 
    392413    //  contents in a popup 
     
    14791500 
    14801501        jScrollPane11.setViewportView(dataFieldsTable); 
     1502        jScrollPane2.setViewportView(upperCommentBox); 
    14811503 
    14821504        dataFieldsLabel.setText("Data Fields"); 
     
    24132435    private javax.swing.JTextField userDataTimeField; 
    24142436    private javax.swing.JTextField userDataTimeStampField; 
     2437    private javax.swing.JTextArea upperCommentBox = new javax.swing.JTextArea(); 
    24152438    // End of variables declaration//GEN-END:variables 
    24162439} 
Note: See TracChangeset for help on using the changeset viewer.