uk.co.keang.swingaddons
Class Gesture

java.lang.Object
  extended by uk.co.keang.swingaddons.Gesture
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener

public class Gesture
extends java.lang.Object
implements java.awt.event.MouseMotionListener, java.awt.event.MouseListener

Recognises gestures and notifies listeners. Compound gestures are also recognised, although by default this feature is disabled. Two notification mechanisms are supported. 1. Basic Listener registration and notification. 2. A mapping of Gesture types to an ID and a mapping from the ID to an Action Object.

Author:
A.G.Docherty

Nested Class Summary
static class Gesture.Direction
           
 
Constructor Summary
Gesture()
           
 
Method Summary
 void addAction(java.lang.String name, java.awt.event.ActionListener act)
          Adds an action with this identifier
 void addComponent(java.awt.Component c)
          Adds a component as a source of gestures
 void addGestureActionMapping(Gesture.Direction gesture, java.lang.String name)
          Adds a gesture mapping
 void addGestureActionMapping(java.util.List<Gesture.Direction> gesture, java.lang.String name)
          Adds a gesture mapping
 void addGestureListener(IGestureListener listener)
          Adds a listener of Gestures
 int getMinMovement()
          Gets the minimum movement required to generate a gesture
 boolean isCompoundEnabled()
          Gets the compound gesture enabled state
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent event)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void removeAction(java.lang.String name)
          Removes an action with this identifier
 void removeAllActionMapping()
          Removes all gesture mappings
 void removeAllGestureMapping()
          Removes all gesture mappings
 void removeComponent(java.awt.Component c)
          Remove a component as a source of gestures
 void removeGestureActionMapping(java.util.List<Gesture.Direction> g)
          Removes a gesture mapping
 void removeGestureActionMapping(java.lang.String name)
          Removes a gesture mapping
 void removeGestureListener(IGestureListener listener)
          Removes a listener of Gestures
 void setCompoundEnabled(boolean state)
          Sets the compound gestures enabled state.
 void setEnabled(boolean state)
          Sets the enabled state of the gesture handler
 void setMinMovement(int min)
          Sets the minimum movement required to generate a gesture
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Gesture

public Gesture()
Method Detail

addComponent

public void addComponent(java.awt.Component c)
Adds a component as a source of gestures

Parameters:
c - - the source component

removeComponent

public void removeComponent(java.awt.Component c)
Remove a component as a source of gestures

Parameters:
c - - the source component

addGestureListener

public void addGestureListener(IGestureListener listener)
Adds a listener of Gestures

Parameters:
listener - - the listener to add

removeGestureListener

public void removeGestureListener(IGestureListener listener)
Removes a listener of Gestures

Parameters:
listener - - the listener to add

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent event)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

getMinMovement

public int getMinMovement()
Gets the minimum movement required to generate a gesture

Returns:
the minimum movement in pixels

setMinMovement

public void setMinMovement(int min)
Sets the minimum movement required to generate a gesture

Parameters:
min - - the minMovement in pixels

setEnabled

public void setEnabled(boolean state)
Sets the enabled state of the gesture handler

Parameters:
state - - true to enable gesture recognition

addAction

public void addAction(java.lang.String name,
                      java.awt.event.ActionListener act)
Adds an action with this identifier

Parameters:
name - - the id
act - - the action

removeAction

public void removeAction(java.lang.String name)
Removes an action with this identifier

Parameters:
name - - the id

removeAllActionMapping

public void removeAllActionMapping()
Removes all gesture mappings


addGestureActionMapping

public void addGestureActionMapping(Gesture.Direction gesture,
                                    java.lang.String name)
Adds a gesture mapping

Parameters:
gesture - - the gesture
name - - the action id

addGestureActionMapping

public void addGestureActionMapping(java.util.List<Gesture.Direction> gesture,
                                    java.lang.String name)
Adds a gesture mapping

Parameters:
gesture - - the compound gesture
name - - the action id

removeGestureActionMapping

public void removeGestureActionMapping(java.util.List<Gesture.Direction> g)
Removes a gesture mapping

Parameters:
g - - the gesture

removeGestureActionMapping

public void removeGestureActionMapping(java.lang.String name)
Removes a gesture mapping

Parameters:
name - - the action id

removeAllGestureMapping

public void removeAllGestureMapping()
Removes all gesture mappings


isCompoundEnabled

public boolean isCompoundEnabled()
Gets the compound gesture enabled state

Returns:
true if compound gestures will be detected

setCompoundEnabled

public void setCompoundEnabled(boolean state)
Sets the compound gestures enabled state. If compound gestures are not enabled only the first gesture is detected and all subsequent movements are ignored.

Parameters:
state - true to allow compound gestures to be detected