Example usage for javafx.scene Node localToScreen

List of usage examples for javafx.scene Node localToScreen

Introduction

In this page you can find the example usage for javafx.scene Node localToScreen.

Prototype

public Point2D localToScreen(double localX, double localY) 

Source Link

Document

Transforms a point from the local coordinate space of this Node into the coordinate space of its javafx.stage.Screen .

Usage

From source file:org.eclipse.jubula.rc.javafx.driver.RobotJavaFXImpl.java

/**
 * Gets a location inside the component. If <code>offset</code> is
 * <code>null</code>, it returns the middle of the component otherwise it
 * adds the offset to the upper left corner.
 *
 * @param comp/*from w  w w  .ja  v a2  s .com*/
 *            the component to get the location for
 * @param offset
 *            the offset
 * @throws IllegalArgumentException
 *             if <code>component</code> is null
 * @return the <b>global </b> coordinates of <code>component</code>
 */
private Point getLocation(Node comp, final Point offset) throws IllegalArgumentException {

    Validate.notNull(comp, "component must not be null"); //$NON-NLS-1$

    Scene s = comp.getScene();
    s.getRoot().layout();

    Point2D pos = comp.localToScreen(0, 0);

    double x = pos.getX();
    double y = pos.getY();
    if (offset == null) {
        final Bounds boundsInParent = comp.getBoundsInParent();
        x += boundsInParent.getWidth() / 2;
        y += boundsInParent.getHeight() / 2;
    } else {
        x += offset.x;
        y += offset.y;
    }

    return new Point(Rounding.round(x), Rounding.round(y));
}