public interface EventHandlerProperty extends ReadOnlyProperty<EventHandler<? super ActionDataEvent>>
EventHandler. Use one of
FXBeanInfo.Builder.action(java.lang.String, java.lang.Runnable) methods to create instance of the
property rather than implementing the interface manually.
The following example defines a class with three action methods and then uses their handle references to register them into the builder:
class CountingBean implementsFXBeanInfo.Provider { private int count; private void addAction(ActionEventev) { count += ((Number) ev.getSource()).intValue(); } private void incrementAction() { count++; } private void addTwiceAction(ActionDataEventev) { count += ev.getSource(Number.class).intValue(); count += ev.getProperty(Number.class, "any").intValue(); } private finalFXBeanInfoinfoWithActions =FXBeanInfo.newBuilder(this) .action("actionWithEvent", this::addAction) .action("actionWithoutParameters", this::incrementAction) .action("actionWithData", this::addTwiceAction) .build(); @OverridepublicFXBeanInfogetFXBeanInfo() { return infoWithActions; } }
The handler method may take no arguments, a single ActionEvent parameter
or a single ActionDataEvent parameter.
The registered methods are then accessible via FXBeanInfo.getActions()
map.
There is also a way to register the actions directly via properties. Here is an example:
class CountingBean implementsFXBeanInfo.Provider { private int count; finalEventHandlerPropertyincrementAction = newSimpleEventHandlerProperty(this, "actionWithoutParameters", (ev) -> { count++; }); finalEventHandlerPropertyaddAction = newSimpleEventHandlerProperty(this, "actionWithEvent", (ev) -> { count += ((Number) ev.getSource()).intValue(); }); finalEventHandlerPropertyaddTwiceAction = newSimpleEventHandlerProperty(this, "actionWithData", (ev) -> { count += ev.getSource(Number.class).intValue(); count += ev.getProperty(Number.class, "any").intValue(); }); private finalFXBeanInfoinfo =FXBeanInfo.newBuilder(this) .action(this.incrementAction) .action(this.addAction) .action(this.addTwiceAction) .build(); @OverridepublicFXBeanInfogetFXBeanInfo() { return info; } }
getBean, getNameaddListener, getValue, removeListeneraddListener, removeListenerCopyright © 2020. All rights reserved.