Class InputHandler

java.lang.Object
java.awt.event.KeyAdapter
mars.venus.editor.jeditsyntax.InputHandler
All Implemented Interfaces:
KeyListener, EventListener
Direct Known Subclasses:
DefaultInputHandler

public abstract class InputHandler extends KeyAdapter
An input handler converts the user's key strokes into concrete actions. It also takes care of macro recording and action repetition.

This class provides all the necessary support code for an input handler, but doesn't actually do any key binding logic. It is up to the implementations of this class to do so.

08/12/2002: Clipboard actions (Oliver Henning)

Version:
$Id: InputHandler.java,v 1.14 1999/12/13 03:40:30 sp Exp $
Author:
Slava Pestov
See Also:
  • Field Details

  • Constructor Details

    • InputHandler

      public InputHandler()
  • Method Details

    • getAction

      public static ActionListener getAction(String name)
      Returns a named text area action.
      Parameters:
      name - The action name
    • getActionName

      public static String getActionName(ActionListener action)
      Returns the name of the specified text area action.
      Parameters:
      action - The action
    • addDefaultKeyBindings

      public abstract void addDefaultKeyBindings()
      Adds the default key bindings to this input handler. This should not be called in the constructor of this input handler, because applications might load the key bindings from a file, etc.
    • addKeyBinding

      public abstract void addKeyBinding(String keyBinding, ActionListener action)
      Adds a key binding to this input handler.
      Parameters:
      keyBinding - The key binding (the format of this is input-handler specific)
      action - The action
    • removeKeyBinding

      public abstract void removeKeyBinding(String keyBinding)
      Removes a key binding from this input handler.
      Parameters:
      keyBinding - The key binding
    • removeAllKeyBindings

      public abstract void removeAllKeyBindings()
      Removes all key bindings from this input handler.
    • grabNextKeyStroke

      public void grabNextKeyStroke(ActionListener action)
      Grabs the next key typed event and invokes the specified action with the key as a the action command.
      Parameters:
      action - The action
    • isRepeatEnabled

      public boolean isRepeatEnabled()
      Returns if repeating is enabled. When repeating is enabled, actions will be executed multiple times. This is usually invoked with a special key stroke in the input handler.
    • setRepeatEnabled

      public void setRepeatEnabled(boolean repeat)
      Enables repeating. When repeating is enabled, actions will be executed multiple times. Once repeating is enabled, the input handler should read a number from the keyboard.
    • getRepeatCount

      public int getRepeatCount()
      Returns the number of times the next action will be repeated.
    • setRepeatCount

      public void setRepeatCount(int repeatCount)
      Sets the number of times the next action will be repeated.
      Parameters:
      repeatCount - The repeat count
    • getMacroRecorder

      public InputHandler.MacroRecorder getMacroRecorder()
      Returns the macro recorder. If this is non-null, all executed actions should be forwarded to the recorder.
    • setMacroRecorder

      public void setMacroRecorder(InputHandler.MacroRecorder recorder)
      Sets the macro recorder. If this is non-null, all executed actions should be forwarded to the recorder.
      Parameters:
      recorder - The macro recorder
    • copy

      public abstract 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.
    • executeAction

      public void executeAction(ActionListener action, Object source, String actionCommand)
      Executes the specified action, repeating and recording it as necessary.
      Parameters:
      action - The action listener
      source - The event source
      actionCommand - The action command
    • getTextArea

      public static JEditTextArea getTextArea(EventObject event)
      Returns the text area that fired the specified event.
      Parameters:
      event - The event
    • handleGrabAction

      protected void handleGrabAction(KeyEvent event)
      If a key is being grabbed, this method should be called with the appropriate key event. It executes the grab action with the typed character as the parameter.