Top Description Fields Constructors Methods
jfx.incubator.scene.control.input

public final Class InputMap

extends Object
Class Inheritance
Imports
java.util.HashMap, .HashSet, .Iterator, .Map, .Objects, .Set, java.util.function.BooleanSupplier, javafx.event.Event, .EventHandler, .EventType, javafx.scene.control.Control, javafx.scene.input.KeyEvent, com.sun.javafx.ModuleUtil, com.sun.jfx.incubator.scene.control.input.EventHandlerPriority, .InputMapHelper, .KeyEventMapper, .PHList, .SkinInputMap

InputMap is a property of the 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:

For key mappings, the 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

Field Summary

Modifier and TypeField and Description
private final Control
private final EventHandler<Event>
private final KeyEventMapper
private final HashMap<Object, Object>
map

 KeyBinding -> FunctionTag or Runnable
FunctionTag -> Runnable
EventType -> PHList
private static final Object
private SkinInputMap

Constructor Summary

AccessConstructor and Description
public
InputMap(Control
the owner control
control
)

The constructor.

Method Summary

Modifier and TypeMethod and Description
public <
the actual event type
T extends Event
>
void
addHandler(EventType<T>
the event type
type
,
EventHandler<T>
the event handler
handler
)

Adds an event handler for the specified event type.

private Set<KeyBinding>
public void
disableKeyBinding(KeyBinding
the key binding
k
)

Disables the specified key binding.

private boolean
pack-priv boolean
execute(Object source, FunctionTag tag)

pack-priv boolean
private <T extends Event> void
public Set<KeyBinding>

Returns:

the set of key bindings
getKeyBindings
()

Collects all mapped key bindings.

public Set<KeyBinding>

Returns:

the set of KeyBindings, non-null
getKeyBindingsFor
(FunctionTag
the function tag
tag
)

Returns the set of key bindings mapped to the specified function tag.

private void
private void
private static void
public void
register(KeyBinding
the key binding
k
,
Runnable
the function
function
)

Registers a function for the given key binding.

public void
registerFunction(FunctionTag
the function tag
tag
,
Runnable
the function
function
)

Adds (or overrides) a user-specified function under the given function tag.

public void
registerKey(KeyBinding
the key binding
k
,
FunctionTag
the function tag
tag
)

Link a key binding to the specified function tag.

public <
the event class
T extends Event
>
void
removeHandler(EventType<T>
the event type
type
,
EventHandler<T>
the handler to remove
handler
)

Removes the specified handler.

private <T extends Event> void
public void
removeKeyBindingsFor(FunctionTag
the function tag
tag
)

Removes all the key bindings mapped to the specified function tag, either by the application or by the skin.

public void
resetKeyBindings()

Reverts all the key bindings set by user.

private Object
public void
restoreDefaultFunction(FunctionTag
the function tag
tag
)

Restores the specified function tag to the value set by the skin, if any.

public void
restoreDefaultKeyBinding(KeyBinding
the key binding
k
)

Restores the specified key binding to the value set by the skin, if any.

private void
setSkinInputMap(SkinInputMap
the skin input map
m
)

Sets the skin input map, adding necessary event handlers to the control instance when required.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

controlback to summary
private final Control control
eventHandlerback to summary
private final EventHandler<Event> eventHandler
kmapperback to summary
private final KeyEventMapper kmapper
mapback to summary
private final HashMap<Object, Object> map
 KeyBinding -> FunctionTag or Runnable
FunctionTag -> Runnable
EventType -> PHList
NULLback to summary
private static final Object NULL
skinInputMapback to summary
private SkinInputMap skinInputMap

Constructor Detail

InputMapback to summary
public InputMap(Control control)

The constructor.

Parameters
control:Control

the owner control

Method Detail

addHandlerback to summary
public <T extends Event> void addHandler(EventType<T> type, EventHandler<T> handler)

Adds an event handler for the specified event type. Event handlers added with this method will always be called before any handlers registered by the skin.

