public class DecorationUtils
extends java.lang.Object
DecorationUtils provides a few convenient ways to install (and uninstall) decorators to a target node.
You can install multiple decorators to the same node, which can be achieved by calling install several times or installAll with all the decorators. However if you only call install or installAll methods, the decorations won't show up yet. The other part of the story is to use DecorationPane as the targetNode?s ancestor. It doesn't have to be the immediate ancestor. It will work as long as the DecorationPane is one of its ancestors. You can create a form with a bunch of nodes, fields, comboboxes, tables, lists, whatever you want, call DecorationUtils.install to add decoration to some of them, then wrap the whole form in the DecorationPane at the end. See below for a sample code.
// create nodes and add it to a pane
Pane pane = new Xxxx ();
pane.getChildren().addAll(?);
return new DecorationPane(pane); // instead of return pane, you wrap it
into
a DecorationPane
It is the DecorationPane which will search for all the decorators installed on its children (more precisely, descendants) and placed them at the position as specified in the Decorator interface.
Please note, JavaFX only allows a Node to be added to the same Scene just once. The decoration is a Node as well so it cannot be reused to decorate several target Nodes. If you want to use the same decoration several times, please use a factory pattern like this.
Supplier<Decorator> asteriskFactory = new Supplier<Decorator>() {
public Decorator get() {
Label label = new Label("*", asteriskImage);
return new Decorator(label, Pos.TOP_RIGHT);
}
};
// you can use it's create method to create multiple same decorators and use
them on different Nodes.
DecorationUtils.install(nameField, asteriskFactory.get());
DecorationUtils.install(emailField, asteriskFactory.get());
| Constructor and Description |
|---|
DecorationUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Object |
getDecorators(javafx.scene.Node targetNode)
Gets the decorators.
|
static boolean |
hasDecorators(javafx.scene.Node targetNode)
Checks if the node has decorator(s) installed.
|
static void |
install(javafx.scene.Node targetNode,
Decorator decorator)
Installs a
Decorator to a target Node. |
static void |
installAll(java.util.List<javafx.scene.Node> targetNodes,
java.util.function.Supplier<Decorator> decoratorFactory)
Installs a same
Decorator to many target Nodes. |
static void |
installAll(javafx.scene.Node targetNode,
Decorator... decorators)
Installs some
Decorators to a target Node. |
static boolean |
isAnimationPlayed(javafx.scene.Node decorateNode)
To determine if the animation on a decorator has been played.
|
static void |
setAnimationPlayed(javafx.scene.Node decorateNode,
boolean played)
Set the status of playing of the animation on a decorator.
|
static void |
setTargetDecoratorCleaned(javafx.scene.Node targetNode,
boolean clean)
Set the status of decorators on a node.
|
static void |
uninstall(javafx.scene.Node targetNode)
Uninstalls all decorators from the target Node.
|
static void |
uninstall(javafx.scene.Node targetNode,
Decorator decorator)
Uninstalls a decorator from the target Node.
|
public static void install(javafx.scene.Node targetNode,
Decorator decorator)
Decorator to a target Node.targetNode - the target Node where the Decorator will be installed.decorator - a Decoratorpublic static void installAll(javafx.scene.Node targetNode,
Decorator... decorators)
Decorators to a target Node.targetNode - the target Node where the Decorators will be installed.decorators - Decorators that will be installed.public static void installAll(java.util.List<javafx.scene.Node> targetNodes,
java.util.function.Supplier<Decorator> decoratorFactory)
Decorator to many target Nodes. Because each Decorator instance can only be
installed to one Node, that's why we use a Factory here so that for each target Node, a new Decorator
will be created.targetNodes - the target Nodes where the Decorator will be installed.decoratorFactory - a Factory that will create a new Decorator for each target Node.public static boolean hasDecorators(javafx.scene.Node targetNode)
targetNode - the target Node.public static java.lang.Object getDecorators(javafx.scene.Node targetNode)
targetNode - the target Node.public static void uninstall(javafx.scene.Node targetNode)
targetNode - the target Node.public static void uninstall(javafx.scene.Node targetNode,
Decorator decorator)
targetNode - the target Node.decorator - the decorator to be uninstalled.public static void setTargetDecoratorCleaned(javafx.scene.Node targetNode,
boolean clean)
targetNode - the node which has decorators.clean - true, set the status to be status of cleaned. false, clear the status.public static boolean isAnimationPlayed(javafx.scene.Node decorateNode)
decorateNode - the decorate node related with an animation.setAnimationPlayed(javafx.scene.Node, boolean)public static void setAnimationPlayed(javafx.scene.Node decorateNode,
boolean played)
decorateNode - the decorate node related with an animation.played - the status to be set.isAnimationPlayed(javafx.scene.Node)