- java.lang.Object
-
- io.github.interacto.fsm.FSM<E>
-
public class FSM<E> extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected OutputState<E>currentStateprotected io.reactivex.subjects.PublishSubject<Map.Entry<OutputState<E>,OutputState<E>>>currentStatePublisherprotected FSM<E>currentSubFSMprotected TimeoutTransition<E>currentTimeoutThe current timeout in progress.protected List<E>eventsToProcessThe events still in process.protected Set<FSMHandler>handlersThe handler that want to be notified when the state machine of the interaction changed.protected InitState<E>initStateprotected booleaninnerprotected Loggerloggerprotected booleanstartedGoes with 'startingState'.protected State<E>startingStateBy default an FSM triggers its 'start' event when it leaves its initial state.protected Set<State<E>>statesThe states that compose the finite state machine.
-
Constructor Summary
Constructors Constructor Description FSM()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHandler(FSMHandler handler)protected voidaddRemaningEventsToProcess(E event)protected voidaddState(InputState<E> state)Adds a state to the state machine.protected voidcheckTimeoutTransition()Checks whether the current state has a timeout transition.io.reactivex.Observable<Map.Entry<OutputState<E>,OutputState<E>>>currentState()protected voidenterStdState(StdState<E> state)voidfullReinit()OutputState<E>getCurrentState()Set<State<E>>getStates()booleanisInner()booleanisStarted()voidlog(boolean log)protected voidnotifyHandlerOnCancel()Notifies handler that the interaction is cancelled.protected voidnotifyHandlerOnStart()Notifies handler that the interaction starts.protected voidnotifyHandlerOnStop()Notifies handler that the interaction stops.protected voidnotifyHandlerOnUpdate()Notifies handler that the interaction updates.protected voidonCancelling()Cancels the state machine.voidonStarting()Starts the state machine.protected voidonTerminating()Terminates the state machine.protected voidonTimeout()Jobs to do when a timeout transition is executed.voidonUpdating()Updates the state machine.booleanprocess(E event)protected voidprocessRemainingEvents()At the end of the FSM execution, the events still (eg keyPress) in process must be recycled to be reused in the FSM.voidreinit()voidremoveHandler(FSMHandler handler)protected voidsetCurrentState(OutputState<E> state)voidsetInner(boolean inner)protected voidstopCurrentTimeout()Stops the current timeout transition.voiduninstall()
-
-
-
Field Detail
-
logger
protected Logger logger
-
inner
protected boolean inner
-
startingState
protected State<E> startingState
By default an FSM triggers its 'start' event when it leaves its initial state. In some cases, this is not the case. For example, a double-click interaction is an FSM that must trigger its start event when the FSM reaches... its terminal state. Similarly, a DnD must trigger its start event on the first move, not on the first press. The goal of this attribute is to identify the state of the FSM that must trigger the start event. By default, this attribute is set with the initial state of the FSM.
-
started
protected boolean started
Goes with 'startingState'. It permits to know whether the FSM has started, ie whether the 'starting state' has been reached.
-
currentState
protected OutputState<E> currentState
-
currentStatePublisher
protected final io.reactivex.subjects.PublishSubject<Map.Entry<OutputState<E>,OutputState<E>>> currentStatePublisher
-
handlers
protected final Set<FSMHandler> handlers
The handler that want to be notified when the state machine of the interaction changed.
-
eventsToProcess
protected final List<E> eventsToProcess
The events still in process. For example when the user press key ctrl and scroll one time using the wheel of the mouse, the interaction scrolling is finished but the event keyPressed 'ctrl' is still in process. At the end of the interaction, these events are re-introduced into the state machine of the interaction for processing.
-
currentTimeout
protected TimeoutTransition<E> currentTimeout
The current timeout in progress.
-
-
Method Detail
-
getCurrentState
public OutputState<E> getCurrentState()
-
currentState
public io.reactivex.Observable<Map.Entry<OutputState<E>,OutputState<E>>> currentState()
-
setInner
public void setInner(boolean inner)
-
isInner
public boolean isInner()
-
process
public boolean process(E event)
-
enterStdState
protected void enterStdState(StdState<E> state) throws CancelFSMException
- Throws:
CancelFSMException
-
isStarted
public boolean isStarted()
-
setCurrentState
protected void setCurrentState(OutputState<E> state)
-
processRemainingEvents
protected void processRemainingEvents()
At the end of the FSM execution, the events still (eg keyPress) in process must be recycled to be reused in the FSM.
-
addRemaningEventsToProcess
protected void addRemaningEventsToProcess(E event)
-
onTerminating
protected void onTerminating() throws CancelFSMExceptionTerminates the state machine.- Throws:
CancelFSMException
-
onCancelling
protected void onCancelling()
Cancels the state machine.
-
onStarting
public void onStarting() throws CancelFSMExceptionStarts the state machine.- Throws:
CancelFSMException
-
onUpdating
public void onUpdating() throws CancelFSMExceptionUpdates the state machine.- Throws:
CancelFSMException
-
addState
protected void addState(InputState<E> state)
Adds a state to the state machine.- Parameters:
state- The state to add. Must not be null.
-
log
public void log(boolean log)
-
reinit
public void reinit()
-
fullReinit
public void fullReinit()
-
onTimeout
protected void onTimeout()
Jobs to do when a timeout transition is executed. Because the timeout transition is based on a separated thread, the job done by this method must be executed in the UI thread. UI Platforms must override this method to do that.
-
stopCurrentTimeout
protected void stopCurrentTimeout()
Stops the current timeout transition.
-
checkTimeoutTransition
protected void checkTimeoutTransition()
Checks whether the current state has a timeout transition. If it is the case, the timeout transition is launched.
-
addHandler
public void addHandler(FSMHandler handler)
-
removeHandler
public void removeHandler(FSMHandler handler)
-
notifyHandlerOnStart
protected void notifyHandlerOnStart() throws CancelFSMExceptionNotifies handler that the interaction starts.- Throws:
CancelFSMException
-
notifyHandlerOnUpdate
protected void notifyHandlerOnUpdate() throws CancelFSMExceptionNotifies handler that the interaction updates.- Throws:
CancelFSMException
-
notifyHandlerOnStop
protected void notifyHandlerOnStop() throws CancelFSMExceptionNotifies handler that the interaction stops.- Throws:
CancelFSMException
-
notifyHandlerOnCancel
protected void notifyHandlerOnCancel()
Notifies handler that the interaction is cancelled.
-
uninstall
public void uninstall()
-
-