Class KeyStroke
- java.lang.Object
-
- org.eclipse.jface.bindings.Trigger
-
- org.eclipse.jface.bindings.keys.KeyStroke
-
- All Implemented Interfaces:
Comparable
public final class KeyStroke extends Trigger
A
KeyStrokeis defined as an optional set of modifier keys followed optionally by a natural key. AKeyStrokeis said to be complete if it contains a natural key. A natural key is any Unicode character (e.g., "backspace", etc.), any character belonging to a natural language (e.g., "A", "1", "[", etc.), or any special control character specific to computers (e.g., "F10", "PageUp", etc.).All
KeyStrokeobjects have a formal string representation available via thetoString()method. There are a number of methods to get instances ofKeyStrokeobjects, including one which can parse this formal string representation.All
KeyStrokeobjects, via theformat()method, provide a version of their formal string representation translated by platform and locale, suitable for display to a user.KeyStrokeobjects are immutable. Clients are not permitted to extend this class.- Since:
- 3.1
-
-
Field Summary
Fields Modifier and Type Field Description static StringKEY_DELIMITERThe delimiter between multiple keys in a single key strokes -- expressed in the formal key stroke grammar.static StringKEY_DELIMITERSThe set of delimiters forKeyobjects allowed during parsing of the formal string representation.static intNO_KEYThe representation for no key.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Object object)booleanequals(Object object)Tests whether this object is equal to another object.Stringformat()Formats this key stroke into the current default look.static KeyStrokegetInstance(int naturalKey)Creates an instance ofKeyStrokegiven a natural key.static KeyStrokegetInstance(int modifierKeys, int naturalKey)Creates an instance ofKeyStrokegiven a set of modifier keys and a natural key.static KeyStrokegetInstance(String string)Creates an instance ofKeyStrokeby parsing a given a formal string representation.intgetModifierKeys()Returns the modifier keys for this key stroke.intgetNaturalKey()Returns the natural key for this key stroke.inthashCode()Computes the hash code for this object.booleanisComplete()Returns whether or not this key stroke is complete.StringtoString()Returns the formal string representation for this key stroke.
-
-
-
Field Detail
-
KEY_DELIMITER
public static final String KEY_DELIMITER
The delimiter between multiple keys in a single key strokes -- expressed in the formal key stroke grammar. This is not to be displayed to the user. It is only intended as an internal representation.- See Also:
- Constant Field Values
-
KEY_DELIMITERS
public static final String KEY_DELIMITERS
The set of delimiters forKeyobjects allowed during parsing of the formal string representation.- See Also:
- Constant Field Values
-
NO_KEY
public static final int NO_KEY
The representation for no key.- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static final KeyStroke getInstance(int naturalKey)
Creates an instance ofKeyStrokegiven a natural key.- Parameters:
naturalKey- the natural key. The format of this integer is defined by whichever widget toolkit you are using;NO_KEYalways means no natural key.- Returns:
- a key stroke. This key stroke will have no modifier keys.
Guaranteed not to be
null. - See Also:
SWTKeySupport
-
getInstance
public static final KeyStroke getInstance(int modifierKeys, int naturalKey)
Creates an instance ofKeyStrokegiven a set of modifier keys and a natural key.- Parameters:
modifierKeys- the modifier keys. The format of this integer is defined by whichever widget toolkit you are using;NO_KEYalways means no modifier keys.naturalKey- the natural key. The format of this integer is defined by whichever widget toolkit you are using;NO_KEYalways means no natural key.- Returns:
- a key stroke. Guaranteed not to be
null. - See Also:
SWTKeySupport
-
getInstance
public static final KeyStroke getInstance(String string) throws ParseException
Creates an instance ofKeyStrokeby parsing a given a formal string representation.- Parameters:
string- the formal string representation to parse.- Returns:
- a key stroke. Guaranteed not to be
null. - Throws:
ParseException- if the given formal string representation could not be parsed to a valid key stroke.
-
compareTo
public final int compareTo(Object object)
-
equals
public final boolean equals(Object object)
Description copied from class:TriggerTests whether this object is equal to another object. A handle object is only equal to another trigger with the same properties.
-
format
public final String format()
Formats this key stroke into the current default look.- Returns:
- A string representation for this key stroke using the default
look; never
null.
-
getModifierKeys
public final int getModifierKeys()
Returns the modifier keys for this key stroke.- Returns:
- the bit mask of modifier keys;
NO_KEYmeans that there is no modifier key.
-
getNaturalKey
public final int getNaturalKey()
Returns the natural key for this key stroke.- Returns:
- The natural key for this key stroke. This value is
NO_KEYif the key stroke is incomplete (i.e., has no natural key).
-
hashCode
public final int hashCode()
Description copied from class:TriggerComputes the hash code for this object.
-
isComplete
public final boolean isComplete()
Returns whether or not this key stroke is complete. Key strokes are complete iff they have a natural key which is notNO_KEY.- Returns:
true, iff the key stroke is complete.
-
-