public class BasicInputStateMachine extends StateMachine implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.awt.event.KeyListener
The complete list of event types of a BasicInputStateMachine is:
Press: pressing a mouse button anywhere;
Release: releasing a mouse button anywhere;
Click: clicking (pressing and releasing in quick succession) a mouse button anywhere;
Move: moving the mouse with no button pressed anywhere;
Drag: moving the mouse with a button pressed anywhere;
KeyPress, KeyRelease, KeyType: typing a key (pressing, releasing, press then release in quick succession);
TimeOut: delay specified by armTimer expired.
Event: high-level events
// 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);
StateMachine| Modifier and Type | Field and Description |
|---|---|
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.
|
TIME_OUT| Constructor and Description |
|---|
BasicInputStateMachine()
Builds a state machine that handles basic input events.
|
| Modifier and Type | Method and Description |
|---|---|
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. |
actionPerformed, addStateMachineListener, addStateMachineListener, armTimer, armTimer, consumes, disarmTimer, disarmTimer, doReset, doResume, doSuspend, eventOccured, fireEvent, fireEvent, getAllStates, getCurrentState, getInitialState, getState, hasConsumed, init, initStatesAndTransitions, isActive, isInited, processEvent, processEvent, removeStateMachineListener, removeStateMachineListener, reset, resume, setActive, suspendpublic static final int NOBUTTON
public static final int ANYBUTTON
public static final int BUTTON1
public static final int BUTTON2
public static final int BUTTON3
public static final int NOMODIFIER
public static final int SHIFT
public static final int CONTROL
public static final int ALT
public static final int CONTROL_SHIFT
public static final int ALT_SHIFT
public static final int ALT_CONTROL
public static final int ALT_CONTROL_SHIFT
public static final int ANYMODIFIER
public BasicInputStateMachine()
public BasicInputStateMachine addAsListenerOf(java.awt.Component c)
BasicInputStateMachine
as a listener of a given graphical component.c - The graphical componentBasicInputStateMachine.public BasicInputStateMachine removeAsListenerOf(java.awt.Component c)
BasicInputStateMachine
as a listener of a given graphical component.c - The graphical componentBasicInputStateMachine.public void mouseClicked(java.awt.event.MouseEvent arg0)
mouseClicked in interface java.awt.event.MouseListenerpublic void mouseReleased(java.awt.event.MouseEvent arg0)
mouseReleased in interface java.awt.event.MouseListenerpublic void mouseEntered(java.awt.event.MouseEvent arg0)
mouseEntered in interface java.awt.event.MouseListenerpublic void mouseExited(java.awt.event.MouseEvent arg0)
mouseExited in interface java.awt.event.MouseListenerpublic void mouseDragged(java.awt.event.MouseEvent arg0)
mouseDragged in interface java.awt.event.MouseMotionListenerpublic void mouseMoved(java.awt.event.MouseEvent arg0)
mouseMoved in interface java.awt.event.MouseMotionListenerpublic void mouseWheelMoved(java.awt.event.MouseWheelEvent arg0)
mouseWheelMoved in interface java.awt.event.MouseWheelListenerpublic void mousePressed(java.awt.event.MouseEvent arg0)
mousePressed in interface java.awt.event.MouseListenerpublic void keyTyped(java.awt.event.KeyEvent arg0)
keyTyped in interface java.awt.event.KeyListenerpublic void keyPressed(java.awt.event.KeyEvent arg0)
keyPressed in interface java.awt.event.KeyListenerpublic void keyReleased(java.awt.event.KeyEvent arg0)
keyReleased in interface java.awt.event.KeyListener