public class NodeUtil extends Object
Utility class that provides methods to simplify node handling. Possible use cases are searching for nodes at specific locations, adding/removing nodes to/from parents (Parent interface does not give write access to children).
Modifier and Type | Method and Description |
---|---|
static void |
addStyleClass(Node node,
String styleclass)
This method is used to prevent the remove-add constructs on styleclasses.
|
static void |
addToParent(Parent p,
Node n)
Adds the given node to the specified parent.
|
static String |
deriveCssFile(Node n)
Derive a CSS file in the same package and with the same name as the node
|
static Node |
getNode(Parent p,
double sceneX,
double sceneY,
Class<?> nodeClass)
Returns the first node at the given location that is an instance of the
specified class object.
|
static boolean |
isEffectivelyVisible(Node n)
Determine if a node is effectively visible.
|
static void |
removeFromParent(Node n)
Removes the specified node from its parent.
|
static void |
removeStyleClass(Node node,
String styleclass)
The remove operation is already "cheap", so this method is here to only mirror the addStyleClass (which is not cheap)
|
static double |
sceneX(Node node) |
static double |
sceneY(Node node) |
static double |
screenX(Node node) |
static double |
screenY(Node node) |
static double |
snapWH(double position,
double offset)
This method prevents blurry horizontal or vertical lines, use snapWH(x, w) instead of w.
|
static DoubleBinding |
snapWH(ObservableNumberValue position,
ObservableNumberValue offset,
Observable... dependencies)
This is the snapXY method for using in a binding, for example:
p1.bind( snapXY( p2.multiply(0.1) ));
|
static double |
snapXY(double position)
This method prevents blurry horizontal or vertical lines, use snapXY(x) instead of x.
|
static DoubleBinding |
snapXY(ObservableNumberValue position)
This is the snapXY method for using in a binding, for example:
p1.bind( snapXY( p2.multiply(0.1) ));
|
static double |
xInParent(Node node,
Node parent) |
static double |
yInParent(Node node,
Node parent) |
public static double xInParent(Node node, Node parent)
node
- public static double yInParent(Node node, Node parent)
node
- public static double screenX(Node node)
node
- public static double screenY(Node node)
node
- public static double sceneX(Node node)
node
- public static double sceneY(Node node)
node
- public static void removeFromParent(Node n)
Removes the specified node from its parent.
n
- the node to removeIllegalArgumentException
- if an unsupported parent class has been
specified or the parent is <code>null</code>public static void addToParent(Parent p, Node n)
Adds the given node to the specified parent.
p
- parentn
- nodeIllegalArgumentException
- if an unsupported parent class has been
specified or the parent is <code>null</code>public static Node getNode(Parent p, double sceneX, double sceneY, Class<?> nodeClass)
Returns the first node at the given location that is an instance of the specified class object. The search is performed recursively until either a node has been found or a leaf node is reached.
p
- parent nodesceneX
- x coordinatesceneY
- y coordinatenodeClass
- node class to search fornull
if no such node
existpublic static double snapXY(double position)
This method prevents blurry horizontal or vertical lines, use snapXY(x) instead of x.
position
- (x or y)public static DoubleBinding snapXY(ObservableNumberValue position)
This is the snapXY method for using in a binding, for example: p1.bind( snapXY( p2.multiply(0.1) ));
position
- (x or y)public static double snapWH(double position, double offset)
This method prevents blurry horizontal or vertical lines, use snapWH(x, w) instead of w.
position
- (x or y)offset
- (width or height)public static DoubleBinding snapWH(ObservableNumberValue position, ObservableNumberValue offset, Observable... dependencies)
This is the snapXY method for using in a binding, for example: p1.bind( snapXY( p2.multiply(0.1) ));
position
- (x or y)offset
- (width or height)dependencies
- public static void addStyleClass(Node node, String styleclass)
This method is used to prevent the remove-add constructs on styleclasses. This prevents CSS reprocessed unnecessary, because that is a time consuming process.
node
- styleclass
- public static void removeStyleClass(Node node, String styleclass)
The remove operation is already "cheap", so this method is here to only mirror the addStyleClass (which is not cheap)
node
- styleclass
- public static String deriveCssFile(Node n)
Derive a CSS file in the same package and with the same name as the node
n
- public static boolean isEffectivelyVisible(Node n)
Determine if a node is effectively visible. This means that if the node or any of its parents are not visible, the node is effectively not visible. Otherwise it is visible.
n
-