@Retention(value=RUNTIME) @Target(value=FIELD) @Repeatable(value=SaveProperties.class) public @interface SavePropertyFrom
For example, take a widget class has a slider that controls the speed of something. In the old API, the widget
would have export its properties directly (which doesn't give descriptive names in the widget's context, and can
run into conflicts), or create new properties with the desired names and bind those to the properties of the slider.
This takes a lot of code and makes the class less readable; there is a lot of boilerplate. It is also not ideal,
because properties exported via Component.getSettings()
are also configurable through the property editor for
the widget, even if the author does not want them to be user-editable, or if they are already editable through the
controls in the widget; for example, the value of the slider changes when a user moves the slider - it does not need
to be editable another way.
// Bad API -- exposes properties to the user that should not be editable! class MyWidget implements Widget { private final Slider speedSlider = new Slider(); private final DoubleProperty speed = new SimpleDoubleProperty(this, "speed"); private final DoubleProperty minSpeed = new SimpleDoubleProperty(this, "minSpeed"); private final DoubleProperty maxSpeed = new SimpleDoubleProperty(this, "maxSpeed"); public MyWidget() { speedSlider.valueProperty().bindBidirectional(speed); speedSlider.minProperty().bindBidirectional(minSpeed); speedSlider.maxProperty().bindBidirectional(maxSpeed); }
Modifier and Type | Required Element and Description |
---|---|
java.lang.String |
propertyName
The name of the property to save.
|
Modifier and Type | Optional Element and Description |
---|---|
java.lang.String |
savedName
The name to save the property as.
|