Class NodeUtils
NodeUtils
class contains utility methods for working with JavaFX:
- transforming
IGeometry
s from/to different JavaFX coordinate systems (localToParent(Node, IGeometry)
,localToScene(Node, IGeometry)
,localToScene(Node, Point)
,parentToLocal(Node, IGeometry)
,sceneToLocal(Node, IGeometry)
) - determining the actual local-to-scene or scene-to-local transform for a
JavaFX
Node
(getLocalToSceneTx(Node)
,getSceneToLocalTx(Node)
) - perform picking of
Node
s at a specific position within the JavaFX scene graph (getNodesAt(Node, double, double)
)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Returnstrue
if the givenAffine
s are equal.static IGeometry
getGeometricOutline
(Node visual) static AffineTransform
getLocalToSceneTx
(Node node) Returns anAffineTransform
which represents the transformation matrix to transform geometries from the local coordinate system of the givenNode
into the coordinate system of theScene
.static Node
getNearestCommonAncestor
(Node source, Node target) Computes the nearest common ancestor for two given nodes.getNodesAt
(Node root, double sceneX, double sceneY) Performs picking on the scene graph beginning at the specified root node and processing its transitive children.static IGeometry
getResizedToShapeBounds
(Node visual, IGeometry geometry) Creates a copy of the givenIGeometry
and resizes it to fit the (corrected) layout-bounds (seegetShapeBounds(Node)
) of the givenNode
.static AffineTransform
getSceneToLocalTx
(Node node) Returns the scene-to-local transform for the givenNode
.static Rectangle
getShapeBounds
(Node node) Returns the layout-bounds of the givenNode
, which might be adjusted to ensure that it exactly fits the visualization.static IGeometry
getShapeOutline
(Node node) Creates a geometry whose outline represents the outline of the givenNode
, including its stroke.static boolean
static IGeometry
localToParent
(Node n, IGeometry g) static Point
localToParent
(Node n, Point p) static IGeometry
localToScene
(Node n, IGeometry g) static Point
localToScene
(Node n, Point p) static IGeometry
parentToLocal
(Node n, IGeometry g) static Point
parentToLocal
(Node n, Point p) static IGeometry
sceneToLocal
(Node n, IGeometry g) static Point
sceneToLocal
(Node n, Point p) static Affine
-
Constructor Details
-
NodeUtils
public NodeUtils()
-
-
Method Details
-
equals
- Parameters:
a1
- The first operand.a2
- The second operand.- Returns:
true
if the givenAffine
s are equal, otherwisefalse
.
-
getGeometricOutline
Returns anIGeometry
that corresponds whose outline represents the geometric outline of the givenNode
, excluding its stroke.The
IGeometry
is specified within the local coordinate system of the givenNode
.The following
Node
s are supported:- Parameters:
visual
- TheNode
of which the geometric outline is returned.- Returns:
- An
IGeometry
that corresponds to the geometric outline of the givenNode
. - Throws:
IllegalArgumentException
- if the givenNode
is not supported.
-
getLocalToSceneTx
Returns anAffineTransform
which represents the transformation matrix to transform geometries from the local coordinate system of the givenNode
into the coordinate system of theScene
.JavaFX
Node
provides a (lazily computed) local-to-scene-transform property which we could access to get that transform. Unfortunately, this property is not updated correctly, i.e. its value can differ from the actual local-to-scene-transform. Therefore, we compute the local-to-scene-transform for the given node here by concatenating the local-to-parent-transforms along the hierarchy.Note that in situations where you do not need the actual transform, but instead perform a transformation, you can use the
Node#localToScene(...)
methods on the node directly, because it does not make use of the local-to-scene-transform property, but uses localToParent() internally.- Parameters:
node
- The JavaFXNode
for which the local-to-scene transformation matrix is to be computed.- Returns:
- An
AffineTransform
representing the local-to-scene transformation matrix for the givenNode
.
-
getNearestCommonAncestor
Computes the nearest common ancestor for two given nodes.- Parameters:
source
- The first node.target
- The second node.- Returns:
- The nearest common ancestor in the scene graph.
-
getNodesAt
Performs picking on the scene graph beginning at the specified root node and processing its transitive children.- Parameters:
sceneX
- The x-coordinate of the position to pick nodes at, interpreted in scene coordinate space.sceneY
- The y-coordinate of the position to pick nodes at, interpreted in scene coordinate space.root
- The root node at which to start with picking- Returns:
- A list of
Node
s which contain the the given coordinate.
-
getResizedToShapeBounds
Creates a copy of the givenIGeometry
and resizes it to fit the (corrected) layout-bounds (seegetShapeBounds(Node)
) of the givenNode
. The new, resizedIGeometry
is returned. -
getSceneToLocalTx
Returns the scene-to-local transform for the givenNode
. -
getShapeBounds
Returns the layout-bounds of the givenNode
, which might be adjusted to ensure that it exactly fits the visualization. -
getShapeOutline
Creates a geometry whose outline represents the outline of the givenNode
, including its stroke.The
IGeometry
is specified within the local coordinate system of the givenNode
.- Parameters:
node
- The node to infer an outline geometry for.- Returns:
- An
IGeometry
from which the outline may be retrieved.
-
isNested
-
localToParent
-
localToParent
-
localToScene
-
localToScene
-
parentToLocal
-
parentToLocal
-
sceneToLocal
-
sceneToLocal
-
setAffine
-