JavaFX Utils

Shortcut

Component to help create shortcuts over Node objects.

To help Shortcut implementation and increase legibility it was created Keys class which is class that permits to collect Key objects. An Key object has 3 fields :

  • private final CommandKey[] commandKeys : secundary keys
  • private final KeyCode code : shortcut key
  • private final Consumer<KeyEvent> action : action to be executed

This 3 fields are setted on constructor and can be obtained via getter methods.

Constructors

public Shortcut(T node, Keys keys, boolean keepOldHandler, boolean receiveChildEvents)

  • node : Node in which will be mounted shortcuts.
  • keys : shortcuts.
  • keepOldHandler : indicates if old EventHandlers are to keep or discard.
  • receiveChildEvents : indicates if the shortcuts are to be triggered when focus is on child of node.

There are more constructors with different parameters, but all will internally call this first one.

Variations :

  • Constructors that don't receive boolean keepOldHandler this value will be assumed as true.
  • Constructors that don't receive boolean receiveChildEvents this value will be assumed as false.
  • Constructors that receive Collection<Pair<KeyCode, Runnable>> actions will instantiate Keys object with it.
  • Constructors that receive IComponent<T> component obtain Node object from component.getNode().
public Shortcut(T node, Keys keys, boolean keepOldHandler)
public Shortcut(T node, Keys keys)
public Shortcut(T node, Collection<Pair<KeyCode, Runnable>> actions, boolean keepOldHandler)
public Shortcut(T node, Collection<Pair<KeyCode, Runnable>> actions)
public Shortcut(IComponent<T> component, Keys keys, boolean keepOldHandler)
public Shortcut(IComponent<T> component, Keys keys)
public Shortcut(IComponent<T> component, Collection<Pair<KeyCode, Runnable>> actions, boolean keepOldHandler)
public Shortcut(IComponent<T> component, Collection<Pair<KeyCode, Runnable>> actions)

Usage

	Pane pane;
	Button button;

	Keys keys = new Keys();
	keys.add(KeyCode.DELETE, ()->pane.getChildren().remove(button));

	new Shortcut<>(button, keys).mount();
					

Links