Component to help create option menus over Control objects.
If you pretend to create an option menu over a Node object you have Menu component, which creates ContextMenu on mouse left click and adds it to node.
MultiOption class is generic in T extends Control.
To help MultiOption implementation and increase legibility it was created Operations class which is class that permits to collect Operation objects. An Operation object has 2 fields :
private final String name : name to be displayed on menuprivate final Runnable action : action to be executedpublic MultiOption(T control, Operations operations)
There are more constructors with different parameters, but all will internally call this first one.
Variations :
Collection<Pair<String, Runnable>> actions will instantiate Operations object with it.IComponent<T> component obtain Control object from component.getNode().public MultiOption(T control, Collection<Pair<String, Runnable>> actions)
public MultiOption(IComponent<T> component, Operations operations)
public MultiOption(IComponent<T> component, Collection<Pair<String, Runnable>> actions)
Button button;
Operations ops = new Operations();
ops.add("A", ()->button.setGraphic(A_IMAGE));
ops.add("B", ()->button.setGraphic(B_IMAGE));
ops.add("C", ()->button.setGraphic(C_IMAGE));
ops.add("D", ()->button.setGraphic(D_IMAGE));
new MultiOption<>(button, ops).mount();