org.eclipse.gef.fx.utils

## Class NodeUtils

- java.lang.Object
- - org.eclipse.gef.fx.utils.NodeUtils

    public class NodeUtils
    extends Object

The `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
Constructor and Description
`NodeUtils()`

### Method Summary

All Methods Static Methods Concrete Methods
`static boolean` `equals(Affine a1, Affine a2)` Returns `true` if the given `Affine`s are equal.
`static IGeometry` `getGeometricOutline(Node visual)` Returns an `IGeometry` that corresponds whose outline represents the geometric outline of the given `Node`, excluding its stroke.
`static AffineTransform` `getLocalToSceneTx(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 Node` `getNearestCommonAncestor(Node source, Node target)` Computes the nearest common ancestor for two given nodes.
`static List<Node>` `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 given `IGeometry` and resizes it to fit the (corrected) layout-bounds (see `getShapeBounds(Node)`) of the given `Node`.
`static AffineTransform` `getSceneToLocalTx(Node node)` Returns the scene-to-local transform for the given `Node`.
`static Rectangle` `getShapeBounds(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(Node node)` Creates a geometry whose outline represents the outline of the given `Node`, including its stroke.
`static boolean` `isNested(Parent parent, Node node)` Returns true if the given `Node` is contained within the visual hierarchy of the given `Parent`.
`static IGeometry` `localToParent(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(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(Node n, IGeometry g)` Transforms the given `IGeometry` from the local coordinate system of the given `Node` into scene coordinates.
`static Point` `localToScene(Node n, Point p)` Transforms the given `Point` from the local coordinate system of the given `Node` into scene coordinates.
`static IGeometry` `parentToLocal(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(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(Node n, IGeometry g)` Transforms the given `IGeometry` from scene coordinates to the local coordinate system of the given `Node`.
`static Point` `sceneToLocal(Node n, Point p)` Transforms the given `Point` from scene coordinates to the local coordinate system of the given `Node`.
`static Affine` `setAffine(Affine dst, Affine src)` Assigns the transformation values of the src `Affine` to the dst `Affine`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### NodeUtils

    public NodeUtils()

### Method Detail

#### equals

    public static boolean equals(Affine a1,
                                 Affine a2)

Returns `true` if the given `Affine`s are equal. Otherwise returns `false`.

Parameters:
  `a1` - The first operand.
  `a2` - The second operand.
Returns:
  `true` if the given `Affine`s are equal, otherwise `false`.

#### getGeometricOutline

    public static IGeometry getGeometricOutline(Node visual)

Returns an `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`

Parameters:
  `visual` - The `Node` of which the geometric outline is returned.
Returns:
  An `IGeometry` that corresponds to the geometric outline of the given `Node`.
Throws:
  `IllegalArgumentException` - if the given `Node` is not supported.

#### getLocalToSceneTx

    public static AffineTransform getLocalToSceneTx(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`.

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 JavaFX `Node` for which the local-to-scene transformation matrix is to be computed.
Returns:
  An `AffineTransform` representing the local-to-scene transformation matrix for the given `Node`.

#### getNearestCommonAncestor

    public static Node getNearestCommonAncestor(Node source,
                                                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 List<Node> getNodesAt(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 `Node`s which contain the the given coordinate.

#### getResizedToShapeBounds

    public static IGeometry getResizedToShapeBounds(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`. The new, resized `IGeometry` is returned.

Parameters:
  `visual` - The visual of which the layout-bounds are used as the basis for resizing the given `IGeometry`.
  `geometry` - The `IGeometry` that is resized to fit the layout-bounds of the given `Node`.
Returns:
  The new, resized `IGeometry`.

#### getSceneToLocalTx

    public static AffineTransform getSceneToLocalTx(Node node)

Returns the scene-to-local transform for the given `Node`.

Parameters:
  `node` - The `Node` for which the scene-to-local transform is returned.
Returns:
  The scene-to-local transform for the given `Node`.

#### getShapeBounds

    public static Rectangle getShapeBounds(Node node)

Returns the layout-bounds of the given `Node`, which might be adjusted to ensure that it exactly fits the visualization.

Parameters:
  `node` - The `Node` to retrieve the (corrected) layout-bounds of.
Returns:
  A `Rectangle` representing the (corrected) layout-bounds.

#### getShapeOutline

    public static IGeometry getShapeOutline(Node node)

Creates a geometry whose outline represents the outline of the given `Node`, including its stroke.

The `IGeometry` is specified within the local coordinate system of the given `Node`.

Parameters:
  `node` - The node to infer an outline geometry for.
Returns:
  An `IGeometry` from which the outline may be retrieved.

#### isNested

    public static boolean isNested(Parent parent,
                                   Node node)

Returns true if the given `Node` is contained within the visual hierarchy of the given `Parent`.

Parameters:
  `parent` - The `Parent`, whose hierarchy is to be searched.
  `node` - The `Node` to test.
Returns:
  `true` if the given node is contained in the visual hierarchy of the `Parent`, `false` otherwise.

#### localToParent

    public static IGeometry localToParent(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.

Parameters:
  `n` - The `Node` used to determine the transformation matrix.
  `g` - The `IGeometry` to transform.
Returns:
  The new, transformed `IGeometry`.

#### localToParent

    public static Point localToParent(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.

Parameters:
  `n` - The `Node` used to determine the transformation matrix.
  `p` - The `Point` to transform.
Returns:
  The new, transformed `Point`.

#### localToScene

    public static IGeometry localToScene(Node n,
                                         IGeometry g)

Transforms the given `IGeometry` from the local coordinate system of the given `Node` into scene coordinates.

Parameters:
  `n` - The `Node` used to determine the transformation matrix.
  `g` - The `IGeometry` to transform.
Returns:
  The new, transformed `IGeometry`.

#### localToScene

    public static Point localToScene(Node n,
                                     Point p)

Transforms the given `Point` from the local coordinate system of the given `Node` into scene coordinates.

Parameters:
  `n` - The `Node` used to determine the transformation matrix.
  `p` - The `IGeometry` to transform.
Returns:
  The new, transformed `Point`.

#### parentToLocal

    public static IGeometry parentToLocal(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`.

Parameters:
  `n` - The `Node` used to determine the transformation matrix.
  `g` - The `IGeometry` to transform.
Returns:
  The new, transformed `IGeometry`.

#### parentToLocal

    public static Point parentToLocal(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`.

Parameters:
  `n` - The `Node` used to determine the transformation matrix.
  `p` - The `Point` to transform.
Returns:
  The new, transformed `Point`.

#### sceneToLocal

    public static IGeometry sceneToLocal(Node n,
                                         IGeometry g)

Transforms the given `IGeometry` from scene coordinates to the local coordinate system of the given `Node`.

Parameters:
  `n` - The `Node` used to determine the transformation matrix.
  `g` - The `IGeometry` to transform.
Returns:
  The new, transformed `IGeometry`.

#### sceneToLocal

    public static Point sceneToLocal(Node n,
                                     Point p)

Transforms the given `Point` from scene coordinates to the local coordinate system of the given `Node`.

Parameters:
  `n` - The `Node` used to determine the transformation matrix.
  `p` - The `Point` to transform.
Returns:
  The new, transformed `Point`.

#### setAffine

    public static Affine setAffine(Affine dst,
                                   Affine src)

Assigns the transformation values of the src `Affine` to the dst `Affine`.

Parameters:
  `dst` - The destination `Affine`.
  `src` - The source `Affine`.
Returns:
  The destination `Affine` for convenience.