com.borland.primetime.editor
Class DefaultKeymap

java.lang.Object
  |
  +--com.borland.primetime.editor.DefaultKeymap
All Implemented Interfaces:
javax.swing.text.Keymap
Direct Known Subclasses:
TrackingKeymap

public class DefaultKeymap
extends java.lang.Object
implements javax.swing.text.Keymap

This is simply an implementation of the Keymap interface. It comes directly from JTextComponent.DefaultKeymap, which the Swing team neglected to make public. Sigh.

See Also:
javax.swing.text.JTextComponent.DefaultKeymap

Field Summary
protected  java.util.Hashtable bindings
          The place where the key stroke / action pairs are stored.
protected  javax.swing.Action defaultAction
          The default action of this keymap.
protected  javax.swing.text.Keymap master
          The keymap that is the master of this keymap, which makes this keymap a sub keymap
protected  java.lang.String nm
          The name of this keymap
protected  javax.swing.text.Keymap parent
          The first parent in the parent hierarchy of this keymap.
 
Constructor Summary
DefaultKeymap(java.lang.String nm, javax.swing.text.Keymap parent)
          Instantiate a new keymap with a name and a parent.
 
Method Summary
 void addActionForKeyStroke(javax.swing.KeyStroke key, javax.swing.Action a)
          Add a binding of a key stroke to an action in this keymap.
 javax.swing.Action getAction(javax.swing.KeyStroke key)
          Get the action associated with the given key stroke.
 java.util.Hashtable getBindings()
          Get the table of bindings of key strokes for this keymap.
 javax.swing.Action[] getBoundActions()
          Get an array of actions that are bound to key strokes.
 javax.swing.KeyStroke[] getBoundKeyStrokes()
          Get an array of key strokes that have actions associated with them.
 javax.swing.Action getDefaultAction()
          Fetch the default action to fire if a key is typed (ie a KEY_TYPED KeyEvent is received) and there is no binding for it.
 javax.swing.KeyStroke[] getKeyStrokesForAction(javax.swing.Action a)
          Given an action, find all the key strokes that are bound to this action.
 javax.swing.text.Keymap getMaster()
          Get the master of this keymap if any.
 java.lang.String getName()
          Get the name of this keymap, which is the name used when this keymap was instantiated.
 javax.swing.text.Keymap getResolveParent()
          Get the first parent up the parent hierarchy.
 boolean isLocallyDefined(javax.swing.KeyStroke key)
          Determine if a key stroke is bound to an action in this keymap
 void removeBindings()
          Remove all bindings of key strokes from this keymap.
 void removeKeyStrokeBinding(javax.swing.KeyStroke key)
          Remove the binding of a key stroke from this keymap.
 void setBindings(java.util.Hashtable newBindings)
          Set the table of bindings of key strokes for this keymap.
 void setDefaultAction(javax.swing.Action a)
          Set the default action to fire if a key is typed.
 void setMaster(javax.swing.text.Keymap master)
          Set the master of this keymap, and by doing that, make this keymap a sub keymap.
 void setResolveParent(javax.swing.text.Keymap parent)
          Set the first parent in the parent hierarchy.
 java.lang.String toString()
          String representation of the keymap...
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nm

protected java.lang.String nm
The name of this keymap

parent

protected javax.swing.text.Keymap parent
The first parent in the parent hierarchy of this keymap.

bindings

protected java.util.Hashtable bindings
The place where the key stroke / action pairs are stored.

defaultAction

protected javax.swing.Action defaultAction
The default action of this keymap.

master

protected javax.swing.text.Keymap master
The keymap that is the master of this keymap, which makes this keymap a sub keymap
Constructor Detail

DefaultKeymap

public DefaultKeymap(java.lang.String nm,
                     javax.swing.text.Keymap parent)
Instantiate a new keymap with a name and a parent. The name is used to look a keymap up by name, and the parent will be searched for actions if a key is not associated with an action in this keymap.
Method Detail

getDefaultAction

public javax.swing.Action getDefaultAction()
Fetch the default action to fire if a key is typed (ie a KEY_TYPED KeyEvent is received) and there is no binding for it. Typically this would be some action that inserts text so that the keymap doesn't require an action for each possible key.
Specified by:
getDefaultAction in interface javax.swing.text.Keymap
Returns:
the default action of this keymap

setDefaultAction

public void setDefaultAction(javax.swing.Action a)
Set the default action to fire if a key is typed.
Specified by:
setDefaultAction in interface javax.swing.text.Keymap
Parameters:
a - the action that will become the default action of this keymap.

getName

public java.lang.String getName()
Get the name of this keymap, which is the name used when this keymap was instantiated.
Specified by:
getName in interface javax.swing.text.Keymap
Returns:
the name of this keymap

