Example usage for javafx.stage Screen getBounds

List of usage examples for javafx.stage Screen getBounds

Introduction

In this page you can find the example usage for javafx.stage Screen getBounds.

Prototype

public final Rectangle2D getBounds() 

Source Link

Document

Gets the bounds of this Screen .

Usage

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

/**
 * Refreshes the complete layout and returns the bounds of the given
 * Component.//  ww w.  j  av  a 2  s .c o  m
 *
 * @param comp
 *            the Component
 * @param clickOp
 *            not used
 * @return Rectangle with the Bounds
 */
private Rectangle getComponentBounds(final Object comp, ClickOptions clickOp) {

    ComponentHandler.syncStageResize();
    Rectangle bounds = null;
    if (comp instanceof Stage) {
        Stage s = (Stage) comp;
        bounds = new Rectangle(new Point(Rounding.round(s.getX()), Rounding.round(s.getY())));

        // This is not multi display compatible
        Screen screen = Screen.getPrimary();
        final Rectangle2D screenBounds = screen.getBounds();
        int displayWidth = Rounding.round(screenBounds.getWidth());
        int displayHeight = Rounding.round(screenBounds.getHeight());
        if (s.isFullScreen()) {
            bounds.width = Rounding.round(displayWidth);
            bounds.height = Rounding.round(displayHeight);
        } else if (s.isMaximized()) {
            int x = Rounding.round(s.getX());
            int y = Rounding.round(s.getY());
            // trimming the bounds to the display if necessary
            bounds.width = Rounding.round(s.getWidth());
            bounds.height = Rounding.round(s.getHeight());
            if (x < 0 || y < 0) {
                bounds.x = 0;
                bounds.y = 0;
                if (bounds.width > displayWidth) {
                    bounds.width = displayWidth;
                }
                if (bounds.height > displayHeight) {
                    bounds.height = displayHeight;
                }
            }
        } else {
            bounds.width = Rounding.round(s.getWidth());
            bounds.height = Rounding.round(s.getHeight());
        }
    } else {
        final Node node = (Node) comp;
        if (clickOp.isScrollToVisible()) {
            ensureComponentVisible(node);
        }
        bounds = EventThreadQueuerJavaFXImpl.invokeAndWait("Robot get node bounds", new Callable<Rectangle>() { //$NON-NLS-1$

            @Override
            public Rectangle call() throws Exception {
                Rectangle bs = new Rectangle(getLocation(node, new Point(0, 0)));
                Bounds b = node.getBoundsInParent();
                bs.width = Rounding.round(b.getWidth());
                bs.height = Rounding.round(b.getHeight());
                return bs;
            }
        });

    }
    return bounds;
}

From source file:org.openbase.display.HTMLLoader.java

public void init(final Screen screen) {
    variableStore.store("SCREEN_WIDTH", Double.toString(screen.getBounds().getWidth()));
    variableStore.store("SCREEN_HEIGHT", Double.toString(screen.getBounds().getHeight()));
    variableStore.store("APP", JPService.getApplicationName());
}