public class NodeUtils
extends java.lang.Object
NodeUtils
class contains utility methods for working with JavaFX:
IGeometry
s from/to different JavaFX coordinate
systems (localToParent(Node, IGeometry)
,
localToScene(Node, IGeometry)
, localToScene(Node, Point)
,
parentToLocal(Node, IGeometry)
,
sceneToLocal(Node, IGeometry)
)Node
(getLocalToSceneTx(Node)
,
getSceneToLocalTx(Node)
)Node
s at a specific position within the JavaFX
scene graph (getNodesAt(Node, double, double)
)Constructor and Description |
---|
NodeUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
equals(javafx.scene.transform.Affine a1,
javafx.scene.transform.Affine a2)
Returns
true if the given Affine s are equal. |
static IGeometry |
getGeometricOutline(javafx.scene.Node visual)
Returns an
IGeometry that corresponds whose outline represents
the geometric outline of the given Node , excluding its stroke. |
static AffineTransform |
getLocalToSceneTx(javafx.scene.Node node)
Returns an
AffineTransform which represents the transformation
matrix to transform geometries from the local coordinate system of the
given Node into the coordinate system of the Scene . |
static javafx.scene.Node |
getNearestCommonAncestor(javafx.scene.Node source,
javafx.scene.Node target)
Computes the nearest common ancestor for two given nodes.
|
static java.util.List<javafx.scene.Node> |
getNodesAt(javafx.scene.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(javafx.scene.Node visual,
IGeometry geometry)
Creates a copy of the given
IGeometry and resizes it to fit the
(corrected) layout-bounds (see getShapeBounds(Node) ) of the
given Node . |
static AffineTransform |
getSceneToLocalTx(javafx.scene.Node node)
Returns the scene-to-local transform for the given
Node . |
static Rectangle |
getShapeBounds(javafx.scene.Node node)
Returns the layout-bounds of the given
Node , which might be
adjusted to ensure that it exactly fits the visualization. |
static IGeometry |
getShapeOutline(javafx.scene.Node node)
Creates a geometry whose outline represents the outline of the given
Node , including its stroke. |
static IGeometry |
localToParent(javafx.scene.Node n,
IGeometry g)
Transforms the given
IGeometry from the local coordinate system
of the given Node into the coordinate system of the Node
's parent. |
static Point |
localToParent(javafx.scene.Node n,
Point p)
Transforms the given
Point from the local coordinate system of
the given Node into the coordinate system of the Node 's
parent. |
static IGeometry |
localToScene(javafx.scene.Node n,
IGeometry g)
Transforms the given
IGeometry from the local coordinate system
of the given Node into scene coordinates. |
static Point |
localToScene(javafx.scene.Node n,
Point p)
Transforms the given
Point from the local coordinate system of
the given Node into scene coordinates. |
static IGeometry |
parentToLocal(javafx.scene.Node n,
IGeometry g)
Transforms the given
IGeometry from the parent coordinate system
of the given Node into the local coordinate system of the
Node . |
static Point |
parentToLocal(javafx.scene.Node n,
Point p)
Transforms the given
Point from the parent coordinate system of
the given Node into the local coordinate system of the
Node . |
static IGeometry |
sceneToLocal(javafx.scene.Node n,
IGeometry g)
Transforms the given
IGeometry from scene coordinates to the
local coordinate system of the given Node . |
static Point |
sceneToLocal(javafx.scene.Node n,
Point p)
Transforms the given
Point from scene coordinates to the local
coordinate system of the given Node . |
static javafx.scene.transform.Affine |
setAffine(javafx.scene.transform.Affine dst,
javafx.scene.transform.Affine src)
Assigns the transformation values of the src
Affine to the
dst Affine . |
public static boolean equals(javafx.scene.transform.Affine a1, javafx.scene.transform.Affine a2)
true
if the given Affine
s are equal.
Otherwise returns false
.a1
- The first operand.a2
- The second operand.true
if the given Affine
s are equal,
otherwise false
.public static IGeometry getGeometricOutline(javafx.scene.Node visual)
IGeometry
that corresponds whose outline represents
the geometric outline of the given Node
, excluding its stroke.
The IGeometry
is specified within the local coordinate system of
the given Node
.
The following Node
s are supported:
Connection
GeometryNode
Arc
Circle
CubicCurve
Ellipse
Line
Path
Polygon
Polyline
QuadCurve
Rectangle
visual
- The Node
of which the geometric outline is returned.IGeometry
that corresponds to the geometric outline of
the given Node
.java.lang.IllegalArgumentException
- if the given Node
is not supported.public static AffineTransform getLocalToSceneTx(javafx.scene.Node node)
AffineTransform
which represents the transformation
matrix to transform geometries from the local coordinate system of the
given Node
into the coordinate system of the Scene
.
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.
node
- The JavaFX Node
for which the local-to-scene
transformation matrix is to be computed.AffineTransform
representing the local-to-scene
transformation matrix for the given Node
.public static javafx.scene.Node getNearestCommonAncestor(javafx.scene.Node source, javafx.scene.Node target)
source
- The first node.target
- The second node.public static java.util.List<javafx.scene.Node> getNodesAt(javafx.scene.Node root, double sceneX, double sceneY)
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 pickingNode
s which contain the the given coordinate.public static IGeometry getResizedToShapeBounds(javafx.scene.Node visual, IGeometry geometry)
IGeometry
and resizes it to fit the
(corrected) layout-bounds (see getShapeBounds(Node)
) of the
given Node
. The new, resized IGeometry
is returned.public static AffineTransform getSceneToLocalTx(javafx.scene.Node node)
Node
.node
- The Node
for which the scene-to-local transform is
returned.Node
.public static Rectangle getShapeBounds(javafx.scene.Node node)
Node
, which might be
adjusted to ensure that it exactly fits the visualization.node
- The Node
to retrieve the (corrected) layout-bounds of.Rectangle
representing the (corrected) layout-bounds.public static IGeometry getShapeOutline(javafx.scene.Node node)
Node
, including its stroke.
The IGeometry
is specified within the local coordinate system of
the given Node
.
node
- The node to infer an outline geometry for.IGeometry
from which the outline may be retrieved.public static IGeometry localToParent(javafx.scene.Node n, IGeometry g)
IGeometry
from the local coordinate system
of the given Node
into the coordinate system of the Node
's parent.public static Point localToParent(javafx.scene.Node n, Point p)
Point
from the local coordinate system of
the given Node
into the coordinate system of the Node
's
parent.public static IGeometry localToScene(javafx.scene.Node n, IGeometry g)
IGeometry
from the local coordinate system
of the given Node
into scene coordinates.public static Point localToScene(javafx.scene.Node n, Point p)
Point
from the local coordinate system of
the given Node
into scene coordinates.public static IGeometry parentToLocal(javafx.scene.Node n, IGeometry g)
IGeometry
from the parent coordinate system
of the given Node
into the local coordinate system of the
Node
.public static Point parentToLocal(javafx.scene.Node n, Point p)
Point
from the parent coordinate system of
the given Node
into the local coordinate system of the
Node
.public static IGeometry sceneToLocal(javafx.scene.Node n, IGeometry g)
IGeometry
from scene coordinates to the
local coordinate system of the given Node
.public static Point sceneToLocal(javafx.scene.Node n, Point p)
Point
from scene coordinates to the local
coordinate system of the given Node
.public static javafx.scene.transform.Affine setAffine(javafx.scene.transform.Affine dst, javafx.scene.transform.Affine src)
Affine
to the
dst Affine
.dst
- The destination Affine
.src
- The source Affine
.Affine
for convenience.Copyright (c) 2014 itemis AG and others. All rights reserved.