public final class FXBeanInfo extends Object
actions of a JavaFX bean. Beans supporting this
protocol should implement FXBeanInfo.Provider - use its FXBeanInfo.Provider.getFXBeanInfo()
method to obtain instance of the info for given bean.
If you have a bean willing to provide the info, use FXBeanInfo.newBuilder(java.lang.Object)
and FXBeanInfo.Builder to create it. Then return it from your
FXBeanInfo.Provider.getFXBeanInfo() method. Here is an example defining
one string property and one action:
public class HTMLController implementsFXBeanInfo.Provider { private finalStringPropertylabelText = newSimpleStringProperty(this, "labelText", ""); private void handleButtonAction(ActionEventevent) {System.out.println("You clicked me!"); labelText.set("Hello World!"); } private finalFXBeanInfoinfo =FXBeanInfo.newBuilder(this) .action("action", this::handleButtonAction) .property(labelText) .build(); @OverridepublicFXBeanInfogetFXBeanInfo() { return info; } }
| Modifier and Type | Class and Description |
|---|---|
class |
FXBeanInfo.Builder
Builder (obtained via
FXBeanInfo.newBuilder(java.lang.Object) method) to
create a description of a JavaFX bean and represent it as
FXBeanInfo. |
static interface |
FXBeanInfo.Generate
|
static interface |
FXBeanInfo.Provider
Single method interface for JavaFX beans that can provide
FXBeanInfo. |
| Modifier and Type | Method and Description |
|---|---|
Map<String,EventHandlerProperty> |
getActions()
EventHandler properties for this bean. |
Object |
getBean()
The associated bean.
|
Map<String,ObservableValue<?>> |
getProperties()
Properties of this bean.
|
<T> T |
lookup(Class<T> type)
Extra information associated with this bean info.
|
static FXBeanInfo.Builder |
newBuilder(Object bean)
Start creating new
FXBeanInfo for provided bean. |
public Object getBean()
was created forpublic Map<String,ObservableValue<?>> getProperties()
Bindings:
class Multiply implementsFXBeanInfo.Provider { finalIntegerPropertya = newSimpleIntegerProperty(this, "a", 0); finalIntegerPropertyb = newSimpleIntegerProperty(this, "b", 0); /** function to multiply two properties */ int mul() { return a.get() * b.get(); } /** property that depends on a and b and uses {@link #mul()} */ finalIntegerBindingmul =Bindings.createIntegerBinding(this::mul, a, b); finalFXBeanInfoinfo =FXBeanInfo.newBuilder(this). property(a). property(b). property("mul", mul). property("add",Bindings.createIntegerBinding( // defining derived property as lamda function () -> a.get() + b.get(), a, b )). build(); @OverridepublicFXBeanInfogetFXBeanInfo() { return info; } } Multiply m = new Multiply(); m.a.set(13); m.b.set(7); finalFXBeanInfomInfo = m.getFXBeanInfo();ObservableValue<?> add = mInfo.getProperties().get("add");ObservableValue<?> mul = mInfo.getProperties().get("mul"); assertEquals(20, add.getValue()); assertEquals(91, mul.getValue());
public Map<String,EventHandlerProperty> getActions()
EventHandler properties for this bean.
Use following code to invoke them:
private static void dispatchEvent(FXBeanInfo.Provider bean,Stringname) { finalFXBeanInfoinfo = bean.getFXBeanInfo(); finalMap<String,EventHandlerProperty> actions = info.getActions();EventHandlerPropertyproperty = actions.get(name); finalEventHandler<? superActionDataEvent> handler = property.getValue(); handler.handle(newActionDataEvent(bean, 7, 13)); }
event handlersActionDataEventpublic <T> T lookup(Class<T> type)
T - type of the informationtype - class describing the requested typeFXBeanInfoProviderpublic static FXBeanInfo.Builder newBuilder(Object bean)
FXBeanInfo for provided bean.
Use FXBeanInfo.Builder methods like FXBeanInfo.Builder.property(javafx.beans.property.ReadOnlyProperty)
or FXBeanInfo.Builder.action(javafx.beans.property.ReadOnlyProperty) followed
by final FXBeanInfo.Builder.build() to create the info.bean - the bean to create the info forCopyright © 2020. All rights reserved.