com.hdcookbook.grin.input
Class CommandRCHandler

java.lang.Object
  extended by com.hdcookbook.grin.input.RCHandler
      extended by com.hdcookbook.grin.input.CommandRCHandler
All Implemented Interfaces:
Node

public class CommandRCHandler
extends RCHandler
implements Node

This remote control handler will trigger a set of commands whenever one of a set of keys is pressed.

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

Field Summary
protected  Command[] commands
           
protected  int mask
           
protected  boolean wantKeypress
           
 
Fields inherited from class com.hdcookbook.grin.input.RCHandler
name, show
 
Constructor Summary
CommandRCHandler()
           
 
Method Summary
 void activate(Segment s)
          Called for handlers in s when s is activated
 boolean handleKeyPressed(RCKeyEvent ke, Show caller)
          Handle a remote control key press.
 boolean handleKeyReleased(RCKeyEvent ke, Show caller)
          Handle a remote control key release.
 boolean handleKeyTyped(RCKeyEvent ke, Show caller)
          Handle a key typed event.
 boolean handleMouse(int x, int y, boolean activate)
          
 void nextFrame()
          Called by the show to let us know as the model progresses through time.
 void readInstanceData(GrinDataInputStream in, int length)
          Reads in this node information from the binary file format.
 
Methods inherited from class com.hdcookbook.grin.input.RCHandler
getName, setName, setShow, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mask

protected int mask

commands

protected Command[] commands

wantKeypress

protected boolean wantKeypress
Constructor Detail

CommandRCHandler

public CommandRCHandler()
Method Detail

handleKeyPressed

public boolean handleKeyPressed(RCKeyEvent ke,
                                Show caller)
Handle a remote control key press. This is called on the animation thread, at a time when it's safe to modify the scene graph. The show lock will be held, and the show won't be between a call to addDisplayAreas() and paintFrame().

Specified by:
handleKeyPressed in class RCHandler
Returns:
true if the keypress is used

handleKeyReleased

public boolean handleKeyReleased(RCKeyEvent ke,
                                 Show caller)
Handle a remote control key release. This is not supported on all devices. This is called on the animation thread, at a time when it's safe to modify the scene graph. The show lock will be held, and the show won't be between a call to addDisplayAreas() and paintFrame().

Specified by:
handleKeyReleased in class RCHandler
Returns:
true if the keypress is used

handleKeyTyped

public boolean handleKeyTyped(RCKeyEvent ke,
                              Show caller)
Handle a key typed event. Key typed events can be part of a GRIN extension; see the protected constructor of RCKeyEvent for details. This is called on the animatino thread when it's safe to modify the scene graph. The show lock will be held, and the show won't be between a call to addDisplayAreas() and paintFrame().

Specified by:
handleKeyTyped in class RCHandler
Returns:
true if the keypress is used

handleMouse

public boolean handleMouse(int x,
                           int y,
                           boolean activate)

Specified by:
handleMouse in class RCHandler
Returns:
true if something is done with the mouse

activate

public void activate(Segment s)
Called for handlers in s when s is activated

Specified by:
activate in class RCHandler

nextFrame

public void nextFrame()
Called by the show to let us know as the model progresses through time. This can be useful for things like timeouts.

Specified by:
nextFrame in class RCHandler

readInstanceData

public void readInstanceData(GrinDataInputStream in,
                             int length)
                      throws java.io.IOException
Description copied from interface: Node
Reads in this node information from the binary file format.

An implementation of this method is recommended to call in.readSuperClassData(this) as the first line of the method to read in information that is defined in the base class of this Node type.

This should only be called while initializing this object.

Specified by:
readInstanceData in interface Node
Parameters:
in - InputStream to read data from.
length - the number of bytes that this node's information occupies in the InputStream. The implementation of this method is expected to read exactly this number of bytes from the stream. This can be used for a debugging purpose.
Throws:
java.io.IOException - if error occurs.
See Also:
GrinDataInputStream.readSuperClassData(Feature), GrinDataInputStream.readSuperClassData(RCHandler), GrinDataInputStream.readSuperClassData(Segment), GrinDataInputStream.readSuperClassData(Command)