de.matthiasmann.twl
Class KeyStroke

java.lang.Object
  extended by de.matthiasmann.twl.KeyStroke

public final class KeyStroke
extends java.lang.Object

A class to represent a key stroke and it's associated action. NOTE: equals() and hashCode() do NOT check the action.


Method Summary
 boolean equals(java.lang.Object obj)
          Two KeyStroke objects are equal if the have the same key stroke, it does not compare the action.
static KeyStroke fromEvent(Event event, java.lang.String action)
          Creates a KeyStroke from the KEY_PRESSED event.
 java.lang.String getAction()
          Returns the action name for this key stroke
 java.lang.String getStroke()
          Returns the key stroke in parsable form
 int hashCode()
          Computes the hash code for this key stroke without the action.
static KeyStroke parse(java.lang.String stroke, java.lang.String action)
          Parses a key stroke from string representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAction

public java.lang.String getAction()
Returns the action name for this key stroke

Returns:
the action name

getStroke

public java.lang.String getStroke()
Returns the key stroke in parsable form

Returns:
the key stroke
See Also:
parse(java.lang.String, java.lang.String)

equals

public boolean equals(java.lang.Object obj)
Two KeyStroke objects are equal if the have the same key stroke, it does not compare the action.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the other object to compare against
Returns:
true if the other object is a KeyStroke and responds to the same input event
See Also:
getStroke()

hashCode

public int hashCode()
Computes the hash code for this key stroke without the action.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

parse

public static KeyStroke parse(java.lang.String stroke,
                              java.lang.String action)
Parses a key stroke from string representation.

The following syntax is supported:

Thw folloiwng modifiers are supported; All matching is case insensitive.

Parameters:
stroke - the key stroke
action - the action to associate
Returns:
the parsed KeyStroke
Throws:
java.lang.IllegalArgumentException - if the key stroke can't be parsed
See Also:
Keyboard#getKeyIndex(java.lang.String)

fromEvent

public static KeyStroke fromEvent(Event event,
                                  java.lang.String action)
Creates a KeyStroke from the KEY_PRESSED event.

Parameters:
event - the input event
action - the action to associate
Returns:
the KeyStroke for this event and action
Throws:
java.lang.IllegalArgumentException - if the event is not a Type.KEY_PRESSED