com.tensegrity.gui
Class KeyStrokeProvider

java.lang.Object
  extended bycom.tensegrity.gui.KeyStrokeProvider
Direct Known Subclasses:
SwingKeyStrokeProvider, SwtKeyStrokeProvider

public abstract class KeyStrokeProvider
extends java.lang.Object

This abstract class defines and provides a single point of access to the KeyStroke s used as shortcut keys for some commands. Use addToMap(String, KeyStroke) in order to add elements to the local Map. Utility method dumpKeyStrokes() can prove being useful when one needs to add application specific shortcut key commands. This class programmatically defines in its constructor Command Id/KeyStroke associations for common commands. However it is possible to change the KeyStroke associated to a common command through the properties files. In order to do so, specific entries have to be added to the property files. The current entry format is:
Command Id + �.keystroke�. Then the keystroke should be defined as follow:
Keycode + �|� + Modifiers KeyCode being one of the constants starting with �VK_� defined in KeyEvent, without the �VK_� prefix. Example:
W for VK_W Valid modifiers are defined in KeyStrokeBuilder.VALID_MODIFIERS. They have to be separated using the following separator: KeyStrokeBuilder.MODIFIERS_SEPARATOR. Example:
Command.AddNodeAbove.keystroke=A|CTRL+SHIFT Important: When subclassing this class, one should override initSubclassKeyStrokesFromPropertyFile() in order to be able to change programmatically defined keystrokes through property files.

Version:
$Id: KeyStrokeProvider.java,v 1.8 2006/03/02 15:23:10 BurkhardWick Exp $
Author:
S�bastien Guyon

Field Summary
static java.lang.String KEYCODE_VS_MODIFIERS_SEPARATOR
          This is the separator used in keystrokes entry definitions for key codes and modifiers.
static java.lang.String KEYSTROKE_DEFINITION_SUFFIX
          ATTENTION: This is a reserved String that should not be used as part of an entry definition in property files apart for defining commands keystrokes.
protected  java.util.Map map
          local map of Command Ids/KeyStrokes
protected  UIManager uiManager
          This is the UIManager local instance
 
Constructor Summary
protected KeyStrokeProvider(UIManager uiManager)
           This is the default constructor initilazing the internal UIManager instance.
 
Method Summary
protected  void addToMap(java.lang.String commandId, KeyStroke keystroke)
           Simple wrapper allowing extra checks before adding elements to the local Map.
 void dumpKeyStrokes()
           Internal use only.
 java.util.Collection getCommandIds()
           This method returns the set of command Ids for which the corresponding command has an associated keyStroke.
 KeyStroke getKeyStroke(java.lang.String commandId)
           Returns the KeyStrokeassociated with the passed command Id.
protected abstract  KeyStrokeBuilder getKeyStrokeBuilderInstance()
          Returns the local instance of KeyStrokeBuilder.
protected abstract  void initKeyStrokesFromPropertyFile()
           This method tries to overwrite all the command Id/KeyStroke associations programmatically set up in the constructor with other associations potentially defined into the property files.
protected  void initSingleKeyStroke(java.lang.String commandId)
           This method attempts to find in the UIManager a keystroke definition associated to the passed command.
protected abstract  void initSubclassKeyStrokesFromPropertyFile()
           Subclasses of KeyStrokeProvider should implement this method and call it at the end of their constructor in order to allow the keystokes to be changed through property files.
 void loadFromDescription(java.lang.String commandId, java.lang.String keyStrokeDescription)
           This method creates a KeyStroke instance from the passed keyStrokeDescription parameter and associates it to the command with id commandId.
 java.lang.String toString()
          Simply calls toString() the local map of Command Ids/KeyStrokes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

map

protected java.util.Map map
local map of Command Ids/KeyStrokes


uiManager

protected UIManager uiManager
This is the UIManager local instance


KEYSTROKE_DEFINITION_SUFFIX

public static final java.lang.String KEYSTROKE_DEFINITION_SUFFIX
ATTENTION: This is a reserved String that should not be used as part of an entry definition in property files apart for defining commands keystrokes.

See Also:
Constant Field Values

KEYCODE_VS_MODIFIERS_SEPARATOR

public static final java.lang.String KEYCODE_VS_MODIFIERS_SEPARATOR
This is the separator used in keystrokes entry definitions for key codes and modifiers. Example:a_command_Id.keystroke=A|CTRL+SHIFT

See Also:
Constant Field Values
Constructor Detail

KeyStrokeProvider

protected KeyStrokeProvider(UIManager uiManager)

This is the default constructor initilazing the internal UIManager instance.

Parameters:
uiManager - this is the application UIManager
Method Detail

getKeyStrokeBuilderInstance

protected abstract KeyStrokeBuilder getKeyStrokeBuilderInstance()
Returns the local instance of KeyStrokeBuilder.

Returns:
Returns the KeyStrokeBuilder instance.

loadFromDescription

public void loadFromDescription(java.lang.String commandId,
                                java.lang.String keyStrokeDescription)

This method creates a KeyStroke instance from the passed keyStrokeDescription parameter and associates it to the command with id commandId. Note that if the provided id corresponds to a command for which a keystroke has already been programmatically setup, the later one will be overridden.

Parameters:
commandId - unique identifier for a command.
keyStrokeDescription - this is the keystroke description which defines the keystroke to be associated with the command with id commandId. Please refere to this class comments for more information on this description format.

initSingleKeyStroke

protected void initSingleKeyStroke(java.lang.String commandId)

This method attempts to find in the UIManager a keystroke definition associated to the passed command. If it finds it, then a KeyStroke instance is created and associated to the command with id 'commandId'. Note that any other association between a keystroke and this particular command will then be lost.

Parameters:
commandId - this is a command unique identifier.
See Also:
loadFromDescription(String, String)

initKeyStrokesFromPropertyFile

protected abstract void initKeyStrokesFromPropertyFile()

This method tries to overwrite all the command Id/KeyStroke associations programmatically set up in the constructor with other associations potentially defined into the property files.


initSubclassKeyStrokesFromPropertyFile

protected abstract void initSubclassKeyStrokesFromPropertyFile()

Subclasses of KeyStrokeProvider should implement this method and call it at the end of their constructor in order to allow the keystokes to be changed through property files. Typically, for each keystroke programmatically defined in the constructor, a call to initSingleKeyStroke(String) should be made in this method.


addToMap

protected final void addToMap(java.lang.String commandId,
                              KeyStroke keystroke)

Simple wrapper allowing extra checks before adding elements to the local Map.

Parameters:
commandId - this is a command unique identifier.
keystroke - this is the KeyStroke associated with the command with id commandId.

dumpKeyStrokes

public void dumpKeyStrokes()

Internal use only. Use this method in order to view the local Map's content. This can prove being useful when one wants to add custom shortcut key commands and be sure that they are not already used.


toString

public java.lang.String toString()
Simply calls toString() the local map of Command Ids/KeyStrokes

Returns:
the String representation of the local map of Command Ids/KeyStrokes
See Also:
Object.toString()

getCommandIds

public java.util.Collection getCommandIds()

This method returns the set of command Ids for which the corresponding command has an associated keyStroke.

Returns:
a Collection of Strings representing ids of commands which have an associated keyStroke.

getKeyStroke

public KeyStroke getKeyStroke(java.lang.String commandId)

Returns the KeyStrokeassociated with the passed command Id.

Parameters:
commandId - this is a unique identifier for a command.
Returns:
KeyStrokeassociated with the passed command Id


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.