Parameters
<T>
the actual event type
type:EventType<T>

the event type

handler:EventHandler<T>

the event handler

collectKeyBindingsback to summary
private Set<KeyBinding> collectKeyBindings(FunctionTag tag)
disableKeyBindingback to summary
public void disableKeyBinding(KeyBinding k)

Disables the specified key binding. Calling this method will disable any mappings made with register(KeyBinding, Runnable), registerKey(KeyBinding, FunctionTag), or registered by the skin.

Parameters
k:KeyBinding

the key binding

executeback to summary
private boolean execute(Object source, KeyBinding k)
executeback to summary
pack-priv boolean execute(Object source, FunctionTag tag)
executeDefaultback to summary
pack-priv boolean executeDefault(Object source, FunctionTag tag)
extendHandlerback to summary
private <T extends Event> void extendHandler(EventType<T> t, EventHandler<T> handler, EventHandlerPriority pri)
getKeyBindingsback to summary
public Set<KeyBinding> getKeyBindings()

Collects all mapped key bindings.

Returns:Set<KeyBinding>

the set of key bindings

getKeyBindingsForback to summary
public Set<KeyBinding> getKeyBindingsFor(FunctionTag tag)

Returns the set of key bindings mapped to the specified function tag.

Parameters
tag:FunctionTag

the function tag

Returns:Set<KeyBinding>

the set of KeyBindings, non-null

handleEventback to summary
private void handleEvent(Event ev)
handleKeyBindingEventback to summary
private void handleKeyBindingEvent(Event ev)
initAccessorback to summary
private static void initAccessor()
registerback to summary
public void register(KeyBinding k, Runnable function)

Registers a function for the given key binding. This mapping will take precedence over the default mapping set by the skin.

Parameters
k:KeyBinding

the key binding

function:Runnable

the function

registerFunctionback to summary
public void registerFunction(FunctionTag tag, Runnable function)

Adds (or overrides) a user-specified function under the given function tag. This function will take precedence over any default function set by the skin.

Parameters
tag:FunctionTag

the function tag

function:Runnable

the function

registerKeyback to summary
public void registerKey(KeyBinding k, FunctionTag tag)

Link a key binding to the specified function tag. When the key binding matches the input event, the function is executed, the event is consumed, and the process of dispatching is stopped.

This method will take precedence over any default function set by the skin.

Parameters
k:KeyBinding

the key binding

tag:FunctionTag

the function tag

removeHandlerback to summary
public <T extends Event> void removeHandler(EventType<T> type, EventHandler<T> handler)

Removes the specified handler.

Parameters
<T>
the event class
type:EventType<T>

the event type

handler:EventHandler<T>

the handler to remove

removeHandlerback to summary
private <T extends Event> void removeHandler(EventType<T> type, EventHandlerPriority pri)
removeKeyBindingsForback to summary
public void removeKeyBindingsFor(FunctionTag tag)

Removes all the key bindings mapped to the specified function tag, either by the application or by the skin. This is an irreversible operation.

Parameters
tag:FunctionTag

the function tag

resetKeyBindingsback to summary
public void resetKeyBindings()

Reverts all the key bindings set by user. This method restores key bindings set by the skin which were overwritten by the user.

resolveback to summary
private Object resolve(KeyBinding k)
restoreDefaultFunctionback to summary
public void restoreDefaultFunction(FunctionTag tag)

Restores the specified function tag to the value set by the skin, if any.

Parameters
tag:FunctionTag

the function tag

restoreDefaultKeyBindingback to summary
public void restoreDefaultKeyBinding(KeyBinding k)

Restores the specified key binding to the value set by the skin, if any.

Parameters
k:KeyBinding

the key binding

setSkinInputMapback to summary
private void setSkinInputMap(SkinInputMap m)

Sets the skin input map, adding necessary event handlers to the control instance when required. This method must be called by the skin only from its Skin.install() method.

This method removes all the mappings from the previous skin input map, if any.

Parameters
m:SkinInputMap

the skin input map