/** * Allows the default keyboard event handling when the shortcut is invoked. * @return this <code>ShortcutRegistration</code> */ public ShortcutRegistration allowBrowserDefault() { if (preventDefault) { preventDefault = false; prepareForClientResponse(); } return this; }
/** * Allow the event to propagate upwards in the dom tree, when the * shortcut is invoked. * @return this <code>ShortcutRegistration</code> */ public ShortcutRegistration allowEventPropagation() { if (stopPropagation) { stopPropagation = false; prepareForClientResponse(); } return this; }
private void addKey(Key key) { assert key != null; HashableKey hashableKey = new HashableKey(key); if (Key.isModifier(key)) { if (!modifiers.contains(hashableKey)) { modifiers.add(hashableKey); prepareForClientResponse(); } } else { if (primaryKey == null || !primaryKey.equals(hashableKey)) { primaryKey = hashableKey; prepareForClientResponse(); } } }
/** * Fluently define the {@link Component} onto which the shortcut's listener * is bound. Calling this method will remove the previous listener from the * {@code component} it was bound to. * * @param listenOnComponent {@code Component} onto which the shortcut * listener is bound. * @return this <code>ShortcutRegistration</code> */ public ShortcutRegistration listenOn(Component listenOnComponent) { removeAllListenerRegistrations(); this.listenOnSupplier = () -> listenOnComponent; prepareForClientResponse(); return this; }
/** * Configures {@link KeyModifier KeyModifiers} for the shortcut. * Calling this method will overwrite any previously set modifier keys. * Hence, calling {@code shortcutRegistration.withModifiers();} will remove * all previously set modifier keys. * * @param keyModifiers Key modifiers. Can be empty. * @return this <code>ShortcutRegistration</code> */ public ShortcutRegistration withModifiers(KeyModifier... keyModifiers) { this.modifiers.clear(); prepareForClientResponse(); for (KeyModifier keyModifier : keyModifiers) { addKey(keyModifier); } return this; }