public abstract class CStateMachine extends BasicInputStateMachine
A state machine to handle events with one or more CElement
(Canvas
,
CTag
or CShape
).
A CStateMachine
handles events handled by a
BasicInputStateMachine
plus the following list:
PressOnShape
, PressOnTag
: pressing a
mouse button on a shape / on a shape with a given tag;
ReleaseOnShape
, ReleaseOnTag
: releasing
a mouse button on a shape / on a shape with a given tag;
ClickOnShape
, ClickOnTag
: clicking
(pressing and releasing in quick succession) a mouse button on a shape / on a
shape with a given tag;
MoveOnShape
, MoveOnTag
: moving the mouse
with no button pressed on a shape / on a shape with a given tag;
DragOnShape
, DragOnTag
: moving the mouse
with a button pressed on a shape / on a shape with a given tag;
WheelOnShape
, WheelOnTag
: rotating the
mouse wheel on a shape / on a shape with a given tag;
EnterOnShape
, EnterOnTag
: cursor enters
a shape / a shape with a given tag;
LeaveOnShape
, LeaveOnTag
: cursor leaves
a shape / a shape with a given tag;
AnimationStarted
, AnimationStopped
,
AnimationSuspended
and AnimationResumed
: a
given animation has started, stopped, been suspended or been resumed.
CElementEvent
: a given graphical element has changed.
BasicInputStateMachine
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ANIMATION_RESUMED
The key string of events that triggered
AnimationResumed transitions. |
static java.lang.String |
ANIMATION_STARTED
The key string of events that triggered
AnimationStarted transitions. |
static java.lang.String |
ANIMATION_STOPPED
The key string of events that triggered
AnimationStopped transitions. |
static java.lang.String |
ANIMATION_SUSPENDED
The key string of events that triggered
AnimationSuspended transitions. |
ALT, ALT_CONTROL, ALT_CONTROL_SHIFT, ALT_SHIFT, ANYBUTTON, ANYMODIFIER, BUTTON1, BUTTON2, BUTTON3, CONTROL, CONTROL_SHIFT, NOBUTTON, NOMODIFIER, SHIFT
TIME_OUT
Constructor and Description |
---|
CStateMachine()
Builds a CStateMachine.
|
CStateMachine(CElement ce)
Builds a CStateMachine.
|
Modifier and Type | Method and Description |
---|---|
void |
attachTo(CElement ce)
Attaches a state machine to a given
CElement and
resets it. |
void |
attachTo(CElement ce,
boolean reset)
Attaches a state machine to a given
CElement . |
boolean |
controls(CShape source) |
void |
detach(CElement ce)
Detaches a state machine from a
CElement object. |
java.util.LinkedList<CElement> |
getControlledObjects()
Returns the linked list of
CElement objects to which this
state machine is attached, or null is the machine is not attached. |
CStateMachine |
greaterPriorityThan(CStateMachine smLower,
Canvas canvas)
Makes this state machine have a greater priority than another state
machine.
|
CStateMachine |
greatestPriority(Canvas canvas)
Makes this state machine have the greatest priority.
|
boolean |
isAttachedTo(CElement ce)
Tests if this state machine is attached to a given
CElement
object. |
void |
lowerPriorityThan(CStateMachine smGreater,
Canvas canvas)
Makes this state machine having a lower priority than another state
machine.
|
CStateMachine |
lowestPriority(Canvas canvas)
Makes this state machine have the lowest priority.
|
addAsListenerOf, keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, removeAsListenerOf
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, suspend
public static java.lang.String ANIMATION_STOPPED
AnimationStopped
transitions.public static java.lang.String ANIMATION_STARTED
AnimationStarted
transitions.public static java.lang.String ANIMATION_SUSPENDED
AnimationSuspended
transitions.public static java.lang.String ANIMATION_RESUMED
AnimationResumed
transitions.public CStateMachine()
public CStateMachine(CElement ce)
ce
- The canvas element whose events must be handled by this state
machine.public void attachTo(CElement ce, boolean reset)
CElement
. Attaching a CStateMachine to
a CElement (a shape, a tag or a canvas) causes the transitions *OnShape and *OnTag
(e.g. PressOnShape, PressOnTag, ReleaseOnShape...)
to be fired only on shapes that are parts of the attached element. Note that
all other transitions that can occur anywhere (e.g. Press, Release...) remains firable.
For example, the transition t1
will be fired only if a mouse press occurs on
a shape that holds the tag movable
while the transition t2
will still be
fired by any mouse press event on the canvas:
CStateMachine machine = new CStateMachine() { State start = new State() { Transition t1 = new PressOnShape(BUTTON1, ">> moveShape") { ... }; Transition t2 = new Press(BUTTON1, ">> panView") { ... }; }; State moveShape = new State() { ... }; State panView = new State() { ... }; ... }; ... CTag movable = ...; ... machine.attachTo(movable);
ce
- The CElement
to which this state machine
must be attached.reset
- Whether or not the state machine must be reset.public void attachTo(CElement ce)
CElement
and
resets it.ce
- The CElement
to which this state machine
must be attached.attachTo(CElement, boolean)
public boolean isAttachedTo(CElement ce)
CElement
object.ce
- The CElement
object to testce
.public java.util.LinkedList<CElement> getControlledObjects()
CElement
objects to which this
state machine is attached, or null is the machine is not attached.CElement
objects to which this
state machine is attached.public void detach(CElement ce)
CElement
object. Does
nothing if it was not attached.ce
- The CElement
object from which this state
machine must be detachedpublic boolean controls(CShape source)
public void lowerPriorityThan(CStateMachine smGreater, Canvas canvas)
smGreater
- The state machine that must have a greater priority than
smLower.canvas
- The canvas.public CStateMachine lowestPriority(Canvas canvas)
canvas
- The canvas.public CStateMachine greaterPriorityThan(CStateMachine smLower, Canvas canvas)
smLower
- The state machine that must have a lower priority than
smGreater.canvas
- The canvas.public CStateMachine greatestPriority(Canvas canvas)
canvas
- The canvas.