Module interacto.java.api
Package io.github.interacto.interaction
Class InteractionImpl<D extends InteractionData,E,F extends FSM<E>>
- java.lang.Object
-
- io.github.interacto.interaction.InteractionImpl<D,E,F>
-
- Type Parameters:
D- The type of the interaction data.E- The type of the events that the interaction will process.F- The type of the FSM.
public abstract class InteractionImpl<D extends InteractionData,E,F extends FSM<E>> extends Object
The base implementation of a user interaction.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanactivatedDefines whether the interaction is activated.protected EcurrentThrottledEventprotected Future<?>currThrottleTimeoutFutureThe current throttle thread in progress.protected io.reactivex.disposables.Disposabledisposableprotected ExecutorServiceexecutorprotected Ffsmprotected Loggerloggerprotected AtomicLongthrottleCounterprotected longthrottleTimeout
-
Constructor Summary
Constructors Modifier Constructor Description protectedInteractionImpl(F fsm)Creates the interaction.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidconsumeEvent(E event)voidfullReinit()Reinitialises the user interactionabstract DgetData()FgetFsm()booleanisActivated()protected abstract booleanisEventsOfSameType(E evt1, E evt2)Defines whether the two given events are of the same type.booleanisRunning()voidlog(boolean log)Sets the logging of the user interaction.voidprocessEvent(E event)Processes the given UI event.protected voidreinit()protected abstract voidreinitData()protected abstract voidrunInUIThread(Runnable cmd)Runs the given command in the UI thread.voidsetActivated(boolean activated)Sets whether the user interaction is activated.voidsetConsumeEvents(boolean consumeEvents)Sets whether the user interaction will consume the processed UI events.static voidsetLogger(Logger logger)Sets the logger to use.voidsetThrottleTimeout(long timeout)Sets the throttle timeout the interaction will use.voiduninstall()Uninstall the user interaction.protected abstract voidupdateEventsRegistered(OutputState<E> newState, OutputState<E> oldState)
-
-
-
Field Detail
-
activated
protected boolean activated
Defines whether the interaction is activated. If not, the interaction will not change on events.
-
logger
protected Logger logger
-
throttleTimeout
protected long throttleTimeout
-
throttleCounter
protected final AtomicLong throttleCounter
-
currentThrottledEvent
protected E currentThrottledEvent
-
currThrottleTimeoutFuture
protected Future<?> currThrottleTimeoutFuture
The current throttle thread in progress.
-
executor
protected ExecutorService executor
-
disposable
protected final io.reactivex.disposables.Disposable disposable
-
-
Constructor Detail
-
InteractionImpl
protected InteractionImpl(F fsm)
Creates the interaction.- Parameters:
fsm- The FSM that defines the behavior of the user interaction.- Throws:
IllegalArgumentException- If the given FSM is null.
-
-
Method Detail
-
setLogger
public static void setLogger(Logger logger)
Sets the logger to use. Cannot be null. Does not change the loggers of existing user interactions.- Parameters:
logger- The new logger to use.
-
getData
public abstract D getData()
- Returns:
- The interaction data of the user interaction. Cannot be null.
-
setThrottleTimeout
public void setThrottleTimeout(long timeout)
Sets the throttle timeout the interaction will use.- Parameters:
timeout- The throttle value.
-
updateEventsRegistered
protected abstract void updateEventsRegistered(OutputState<E> newState, OutputState<E> oldState)
-
isRunning
public boolean isRunning()
- Returns:
- Whether the user interaction is running.
-
fullReinit
public void fullReinit()
Reinitialises the user interaction
-
consumeEvent
protected abstract void consumeEvent(E event)
-
setConsumeEvents
public void setConsumeEvents(boolean consumeEvents)
Sets whether the user interaction will consume the processed UI events. This is related to the event.consume() method.- Parameters:
consumeEvents- True: the processed events will be consumed.
-
isEventsOfSameType
protected abstract boolean isEventsOfSameType(E evt1, E evt2)
Defines whether the two given events are of the same type. For example, whether they are both mouse move events. This check is platform specific.- Parameters:
evt1- The first event to check.evt2- The second event to check.- Returns:
- True: the two events are of the same type.
-
runInUIThread
protected abstract void runInUIThread(Runnable cmd)
Runs the given command in the UI thread. This is necessary since some created threads (e.g. throttling, timeout transition) exit the UI thread but may require some job to be executed in the UI thread.- Parameters:
cmd- The job to execute in the UI thread.
-
processEvent
public void processEvent(E event)
Processes the given UI event.- Parameters:
event- The event to process.
-
log
public void log(boolean log)
Sets the logging of the user interaction.- Parameters:
log- True: the user interaction will log information.
-
isActivated
public boolean isActivated()
- Returns:
- True if the user interaction is activated.
-
setActivated
public void setActivated(boolean activated)
Sets whether the user interaction is activated. When not activated, a user interaction does not process input events any more.- Parameters:
activated- True: the user interaction will be activated.
-
getFsm
public F getFsm()
- Returns:
- The FSM of the user interaction.
-
reinit
protected void reinit()
-
reinitData
protected abstract void reinitData()
-
uninstall
public void uninstall()
Uninstall the user interaction. Used to free memory. Then, user interaction can be used any more.
-
-