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 finalStringProperty
labelText = newSimpleStringProperty
(this, "labelText", ""); private void handleButtonAction(ActionEvent
event) {System
.out.println("You clicked me!"); labelText.set("Hello World!"); } private finalFXBeanInfo
info =FXBeanInfo
.newBuilder(this) .action("action", this::handleButtonAction) .property(labelText) .build(); @Override
publicFXBeanInfo
getFXBeanInfo() { 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 { finalIntegerProperty
a = newSimpleIntegerProperty
(this, "a", 0); finalIntegerProperty
b = 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()} */ finalIntegerBinding
mul =Bindings
.createIntegerBinding(this::mul, a, b); finalFXBeanInfo
info =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(); @Override
publicFXBeanInfo
getFXBeanInfo() { return info; } } Multiply m = new Multiply(); m.a.set(13); m.b.set(7); finalFXBeanInfo
mInfo = 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,String
name) { finalFXBeanInfo
info = bean.getFXBeanInfo(); finalMap
<String
,EventHandlerProperty
> actions = info.getActions();EventHandlerProperty
property = actions.get(name); finalEventHandler
<? superActionDataEvent
> handler = property.getValue(); handler.handle(newActionDataEvent
(bean, 7, 13)); }
event handlers
ActionDataEvent
public <T> T lookup(Class<T> type)
T
- type of the informationtype
- class describing the requested typeFXBeanInfoProvider
public 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.