Class DefaultInputHandler

  • All Implemented Interfaces:
    java.awt.event.KeyListener, java.util.EventListener
    Direct Known Subclasses:
    CutCopyPasteInputHandler

    public class DefaultInputHandler
    extends InputHandler
    The default input handler. It maps sequences of keystrokes into actions and inserts key typed events into the text area.
    • Constructor Detail

      • DefaultInputHandler

        public DefaultInputHandler()
        Creates a new input handler with no key bindings defined.
    • Method Detail

      • addKeyBinding

        public void addKeyBinding​(java.lang.String keyBinding,
                                  java.awt.event.ActionListener action)
        Adds a key binding to this input handler. The key binding is a list of white space separated key strokes of the form [modifiers+]key where modifier is C for Control, A for Alt, or S for Shift, and key is either a character (a-z) or a field name in the KeyEvent class prefixed with VK_ (e.g., BACK_SPACE)
        Specified by:
        addKeyBinding in class InputHandler
        Parameters:
        keyBinding - The key binding
        action - The action
      • removeKeyBinding

        public void removeKeyBinding​(java.lang.String keyBinding)
        Removes a key binding from this input handler. This is not yet implemented.
        Specified by:
        removeKeyBinding in class InputHandler
        Parameters:
        keyBinding - The key binding
      • removeAllKeyBindings

        public void removeAllKeyBindings()
        Removes all key bindings from this input handler.
        Specified by:
        removeAllKeyBindings in class InputHandler
      • copy

        public InputHandler copy()
        Returns a copy of this input handler that shares the same key bindings. Setting key bindings in the copy will also set them in the original.
        Specified by:
        copy in class InputHandler
      • keyPressed

        public void keyPressed​(java.awt.event.KeyEvent evt)
        Handle a key pressed event. This will look up the binding for the key stroke and execute it.
        Specified by:
        keyPressed in interface java.awt.event.KeyListener
        Overrides:
        keyPressed in class java.awt.event.KeyAdapter
      • keyTyped

        public void keyTyped​(java.awt.event.KeyEvent evt)
        Handle a key typed event. This inserts the key into the text area.
        Specified by:
        keyTyped in interface java.awt.event.KeyListener
        Overrides:
        keyTyped in class java.awt.event.KeyAdapter
      • parseKeyStroke

        public static javax.swing.KeyStroke parseKeyStroke​(java.lang.String keyStroke)
        Converts a string to a keystroke. The string should be of the form modifiers+shortcut where modifiers is any combination of A for Alt, C for Control, S for Shift or M for Meta, and shortcut is either a single character, or a keycode name from the KeyEvent class, without the VK_ prefix.
        Parameters:
        keyStroke - A string description of the key stroke