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(ActionEvent
ev) { count += ((Number
) ev.getSource()).intValue(); } private void incrementAction() { count++; } private void addTwiceAction(ActionDataEvent
ev) { count += ev.getSource(Number
.class).intValue(); count += ev.getProperty(Number
.class, "any").intValue(); } private finalFXBeanInfo
infoWithActions =FXBeanInfo
.newBuilder(this) .action("actionWithEvent", this::addAction) .action("actionWithoutParameters", this::incrementAction) .action("actionWithData", this::addTwiceAction) .build(); @Override
publicFXBeanInfo
getFXBeanInfo() { 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; finalEventHandlerProperty
incrementAction = newSimpleEventHandlerProperty
(this, "actionWithoutParameters", (ev) -> { count++; }); finalEventHandlerProperty
addAction = newSimpleEventHandlerProperty
(this, "actionWithEvent", (ev) -> { count += ((Number
) ev.getSource()).intValue(); }); finalEventHandlerProperty
addTwiceAction = newSimpleEventHandlerProperty
(this, "actionWithData", (ev) -> { count += ev.getSource(Number
.class).intValue(); count += ev.getProperty(Number
.class, "any").intValue(); }); private finalFXBeanInfo
info =FXBeanInfo
.newBuilder(this) .action(this.incrementAction) .action(this.addAction) .action(this.addTwiceAction) .build(); @Override
publicFXBeanInfo
getFXBeanInfo() { return info; } }
getBean, getName
addListener, getValue, removeListener
addListener, removeListener
Copyright © 2020. All rights reserved.