Class NodeUtils
- java.lang.Object
-
- org.eclipse.gef.fx.utils.NodeUtils
-
public class NodeUtils extends java.lang.ObjectTheNodeUtilsclass contains utility methods for working with JavaFX:- transforming
IGeometrys 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
Nodes at a specific position within the JavaFX scene graph (getNodesAt(Node, double, double))
- transforming
-
-
Constructor Summary
Constructors Constructor Description NodeUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanequals(javafx.scene.transform.Affine a1, javafx.scene.transform.Affine a2)Returnstrueif the givenAffines are equal.static IGeometrygetGeometricOutline(javafx.scene.Node visual)Returns anIGeometrythat corresponds whose outline represents the geometric outline of the givenNode, excluding its stroke.static AffineTransformgetLocalToSceneTx(javafx.scene.Node node)Returns anAffineTransformwhich represents the transformation matrix to transform geometries from the local coordinate system of the givenNodeinto the coordinate system of theScene.static javafx.scene.NodegetNearestCommonAncestor(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 IGeometrygetResizedToShapeBounds(javafx.scene.Node visual, IGeometry geometry)Creates a copy of the givenIGeometryand resizes it to fit the (corrected) layout-bounds (seegetShapeBounds(Node)) of the givenNode.static AffineTransformgetSceneToLocalTx(javafx.scene.Node node)Returns the scene-to-local transform for the givenNode.static RectanglegetShapeBounds(javafx.scene.Node node)Returns the layout-bounds of the givenNode, which might be adjusted to ensure that it exactly fits the visualization.static IGeometrygetShapeOutline(javafx.scene.Node node)Creates a geometry whose outline represents the outline of the givenNode, including its stroke.static booleanisNested(javafx.scene.Parent parent, javafx.scene.Node node)Returns true if the givenNodeis contained within the visual hierarchy of the givenParent.static IGeometrylocalToParent(javafx.scene.Node n, IGeometry g)Transforms the givenIGeometryfrom the local coordinate system of the givenNodeinto the coordinate system of theNode's parent.static PointlocalToParent(javafx.scene.Node n, Point p)Transforms the givenPointfrom the local coordinate system of the givenNodeinto the coordinate system of theNode's parent.static IGeometrylocalToScene(javafx.scene.Node n, IGeometry g)Transforms the givenIGeometryfrom the local coordinate system of the givenNodeinto scene coordinates.static PointlocalToScene(javafx.scene.Node n, Point p)Transforms the givenPointfrom the local coordinate system of the givenNodeinto scene coordinates.static IGeometryparentToLocal(javafx.scene.Node n, IGeometry g)Transforms the givenIGeometryfrom the parent coordinate system of the givenNodeinto the local coordinate system of theNode.static PointparentToLocal(javafx.scene.Node n, Point p)Transforms the givenPointfrom the parent coordinate system of the givenNodeinto the local coordinate system of theNode.static IGeometrysceneToLocal(javafx.scene.Node n, IGeometry g)Transforms the givenIGeometryfrom scene coordinates to the local coordinate system of the givenNode.static PointsceneToLocal(javafx.scene.Node n, Point p)Transforms the givenPointfrom scene coordinates to the local coordinate system of the givenNode.static javafx.scene.transform.AffinesetAffine(javafx.scene.transform.Affine dst, javafx.scene.transform.Affine src)Assigns the transformation values of the srcAffineto the dstAffine.
-
-
-
Method Detail
-
equals
public static boolean equals(javafx.scene.transform.Affine a1, javafx.scene.transform.Affine a2)Returnstrueif the givenAffines are equal. Otherwise returnsfalse.- Parameters:
a1- The first operand.a2- The second operand.- Returns:
trueif the givenAffines are equal, otherwisefalse.
-
getGeometricOutline
public static IGeometry getGeometricOutline(javafx.scene.Node visual)
Returns anIGeometrythat corresponds whose outline represents the geometric outline of the givenNode, excluding its stroke.The
IGeometryis specified within the local coordinate system of the givenNode.The following
Nodes are supported:ConnectionGeometryNodeArcCircleCubicCurveEllipseLinePathPolygonPolylineQuadCurveRectangle
- Parameters:
visual- TheNodeof which the geometric outline is returned.- Returns:
- An
IGeometrythat corresponds to the geometric outline of the givenNode. - Throws:
java.lang.IllegalArgumentException- if the givenNodeis not supported.
-
getLocalToSceneTx
public static AffineTransform getLocalToSceneTx(javafx.scene.Node node)
Returns anAffineTransformwhich represents the transformation matrix to transform geometries from the local coordinate system of the givenNodeinto the coordinate system of theScene.JavaFX
Nodeprovides 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 JavaFXNodefor which the local-to-scene transformation matrix is to be computed.- Returns:
- An
AffineTransformrepresenting the local-to-scene transformation matrix for the givenNode.
-
getNearestCommonAncestor
public static javafx.scene.Node getNearestCommonAncestor(javafx.scene.Node source, javafx.scene.Node target)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
public 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.- 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
Nodes which contain the the given coordinate.
-
getResizedToShapeBounds
public static IGeometry getResizedToShapeBounds(javafx.scene.Node visual, IGeometry geometry)
Creates a copy of the givenIGeometryand resizes it to fit the (corrected) layout-bounds (seegetShapeBounds(Node)) of the givenNode. The new, resizedIGeometryis returned.
-
getSceneToLocalTx
public static AffineTransform getSceneToLocalTx(javafx.scene.Node node)
Returns the scene-to-local transform for the givenNode.- Parameters:
node- TheNodefor which the scene-to-local transform is returned.- Returns:
- The scene-to-local transform for the given
Node.
-
getShapeBounds
public static Rectangle getShapeBounds(javafx.scene.Node node)
Returns the layout-bounds of the givenNode, which might be adjusted to ensure that it exactly fits the visualization.- Parameters:
node- TheNodeto retrieve the (corrected) layout-bounds of.- Returns:
- A
Rectanglerepresenting the (corrected) layout-bounds.
-
getShapeOutline
public static IGeometry getShapeOutline(javafx.scene.Node node)
Creates a geometry whose outline represents the outline of the givenNode, including its stroke.The
IGeometryis specified within the local coordinate system of the givenNode.- Parameters:
node- The node to infer an outline geometry for.- Returns:
- An
IGeometryfrom which the outline may be retrieved.
-
isNested
public static boolean isNested(javafx.scene.Parent parent, javafx.scene.Node node)Returns true if the givenNodeis contained within the visual hierarchy of the givenParent.- Parameters:
parent- TheParent, whose hierarchy is to be searched.node- TheNodeto test.- Returns:
trueif the given node is contained in the visual hierarchy of theParent,falseotherwise.
-
localToParent
public static IGeometry localToParent(javafx.scene.Node n, IGeometry g)
Transforms the givenIGeometryfrom the local coordinate system of the givenNodeinto the coordinate system of theNode's parent.
-
localToParent
public static Point localToParent(javafx.scene.Node n, Point p)
Transforms the givenPointfrom the local coordinate system of the givenNodeinto the coordinate system of theNode's parent.
-
localToScene
public static IGeometry localToScene(javafx.scene.Node n, IGeometry g)
Transforms the givenIGeometryfrom the local coordinate system of the givenNodeinto scene coordinates.
-
localToScene
public static Point localToScene(javafx.scene.Node n, Point p)
Transforms the givenPointfrom the local coordinate system of the givenNodeinto scene coordinates.
-
parentToLocal
public static IGeometry parentToLocal(javafx.scene.Node n, IGeometry g)
Transforms the givenIGeometryfrom the parent coordinate system of the givenNodeinto the local coordinate system of theNode.
-
parentToLocal
public static Point parentToLocal(javafx.scene.Node n, Point p)
Transforms the givenPointfrom the parent coordinate system of the givenNodeinto the local coordinate system of theNode.
-
sceneToLocal
public static IGeometry sceneToLocal(javafx.scene.Node n, IGeometry g)
Transforms the givenIGeometryfrom scene coordinates to the local coordinate system of the givenNode.
-
sceneToLocal
public static Point sceneToLocal(javafx.scene.Node n, Point p)
Transforms the givenPointfrom scene coordinates to the local coordinate system of the givenNode.
-
setAffine
public static javafx.scene.transform.Affine setAffine(javafx.scene.transform.Affine dst, javafx.scene.transform.Affine src)Assigns the transformation values of the srcAffineto the dstAffine.- Parameters:
dst- The destinationAffine.src- The sourceAffine.- Returns:
- The destination
Affinefor convenience.
-
-