com.vaadin.flow.component.
Class ShortcutRegistration
- java.lang.Object
-
- com.vaadin.flow.component.ShortcutRegistration
-
All Implemented Interfaces:
public class ShortcutRegistration extends Object implements Registration, Serializable
A registration object for both configuring and removing the registered keyboard shortcut.
Since:
1.3
Author:
Vaadin Ltd.
See Also:
-
-
Method Summary
All Methods Modifier and Type Method and Description ShortcutRegistration
allowBrowserDefault()
Allows the default keyboard event handling when the shortcut is invoked.
ShortcutRegistration
allowEventPropagation()
Allow the event to propagate upwards in the DOM tree, when the shortcut is invoked.
ShortcutRegistration
bindLifecycleTo(Component component)
Binds the shortcut's life cycle to that of the given
Component
.Key
getKey()
Get the primary
Key
of the shortcut.Component
getLifecycleOwner()
Component
which controls when the shortcut is active and when it is not.Set<Key>
getModifiers()
Get a set of
keys
where eachkey
is an instance of aKeyModifier
.Component
getOwner()
Deprecated.
This component has now multiple owners so this method has been replaced by #getOwners().Component[]
getOwners()
The
Component
s which own the shortcuts key event listeners.boolean
isBrowserDefaultAllowed()
Checks if the default key behaviour in the browser is allowed by the shortcut.
boolean
isEventPropagationAllowed()
Checks if the shortcut allows keydown event (associated with the shortcut) propagation in the browser.
boolean
isShortcutActive()
Is the shortcut active on the current UI.
ShortcutRegistration
listenOn(Component... listenOnComponents)
Fluently define the components to listen for shortcuts on.
ShortcutRegistration
listenOn(Component listenOnComponent)
Fluently define the component to listen for shortcuts on.
boolean
preventsDefault()
Deprecated.
Replaced byisBrowserDefaultAllowed()
in 1.4void
remove()
Removes the
ShortcutRegistration
void
setBrowserDefaultAllowed(boolean browserDefaultAllowed)
Set whether the default key behavior is allowed in the browser.
void
setEventPropagationAllowed(boolean eventPropagationAllowed)
Set whether shortcut's keydown event is allowed to propagate up the DOM tree in the browser.
boolean
stopsPropagation()
Deprecated.
Replaced byisEventPropagationAllowed()
in 1.4String
toString()
ShortcutRegistration
withAlt()
Fluently adds
KeyModifier.ALT
to the shortcut's modifiers.ShortcutRegistration
withCtrl()
Fluently adds
KeyModifier.CONTROL
to the shortcut's modifiers.ShortcutRegistration
withMeta()
Fluently adds
KeyModifier.META
to the shortcut's modifiers.ShortcutRegistration
withModifiers(KeyModifier... keyModifiers)
Configures
KeyModifiers
for the shortcut.ShortcutRegistration
withShift()
Fluently adds
KeyModifier.SHIFT
to the shortcut's modifiers.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.shared.Registration
addAndRemove, combine, once
-
-
-
-
Method Detail
-
withModifiers
public ShortcutRegistration withModifiers(KeyModifier... keyModifiers)
Configures
KeyModifiers
for the shortcut. Calling this method will overwrite any previously set modifier keys. Hence, callingshortcutRegistration.withModifiers();
will remove all previously set modifier keys.Parameters:
keyModifiers
- Key modifiers. Can be empty.Returns:
this
ShortcutRegistration
-
withAlt
public ShortcutRegistration withAlt()
Fluently adds
KeyModifier.ALT
to the shortcut's modifiers.Returns:
this
ShortcutRegistration
-
withCtrl
public ShortcutRegistration withCtrl()
Fluently adds
KeyModifier.CONTROL
to the shortcut's modifiers.Returns:
this
ShortcutRegistration
-
withMeta
public ShortcutRegistration withMeta()
Fluently adds
KeyModifier.META
to the shortcut's modifiers.Returns:
this
ShortcutRegistration
-
withShift
public ShortcutRegistration withShift()
Fluently adds
KeyModifier.SHIFT
to the shortcut's modifiers.Returns:
this
ShortcutRegistration
-
allowBrowserDefault
public ShortcutRegistration allowBrowserDefault()
Allows the default keyboard event handling when the shortcut is invoked.
Returns:
this
ShortcutRegistration
See Also:
-
allowEventPropagation
public ShortcutRegistration allowEventPropagation()
Allow the event to propagate upwards in the DOM tree, when the shortcut is invoked.
Returns:
this
ShortcutRegistration
See Also:
-
bindLifecycleTo
public ShortcutRegistration bindLifecycleTo(Component component)
Binds the shortcut's life cycle to that of the given
Component
. When the givencomponent
is attached, the shortcut's listener is attached to theComponent
that owns the shortcut. When the givencomponent
is detached, so is the listener. is detached, the shortcut is removed from all attached scopes.Parameters:
component
- New lifecycle owner of the shortcutReturns:
this
ShortcutRegistration
-
listenOn
public ShortcutRegistration listenOn(Component listenOnComponent)
Fluently define the component to listen for shortcuts on. Calling this method will remove any previous listeners.
This method only exists to retain backwards compatibility after support for listening on multiple components was added with the method
listenOn(Component...)
.Parameters:
listenOnComponent
- components to listen for the shortcut on. Must not be null.Returns:
this
ShortcutRegistration
-
listenOn
public ShortcutRegistration listenOn(Component... listenOnComponents)
Fluently define the components to listen for shortcuts on. Calling this method will remove any previous listeners.
Parameters:
listenOnComponents
-Component
s onto which the shortcut listeners are bound. Must not be null. Must not contain null. Must not have duplicate components.Returns:
this
ShortcutRegistration
-
remove
public void remove()
Removes the
ShortcutRegistration
Removes all the underlying registrations tied to owner and lifecycle owner
components
.Specified by:
remove
in interfaceRegistration
See Also:
-
isShortcutActive
public boolean isShortcutActive()
Is the shortcut active on the current UI. For this to be true, the lifecycle owner needs to be attached and visible and handler owner needs to be attached.
Returns:
Is the shortcut active
-
getKey
public Key getKey()
Get the primary
Key
of the shortcut. Primary key can be any key besides modifier keys.Returns:
Primary key
-
getModifiers
public Set<Key> getModifiers()
Get a set of
keys
where eachkey
is an instance of aKeyModifier
.Returns:
Set of modifier keys
-
preventsDefault
@Deprecated public boolean preventsDefault()
Deprecated. Replaced by
isBrowserDefaultAllowed()
in 1.4Is the shortcut preventing default key behaviour.
Returns:
Prevents default behavior
-
isBrowserDefaultAllowed
public boolean isBrowserDefaultAllowed()
Checks if the default key behaviour in the browser is allowed by the shortcut. The default value is
false
.Returns:
Allows default key behavior
-
setBrowserDefaultAllowed
public void setBrowserDefaultAllowed(boolean browserDefaultAllowed)
Set whether the default key behavior is allowed in the browser. The default value is
false
, and it prevents the default key events from taking place in the browser.Parameters:
browserDefaultAllowed
- Allow default behavior on keydown
-
stopsPropagation
@Deprecated public boolean stopsPropagation()
Deprecated. Replaced by
isEventPropagationAllowed()
in 1.4Is the shortcut stopping the keyboard event from propagating up the DOM tree.
Returns:
Stops propagation
-
isEventPropagationAllowed
public boolean isEventPropagationAllowed()
Checks if the shortcut allows keydown event (associated with the shortcut) propagation in the browser. The default value is
false
.Returns:
Allows event propagation
-
setEventPropagationAllowed
public void setEventPropagationAllowed(boolean eventPropagationAllowed)
Set whether shortcut's keydown event is allowed to propagate up the DOM tree in the browser. The default value is
false
, and the DOM event is consumed by the shortcut handler.Parameters:
eventPropagationAllowed
- Allow event propagation
-
getOwner
@Deprecated public Component getOwner()
Deprecated. This component has now multiple owners so this method has been replaced by #getOwners().
Component
which owns the first shortcuts key event listener.Returns:
Component
-
getOwners
public Component[] getOwners()
The
Component
s which own the shortcuts key event listeners.Returns:
Component[]
-
getLifecycleOwner
public Component getLifecycleOwner()
Component
which controls when the shortcut is active and when it is not.Returns:
Component
See Also:
-
-