Search in sources :

Example 6 with BoundingBox

use of javafx.geometry.BoundingBox in project TestFX by TestFX.

the class BoundsQueryUtilsTest method boundsOnScreen_screen.

@Test
public void boundsOnScreen_screen() {
    Bounds bounds = BoundsQueryUtils.boundsOnScreen(new BoundingBox(1, 2, 3, 4), Screen.getPrimary().getBounds());
    verifyThat(bounds, hasBounds(1, 2, 3, 4));
}
Also used : Bounds(javafx.geometry.Bounds) BoundingBox(javafx.geometry.BoundingBox) Test(org.junit.Test)

Example 7 with BoundingBox

use of javafx.geometry.BoundingBox in project TestFX by TestFX.

the class PointQueryUtilsTest method atPositionFactors_with_positionFactors.

@Test
public void atPositionFactors_with_positionFactors() {
    // given:
    BoundingBox bounds = new BoundingBox(100, 1000, 200, 2000);
    // then:
    assertThat(atPositionFactors(bounds, new Point2D(0.0, 0.0)), is(new Point2D(100, 1000)));
    assertThat(atPositionFactors(bounds, new Point2D(0.5, 0.0)), is(new Point2D(200, 1000)));
    assertThat(atPositionFactors(bounds, new Point2D(1.0, 0.0)), is(new Point2D(300, 1000)));
    assertThat(atPositionFactors(bounds, new Point2D(0.0, 0.5)), is(new Point2D(100, 2000)));
    assertThat(atPositionFactors(bounds, new Point2D(0.5, 0.5)), is(new Point2D(200, 2000)));
    assertThat(atPositionFactors(bounds, new Point2D(1.0, 0.5)), is(new Point2D(300, 2000)));
    assertThat(atPositionFactors(bounds, new Point2D(0.0, 1.0)), is(new Point2D(100, 3000)));
    assertThat(atPositionFactors(bounds, new Point2D(0.5, 1.0)), is(new Point2D(200, 3000)));
    assertThat(atPositionFactors(bounds, new Point2D(1.0, 1.0)), is(new Point2D(300, 3000)));
}
Also used : Point2D(javafx.geometry.Point2D) BoundingBox(javafx.geometry.BoundingBox) Test(org.junit.Test)

Example 8 with BoundingBox

use of javafx.geometry.BoundingBox in project JavaFXLibrary by eficode.

the class BoundsLocation method getBounds.

/*
        TestFX has a bug in BoundQueryUtils boundsOnScreen(Bounds b, Window w) method which causes window location data
        to be incorrect. Problem is that the method first takes windows location with getMinX() and getMinY() (that
        already return the location on the screen) and then add an extra offset (getMinX() and getMinY() again) to them.
        This results the coordinates to be always twice as large than they should be.

        This bug also affects bounds(Scene s) method, as it uses the buggy boundsOnScreen to count the offset for the
        scene. Both of these method calls have been replaced with pure JavaFX, and shouldn't be affected in any way in
        case TestFX gets changed.

        Details:
        - version: testfx-core 4.0.6-alpha
        - location: main/java/org/testfx/api/util/BoundsQueryUtils.java: rows 153-160
     */
