junit.extensions.jfcunit.keyboard
Class AbstractKeyMapping

java.lang.Object
  extended byjunit.extensions.jfcunit.keyboard.AbstractKeyMapping
All Implemented Interfaces:
KeyMapping
Direct Known Subclasses:
DefaultKeyMapping

public abstract class AbstractKeyMapping
extends java.lang.Object
implements KeyMapping

Abstract key mapping is used to translate key codes or characters into key strokes. Any characters or key codes which do not map are dropped.

To create a new mapping:
1) extend this class
2) Define the Object[][]: See DefaultKeyMapping for example.
3) Create a default constructor that passes the code array to this class.
4) Install the class into the AbstractKeyEventData by calling AbstractKeyEventData.setKeyMapping(yourMapping)

Note: Not all key codes are valid on all systems with the Robot. Invalid keycodes or modifiers for the OS will throw exceptions. Extensions of this class can be used to allow users to map their keyboard mappings.

Author:
Kevin Wilson

Field Summary
private  java.util.HashMap m_mapChar
          The hash map is used to quickly access the key strokes for characters.
private  java.util.HashMap m_mapCode
          The hash map is used to quickly access the key strokes for codes.
 
Constructor Summary
AbstractKeyMapping(java.lang.Object[][] charMap)
          Constructor that loads the two distinct mappings of the charMap into a HashMap for quick access.
 
Method Summary
 JFCKeyStroke[] getKeyStrokes(char c)
          Get the key codes required to construct the character.
 JFCKeyStroke[] getKeyStrokes(int keyCode)
          Get the key strokes required to construct the keyCode.
private  JFCKeyStroke[] getKeyStrokes(java.lang.Object key, java.util.HashMap map)
          Get the key strokes form the mapping specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_mapChar

private final java.util.HashMap m_mapChar
The hash map is used to quickly access the key strokes for characters.


m_mapCode

private final java.util.HashMap m_mapCode
The hash map is used to quickly access the key strokes for codes.

Constructor Detail

AbstractKeyMapping

public AbstractKeyMapping(java.lang.Object[][] charMap)
Constructor that loads the two distinct mappings of the charMap into a HashMap for quick access.

Parameters:
charMap - mapping to be loaded.
Method Detail

getKeyStrokes

public JFCKeyStroke[] getKeyStrokes(char c)
Get the key codes required to construct the character.

Specified by:
getKeyStrokes in interface KeyMapping
Parameters:
c - Character to be constructed.
Returns:
JFCKeyStroke[] containing the key strokes used to create the character.

getKeyStrokes

public JFCKeyStroke[] getKeyStrokes(int keyCode)
Get the key strokes required to construct the keyCode.

Specified by:
getKeyStrokes in interface KeyMapping
Parameters:
keyCode - Key code to be constructed.
Returns:
JFCKeyStroke[] containing the key strokes used to enter the key code.

getKeyStrokes

private JFCKeyStroke[] getKeyStrokes(java.lang.Object key,
                                     java.util.HashMap map)
Get the key strokes form the mapping specified.

Parameters:
key - Key object to be found.
map - Map to look for the key in.
Returns:
JFCKeyStroke[] array of key strokes copied from the mapping.


Licensed under: GNU Lesser General Public License, Ver 2.1, February 1999