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
matchespublic abstract class InputMapTemplate<S,E extends javafx.event.Event>
extends java.lang.Object
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.
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)
.
Modifier and Type | Class and Description |
---|---|
static interface |
InputMapTemplate.HandlerTemplateConsumer<S,E extends javafx.event.Event> |
Constructor and Description |
---|
InputMapTemplate() |
Modifier and Type | Method and Description |
---|---|
static <S,T extends javafx.event.Event,U extends T> |
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
InputMap s (if they exist). |
static <S,T extends javafx.event.Event,U extends T> |
consume(EventPattern<? super T,? extends U> eventPattern,
java.util.function.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 InputMap s (if they exist). |
static <S,T extends javafx.event.Event> |
consume(javafx.event.EventType<? extends T> eventType)
When the given event type occurs, consumes the event and does not attempt
to match additional
InputMap s (if they exist). |
static <S,T extends javafx.event.Event> |
consume(javafx.event.EventType<? extends T> eventType,
java.util.function.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
InputMap s (if they exist). |
static <S,T extends javafx.event.Event,U extends T> |
consumeUnless(EventPattern<? super T,? extends U> eventPattern,
java.util.function.Predicate<? super S> condition,
java.util.function.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
InputMap s (if they exist). |
static <S,T extends javafx.event.Event> |
consumeUnless(javafx.event.EventType<? extends T> eventType,
java.util.function.Predicate<? super S> condition,
java.util.function.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
InputMap s (if they exist). |
static <S,T extends javafx.event.Event,U extends T> |
consumeWhen(EventPattern<? super T,? extends U> eventPattern,
java.util.function.Predicate<? super S> condition,
java.util.function.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
InputMap s (if they exist). |
static <S,T extends javafx.event.Event> |
consumeWhen(javafx.event.EventType<? extends T> eventType,
java.util.function.Predicate<? super S> condition,
java.util.function.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
InputMap s (if they exist). |
void |
forEachEventType(InputMapTemplate.HandlerTemplateConsumer<S,? super E> f) |
protected abstract org.fxmisc.wellbehaved.event.template.InputHandlerTemplateMap<S,E> |
getInputHandlerTemplateMap() |
InputMapTemplate<S,E> |
ifConsumed(java.util.function.BiConsumer<? super S,? super E> postConsumption)
Executes some additional handler if the event was consumed (e.g.
|
InputMapTemplate<S,E> |
ifIgnored(java.util.function.BiConsumer<? super S,? super E> postIgnore)
Executes some additional handler if the event was ignored
(e.g.
|
InputMapTemplate<S,E> |
ifProcessed(java.util.function.BiConsumer<? super S,? super E> postProceed)
Executes some additional handler if the event was consumed (e.g.
|
static <S,T extends javafx.event.Event,U extends T> |
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 InputMap s (if they exist). |
static <S,T extends javafx.event.Event> |
ignore(javafx.event.EventType<? extends T> eventType)
When the given event type occurs, does nothing and does not attempt to match additional
InputMap s (if they exist). |
static <S extends javafx.scene.Node,E extends javafx.event.Event> |
installFallback(InputMapTemplate<S,E> imt,
S node)
Instantiates the input map and installs it into the node via
Nodes.addFallbackInputMap(Node, InputMap) |
static <S,N extends javafx.scene.Node,E extends javafx.event.Event> |
installFallback(InputMapTemplate<S,E> imt,
S target,
java.util.function.Function<? super S,? extends N> getNode)
Instantiates the input map and installs it into the node via
Nodes.addFallbackInputMap(Node, InputMap) |
static <S extends javafx.scene.Node,E extends javafx.event.Event> |
installOverride(InputMapTemplate<S,E> imt,
S node)
Instantiates the input map and installs it into the node via
Nodes.addInputMap(Node, InputMap) |
static <S,N extends javafx.scene.Node,E extends javafx.event.Event> |
installOverride(InputMapTemplate<S,E> imt,
S target,
java.util.function.Function<? super S,? extends N> getNode)
Instantiates the input map and installs it into the node via
Nodes.addInputMap(Node, InputMap) |
InputMap<E> |
instantiate(S target)
Converts this InputMapTemplate into an
InputMap for the given target |
static <S,T,E extends javafx.event.Event> |
lift(InputMapTemplate<T,E> imt,
java.util.function.Function<? super S,? extends T> f) |
InputMapTemplate<S,E> |
orElse(InputMapTemplate<S,? extends E> that)
Shorthand for
sequence(InputMapTemplate[]) sequence(this, that)} |
static <S,T extends javafx.event.Event,U extends T> |
process(EventPattern<? super T,? extends U> eventPattern,
java.util.function.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). |
static <S,T extends javafx.event.Event> |
process(javafx.event.EventType<? extends T> eventType,
java.util.function.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). |
static <S,E extends javafx.event.Event> |
sequence(InputMapTemplate<S,? extends E>... templates)
Creates a single InputMapTemplate that pattern matches a given event type against all the given
InputMapTemplates.
|
static <S extends javafx.scene.Node,E extends javafx.event.Event> |
uninstall(InputMapTemplate<S,E> imt,
S node)
Removes the input map template's instance from the given node.
|
static <S,N extends javafx.scene.Node,E extends javafx.event.Event> |
uninstall(InputMapTemplate<S,E> imt,
S target,
java.util.function.Function<? super S,? extends N> getNode)
Removes the input map template's instance from the given node.
|
static <S,T extends javafx.event.Event> |
unless(java.util.function.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). |
static <S,T extends javafx.event.Event> |
when(java.util.function.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). |
public final void forEachEventType(InputMapTemplate.HandlerTemplateConsumer<S,? super E> f)
public final InputMapTemplate<S,E> orElse(InputMapTemplate<S,? extends E> that)
sequence(InputMapTemplate[])
sequence(this, that)}public final InputMap<E> instantiate(S target)
InputMap
for the given target
protected abstract org.fxmisc.wellbehaved.event.template.InputHandlerTemplateMap<S,E> getInputHandlerTemplateMap()
@SafeVarargs public static <S,E extends javafx.event.Event> InputMapTemplate<S,E> sequence(InputMapTemplate<S,? extends E>... templates)
public static <S,T extends javafx.event.Event,U extends T> InputMapTemplate<S,U> process(EventPattern<? super T,? extends U> eventPattern, java.util.function.BiFunction<? super S,? super U,InputHandler.Result> action)
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 javafx.event.Event> InputMapTemplate<S,T> process(javafx.event.EventType<? extends T> eventType, java.util.function.BiFunction<? super S,? super T,InputHandler.Result> action)
InputMap
(if one exists).public InputMapTemplate<S,E> ifConsumed(java.util.function.BiConsumer<? super S,? super E> postConsumption)
InputHandler.process(Event)
returns
InputHandler.Result.CONSUME
).public InputMapTemplate<S,E> ifIgnored(java.util.function.BiConsumer<? super S,? super E> postIgnore)
InputHandlerTemplate.process(Object, Event)
returns InputHandler.Result.IGNORE
).public InputMapTemplate<S,E> ifProcessed(java.util.function.BiConsumer<? super S,? super E> postProceed)
InputHandler.process(Event)
returns
InputHandler.Result.CONSUME
).public static <S,T extends javafx.event.Event,U extends T> InputMapTemplate<S,U> consume(EventPattern<? super T,? extends U> eventPattern, java.util.function.BiConsumer<? super S,? super U> action)
EventPattern
matches the given event type, runs the given action, consumes the event,
and does not attempt to match additional InputMap
s (if they exist).public static <S,T extends javafx.event.Event> InputMapTemplate<S,T> consume(javafx.event.EventType<? extends T> eventType, java.util.function.BiConsumer<? super S,? super T> action)
InputMap
s (if they exist).public static <S,T extends javafx.event.Event,U extends T> InputMapTemplate<S,U> consume(EventPattern<? super T,? extends U> eventPattern)
EventPattern
matches the given event type,
consumes the event and does not attempt to match additional
InputMap
s (if they exist).public static <S,T extends javafx.event.Event> InputMapTemplate<S,T> consume(javafx.event.EventType<? extends T> eventType)
InputMap
s (if they exist).public static <S,T extends javafx.event.Event,U extends T> InputMapTemplate<S,U> consumeWhen(EventPattern<? super T,? extends U> eventPattern, java.util.function.Predicate<? super S> condition, java.util.function.BiConsumer<? super S,? super U> action)
EventPattern
matches the given event type and condition
is true,
consumes the event and does not attempt to match additional
InputMap
s (if they exist).public static <S,T extends javafx.event.Event> InputMapTemplate<S,T> consumeWhen(javafx.event.EventType<? extends T> eventType, java.util.function.Predicate<? super S> condition, java.util.function.BiConsumer<? super S,? super T> action)
condition
is true,
consumes the event and does not attempt to match additional
InputMap
s (if they exist).public static <S,T extends javafx.event.Event,U extends T> InputMapTemplate<S,U> consumeUnless(EventPattern<? super T,? extends U> eventPattern, java.util.function.Predicate<? super S> condition, java.util.function.BiConsumer<? super S,? super U> action)
EventPattern
matches the given event type and condition
is false,
consumes the event and does not attempt to match additional
InputMap
s (if they exist). If condition
is true, continues to try to pattern match
the event type with the next InputMap
(if one exists).public static <S,T extends javafx.event.Event> InputMapTemplate<S,T> consumeUnless(javafx.event.EventType<? extends T> eventType, java.util.function.Predicate<? super S> condition, java.util.function.BiConsumer<? super S,? super T> action)
condition
is false,
consumes the event and does not attempt to match additional
InputMap
s (if they exist). If condition
is true, continues to try to pattern match
the event type with the next InputMap
(if one exists).public static <S,T extends javafx.event.Event,U extends T> InputMapTemplate<S,U> ignore(EventPattern<? super T,? extends U> eventPattern)
EventPattern
matches the given event type, does nothing and does not attempt
to match additional InputMap
s (if they exist).public static <S,T extends javafx.event.Event> InputMapTemplate<S,T> ignore(javafx.event.EventType<? extends T> eventType)
InputMap
s (if they exist).public static <S,T extends javafx.event.Event> InputMapTemplate<S,T> when(java.util.function.Predicate<? super S> condition, InputMapTemplate<S,T> imt)
condition
is true, pattern matches the event with the given InputMap
or
proceeds to the next InputMap
(if it exists).public static <S,T extends javafx.event.Event> InputMapTemplate<S,T> unless(java.util.function.Predicate<? super S> condition, InputMapTemplate<S,T> imt)
condition
is false, pattern matches the event with the given InputMap
or
proceeds to the next InputMap
(if it exists).public static <S,T,E extends javafx.event.Event> InputMapTemplate<S,E> lift(InputMapTemplate<T,E> imt, java.util.function.Function<? super S,? extends T> f)
public static <S extends javafx.scene.Node,E extends javafx.event.Event> void installOverride(InputMapTemplate<S,E> imt, S node)
Nodes.addInputMap(Node, InputMap)
public static <S,N extends javafx.scene.Node,E extends javafx.event.Event> void installOverride(InputMapTemplate<S,E> imt, S target, java.util.function.Function<? super S,? extends N> getNode)
Nodes.addInputMap(Node, InputMap)
public static <S extends javafx.scene.Node,E extends javafx.event.Event> void installFallback(InputMapTemplate<S,E> imt, S node)
Nodes.addFallbackInputMap(Node, InputMap)
public static <S,N extends javafx.scene.Node,E extends javafx.event.Event> void installFallback(InputMapTemplate<S,E> imt, S target, java.util.function.Function<? super S,? extends N> getNode)
Nodes.addFallbackInputMap(Node, InputMap)
public static <S extends javafx.scene.Node,E extends javafx.event.Event> void uninstall(InputMapTemplate<S,E> imt, S node)
public static <S,N extends javafx.scene.Node,E extends javafx.event.Event> void uninstall(InputMapTemplate<S,E> imt, S target, java.util.function.Function<? super S,? extends N> getNode)