Class NodeUtil
java.lang.Object
jfxtras.util.NodeUtil
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).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddStyleClass(javafx.scene.Node node, String styleclass) This method is used to prevent the remove-add constructs on styleclasses.static voidaddToParent(javafx.scene.Parent p, javafx.scene.Node n) Adds the given node to the specified parent.static StringderiveCssFile(javafx.scene.Node n) Derive a CSS file in the same package and with the same name as the nodestatic javafx.scene.NodeReturns the first node at the given location that is an instance of the specified class object.static booleanisEffectivelyVisible(javafx.scene.Node n) Determine if a node is effectively visible.static voidremoveFromParent(javafx.scene.Node n) Removes the specified node from its parent.static voidremoveStyleClass(javafx.scene.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 doublesceneX(javafx.scene.Node node) static doublesceneY(javafx.scene.Node node) static doublescreenX(javafx.scene.Node node) static doublescreenY(javafx.scene.Node node) static doublesnapWH(double position, double offset) This method prevents blurry horizontal or vertical lines, use snapWH(x, w) instead of w.static javafx.beans.binding.DoubleBindingsnapWH(javafx.beans.value.ObservableNumberValue position, javafx.beans.value.ObservableNumberValue offset, javafx.beans.Observable... dependencies) This is the snapXY method for using in a binding, for example: p1.bind( snapXY( p2.multiply(0.1) ));static doublesnapXY(double position) This method prevents blurry horizontal or vertical lines, use snapXY(x) instead of x.static javafx.beans.binding.DoubleBindingsnapXY(javafx.beans.value.ObservableNumberValue position) This is the snapXY method for using in a binding, for example: p1.bind( snapXY( p2.multiply(0.1) ));static doublexInParent(javafx.scene.Node node, javafx.scene.Node parent) static doubleyInParent(javafx.scene.Node node, javafx.scene.Node parent)
-
Constructor Details
-
NodeUtil
private NodeUtil()
-
-
Method Details
-
xInParent
public static double xInParent(javafx.scene.Node node, javafx.scene.Node parent) - Parameters:
node-- Returns:
- The X coordinate of the node within the parent.
-
yInParent
public static double yInParent(javafx.scene.Node node, javafx.scene.Node parent) - Parameters:
node-- Returns:
- The Y coordinate of the node within the parent.
-
screenX
public static double screenX(javafx.scene.Node node) - Parameters:
node-- Returns:
- The X screen coordinate of the node.
-
screenY
public static double screenY(javafx.scene.Node node) - Parameters:
node-- Returns:
- The Y screen coordinate of the node.
-
sceneX
public static double sceneX(javafx.scene.Node node) - Parameters:
node-- Returns:
- The X scene coordinate of the node.
-
sceneY
public static double sceneY(javafx.scene.Node node) - Parameters:
node-- Returns:
- The Y scene coordinate of the node.
-
removeFromParent
public static void removeFromParent(javafx.scene.Node n) Removes the specified node from its parent.- Parameters:
n- the node to remove- Throws:
IllegalArgumentException- if an unsupported parent class has been specified or the parent isnull
-
addToParent
public static void addToParent(javafx.scene.Parent p, javafx.scene.Node n) Adds the given node to the specified parent.- Parameters:
p- parentn- node- Throws:
IllegalArgumentException- if an unsupported parent class has been specified or the parent isnull
-
getNode
public static javafx.scene.Node getNode(javafx.scene.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.- Parameters:
p- parent nodesceneX- x coordinatesceneY- y coordinatenodeClass- node class to search for- Returns:
- a node that contains the specified screen coordinates and is an
instance of the specified class or
nullif no such node exist
-
snapXY
public static double snapXY(double position) This method prevents blurry horizontal or vertical lines, use snapXY(x) instead of x.- Parameters:
position- (x or y)- Returns:
-
snapXY
public static javafx.beans.binding.DoubleBinding snapXY(javafx.beans.value.ObservableNumberValue position) This is the snapXY method for using in a binding, for example: p1.bind( snapXY( p2.multiply(0.1) ));- Parameters:
position- (x or y)- Returns:
-
snapWH
public static double snapWH(double position, double offset) This method prevents blurry horizontal or vertical lines, use snapWH(x, w) instead of w.- Parameters:
position- (x or y)offset- (width or height)- Returns:
-
snapWH
public static javafx.beans.binding.DoubleBinding snapWH(javafx.beans.value.ObservableNumberValue position, javafx.beans.value.ObservableNumberValue offset, javafx.beans.Observable... dependencies) This is the snapXY method for using in a binding, for example: p1.bind( snapXY( p2.multiply(0.1) ));- Parameters:
position- (x or y)offset- (width or height)dependencies-- Returns:
-
addStyleClass
This method is used to prevent the remove-add constructs on styleclasses. This prevents CSS reprocessed unnecessary, because that is a time consuming process.- Parameters:
node-styleclass-
-
removeStyleClass
The remove operation is already "cheap", so this method is here to only mirror the addStyleClass (which is not cheap)- Parameters:
node-styleclass-
-
deriveCssFile
Derive a CSS file in the same package and with the same name as the node- Parameters:
n-- Returns:
-
isEffectivelyVisible
public static boolean isEffectivelyVisible(javafx.scene.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.- Parameters:
n-- Returns:
-