org.openbp.jaspira.action.keys
Class KeySequence

java.lang.Object
  extended by org.openbp.jaspira.action.keys.KeySequence

public class KeySequence
extends java.lang.Object

A key sequence describes a chain of key combinations. Key sequences can be represented as strings. There are two forms: A short form and a long form of the string representation. The short form is used to define a key sequence, e. g. in resource files. Modifiers are represented by the letters C, S and A for control, shift and alt, respectively. For example, Control-Shift j would be represented as "C-S-j". The long form will be presented to the user, e. g. as accelerator key in a tool tip. Modifiers are represented by their full name (CTRL, SHIFT, ALT). The "+" character is used as delimiter. For example, Control-Shift j would be represented as "CTRL+SHIFT+j".

Author:
Stephan Moritz

Field Summary
static java.lang.String LONG_ALT
          ALT delimiter (long form)
static java.lang.String LONG_CTRL
          CTRL delimiter (long form)
static char LONG_DELIM
          Delimeter between modifiers and the actual key (long form)
static java.lang.String LONG_SHIFT
          SHIFT delimiter (long form)
static java.lang.String SHORT_ALT
          ALT delimiter (short form)
static java.lang.String SHORT_CTRL
          CTRL delimiter (short form)
static char SHORT_DELIM
          Delimeter between modifiers and the actual key (short form)
static java.lang.String SHORT_SHIFT
          SHIFT delimiter (short form)
 
Constructor Summary
KeySequence(java.lang.String sequence)
          Constructor.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Checks two objects for equality.
 javax.swing.KeyStroke getKeyAt(int n)
          Returns the n'th key combination of the sequence.
 KeySequence getSequenceTail()
          Returns a tailsequence of this sequence, i\.e\. the last length - 1 key combinations.
 KeySequence getSubSequence(int n)
          Returns a subsequence of this sequence, i\.e\. the first n key combinations.
 int hashCode()
          Returns the hashcode of this sequence, which is determined using the string representation .
static java.lang.String keyToString(javax.swing.KeyStroke key, boolean longForm)
          Returns a string representation of a given key stroke.
 int length()
          Returns the length of the key-sequence.
static javax.swing.KeyStroke stringToKey(java.lang.String string)
          Converts a string representation (short form) into a corresponding key.
 java.lang.String toString()
          Returns a string representation of this KeySequence.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SHORT_DELIM

public static final char SHORT_DELIM
Delimeter between modifiers and the actual key (short form)

See Also:
Constant Field Values

SHORT_SHIFT

public static final java.lang.String SHORT_SHIFT
SHIFT delimiter (short form)

See Also:
Constant Field Values

SHORT_CTRL

public static final java.lang.String SHORT_CTRL
CTRL delimiter (short form)

See Also:
Constant Field Values

SHORT_ALT

public static final java.lang.String SHORT_ALT
ALT delimiter (short form)

See Also:
Constant Field Values

LONG_DELIM

public static final char LONG_DELIM
Delimeter between modifiers and the actual key (long form)

See Also:
Constant Field Values

LONG_SHIFT

public static final java.lang.String LONG_SHIFT
SHIFT delimiter (long form)

See Also:
Constant Field Values

LONG_CTRL

public static final java.lang.String LONG_CTRL
CTRL delimiter (long form)

See Also:
Constant Field Values

LONG_ALT

public static final java.lang.String LONG_ALT
ALT delimiter (long form)

See Also:
Constant Field Values
Constructor Detail

KeySequence

public KeySequence(java.lang.String sequence)
Constructor. Creates a key sequence from a given key string.

Parameters:
sequence - Key sequence
Method Detail

length

public int length()
Returns the length of the key-sequence.


getKeyAt

public javax.swing.KeyStroke getKeyAt(int n)
Returns the n'th key combination of the sequence.


getSubSequence

public KeySequence getSubSequence(int n)
Returns a subsequence of this sequence, i\.e\. the first n key combinations.

Parameters:
n - number of combinations that the new sequence should contain
Returns:
The subsequence

getSequenceTail

public KeySequence getSequenceTail()
Returns a tailsequence of this sequence, i\.e\. the last length - 1 key combinations.

Returns:
The subsequence

toString

public java.lang.String toString()
Returns a string representation of this KeySequence.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Checks two objects for equality.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns the hashcode of this sequence, which is determined using the string representation .

Overrides:
hashCode in class java.lang.Object

stringToKey

public static javax.swing.KeyStroke stringToKey(java.lang.String string)
Converts a string representation (short form) into a corresponding key.

Parameters:
string - String to parse
Returns:
The key stroke

keyToString

public static java.lang.String keyToString(javax.swing.KeyStroke key,
                                           boolean longForm)
Returns a string representation of a given key stroke.

Parameters:
key - The key to be converted
longForm - true Returns the long form of the string representation
false Returns the short form of the string representation
Returns:
The string representation


Copyright © 2011. All Rights Reserved.