Additional top-level classes in compilation unit: PatternActionMap, InputMapChain.
InputMap<E> certainly does not handle any events that
are not of type E; it does not mean it handles any
event of type E.
Events.
InputMap as a powerful switch statement:
switch (eventType) {
case KEY_PRESSED: // the basic EventPattern
doCodeWithEvent(e); // the basic InputHandler
break;
// an EventPattern with a condition
// it only matches KeyTyped events whose text is a space character
// other KeyTyped events don't run the space insertion code beow
case KEY_TYPED e if e.getText().equals(" "):
addSpaceToText();
break;
// an EventPattern with another condition
case MOUSE_MOVED && otherNode.isVisible():
otherNode.hide();
thirdNode.show();
break;
// runs the same behavior for multiple event types
case MOUSE_PRESSED || MOUSE_RELEASED || MOUSE_DRAGGED || MOUSE_ENTERED_TARGET:
showPopupThatSays("You did something with the mouse!")
// sometimes there is no "default" behavior and the event bubbles back up
default:
break;
}
There are a few types of InputMaps:
ignore(EventType), consume(EventType), and
process(EventType, Function) (and all their variations).
sequence(InputMap[])/orElse(InputMap),
upCast(InputMap), and without(InputMap).
when(BooleanSupplier, InputMap) and
unless(BooleanSupplier, InputMap)
consumeWhen(EventType, BooleanSupplier, Consumer)
and consumeUnless(EventType, BooleanSupplier, Consumer)
ifIgnored(Consumer), ifProcessed(Consumer),
ifConsumed(Consumer).
InputMap<KeyEvent> typeTheLetter = consume(
// event pattern (e.g. the "case" line in a switch statement)
keyTyped(),
// input handler (e.g. the "block of code" for a case in a switch statement
e -> textField.addLetter(e.getText)
);
InputMap<KeyEvent> copy = consume(
anyOf(
keyPressed(KeyCode.C, KeyCode.SHORTCUT),
keyPressed(KeyCode.COPY)
),
e -> textField.copyToClipboard()
);
InputMap<KeyEvent> pasteThenClearTextField = consume(
// event pattern
anyOf(
keyPressed(KeyCode.V, KeyCode.SHORTCUT),
keyPressed(KeyCode.PASTE)
),
e -> textField.copyToClipboard()
).ifConsumed(ignoreMe -> textField.clearText();
InputMap<CustomEvent> someCustomEventInputMap = // imagine I put something here...
// notice the very generic "Event" event type
InputMap<? super Event> allBehaviorForCustomTextField = sequence(
// when an event occurs, check whether the below input map's EventPattern matches the given event
typeTheLetter,
// only pattern match against the below input map if the previous one didn't match
copy,
// check this one only if the above two didn't match
pasteThenClearTextField,
someCustomEventInputMap
// If reach this part, none of them matched, so do nothing
);
// at this point, "allBehaviorForCustomTextField" could be installed into a Node
Nodes.addFallbackInputMap(node, allBehaviorForCustomTextField);
// when user types a letter, the text field adds that letter
// when user moves the mouse over the text field, nothing happens
When creating a subclass of a node that will be instantiated multiple times, use
org. to create an InputMap for each
created javafx. as this saves some memory. See the template class' javadoc for more details.
| Modifier and Type | Class and Description |
|---|---|
| public static interface |
| Modifier and Type | Method and Description |
|---|---|
| public static <T extends Event, U extends T> InputMap | consume(EventPattern<? super T, ? extends U> eventPattern, Consumer<? super U> action)
If the given |
| public static <T extends Event> InputMap | |
| public static <T extends Event, U extends T> InputMap | consume(EventPattern<? super T, ? extends U> eventPattern)
If the given |
| public static <T extends Event> InputMap | |
| public static <T extends Event, U extends T> InputMap | consumeUnless(EventPattern<? super T, ? extends U> eventPattern, BooleanSupplier condition, Consumer<? super U> action)
If the given |
| public static <T extends Event> InputMap | consumeUnless(EventType<? extends T> eventType, BooleanSupplier condition, Consumer<? super T> action)
When the given event type occurs and |
| public static <T extends Event, U extends T> InputMap | consumeWhen(EventPattern<? super T, ? extends U> eventPattern, BooleanSupplier condition, Consumer<? super U> action)
If the given |
| public static <T extends Event> InputMap | consumeWhen(EventType<? extends T> eventType, BooleanSupplier condition, Consumer<? super T> action)
When the given event type occurs and |
| public static <E extends Event> InputMap | |
| public void | forEachEventType(InputMap.
For each |
| public default InputMap | ifConsumed(Consumer<? super E> postConsumption)
Executes some additional handler if the event was consumed (e.g. |
| public default InputMap | ifIgnored(Consumer<? super E> postIgnore)
Executes some additional handler if the event was ignored (e.g. |
| public default InputMap | ifProcessed(Consumer<? super E> postProceed)
Executes some additional handler if the event was matched but not consumed
(e.g. |
| public static <T extends Event, U extends T> InputMap | ignore(EventPattern<? super T, ? extends U> eventPattern)
If the given |
| public static <T extends Event> InputMap | |
| public default InputMap | |
| public static <E extends Event> InputMap | postResult(InputMap<? extends E> map, InputHandler.
|
| public static <T extends Event, U extends T> InputMap | process(EventPattern<? super T, ? extends U> eventPattern, Function<? super U, InputHandler.
If the given |
| public static <T extends Event> InputMap | process(EventType<? extends T> eventType, Function<? super T, InputHandler.
When the given event type occurs, runs the given action, and then attempts
to pattern match the event type with the next |
| public static <E extends Event> InputMap | |
| public static <T extends Event> InputMap | unless(BooleanSupplier condition, InputMap<T> im)
When the given |
| public static <E extends Event> InputMap | |
| public static <T extends Event> InputMap | when(BooleanSupplier condition, InputMap<T> im)
When the given |
| public default InputMap |
| EMPTY | back to summary |
|---|---|
| public static final InputMap<?> EMPTY | |
| consume | back to summary |
|---|---|
| public static <T extends Event, U extends T> InputMap If the given | |
| consume | back to summary |
|---|---|
| public static <T extends Event> InputMap When the given event type occurs, runs the given action, consumes the event,
and does not attempt to match additional | |
| consume | back to summary |
|---|---|
| public static <T extends Event, U extends T> InputMap If the given | |
| consume | back to summary |
|---|---|
| public static <T extends Event> InputMap When the given event type occurs, consumes the event and does not attempt
to match additional | |
| consumeUnless | back to summary |
|---|---|
| public static <T extends Event, U extends T> InputMap If the given | |
| consumeUnless | back to summary |
|---|---|
| public static <T extends Event> InputMap When the given event type occurs and | |
| consumeWhen | back to summary |
|---|---|
| public static <T extends Event, U extends T> InputMap If the given | |
| consumeWhen | back to summary |
|---|---|
| public static <T extends Event> InputMap When the given event type occurs and | |
| empty | back to summary |
|---|---|
| public static <E extends Event> InputMap | |
| forEachEventType | back to summary |
|---|---|
| public void forEachEventType(InputMap. For each | |
| ifConsumed | back to summary |
|---|---|
| public default InputMap Executes some additional handler if the event was consumed (e.g. | |
| ifIgnored | back to summary |
|---|---|
| public default InputMap Executes some additional handler if the event was ignored (e.g. | |
| ifProcessed | back to summary |
|---|---|
| public default InputMap Executes some additional handler if the event was matched but not consumed
(e.g. | |
| ignore | back to summary |
|---|---|
| public static <T extends Event, U extends T> InputMap If the given | |
| ignore | back to summary |
|---|---|
| public static <T extends Event> InputMap When the given event type occurs, does nothing and does not attempt to match additional
| |
| orElse | back to summary |
|---|---|
| public default InputMap Shorthand for | |
| postResult | back to summary |
|---|---|
| public static <E extends Event> InputMap | |
| process | back to summary |
|---|---|
| public static <T extends Event, U extends T> InputMap If the given | |
| process | back to summary |
|---|---|
| public static <T extends Event> InputMap When the given event type occurs, runs the given action, and then attempts
to pattern match the event type with the next | |
| sequence | back to summary |
|---|---|
| public static <E extends Event> InputMap Creates a single InputMap that pattern matches a given event type against all the given input maps. This is often the InputMap installed on a given node since it contains all the other InputMaps.
| |
| unless | back to summary |
|---|---|
| public static <T extends Event> InputMap When the given | |
| upCast | back to summary |
|---|---|
| public static <E extends Event> InputMap | |
| when | back to summary |
|---|---|
| public static <T extends Event> InputMap When the given | |
| without | back to summary |
|---|---|
| public default InputMap Returns an InputMap that does nothing when | |
| Modifier and Type | Method and Description |
|---|---|
| public <F extends E> void |
| accept | back to summary |
|---|---|
| public <F extends E> void accept(EventType<? extends F> t, InputHandler<? super F> h) | |