org.gjt.sp.jedit.gui
Class DefaultInputHandler

java.lang.Object
  |
  +--java.awt.event.KeyAdapter
        |
        +--org.gjt.sp.jedit.gui.InputHandler
              |
              +--org.gjt.sp.jedit.gui.DefaultInputHandler
All Implemented Interfaces:
java.util.EventListener, java.awt.event.KeyListener

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.

Version:
$Id: DefaultInputHandler.java,v 1.15 2003/01/14 20:05:18 spestov Exp $
Author:
Slava Pestov

Field Summary
 
Fields inherited from class org.gjt.sp.jedit.gui.InputHandler
lastAction, lastActionCount, readNextChar, repeat, repeatCount, view
 
Constructor Summary
DefaultInputHandler(View view)
          Creates a new input handler with no key bindings defined.
DefaultInputHandler(View view, DefaultInputHandler copy)
          Creates a new input handler with the same set of key bindings as the one specified.
 
Method Summary
 void addKeyBinding(java.lang.String keyBinding, EditAction 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.
static java.lang.String getModifierString(java.awt.event.InputEvent evt)
          Returns a string containing symbolic modifier names set in the specified event.
static char getSymbolicModifierName(int mod)
          Returns a the symbolic modifier name for the specified Java modifier flag.
 boolean isPrefixActive()
          Returns if a prefix key has been pressed.
 void keyPressed(java.awt.event.KeyEvent evt)
          Handle a key pressed event.
 void keyTyped(java.awt.event.KeyEvent evt)
          Handle a key typed event.
static javax.swing.KeyStroke parseKeyStroke(java.lang.String keyStroke)
          Converts a string to a keystroke.
 void removeAllKeyBindings()
          Removes all key bindings from this input handler.
 void removeKeyBinding(java.lang.String keyBinding)
          Removes a key binding from this input handler.
static void setModifierMapping(int c, int a, int m, int s)
          Changes the mapping between symbolic modifier key names (C, A, M, S) and Java modifier flags.
 
Methods inherited from class org.gjt.sp.jedit.gui.InputHandler
getLastAction, getLastActionCount, getRepeatCount, invokeAction, invokeReadNextChar, isRepeatEnabled, processKeyEvent, readNextChar, readNextChar, resetLastActionCount, setRepeatCount, setRepeatEnabled, userInput
 
Methods inherited from class java.awt.event.KeyAdapter
keyReleased
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultInputHandler

public DefaultInputHandler(View view)
Creates a new input handler with no key bindings defined.

Parameters:
view - The view

DefaultInputHandler

public DefaultInputHandler(View view,
                           DefaultInputHandler copy)
Creates a new input handler with the same set of key bindings as the one specified. Note that both input handlers share a pointer to exactly the same key binding table; so adding a key binding in one will also add it to the other.

Parameters:
copy - The input handler to copy key bindings from
view - The view
Method Detail

addKeyBinding

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

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

isPrefixActive

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

Overrides:
isPrefixActive 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

setModifierMapping

public static void setModifierMapping(int c,
                                      int a,
                                      int m,
                                      int s)
Changes the mapping between symbolic modifier key names (C, A, M, S) and Java modifier flags.

Parameters:
c - The modifier to map the C modifier to
a - The modifier to map the A modifier to
m - The modifier to map the M modifier to
s - The modifier to map the S modifier to
Since:
jEdit 4.1pre3

getSymbolicModifierName

public static char getSymbolicModifierName(int mod)
Returns a the symbolic modifier name for the specified Java modifier flag.

Parameters:
mod - A modifier constant from InputEvent
Since:
jEdit 4.1pre3

getModifierString

public static java.lang.String getModifierString(java.awt.event.InputEvent evt)
Returns a string containing symbolic modifier names set in the specified event.

Parameters:
evt - The event
Since:
jEdit 4.1pre3

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