org.gjt.sp.jedit.input
Class AbstractInputHandler<E extends JEditAbstractEditAction>

java.lang.Object
  extended by org.gjt.sp.jedit.input.AbstractInputHandler<E>
Direct Known Subclasses:
InputHandler, TextAreaInputHandler

public abstract class AbstractInputHandler<E extends JEditAbstractEditAction>
extends java.lang.Object

The abstract input handler manage the keyboard handling. The entry point is processKeyEvent(java.awt.event.KeyEvent, int, boolean)


Field Summary
protected  java.util.Hashtable bindings
           
protected  java.util.Hashtable currentBindings
           
protected  java.awt.event.KeyListener keyEventInterceptor
          This listener will receive keyboard events if it is not null.
protected  E lastAction
           
protected  int lastActionCount
           
static java.lang.Object PREFIX_STR
           
protected  java.lang.String readNextChar
           
protected static int REPEAT_COUNT_THRESHOLD
           
protected  int repeatCount
           
protected  boolean shortcutOn
           
 
Constructor Summary
AbstractInputHandler()
           
 
Method Summary
 void addKeyBinding(java.lang.String keyBinding, E action)
          Adds a key binding to this input handler.
 void addKeyBinding(java.lang.String keyBinding, java.lang.Object action)
          Adds a key binding to this input handler.
 void addKeyBinding(java.lang.String keyBinding, java.lang.String action)
          Adds a key binding to this input handler.
 java.lang.Object getKeyBinding(java.lang.String keyBinding)
          Returns either an edit action, or a hashtable if the specified key is a prefix.
 java.awt.event.KeyListener getKeyEventInterceptor()
           
 int getLastActionCount()
          Returns the number of times the last action was executed.
abstract  boolean handleKey(KeyEventTranslator.Key keyStroke, boolean dryRun)
          Handles a keystroke.
abstract  void invokeAction(E action)
           
abstract  void invokeAction(java.lang.String action)
           
 boolean isPrefixActive()
          Returns if a prefix key has been pressed.
abstract  void processKeyEvent(java.awt.event.KeyEvent evt, int from, boolean global)
          Process a keyboard event.
protected  void processKeyEventKeyStrokeHandling(java.awt.event.KeyEvent evt, int from, java.lang.String mode, boolean global)
           
 void removeAllKeyBindings()
          Removes all key bindings from this input handler.
 void removeKeyBinding(java.lang.String keyBinding)
          Removes a key binding from this input handler.
 void resetLastActionCount()
          Resets the last action count.
protected  void sendShortcutPrefixOff()
          If
 void setBindings(java.util.Hashtable bindings)
          Replace the set of key bindings.
 void setCurrentBindings(java.util.Hashtable bindings)
           
 void setKeyEventInterceptor(java.awt.event.KeyListener keyEventInterceptor)
          Sets the listener that will handle all key events in this view.
static java.lang.String toString(java.awt.event.KeyEvent evt)
          Return a String representation of the keyboard event for debugging purpose.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastActionCount

protected int lastActionCount

keyEventInterceptor

protected java.awt.event.KeyListener keyEventInterceptor
This listener will receive keyboard events if it is not null.


readNextChar

protected java.lang.String readNextChar

repeatCount

protected int repeatCount

lastAction

protected E extends JEditAbstractEditAction lastAction

REPEAT_COUNT_THRESHOLD

protected static final int REPEAT_COUNT_THRESHOLD
See Also:
Constant Field Values

PREFIX_STR

public static java.lang.Object PREFIX_STR

shortcutOn

protected boolean shortcutOn

bindings

protected java.util.Hashtable bindings

currentBindings

protected java.util.Hashtable currentBindings
Constructor Detail

AbstractInputHandler

public AbstractInputHandler()
Method Detail

addKeyBinding

public void addKeyBinding(java.lang.String keyBinding,
                          java.lang.String 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)

Parameters:
keyBinding - The key binding
action - The action
Since:
jEdit 4.2pre1

addKeyBinding

public void addKeyBinding(java.lang.String keyBinding,
                          E 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)

Parameters:
keyBinding - The key binding
action - The action

addKeyBinding

public void addKeyBinding(java.lang.String keyBinding,
                          java.lang.Object 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)

Parameters:
keyBinding - The key binding
action - The action
Since:
jEdit 4.3pre1

removeKeyBinding

public void removeKeyBinding(java.lang.String keyBinding)
Removes a key binding from this input handler. This is not yet implemented.

Parameters:
keyBinding - The key binding

removeAllKeyBindings

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


getKeyBinding

public java.lang.Object getKeyBinding(java.lang.String keyBinding)
Returns either an edit action, or a hashtable if the specified key is a prefix.

Parameters:
keyBinding - The key binding
Since:
jEdit 3.2pre5

getLastActionCount

public int getLastActionCount()
Returns the number of times the last action was executed. It can be used with smartHome and smartEnd

Returns:
the number of times the last action was executed
Since:
jEdit 2.5pre5

resetLastActionCount

public void resetLastActionCount()
Resets the last action count. This should be called when an editing operation that is not an action is invoked, for example a mouse click.

Since:
jEdit 4.0pre1

getKeyEventInterceptor

public java.awt.event.KeyListener getKeyEventInterceptor()

setKeyEventInterceptor

public void setKeyEventInterceptor(java.awt.event.KeyListener keyEventInterceptor)
Sets the listener that will handle all key events in this view. For example, the complete word command uses this so that all key events are passed to the word list popup while it is visible.

Parameters:
keyEventInterceptor - the KeyListener that will receive the events

isPrefixActive

public boolean isPrefixActive()
Returns if a prefix key has been pressed.


setBindings

public void setBindings(java.util.Hashtable bindings)
Replace the set of key bindings.

Since:
jEdit 4.3pre1

setCurrentBindings

public void setCurrentBindings(java.util.Hashtable bindings)

handleKey

public abstract boolean handleKey(KeyEventTranslator.Key keyStroke,
                                  boolean dryRun)
Handles a keystroke.

Parameters:
keyStroke - The key stroke.
dryRun - only calculate the return value, do not have any other effect
Returns:
true if the input could be handled.
Since:
jEdit 4.3pre7

processKeyEvent

public abstract void processKeyEvent(java.awt.event.KeyEvent evt,
                                     int from,
                                     boolean global)
Process a keyboard event. This is the entry point of the keyboard handling

Parameters:
evt - the keyboard event
from - the source, it can be View.VIEW, View.ACTION_BAR or View.TEXT_AREA
global - tell if the event comes from the DefaultKeyboardFocusManager or not

sendShortcutPrefixOff

protected void sendShortcutPrefixOff()
If


invokeAction

public abstract void invokeAction(java.lang.String action)

invokeAction

public abstract void invokeAction(E action)

toString

public static java.lang.String toString(java.awt.event.KeyEvent evt)
Return a String representation of the keyboard event for debugging purpose.

Parameters:
evt - the keyboard event
Returns:
a String representation for this keyboard event
Since:
jEdit 4.3pre15

processKeyEventKeyStrokeHandling

protected void processKeyEventKeyStrokeHandling(java.awt.event.KeyEvent evt,
                                                int from,
                                                java.lang.String mode,
                                                boolean global)
Parameters:
evt - the keyboard event
from - the source, it can be View.VIEW, View.ACTION_BAR or View.TEXT_AREA
mode - the mode is "press" or "type" and is used for debug only
global - tell if the event comes from the DefaultKeyboardFocusManager or not