Class InteractionImpl<D extends InteractionData,​E,​F extends FSM<E>>

  • 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 Detail

      • fsm

        protected final F extends FSM<E> fsm
      • 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.
      • 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.