Ignore:
Timestamp:
05/23/2019 08:41:03 PM (7 years ago)
Author:
jdalbey
Message:

IncidentViewer?.java: Modify upperCommentBox behavior to conform to new user requirements: Enter key saves the comment. Exit / Send will send any non-blank entry, or Exit if the field is empty.

File:
1 edited

Legend:

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

    r310 r414  
    33import java.awt.Color; 
    44import java.awt.Dimension; 
     5import java.awt.Event; 
    56import java.awt.event.ActionEvent; 
    67import java.awt.event.ActionListener; 
     8import java.awt.event.KeyEvent; 
    79import java.awt.event.WindowAdapter; 
    810import java.awt.event.WindowEvent; 
     
    1214import java.util.Date; 
    1315import java.util.Stack; 
     16import java.util.logging.Level; 
     17import java.util.logging.Logger; 
     18import javax.swing.AbstractAction; 
     19import javax.swing.ActionMap; 
    1420import javax.swing.BorderFactory; 
    1521import javax.swing.ImageIcon; 
     22import javax.swing.InputMap; 
    1623import javax.swing.JButton; 
     24import javax.swing.JTextArea; 
     25import javax.swing.JTextPane; 
     26import javax.swing.KeyStroke; 
    1727import javax.swing.ListSelectionModel; 
    1828import javax.swing.event.DocumentEvent; 
    1929import javax.swing.event.DocumentListener; 
    2030import javax.swing.table.DefaultTableModel; 
     31import javax.swing.text.BadLocationException; 
     32import javax.swing.text.StyledDocument; 
     33import spikes.TextComponentDemo; 
    2134import tmcsim.client.cadclientgui.enums.CADDataEnums.INC_ADD_INFO; 
    2235import tmcsim.client.cadclientgui.enums.CADDataEnums.INC_CALLBACK; 
     
    5467        initLayout(); 
    5568        initControllers(); 
     69        addBindings(); 
    5670    } 
    5771 
     
    305319                    upperCommentBox.setText(""); 
    306320                } 
    307                 close(); 
     321                else // Exit the window 
     322                { 
     323                    close(); 
     324                } 
    308325            } 
    309326        }; 
    310327    } 
    311  
     328                     
    312329    public DocumentListener newCommentsDocumentListener() 
    313330    { 
     
    318335            } 
    319336 
    320             public void insertUpdate(DocumentEvent e) 
     337            public void insertUpdate(DocumentEvent evt) 
    321338            { 
    322                 commentsNotesSaveButton.setEnabled(true); 
     339                commentsNotesSaveButton.setEnabled(true);            
    323340            } 
    324341 
     
    706723        commentsNotesField.setLineWrap(true); // JD make text wrap inside the field 
    707724        commentsNotesField.setBorder(BorderFactory.createLineBorder(Color.GRAY)); // JD added a border 
    708  
     725        upperCommentBox.setLineWrap(true);  
     726         
    709727        commentsNotesAddButton.setText("Add"); 
    710728        commentsNotesCancelButton.setText("Cancel"); 
     
    21602178        ScreenManager.refreshIncidentEditor(); 
    21612179    } 
     2180    /** Add key binding to upper comment box to catch Enter key 
     2181     *  and save the comment, then clear the field. 
     2182     */ 
     2183    protected void addBindings()  
     2184    { 
     2185        InputMap inputMap = upperCommentBox.getInputMap(); 
     2186        ActionMap actionMap = upperCommentBox.getActionMap(); 
     2187        // Watch for Enter key 
     2188        KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); 
     2189        inputMap.put(key, "clearAction"); 
     2190        actionMap.put("clearAction", new ClearAction()); 
     2191    } 
     2192    /** Custom Action to clear a JTextPane, used to clear upperCommentBox */ 
     2193    class ClearAction extends AbstractAction  
     2194    { 
     2195        public void actionPerformed(ActionEvent evt)  
     2196        { 
     2197            JTextArea src = (JTextArea) evt.getSource(); 
     2198            saveComment(src.getText().toUpperCase()); 
     2199            src.setText(""); // clear the text area 
     2200        } 
     2201    } 
     2202 
    21622203    // Variables declaration - do not modify//GEN-BEGIN:variables 
    21632204    private javax.swing.JPanel activitiesPane; 
Note: See TracChangeset for help on using the changeset viewer.