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));
}
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)));
}
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 + "\"");
}
}
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);
}
}
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();
}
Aggregations