fr.lri.swingstates.sm
Class BasicInputStateMachine

java.lang.Object
  extended by fr.lri.swingstates.sm.StateMachine
      extended by fr.lri.swingstates.sm.BasicInputStateMachine
All Implemented Interfaces:
StateMachineListener, java.awt.event.ActionListener, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.util.EventListener
Direct Known Subclasses:
CStateMachine, JStateMachine

public class BasicInputStateMachine
extends StateMachine
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.awt.event.KeyListener

A state machine to handle basic input events (mouse events and keyboard events).

The complete list of event types of a BasicInputStateMachine is:

An event type in a state machine is the name of the class of a transition:
        // declare a transition to state s2 when pressing the left mouse button..
        Transition t = new Press (BUTTON1) {
                ...
        }
 

A state machine implements MouseListener, MouseWheelListener, MouseMotionListener and KeyListener, it can be attached to any awt component to control it:

        JPanel panel = new JPanel();
        BasicInputStateMachine sm = new BasicInputStateMachine() {
                Point2D pt;
                public State start = new State() {
                        Transition press = new Press(BUTTON1, ">> pressed") {
                                public void action() {
                                        pt = getPoint();
                                        armTimer(500, false);
                                }
                        };
                };
                        
                public State pressed = new State() {
                        Transition timeOut = new TimeOut(">> start") {
                                public void action() {
                                        System.out.println("long press at: "+pt.getX()+", "+pt.getY());
                                }
                        };
                        Transition release = new Release(BUTTON1, ">> start") { };
                };
        };
                
        sm.addAsListenerOf(panel);
 

Author:
Caroline Appert
See Also:
StateMachine

Field Summary
static int ALT
          Specifies that the ALT keyboard modifier must be pressed.
static int ALT_CONTROL
          Specifies that the ALT and CONTROL keyboard modifiers must be pressed.
static int ALT_CONTROL_SHIFT
          Specifies that the ALT, CONTROL and SHIFT keyboard modifiers must be pressed.
static int ALT_SHIFT
          Specifies that the ALT and SHIFT keyboard modifiers must be pressed.
static int ANYBUTTON
          Specifies that the mouse must have any or no button pressed.
static int ANYMODIFIER
          Specifies that any keyboard modifiers can be pressed.
static int BUTTON1
          Specifies that the mouse must have the button 1 pressed.
static int BUTTON2
          Specify that the mouse must have the button 2 pressed.
static int BUTTON3
          Specifies that the mouse must have the button 3 pressed.
static int CONTROL
          Specifies that the CONTROL keyboard modifier must be pressed.
static int CONTROL_SHIFT
          Specifies that the CONTROL and SHIFT keyboard modifiers must be pressed.
static int NOBUTTON
          Specifies that the mouse must have all buttons released.
static int NOMODIFIER
          Specifies that no keyboard modifiers must be pressed.
static int SHIFT
          Specifies that the SHIFT keyboard modifier must be pressed.
 
Fields inherited from class fr.lri.swingstates.sm.StateMachine
TIME_OUT
 
Constructor Summary
BasicInputStateMachine()
          Builds a state machine that handles basic input events.
 
Method Summary
 BasicInputStateMachine addAsListenerOf(java.awt.Component c)
          Installs this BasicInputStateMachine as a listener of a given graphical component.
 void keyPressed(java.awt.event.KeyEvent arg0)
          
 void keyReleased(java.awt.event.KeyEvent arg0)
          
 void keyTyped(java.awt.event.KeyEvent arg0)
          
 void mouseClicked(java.awt.event.MouseEvent arg0)
          
 void mouseDragged(java.awt.event.MouseEvent arg0)
          
 void mouseEntered(java.awt.event.MouseEvent arg0)
          
 void mouseExited(java.awt.event.MouseEvent arg0)
          
 void mouseMoved(java.awt.event.MouseEvent arg0)
          
 void mousePressed(java.awt.event.MouseEvent arg0)
          
 void mouseReleased(java.awt.event.MouseEvent arg0)
          
 void mouseWheelMoved(java.awt.event.MouseWheelEvent arg0)
          
 BasicInputStateMachine removeAsListenerOf(java.awt.Component c)
          Uninstalls this BasicInputStateMachine as a listener of a given graphical component.
 
