Class InputMap
public final class InputMap extends Object
Control class which enables customization by allowing creation of custom key mappings and event handlers. The InputMap serves as a bridge between the Control and its Skin. The InputMap provides an ordered repository of event handlers, working together with the input map managed by the skin, which guarantees the order in which handlers are invoked. It also stores key mappings with a similar guarantee that the application mappings always take precedence over mappings created by the skin, regardless of when the skin was created or replaced.
The class supports the following scenarios:
- Mapping a key binding to a function
- Removing a key binding
- Mapping a new function to an existing key binding
- Retrieving the default function
- Ensuring that the application key mappings take priority over mappings created by the skin
InputMap utilizes a two-stage lookup. First, the key event is matched to a FunctionTag which identifies a function provided either by the skin or the associated behavior (the "default" function), or by the application. When such a mapping exists, the found function tag is matched to a function registered either by the application or by the skin. Additionally, the register(KeyBinding, Runnable) method allows mapping to a function directly, bypassing the function tag.
This mechanism allows for customizing the key mappings and the underlying functions independently and separately.
- Since:
- 24
Constructor Summary
| Constructor | Description |
|---|---|
InputMap |
The constructor. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
<T extends Event> |
addHandler |
Adds an event handler for the specified event type. |
void |
disableKeyBinding |
Disables the specified key binding. |
Set |
getKeyBindings() |
Collects all mapped key bindings. |
Set |
getKeyBindingsFor |
Returns the set of key bindings mapped to the specified function tag. |
void |
register |
Registers a function for the given key binding. |
void |
registerFunction |
Adds (or overrides) a user-specified function under the given function tag. |
void |
registerKey |
Link a key binding to the specified function tag. |
<T extends Event> |
removeHandler |
Removes the specified handler. |
void |
removeKeyBindingsFor |
Removes all the key bindings mapped to the specified function tag, either by the application or by the skin. |
void |
resetKeyBindings() |
Reverts all the key bindings set by user. |
void |
restoreDefaultFunction |
Restores the specified function tag to the value set by the skin, if any. |
void |
restoreDefaultKeyBinding |
Restores the specified key binding to the value set by the skin, if any. |
Constructor Details
InputMap
public InputMap(Control control)
- Parameters:
-
control- the owner control
Method Details
addHandler
public <T extends Event> void addHandler(EventType<T> type, EventHandler<T> handler)
- Type Parameters:
-
T- the actual event type - Parameters:
-
type- the event type -
handler- the event handler
removeHandler
public <T extends Event> void removeHandler(EventType<T> type, EventHandler<T> handler)
- Type Parameters:
-
T- the event class - Parameters:
-
type- the event type -
handler- the handler to remove
register
public void register(KeyBinding k, Runnable function)
- Parameters:
-
k- the key binding -
function- the function
registerFunction
public void registerFunction(FunctionTag tag, Runnable function)
- Parameters:
-
tag- the function tag -
function- the function
registerKey
public void registerKey(KeyBinding k, FunctionTag tag)
This method will take precedence over any default function set by the skin.
- Parameters:
-
k- the key binding -
tag- the function tag
disableKeyBinding
public void disableKeyBinding(KeyBinding k)
register(KeyBinding, Runnable), registerKey(KeyBinding, FunctionTag), or registered by the skin.- Parameters:
-
k- the key binding
resetKeyBindings
public void resetKeyBindings()
restoreDefaultKeyBinding
public void restoreDefaultKeyBinding(KeyBinding k)
- Parameters:
-
k- the key binding
restoreDefaultFunction
public void restoreDefaultFunction(FunctionTag tag)
- Parameters:
-
tag- the function tag
getKeyBindings
public Set<KeyBinding> getKeyBindings()
- Returns:
- the set of key bindings
getKeyBindingsFor
public Set<KeyBinding> getKeyBindingsFor(FunctionTag tag)
- Parameters:
-
tag- the function tag - Returns:
- the set of KeyBindings, non-null
removeKeyBindingsFor
public void removeKeyBindingsFor(FunctionTag tag)
- Parameters:
-
tag- the function tag
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.