preferredBounds.getMinY(),
Math.max(minWidth, preferredBounds.getWidth()),
Math.max(minHeight, preferredBounds.getHeight()));
// Get the Screen to display the dialog
Screen screen = parentBounds != null
? Screen.getScreenForLocation(
(int) (parentBounds.getMinX() + parentBounds.getWidth() / 2),
(int) (parentBounds.getMinY() + parentBounds.getHeight() / 2))
: null;
if (screen == null) {
screen = Screen.getMainScreen();
}
// Make sure the dialog doesn't exceed 70% of the screen size
// Create the unpositioned rectangle for the dialog
Rectangle2D rect = new Rectangle2D(
screen.getX(),
screen.getY(),
Math.min(preferredBounds.getWidth(), screen.getWidth() * 0.7),
Math.min(preferredBounds.getHeight(), screen.getHeight() * 0.7));
// Position the rectangle (center over parent, then make sure it's contained in the screen)
Rectangle2D screenBounds = new Rectangle2D(screen.getX(), screen.getY(), screen.getWidth(), screen.getHeight());
if (parentBounds == null) {
parentBounds = screenBounds;
}
rect = GeoFx.center(rect, parentBounds);