use of javafx.geometry.Rectangle2D in project sakuli by ConSol.
the class UiTestApplication method run.
@Override
public void run() {
Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
// create Login scene
Scene loginScene = gotoLogin();
width = bounds.getWidth();
height = bounds.getHeight() * HEIGHT_PERCENTAGE;
Stage stage = StageBuilder.create().x(0).y(0).width(width).height(height).title("Sakuli Login Sample").scene(loginScene).onCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
LOGGER.info("PLATFORM exit!");
}
}).build();
LOGGER.info("set width '{}' and height '{}'", width, height);
start(stage);
}
use of javafx.geometry.Rectangle2D in project JFoenix by jfoenixadmin.
the class JFXCustomColorPickerDialog method fixPosition.
private void fixPosition() {
Window w = dialog.getOwner();
Screen s = com.sun.javafx.util.Utils.getScreen(w);
Rectangle2D sb = s.getBounds();
double xR = w.getX() + w.getWidth();
double xL = w.getX() - dialog.getWidth();
double x, y;
if (sb.getMaxX() >= xR + dialog.getWidth())
x = xR;
else if (sb.getMinX() <= xL)
x = xL;
else
x = Math.max(sb.getMinX(), sb.getMaxX() - dialog.getWidth());
y = Math.max(sb.getMinY(), Math.min(sb.getMaxY() - dialog.getHeight(), w.getY()));
dialog.setX(x);
dialog.setY(y);
}
use of javafx.geometry.Rectangle2D in project jgnash by ccavanaugh.
the class StageUtils method addBoundsListener.
public static void addBoundsListener(final Stage stage, final String prefNode, @Nullable final Stage parent) {
final String bounds = Preferences.userRoot().node(prefNode).get(DEFAULT_KEY, null);
if (bounds != null) {
// restore to previous size and position
Rectangle2D rectangle = decodeRectangle(bounds);
// relative window placement requested. Modify the coordinates to the current parent placement
if (parent != null) {
rectangle = new Rectangle2D(rectangle.getMinX() + parent.getX(), rectangle.getMinY() + parent.getY(), rectangle.getWidth(), rectangle.getHeight());
}
// Do not try to restore bounds if they exceed available screen space.. user dropped a monitor
if (getMaxVisualBounds().contains(rectangle)) {
final boolean resizable = stage.isResizable();
// Stage will not reposition if resizable is false... JavaFx bug?
stage.setResizable(false);
stage.setX(rectangle.getMinX());
stage.setY(rectangle.getMinY());
if (resizable) {
// don't resize if originally false
if (stage.getMinWidth() != stage.getMaxWidth()) {
// width may be locked
final double width = rectangle.getWidth();
if (stage.isShowing()) {
Platform.runLater(() -> stage.setWidth(width));
} else {
stage.setWidth(width);
}
}
if (stage.getMinHeight() != stage.getMaxHeight()) {
// height may be locked
final double height = rectangle.getHeight();
if (stage.isShowing()) {
Platform.runLater(() -> stage.setHeight(height));
} else {
stage.setHeight(height);
}
}
}
// restore the resize property
stage.setResizable(resizable);
}
}
final ChangeListener<Number> boundsListener = new BoundsListener(stage, prefNode, parent);
stage.widthProperty().addListener(boundsListener);
stage.heightProperty().addListener(boundsListener);
stage.xProperty().addListener(boundsListener);
stage.yProperty().addListener(boundsListener);
}
use of javafx.geometry.Rectangle2D in project jgnash by ccavanaugh.
the class StageUtils method decodeRectangle.
private static Rectangle2D decodeRectangle(final String bounds) {
if (bounds == null) {
return null;
}
Rectangle2D rectangle = null;
final String[] array = bounds.split(String.valueOf(COMMA_DELIMITER));
if (array.length == 4) {
try {
rectangle = new Rectangle2D(Double.parseDouble(array[X]), Double.parseDouble(array[Y]), Double.parseDouble(array[WIDTH]), Double.parseDouble(array[HEIGHT]));
} catch (final NumberFormatException nfe) {
Logger.getLogger(StageUtils.class.getName()).log(Level.SEVERE, null, nfe);
rectangle = null;
}
}
return rectangle;
}
use of javafx.geometry.Rectangle2D in project jgnash by ccavanaugh.
the class StageUtils method getMaxVisualBounds.
/**
* Returns the maximum visual bounds of the users desktop.
*
* @return maximum usable desktop bounds
*/
private static Rectangle2D getMaxVisualBounds() {
double maxX = 0;
double maxY = 0;
double minX = Double.MAX_VALUE;
double minY = Double.MAX_VALUE;
for (final Screen screen : Screen.getScreens()) {
minX = Math.min(minX, screen.getVisualBounds().getMinX());
minY = Math.min(minY, screen.getVisualBounds().getMinY());
maxX = Math.max(maxX, screen.getVisualBounds().getMaxX());
maxY = Math.max(maxY, screen.getVisualBounds().getMaxY());
}
return new Rectangle2D(minX, minY, maxX - minX, maxY - minY);
}
Aggregations