getAction

public javax.swing.Action getAction(javax.swing.KeyStroke key)
Get the action associated with the given key stroke. First this keymap is searched, and if no action was found, the parent hierarchy will be searched.
Specified by:
getAction in interface javax.swing.text.Keymap
Parameters:
key - the key stroke which should trigger an action.
Returns:
the action associated with this key stroke, or null if no action was found.

getBoundKeyStrokes

public javax.swing.KeyStroke[] getBoundKeyStrokes()
Get an array of key strokes that have actions associated with them. Only this instance is searched, the parent hierarchy is not searched.
Specified by:
getBoundKeyStrokes in interface javax.swing.text.Keymap
Returns:
an array of key strokes that have actions associated with them in this particular keymap. Returns a valid array that can have a size of zero.

getBoundActions

public javax.swing.Action[] getBoundActions()
Get an array of actions that are bound to key strokes. Only this instance is searched, the parent hierarchy is not searched.
Specified by:
getBoundActions in interface javax.swing.text.Keymap
Returns:
an array of actions bound to key strokes in this particular keymap. Returns a valid array that can have a size of zero.

getKeyStrokesForAction

public javax.swing.KeyStroke[] getKeyStrokesForAction(javax.swing.Action a)
Given an action, find all the key strokes that are bound to this action. The algorithm determines the bindings in this keymap first, and then travels the parent hierarchy to find more bindings. Any binding in the parents that is not reachable in this keymap will not be reported, for instance if the key strokes that trigger the action in the parent trigger another unrelated action in this keymap.
Specified by:
getKeyStrokesForAction in interface javax.swing.text.Keymap
Parameters:
a - the action we are interested in
Returns:
an array of key strokes that will trigger the action, or null if no key strokes were found

isLocallyDefined

public boolean isLocallyDefined(javax.swing.KeyStroke key)
Determine if a key stroke is bound to an action in this keymap
Specified by:
isLocallyDefined in interface javax.swing.text.Keymap
Parameters:
key - the key stroke we are interested in
Returns:
true if there is an action bound to this key stroke, false otherwise.

addActionForKeyStroke

public void addActionForKeyStroke(javax.swing.KeyStroke key,
                                  javax.swing.Action a)
Add a binding of a key stroke to an action in this keymap.
Specified by:
addActionForKeyStroke in interface javax.swing.text.Keymap
Parameters:
key - the key stroke that will have to trigger the action
a - the action that should be triggered by the key stroke.

removeKeyStrokeBinding

public void removeKeyStrokeBinding(javax.swing.KeyStroke key)
Remove the binding of a key stroke from this keymap. This does not remove the binding in any of the parent keymaps.
Specified by:
removeKeyStrokeBinding in interface javax.swing.text.Keymap
Parameters:
key - the key stroke whose binding should be removed.

removeBindings

public void removeBindings()
Remove all bindings of key strokes from this keymap. This does not remove any bindings in any of the parent keymaps.
Specified by:
removeBindings in interface javax.swing.text.Keymap

getBindings

public java.util.Hashtable getBindings()
Get the table of bindings of key strokes for this keymap. These are only the bindings of this keymap, not of any of its parent keymaps.
Returns:
The table of bindings of this keymap.

setBindings

public void setBindings(java.util.Hashtable newBindings)
Set the table of bindings of key strokes for this keymap. This can be used to reset the keymap after modifications were made to the bindings. Of course, a copy of the keymap should be made before hand after calling getBindings(). This function will clear out the old bindings by calling bindings.clear(), before installing the new bindings.
Parameters:
newBindings - The table of new bindings for this keymap.

getResolveParent

public javax.swing.text.Keymap getResolveParent()
Get the first parent up the parent hierarchy. This is either the parent set during instantiation, or the parent set through a call to setResolveParent.
Specified by:
getResolveParent in interface javax.swing.text.Keymap
Returns:
the direct parent of this keymap.

setResolveParent

public void setResolveParent(javax.swing.text.Keymap parent)
Set the first parent in the parent hierarchy.
Specified by:
setResolveParent in interface javax.swing.text.Keymap
Parameters:
parent - the new parent keymap

getMaster

public javax.swing.text.Keymap getMaster()
Get the master of this keymap if any. If there is a master then this keymap is a sub keymap.

setMaster

public void setMaster(javax.swing.text.Keymap master)
Set the master of this keymap, and by doing that, make this keymap a sub keymap.
Parameters:
master - The new master of this keymap.

toString

public java.lang.String toString()
String representation of the keymap... potentially a very long string.
Overrides:
toString in class java.lang.Object
Returns:
the string representation of this keymap.