net.silentlycrashing.gestures
Class GestureAnalyzer

java.lang.Object
  extended by net.silentlycrashing.gestures.GestureAnalyzer
Direct Known Subclasses:
MouseGestureAnalyzer, WiimoteGestureAnalyzer

public class GestureAnalyzer
extends Object

Records gestures for analysis by the registered GestureListeners.

The analysis algorithm used here is based on the MouseGestures library by Smardec.

Debugging:
The "verbose" flag can be set to print the recorded gestures to standard output.
The "debug" flag can be set to plot the key points on the display.


Field Summary
private  boolean debug
           
static String DOWN
           
private  StringBuffer gesture
           
static int KEY_SIZE
           
static String LEFT
           
private  int minOffset
           
protected  PApplet p
           
static String RIGHT
           
private  Vector startActions
           
private  Point startPoint
           
private  Vector stopActions
           
static String UP
           
private  Vector updateActions
           
private  boolean verbose
           
 
Constructor Summary
GestureAnalyzer(PApplet parent, int min)
          Builds a GestureAnalyzer.
 
Method Summary
 String getGesture()
           
 int getMinOffset()
           
 void invokeStartActions()
          Invokes the start actions.
 void invokeStopActions()
          Invokes the stop actions.
 void invokeUpdateActions()
          Invokes the update actions.
 boolean isDebug()
           
 boolean isRecognized()
           
 boolean isVerbose()
           
 boolean matches(String regex)
          Checks if the passed regular expression matches the saved gesture.
 void registerStartAction(String name, Object o, Class[] cargs)
          Registers the given method as a start action.
 void registerStopAction(String name, Object o, Class[] cargs)
          Registers the given method as a stop action.
 void registerUpdateAction(String name, Object o, Class[] cargs)
          Registers the given method as an update action.
private  void reset()
          Resets the GestureAnalyzer.
private  void saveMove(String move)
          Adds a move to the buffer.
 void setDebug(boolean d)
           
 void setMinOffset(int m)
           
 void setVerbose(boolean v)
           
 void start(Point pt)
          Sets the start Point and invokes all start RegisteredActions.
 void stop(Point pt)
          Invokes all stop RegisteredActions and resets the GestureAnalyzer.
 void update(Point pt)
          Checks if a new move has occurred and if so, invokes all update RegisteredActions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT

public static final String LEFT
See Also:
Constant Field Values

RIGHT

public static final String RIGHT
See Also:
Constant Field Values

UP

public static final String UP
See Also:
Constant Field Values

DOWN

public static final String DOWN
See Also:
Constant Field Values

KEY_SIZE

public static final int KEY_SIZE
See Also:
Constant Field Values

p

protected PApplet p

minOffset

private int minOffset

startPoint

private Point startPoint

gesture

private StringBuffer gesture

startActions

private Vector startActions

updateActions

private Vector updateActions

stopActions

private Vector stopActions

verbose

private boolean verbose

debug

private boolean debug
Constructor Detail

GestureAnalyzer

public GestureAnalyzer(PApplet parent,
                       int min)
Builds a GestureAnalyzer.

Parameters:
parent - the parent PApplet
min - the minimum offset
Method Detail

registerStartAction

public void registerStartAction(String name,
                                Object o,
                                Class[] cargs)
Registers the given method as a start action.

Parameters:
name - the name of the method to register
o - the Object holding the method
cargs - the arguments

invokeStartActions

public void invokeStartActions()
Invokes the start actions.


registerUpdateAction

public void registerUpdateAction(String name,
                                 Object o,
                                 Class[] cargs)
Registers the given method as an update action.

Parameters:
name - the name of the method to register
o - the Object holding the method
cargs - the arguments

invokeUpdateActions

public void invokeUpdateActions()
Invokes the update actions.


registerStopAction

public void registerStopAction(String name,
                               Object o,
                               Class[] cargs)
Registers the given method as a stop action.

Parameters:
name - the name of the method to register
o - the Object holding the method
cargs - the arguments

invokeStopActions

public void invokeStopActions()
Invokes the stop actions.


start

public void start(Point pt)
Sets the start Point and invokes all start RegisteredActions.

Called when the mouse is pressed.

Parameters:
pt - the current mouse Point

update

public void update(Point pt)
Checks if a new move has occurred and if so, invokes all update RegisteredActions.

Called when the mouse is dragged.

Parameters:
pt - the current mouse Point

stop

public void stop(Point pt)
Invokes all stop RegisteredActions and resets the GestureAnalyzer.

Called when the mouse is released.

Parameters:
pt - the current mouse Point (unused)

reset

private void reset()
Resets the GestureAnalyzer.


saveMove

private void saveMove(String move)
Adds a move to the buffer.

Parameters:
move - the recognized move

matches

public boolean matches(String regex)
Checks if the passed regular expression matches the saved gesture.

Parameters:
regex - the regular expression to check
Returns:
whether or not there is a match

getMinOffset

public int getMinOffset()

setMinOffset

public void setMinOffset(int m)

getGesture

public String getGesture()

isRecognized

public boolean isRecognized()

setVerbose

public void setVerbose(boolean v)

isVerbose

public boolean isVerbose()

setDebug

public void setDebug(boolean d)

isDebug

public boolean isDebug()