com.borland.primetime.editor
Class TrackingKeymap

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

public class TrackingKeymap
extends DefaultKeymap

This is a special subclass of DefaultKeymap which wraps retrieved Actions with a special TrackingAction. The TrackingAction is used to store the last action performed on an EditorPane. This class is also used to keep track of action/keyStroke modifiers which allows the actions of the keymap to be mapped to user defined keyStrokes.

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

Inner Class Summary
protected  class TrackingKeymap.ActionModifier
          Helper class to keep track of user defined modifications to the keymap.
static class TrackingKeymap.TrackingAction
          Helper class that wraps an action/keyStroke combination.
 
Field Summary
protected  java.util.ArrayList actionModifiers
          The list of modifiers to action/keyStroke pairs.
protected  boolean modifiersApplied
          We only apply the modifiers on a fresh keymap.
 
Fields inherited from class com.borland.primetime.editor.DefaultKeymap
bindings, defaultAction, master, nm, parent
 
Constructor Summary
TrackingKeymap(java.lang.String nm, javax.swing.text.Keymap parent)
          Create a normal Tracking keymap
 
Method Summary
 boolean actionIsModified(javax.swing.Action action, javax.swing.KeyStroke keyStroke)
          Determine if the incoming action and keystroke pair is a combination that is not present in the original, unmodified keymap.
 void addSubKeymap(javax.swing.text.Keymap subKeymap)
          Add a subKeymap, meaning that we are considered the master of this subKeymap.
 void applyActionModifiers()
          After loading up a keymap, the action modifiers stored in the user.properties file have to be applied to the keymap.
 void applyOneActionModifier(javax.swing.Action action, javax.swing.KeyStroke keyStroke, boolean add)
          Given an action and a keyStroke, either add it to the current keymap, or delete it from the keymap.
 void cancelActionModifiers()
          Cancel any action modifiers that the keymap editor created.
 javax.swing.Action getAction(javax.swing.KeyStroke key)
          Get the action in this keymap that is linked to the incoming keyStroke.
 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.text.Keymap[] getSubKeymaps()
          Return an array of our subKeymaps.
 void resetActionModifiers()
          Cancel any action modifiers that the keymap editor created, and also cancel any action modifiers saved on disk.
 void saveActionModifiers()
          Save the current list of action modifiers to the user.properties file.
 
Methods inherited from class com.borland.primetime.editor.DefaultKeymap
addActionForKeyStroke, getBindings, getBoundActions, getBoundKeyStrokes, getKeyStrokesForAction, getMaster, getName, getResolveParent, isLocallyDefined, removeBindings, removeKeyStrokeBinding, setBindings, setDefaultAction, setMaster, setResolveParent, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

actionModifiers

protected java.util.ArrayList actionModifiers
The list of modifiers to action/keyStroke pairs.

modifiersApplied

protected boolean modifiersApplied
We only apply the modifiers on a fresh keymap.
Constructor Detail

TrackingKeymap

public TrackingKeymap(java.lang.String nm,
                      javax.swing.text.Keymap parent)
Create a normal Tracking keymap
Parameters:
nm - The name of the keymap
parent - The optional parent of 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.
Overrides:
getDefaultAction in class DefaultKeymap
Returns:
The default action, or null if that default action doesn't exist.

getAction

public javax.swing.Action getAction(javax.swing.KeyStroke key)
Get the action in this keymap that is linked to the incoming keyStroke. At this time we wrap the action in a special TrackingAction object.
Overrides:
getAction in class DefaultKeymap
Parameters:
key - The keyStroke we are interested in
Returns:
The action triggered by the incoming keyStroke, or null if no action is found

addSubKeymap

public void addSubKeymap(javax.swing.text.Keymap subKeymap)
Add a subKeymap, meaning that we are considered the master of this subKeymap. This is different from being the parent of a keymap. A specific keyStroke can switch a master keymap to a subKeymap and after handling any keyStroke in the subKeymap, the master keymap is swapped back in. A parent keymap is a keymap that might be searched if a search for a action or keystroke is not satisfied in the current keymap.
Parameters:
subKeymap - The keymap that considers this keymap their master keymap

getSubKeymaps

public javax.swing.text.Keymap[] getSubKeymaps()
Return an array of our subKeymaps.
Returns:
the array of subKeymaps, or null if there are no subKeymaps.

saveActionModifiers

public void saveActionModifiers()
Save the current list of action modifiers to the user.properties file. This function is for internal use. It ties into the keymap editor.

applyActionModifiers

public void applyActionModifiers()
After loading up a keymap, the action modifiers stored in the user.properties file have to be applied to the keymap. This is normally done when a keymap is swapped in. This function is for internal use. It ties into the keymap editor.

applyOneActionModifier

public void applyOneActionModifier(javax.swing.Action action,
                                   javax.swing.KeyStroke keyStroke,
                                   boolean add)
Given an action and a keyStroke, either add it to the current keymap, or delete it from the keymap. This function is for internal use. It ties into the keymap editor
Parameters:
action - The action we are interested in
keyStroke - The keystroke we are interested in
add - If true we want to tie the keystroke to the action, otherwise we want to delete the tie of the keystroke and the action

cancelActionModifiers

public void cancelActionModifiers()
Cancel any action modifiers that the keymap editor created. This is an internal function. It ties into the keymap editor.

resetActionModifiers

public void resetActionModifiers()
Cancel any action modifiers that the keymap editor created, and also cancel any action modifiers saved on disk. This is an internal function. It ties into the keymap editor.

actionIsModified

public boolean actionIsModified(javax.swing.Action action,
                                javax.swing.KeyStroke keyStroke)
Determine if the incoming action and keystroke pair is a combination that is not present in the original, unmodified keymap.
Parameters:
action - The action we're interested in.
keyStroke - The keystroke we're interested in.
Returns:
true if this action/keystroke pair is considered modified, meaning it does not exist in the original unmodified keymap, false otherwise.