com.hdcookbook.grin.input
Class RCKeyEvent

java.lang.Object
  extended by com.hdcookbook.grin.commands.Command
      extended by com.hdcookbook.grin.input.RCKeyEvent

public class RCKeyEvent
extends Command

This class is used to manage constants related to the remote control keys. Instances of RCKeyEvent can be queued as GRIN commands; when they are executed, the show will process the keystroke. The built-in RCKeyEvent class is used for key pressed and key released events, taken from a strictly limited set of keys.

If desired, a GRIN extension can subclass RCKeyEvent to add support for key typed events. GRIN doesn't really support key typed events, but it does provide support for queuing them and dispatching them in the animation thread (as is done with key pressed and released events).

Author:
Bill Foote (http://jovial.com)

Field Summary
static RCKeyEvent KEY_0
           
static RCKeyEvent KEY_1
           
static RCKeyEvent KEY_2
           
static RCKeyEvent KEY_3
           
static RCKeyEvent KEY_4
           
static RCKeyEvent KEY_5
           
static RCKeyEvent KEY_6
           
static RCKeyEvent KEY_7
           
static RCKeyEvent KEY_8
           
static RCKeyEvent KEY_9
           
static RCKeyEvent KEY_BLUE
          The blue color key.
static RCKeyEvent KEY_DOWN
           
static RCKeyEvent KEY_ENTER
           
static RCKeyEvent KEY_FAST_FWD
           
static RCKeyEvent KEY_GREEN
          The green color key.
static RCKeyEvent KEY_INFO
           
static RCKeyEvent KEY_LEFT
           
static RCKeyEvent KEY_PAUSE
           
static RCKeyEvent KEY_PG_TEXTST_ENABLE_DISABLE
           
static RCKeyEvent KEY_PLAY
           
static RCKeyEvent KEY_POPUP_MENU
           
static RCKeyEvent KEY_RED
          The red color key.
static RCKeyEvent KEY_REWIND
           
static RCKeyEvent KEY_RIGHT
           
static RCKeyEvent KEY_SECONDARY_AUDIO_ENABLE_DISABLE
           
static RCKeyEvent KEY_SECONDARY_VIDEO_ENABLE_DISABLE
           
static RCKeyEvent KEY_STILL_OFF
           
static RCKeyEvent KEY_STOP
           
static RCKeyEvent KEY_TRACK_NEXT
           
static RCKeyEvent KEY_TRACK_PREV
           
static RCKeyEvent KEY_UP
           
static RCKeyEvent KEY_YELLOW
          The yellow color key.
 
Fields inherited from class com.hdcookbook.grin.commands.Command
show
 
Constructor Summary
protected RCKeyEvent(int keyCode, int mask)
          Initialize a new key typed event.
 
Method Summary
 void execute()
          Execute the command.
 void execute(Show caller)
          Execute the command.
 int getBitMask()
          A bitmask value is assigned to each remote control key.
static java.util.Vector getEventsFromMask(int mask)
          Returns a vector of events turned-on by the given mask.
static RCKeyEvent getKeyByEventCode(int key)
          Look up the RCKeyEvent corresponding to a VK_ key code.
static RCKeyEvent getKeyByName(java.lang.String name)
          Look up the RCKeyEvent by its logical name.
 int getKeyCode()
           
 RCKeyEvent getKeyReleased()
          Give the RCKeyEvent for this VK code that represents a key release.
 java.lang.String getName()
          Get a developer-friendly name of this key event.
 boolean isKeyPress()
          Return true if this is represents key press, and false if it represents a key release.
 
Methods inherited from class com.hdcookbook.grin.commands.Command
cloneIfNeeded, deferNextCommands, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_0

public static RCKeyEvent KEY_0

KEY_1

public static RCKeyEvent KEY_1

KEY_2

public static RCKeyEvent KEY_2

KEY_3

public static RCKeyEvent KEY_3

KEY_4

public static RCKeyEvent KEY_4

KEY_5

public static RCKeyEvent KEY_5

KEY_6

public static RCKeyEvent KEY_6

KEY_7

public static RCKeyEvent KEY_7

KEY_8

public static RCKeyEvent KEY_8

KEY_9

public static RCKeyEvent KEY_9

KEY_RIGHT

public static RCKeyEvent KEY_RIGHT

KEY_LEFT

public static RCKeyEvent KEY_LEFT

KEY_UP

public static RCKeyEvent KEY_UP

KEY_DOWN

public static RCKeyEvent KEY_DOWN

KEY_ENTER

public static RCKeyEvent KEY_ENTER

KEY_POPUP_MENU

public static RCKeyEvent KEY_POPUP_MENU

KEY_PLAY

public static RCKeyEvent KEY_PLAY

KEY_STOP

public static RCKeyEvent KEY_STOP

KEY_STILL_OFF

public static RCKeyEvent KEY_STILL_OFF

KEY_TRACK_NEXT

public static RCKeyEvent KEY_TRACK_NEXT

KEY_TRACK_PREV

public static RCKeyEvent KEY_TRACK_PREV

KEY_FAST_FWD

public static RCKeyEvent KEY_FAST_FWD

KEY_REWIND

public static RCKeyEvent KEY_REWIND

KEY_PAUSE

public static RCKeyEvent KEY_PAUSE

KEY_SECONDARY_VIDEO_ENABLE_DISABLE

public static RCKeyEvent KEY_SECONDARY_VIDEO_ENABLE_DISABLE

KEY_SECONDARY_AUDIO_ENABLE_DISABLE

public static RCKeyEvent KEY_SECONDARY_AUDIO_ENABLE_DISABLE

KEY_PG_TEXTST_ENABLE_DISABLE

public static RCKeyEvent KEY_PG_TEXTST_ENABLE_DISABLE

KEY_INFO

public static RCKeyEvent KEY_INFO

KEY_RED

public static RCKeyEvent KEY_RED
The red color key.

See Also:
AssetFinder.getColorKeyCode(java.awt.Color)

KEY_GREEN

public static RCKeyEvent KEY_GREEN
The green color key.

See Also:
AssetFinder.getColorKeyCode(java.awt.Color)

KEY_YELLOW

public static RCKeyEvent KEY_YELLOW
The yellow color key.

See Also:
AssetFinder.getColorKeyCode(java.awt.Color)

KEY_BLUE

public static RCKeyEvent KEY_BLUE
The blue color key.

See Also:
AssetFinder.getColorKeyCode(java.awt.Color)
Constructor Detail

RCKeyEvent

protected RCKeyEvent(int keyCode,
                     int mask)
Initialize a new key typed event. This constructor is not used by the internal GRIN support for key pressed and key released handlers; it is intended for a subclass of RCKeyEvent that extends GRIN to support key typed events. It is up to the extension whether or not it chooses to pre-allocate a number of constants, as is done in GRIN, or to allocate a new one with each arriving event.

Not all GEM devices support key typed events, nor do they have keyboards. If you extend GRIN to add support for key typed events, it's up to you how to generate the needed key typed events, e.g. by perhaps adding a virtual keyboard.

NOTE: If you subclass RCKeyEvent, be sure to override execute(Show)

Parameters:
keyCode - The VK code of the key. This can be zero. A subclass will likely add a char data member to contain the character that is typed.
mask - The bitmask of this key event. A bit in the bitmask can be used to identify groups of related keys. The bitmask is used to identify whether or not a segment is interested in receiving key typed events from the corresponding key group.
See Also:
execute(Show), Segment.keyTypedInterest
Method Detail

getName

public java.lang.String getName()
Get a developer-friendly name of this key event. Useful for debugging.


getKeyCode

public int getKeyCode()
Returns:
the VK_ key code corresponding to this key

getBitMask

public int getBitMask()
A bitmask value is assigned to each remote control key. Since there are 27 keys we consider and 32 bits in an int, there's room in an int. Using a bitmask lets us check a key against a set of expected keys very efficiently.

Returns:
The mask for this key.

isKeyPress

public boolean isKeyPress()
Return true if this is represents key press, and false if it represents a key release.


getKeyReleased

public RCKeyEvent getKeyReleased()
Give the RCKeyEvent for this VK code that represents a key release.


execute

public void execute(Show caller)
Execute the command. This causes the command to take whatever action it was created to do. By default, this calls execute().

This version of execute(Show) is only for use by the built-in GRIN support for key pressed and key released events. If you subclass RCKeyEvent to support key typed events, be sure to override this method so that it calls Show.internalHandleKeyTypedEvent().

Overrides:
execute in class Command
Parameters:
caller - The show that is executing this command. This might not be the same as the show this command was created under.

execute

public void execute()
Execute the command. This causes the command to take whatever action it was created to do.

Specified by:
execute in class Command

getKeyByEventCode

public static RCKeyEvent getKeyByEventCode(int key)
Look up the RCKeyEvent corresponding to a VK_ key code. This method is very fast and creates no garbage. It uses a perfect hash function, an idea I lifted from http://www.onjava.com/pub/a/onjava/2001/01/25/hash_functions.html

This returns the RCKeyEvent corresponding to a key press.

Returns:
The RCKeyEvent, or null if there's no corresponding event
See Also:
getKeyReleased()

getKeyByName

public static RCKeyEvent getKeyByName(java.lang.String name)
Look up the RCKeyEvent by its logical name.

Returns:
the RCKeyEvent, or null if there's no corresponding event.

getEventsFromMask

public static java.util.Vector getEventsFromMask(int mask)
Returns a vector of events turned-on by the given mask.