@RobotKeyword("Returns a Bounds object for a region located using given locator. \n\n" + "``locator`` is either a _query_ or _Object:Node, Point2D, Scene, or Window_ for identifying the region" + ", see `3. Locating or specifying UI elements`. \n\n" + "\nExample:\n" + "| ${bounds}= | Get Bounds | ${node} | \n" + "| ${target}= | Create Bounds | 150 | 150 | 200 | 200 | \n" + "| Should Be Equal | ${bounds} | ${target} | \n")
@ArgumentNames({ "locator", "logLevel=" })
public Object getBounds(Object locator, String logLevel) {
    try {
        if (locator instanceof Window) {
            Window window = (Window) locator;
            robotLog(logLevel, "Getting bounds with window \"" + locator.toString() + "\"");
            return mapObject(new BoundingBox(window.getX(), window.getY(), window.getWidth(), window.getHeight()));
        } else if (locator instanceof Scene) {
            Scene scene = (Scene) locator;
            robotLog(logLevel, "Getting bounds with scene \"" + locator.toString() + "\"");
            return mapObject(new BoundingBox(scene.getX() + scene.getWindow().getX(), scene.getY() + scene.getWindow().getY(), scene.getWidth(), scene.getHeight()));
        } else if (locator instanceof Point2D) {
            robotLog(logLevel, "Getting bounds with point object \"" + locator.toString() + "\"");
            return mapObject(robot.bounds((Point2D) locator).query());
        } else if (locator instanceof Node) {
            robotLog(logLevel, "Getting bounds with node \"" + locator.toString() + "\"");
            return mapObject(robot.bounds((Node) locator).query());
        } else if (locator instanceof String) {
            waitUntilExists((String) locator);
            Node node = robot.lookup((String) locator).query();
            robotLog(logLevel, "Getting bounds with query \"" + locator.toString() + "\"");
            return mapObject(robot.bounds(node).query());
        } else if (locator instanceof Bounds) {
            robotLog(logLevel, "Getting bounds with bounds object \"" + locator.toString() + "\"");
            return mapObject(locator);
        } else if (locator instanceof PointQuery) {
            robotLog(logLevel, "Getting bounds with point query \"" + locator.toString() + "\"");
            return mapObject(robot.bounds(((PointQuery) locator).query()).query());
        }
        throw new JavaFXLibraryNonFatalException("Unsupported parameter type: " + locator.toString());
    } catch (Exception e) {
        if (e instanceof JavaFXLibraryNonFatalException) {
            throw e;
        }
        throw new JavaFXLibraryNonFatalException("Couldn't find \"" + locator + "\"");
    }
}
Also used : Window(javafx.stage.Window) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Point2D(javafx.geometry.Point2D) BoundingBox(javafx.geometry.BoundingBox) Node(javafx.scene.Node) Bounds(javafx.geometry.Bounds) Scene(javafx.scene.Scene) PointQuery(org.testfx.service.query.PointQuery) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 9 with BoundingBox

use of javafx.geometry.BoundingBox in project JavaFXLibrary by eficode.

the class ConvenienceKeywords method getPrimaryScreenBounds.

@RobotKeyword("Returns the bounds of primary screen. \n")
public Object getPrimaryScreenBounds() {
    try {
        robotLog("INFO", "Getting the primary screen bounds");
        Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
        return mapObject(new BoundingBox(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight()));
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Unable to get primary screen bounds.", e);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) BoundingBox(javafx.geometry.BoundingBox) Rectangle2D(javafx.geometry.Rectangle2D) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword)

Example 10 with BoundingBox

use of javafx.geometry.BoundingBox in project blue by kunstmusik.

the class BSBObjectViewHolder method recordMouseOrigin.

protected void recordMouseOrigin(MouseEvent evt) {
    final BSBObject bsbObj = (BSBObject) getUserData();
    Rectangle r = (Rectangle) evt.getSource();
    mouseOrigin = r.localToParent(evt.getX(), evt.getY());
    mouseOrigin = localToParent(mouseOrigin);
    originBounds = new BoundingBox(bsbObj.getX(), bsbObj.getY(), rView.getWidgetWidth(), rView.getWidgetHeight());
    evt.consume();
}
Also used : BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) BoundingBox(javafx.geometry.BoundingBox) Rectangle(javafx.scene.shape.Rectangle)

Aggregations

BoundingBox (javafx.geometry.BoundingBox)23 Bounds (javafx.geometry.Bounds)11 Test (org.junit.Test)7 Point2D (javafx.geometry.Point2D)6 Node (javafx.scene.Node)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 DoubleProperty (javafx.beans.property.DoubleProperty)2 ObjectProperty (javafx.beans.property.ObjectProperty)2 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 Rectangle2D (javafx.geometry.Rectangle2D)2 Paint (javafx.scene.paint.Paint)2 Rectangle (javafx.scene.shape.Rectangle)2 JavaFXLibraryNonFatalException (javafxlibrary.exceptions.JavaFXLibraryNonFatalException)2 RobotKeyword (org.robotframework.javalib.annotation.RobotKeyword)2 BSBObject (blue.orchestra.blueSynthBuilder.BSBObject)1 ShapeType (com.almasb.fxgl.physics.box2d.collision.shapes.ShapeType)1 CachedTransition (com.jfoenix.transitions.CachedTransition)1 RectBounds (com.sun.javafx.geom.RectBounds)1