Methods inherited from class fr.lri.swingstates.sm.StateMachine
actionPerformed, addStateMachineListener, addStateMachineListener, armTimer, armTimer, consumes, disarmTimer, disarmTimer, doReset, doResume, doSuspend, eventOccured, fireEvent, fireEvent, getAllStates, getCurrentState, getInitialState, getState, hasConsumed, init, initStatesAndTransitions, isActive, processEvent, processEvent, removeStateMachineListener, removeStateMachineListener, reset, resume, setActive, suspend
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOBUTTON

public static final int NOBUTTON
Specifies that the mouse must have all buttons released.

See Also:
Constant Field Values

ANYBUTTON

public static final int ANYBUTTON
Specifies that the mouse must have any or no button pressed.

See Also:
Constant Field Values

BUTTON1

public static final int BUTTON1
Specifies that the mouse must have the button 1 pressed.

See Also:
Constant Field Values

BUTTON2

public static final int BUTTON2
Specify that the mouse must have the button 2 pressed.

See Also:
Constant Field Values

BUTTON3

public static final int BUTTON3
Specifies that the mouse must have the button 3 pressed.

See Also:
Constant Field Values

NOMODIFIER

public static final int NOMODIFIER
Specifies that no keyboard modifiers must be pressed.

See Also:
Constant Field Values

SHIFT

public static final int SHIFT
Specifies that the SHIFT keyboard modifier must be pressed.

See Also:
Constant Field Values

CONTROL

public static final int CONTROL
Specifies that the CONTROL keyboard modifier must be pressed.

See Also:
Constant Field Values

ALT

public static final int ALT
Specifies that the ALT keyboard modifier must be pressed.

See Also:
Constant Field Values

CONTROL_SHIFT

public static final int CONTROL_SHIFT
Specifies that the CONTROL and SHIFT keyboard modifiers must be pressed.

See Also:
Constant Field Values

ALT_SHIFT

public static final int ALT_SHIFT
Specifies that the ALT and SHIFT keyboard modifiers must be pressed.

See Also:
Constant Field Values

ALT_CONTROL

public static final int ALT_CONTROL
Specifies that the ALT and CONTROL keyboard modifiers must be pressed.

See Also:
Constant Field Values

ALT_CONTROL_SHIFT

public static final int ALT_CONTROL_SHIFT
Specifies that the ALT, CONTROL and SHIFT keyboard modifiers must be pressed.

See Also:
Constant Field Values

ANYMODIFIER

public static final int ANYMODIFIER
Specifies that any keyboard modifiers can be pressed.

See Also:
Constant Field Values
Constructor Detail

BasicInputStateMachine

public BasicInputStateMachine()
Builds a state machine that handles basic input events.

Method Detail

addAsListenerOf

public BasicInputStateMachine addAsListenerOf(java.awt.Component c)
Installs this BasicInputStateMachine as a listener of a given graphical component.

Parameters:
c - The graphical component
Returns:
This BasicInputStateMachine.

removeAsListenerOf

public BasicInputStateMachine removeAsListenerOf(java.awt.Component c)
Uninstalls this BasicInputStateMachine as a listener of a given graphical component.

Parameters:
c - The graphical component
Returns:
This BasicInputStateMachine.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent arg0)

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent arg0)

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent arg0)

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent arg0)

Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent arg0)

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent arg0)

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseWheelMoved

public void mouseWheelMoved(java.awt.event.MouseWheelEvent arg0)

Specified by:
mouseWheelMoved in interface java.awt.event.MouseWheelListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent arg0)

Specified by:
mousePressed in interface java.awt.event.MouseListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent arg0)

Specified by:
keyTyped in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent arg0)

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent arg0)

Specified by:
keyReleased in interface java.awt.event.KeyListener