Top Description Inners Fields Constructors Methods
org.fxmisc.wellbehaved.event.template

public abstract Class InputMapTemplate<S, E extends Event>

Additional top-level classes in compilation unit: PatternActionTemplate, TemplateChain, InputMapTemplateInstance.

extends Object
Class Inheritance
Known Direct Subclasses
org.fxmisc.wellbehaved.event.template.PatternActionTemplate, org.fxmisc.wellbehaved.event.template.TemplateChain
Type Parameters
<S>
the type of the object that will be passed into the InputHandlerTemplate's block of code.
<E>
the event type for which this InputMap's EventPattern matches
Imports
java.util.Arrays, .Objects, java.util.function.BiConsumer, .BiFunction, .Function, .Predicate, javafx.event.Event, .EventType, javafx.scene.Node, org.fxmisc.wellbehaved.event.EventPattern, .InputHandler, .InputHandler.Result, .InputMap, .Nodes

See InputMap for an explanation. This simply turns that concept into a template that can be used to add the same InputMap to multiple instances of the same class.

Adding a template to a class

Given a class, the InputMapTemplate code should be created in a static block and then instantiate itself in the node's constructor:


public class CustomTextField extends TextField {

    private final static InputMapTemplate<? super Event> BEHAVIOR;

    static {

         // creating InputMapTemplates by
         InputMapTemplate<CustomTextField, ? extends KeyEvent> keyEventBehavior = sequence(
             consume(keyTyped(), (field, event) -> field.setText(event.getText()),
             consume(
                 anyOf(
                     mousePressed(),
                     mouseMoved(),
                     mouseReleased()
                 ),
                 (field, event) -> field.setText("Mouse event detected! Event: " + event)
             )
         );

         // Other InputMapTemplates (though these don't need to be broken up by
         // KeyEvent, MouseEvent, etc. They could be interwoven depending on your desired behavior)
         InputMapTemplate<CustomTextField, ? extends MouseEvent> mouseEventBehavior = sequence(
             // other InputMapTemplates go here...
         );

         InputMapTemplate<CustomTextField, ? extends Event> otherCustomEventBehavior = sequence(
             // other InputMapTemplates go here...
         );

         // Tying all of them together into one final InputMapTemplate
         BEHAVIOR = sequence(
             keyEventBehavior,
             mouseEventBehavior,
             otherCustomEventBehavior
         );
    }

    public CustomTextField(Object[] args) {
        super(args);
        // other constructor stuff here

        // Install InputMapTemplate onto this node here via one of the two "install" methods
        // described after this code block
    }

    // rest of the class
}

The InputMapTemplate can be instantiated as a default behavior (installFallback(InputMapTemplate, Node) or as something that overrides prior default behavior (installOverride(InputMapTemplate, Node) (or their variants). Likewise, it can be removed via uninstall(InputMapTemplate, Node).

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Field Summary

Modifier and TypeField and Description
private InputHandlerTemplateMap<S, E>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <S, T extends Event, U extends T> InputMapTemplate<S, U>
consume(EventPattern<? super T, ? extends U> eventPattern, BiConsumer<? super S, ? super U> action)

If the given EventPattern matches the given event type, runs the given action, consumes the event, and does not attempt to match additional InputMaps (if they exist).

public static <S, T extends Event> InputMapTemplate<S, T>
consume(EventType<? extends T> eventType, BiConsumer<? super S, ? super T> action)

When the given event type occurs, runs the given action, consumes the event, and does not attempt to match additional InputMaps (if they exist).

public static <S, T extends Event, U extends T> InputMapTemplate<S, U>
consume(EventPattern<? super T, ? extends U> eventPattern)

If the given EventPattern matches the given event type, consumes the event and does not attempt to match additional InputMaps (if they exist).

public static <S, T extends Event> InputMapTemplate<S, T>
consume(EventType<? extends T> eventType)

When the given event type occurs, consumes the event and does not attempt to match additional InputMaps (if they exist).

public static <S, T extends Event, U extends T> InputMapTemplate<S, U>
consumeUnless(EventPattern<? super T, ? extends U> eventPattern, Predicate<? super S> condition, BiConsumer<? super S, ? super U> action)

If the given EventPattern matches the given event type and condition is false, consumes the event and does not attempt to match additional InputMaps (if they exist).

public static <S, T extends Event> InputMapTemplate<S, T>
consumeUnless(EventType<? extends T> eventType, Predicate<? super S> condition, BiConsumer<? super S, ? super T> action)

When the given event type occurs and condition is false, consumes the event and does not attempt to match additional InputMaps (if they exist).

public static <S, T extends Event, U extends T> InputMapTemplate<S, U>
consumeWhen(EventPattern<? super T, ? extends U> eventPattern, Predicate<? super S> condition, BiConsumer<? super S, ? super U> action)

If the given EventPattern matches the given event type and condition is true, consumes the event and does not attempt to match additional InputMaps (if they exist).

public static <S, T extends Event> InputMapTemplate<S, T>
consumeWhen(EventType<? extends T> eventType, Predicate<? super S> condition, BiConsumer<? super S, ? super T> action)

When the given event type occurs and condition is true, consumes the event and does not attempt to match additional InputMaps (if they exist).

public final void
protected abstract InputHandlerTemplateMap<S, E>
public InputMapTemplate<S, E>
ifConsumed(BiConsumer<? super S, ? super E> postConsumption)

Executes some additional handler if the event was consumed (e.g. InputHandler#process(Event) returns Result#CONSUME).

public InputMapTemplate<S, E>
ifIgnored(BiConsumer<? super S, ? super E> postIgnore)

Executes some additional handler if the event was ignored (e.g. InputHandlerTemplate#process(Object, Event) returns Result#IGNORE).

public InputMapTemplate<S, E>
ifProcessed(BiConsumer<? super S, ? super E> postProceed)

Executes some additional handler if the event was consumed (e.g. InputHandler#process(Event) returns Result#CONSUME).

public static <S, T extends Event, U extends T> InputMapTemplate<S, U>
ignore(EventPattern<? super T, ? extends U> eventPattern)

If the given EventPattern matches the given event type, does nothing and does not attempt to match additional InputMaps (if they exist).

public static <S, T extends Event> InputMapTemplate<S, T>
ignore(EventType<? extends T> eventType)

When the given event type occurs, does nothing and does not attempt to match additional InputMaps (if they exist).

public static <S extends Node, E extends Event> void
installFallback(InputMapTemplate<S, E> imt, S node)

Instantiates the input map and installs it into the node via Nodes#addFallbackInputMap(Node, InputMap)

public static <S, N extends Node, E extends Event> void
installFallback(InputMapTemplate<S, E> imt, S target, Function<? super S, ? extends N> getNode)

Instantiates the input map and installs it into the node via Nodes#addFallbackInputMap(Node, InputMap)

public static <S extends Node, E extends Event> void
installOverride(InputMapTemplate<S, E> imt, S node)

Instantiates the input map and installs it into the node via Nodes#addInputMap(Node, InputMap)

public static <S, N extends Node, E extends Event> void
installOverride(InputMapTemplate<S, E> imt, S target, Function<? super S, ? extends N> getNode)

Instantiates the input map and installs it into the node via Nodes#addInputMap(Node, InputMap)

public final InputMap<E>
instantiate(S target)

Converts this InputMapTemplate into an InputMap for the given target

public static <S, T, E extends Event> InputMapTemplate<S, E>
lift(InputMapTemplate<T, E> imt, Function<? super S, ? extends T> f)

public final InputMapTemplate<S, E>
orElse(InputMapTemplate<S, ? extends E> that)

Shorthand for sequence(InputMapTemplate[]) sequence(this, that)}

private InputMapTemplate<S, E>
postResult(InputHandler.Result checkedResult, BiConsumer<? super S, ? super E> postDesiredResult)

public static <S, T extends Event, U extends T> InputMapTemplate<S, U>
process(EventPattern<? super T, ? extends U> eventPattern, BiFunction<? super S, ? super U, InputHandler.Result> action)

If the given EventPattern matches the given event type, runs the given action, and then attempts to pattern match the event type with the next InputMap (if one exists).

public static <S, T extends Event> InputMapTemplate<S, T>
process(EventType<? extends T> eventType, BiFunction<? super S, ? super T, InputHandler.Result> action)

When the given event type occurs, runs the given action, and then attempts to pattern match the event type with the next InputMap (if one exists).

public static <S, E extends Event> InputMapTemplate<S, E>
sequence(InputMapTemplate<S, ? extends E>... templates)

Creates a single InputMapTemplate that pattern matches a given event type against all the given InputMapTemplates.

public static <S extends Node, E extends Event> void
uninstall(InputMapTemplate<S, E> imt, S node)

Removes the input map template's instance from the given node.

public static <S, N extends Node, E extends Event> void
uninstall(InputMapTemplate<S, E> imt, S target, Function<? super S, ? extends N> getNode)

Removes the input map template's instance from the given node.

public static <S, T extends Event> InputMapTemplate<S, T>
unless(Predicate<? super S> condition, InputMapTemplate<S, T> imt)

When the given condition is false, pattern matches the event with the given InputMap or proceeds to the next InputMap (if it exists).

pack-priv static <S, E extends Event> InputMapTemplate<S, E>
upCast(InputMapTemplate<S, ? extends E> imt)

public static <S, T extends Event> InputMapTemplate<S, T>
when(Predicate<? super S> condition, InputMapTemplate<S, T> imt)

When the given condition is true, pattern matches the event with the given InputMap or proceeds to the next InputMap (if it exists).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

inputHandlerTemplatesback to summary
private InputHandlerTemplateMap<S, E> inputHandlerTemplates

Constructor Detail

InputMapTemplateback to summary
public InputMapTemplate()

Method Detail

consumeback to summary
public static <S, T extends Event, U extends T> InputMapTemplate<S, U> consume(EventPattern<? super T, ? extends U> eventPattern, BiConsumer<? super S, ? super U> action)

If the given EventPattern matches the given event type, runs the given action, consumes the event, and does not attempt to match additional InputMaps (if they exist).

consumeback to summary
public static <S, T extends Event> InputMapTemplate<S, T> consume(EventType<? extends T> eventType, BiConsumer<? super S, ? super T> action)

When the given event type occurs, runs the given action, consumes the event, and does not attempt to match additional InputMaps (if they exist).

consumeback to summary
public static <S, T extends Event, U extends T> InputMapTemplate<S, U> consume(EventPattern<? super T, ? extends U> eventPattern)

If the given EventPattern matches the given event type, consumes the event and does not attempt to match additional InputMaps (if they exist).

consumeback to summary
public static <S, T extends Event> InputMapTemplate<S, T> consume(EventType<? extends T> eventType)

When the given event type occurs, consumes the event and does not attempt to match additional InputMaps (if they exist).

consumeUnlessback to summary
public static <S, T extends Event, U extends T> InputMapTemplate<S, U> consumeUnless(EventPattern<? super T, ? extends U> eventPattern, Predicate<? super S> condition, BiConsumer<? super S, ? super U> action)

If the given EventPattern matches the given event type and condition is false, consumes the event and does not attempt to match additional InputMaps (if they exist). If condition is true, continues to try to pattern match the event type with the next InputMap (if one exists).

consumeUnlessback to summary
public static <S, T extends Event> InputMapTemplate<S, T> consumeUnless(EventType<? extends T> eventType, Predicate<? super S> condition, BiConsumer<? super S, ? super T> action)

When the given event type occurs and condition is false, consumes the event and does not attempt to match additional InputMaps (if they exist). If condition is true, continues to try to pattern match the event type with the next InputMap (if one exists).

consumeWhenback to summary
public static <S, T extends Event, U extends T> InputMapTemplate<S, U> consumeWhen(EventPattern<? super T, ? extends U> eventPattern, Predicate<? super S> condition, BiConsumer<? super S, ? super U> action)

If the given EventPattern matches the given event type and condition is true, consumes the event and does not attempt to match additional InputMaps (if they exist).

consumeWhenback to summary
public static <S, T extends Event> InputMapTemplate<S, T> consumeWhen(EventType<? extends T> eventType, Predicate<? super S> condition, BiConsumer<? super S, ? super T> action)

When the given event type occurs and condition is true, consumes the event and does not attempt to match additional InputMaps (if they exist).

forEachEventTypeback to summary
public final void forEachEventType(InputMapTemplate.HandlerTemplateConsumer<S, ? super E> f)
getInputHandlerTemplateMapback to summary
protected abstract InputHandlerTemplateMap<S, E> getInputHandlerTemplateMap()
ifConsumedback to summary
public InputMapTemplate<S, E> ifConsumed(BiConsumer<? super S, ? super E> postConsumption)

Executes some additional handler if the event was consumed (e.g. InputHandler#process(Event) returns Result#CONSUME).

ifIgnoredback to summary
public InputMapTemplate<S, E> ifIgnored(BiConsumer<? super S, ? super E> postIgnore)

Executes some additional handler if the event was ignored (e.g. InputHandlerTemplate#process(Object, Event) returns Result#IGNORE).

ifProcessedback to summary
public InputMapTemplate<S, E> ifProcessed(BiConsumer<? super S, ? super E> postProceed)

Executes some additional handler if the event was consumed (e.g. InputHandler#process(Event) returns Result#CONSUME).

ignoreback to summary
public static <S, T extends Event, U extends T> InputMapTemplate<S, U> ignore(EventPattern<? super T, ? extends U> eventPattern)

If the given EventPattern matches the given event type, does nothing and does not attempt to match additional InputMaps (if they exist).

ignoreback to summary
public static <S, T extends Event> InputMapTemplate<S, T> ignore(EventType<? extends T> eventType)

When the given event type occurs, does nothing and does not attempt to match additional InputMaps (if they exist).

installFallbackback to summary
public static <S extends Node, E extends Event> void installFallback(InputMapTemplate<S, E> imt, S node)

Instantiates the input map and installs it into the node via Nodes#addFallbackInputMap(Node, InputMap)

installFallbackback to summary
public static <S, N extends Node, E extends Event> void installFallback(InputMapTemplate<S, E> imt, S target, Function<? super S, ? extends N> getNode)

Instantiates the input map and installs it into the node via Nodes#addFallbackInputMap(Node, InputMap)

installOverrideback to summary
public static <S extends Node, E extends Event> void installOverride(InputMapTemplate<S, E> imt, S node)

Instantiates the input map and installs it into the node via Nodes#addInputMap(Node, InputMap)

installOverrideback to summary
public static <S, N extends Node, E extends Event> void installOverride(InputMapTemplate<S, E> imt, S target, Function<? super S, ? extends N> getNode)

Instantiates the input map and installs it into the node via Nodes#addInputMap(Node, InputMap)

instantiateback to summary
public final InputMap<E> instantiate(S target)

Converts this InputMapTemplate into an InputMap for the given target

liftback to summary
public static <S, T, E extends Event> InputMapTemplate<S, E> lift(InputMapTemplate<T, E> imt, Function<? super S, ? extends T> f)
orElseback to summary
public final InputMapTemplate<S, E> orElse(InputMapTemplate<S, ? extends E> that)

Shorthand for sequence(InputMapTemplate[]) sequence(this, that)}

postResultback to summary
private InputMapTemplate<S, E> postResult(InputHandler.Result checkedResult, BiConsumer<? super S, ? super E> postDesiredResult)
processback to summary
public static <S, T extends Event, U extends T> InputMapTemplate<S, U> process(EventPattern<? super T, ? extends U> eventPattern, BiFunction<? super S, ? super U, InputHandler.Result> action)

If the given EventPattern matches the given event type, runs the given action, and then attempts to pattern match the event type with the next InputMap (if one exists).

processback to summary
public static <S, T extends Event> InputMapTemplate<S, T> process(EventType<? extends T> eventType, BiFunction<? super S, ? super T, InputHandler.Result> action)

When the given event type occurs, runs the given action, and then attempts to pattern match the event type with the next InputMap (if one exists).

sequenceback to summary
public static <S, E extends Event> InputMapTemplate<S, E> sequence(InputMapTemplate<S, ? extends E>... templates)

Creates a single InputMapTemplate that pattern matches a given event type against all the given InputMapTemplates. This is often the InputMapTemplate installed on a given node since it contains all the other InputMapTemplates.

Annotations
@SafeVarargs
uninstallback to summary
public static <S extends Node, E extends Event> void uninstall(InputMapTemplate<S, E> imt, S node)

Removes the input map template's instance from the given node.

uninstallback to summary
public static <S, N extends Node, E extends Event> void uninstall(InputMapTemplate<S, E> imt, S target, Function<? super S, ? extends N> getNode)

Removes the input map template's instance from the given node.

unlessback to summary
public static <S, T extends Event> InputMapTemplate<S, T> unless(Predicate<? super S> condition, InputMapTemplate<S, T> imt)

When the given condition is false, pattern matches the event with the given InputMap or proceeds to the next InputMap (if it exists).

upCastback to summary
pack-priv static <S, E extends Event> InputMapTemplate<S, E> upCast(InputMapTemplate<S, ? extends E> imt)
whenback to summary
public static <S, T extends Event> InputMapTemplate<S, T> when(Predicate<? super S> condition, InputMapTemplate<S, T> imt)

When the given condition is true, pattern matches the event with the given InputMap or proceeds to the next InputMap (if it exists).

org.fxmisc.wellbehaved.event.template back to summary

public Interface InputMapTemplate.HandlerTemplateConsumer<S, E extends Event>

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public <F extends E> void
accept(EventType<? extends F> t, InputHandlerTemplate<S, ? super F> h)

public static <S, E extends Event> InputMapTemplate.HandlerTemplateConsumer<S, E>
from(InputMap.HandlerConsumer<E> hc, S target)

Method Detail

acceptback to summary
public <F extends E> void accept(EventType<? extends F> t, InputHandlerTemplate<S, ? super F> h)
fromback to summary
public static <S, E extends Event> InputMapTemplate.HandlerTemplateConsumer<S, E> from(InputMap.HandlerConsumer<E> hc, S target)