From 2ba8f9ea948c536992a002e8f968dd79e7736b92 Mon Sep 17 00:00:00 2001 From: Skinner927 Date: Thu, 9 Jan 2014 21:53:28 -0500 Subject: [PATCH] Center ExceptionDialog to Parent Exception Dialog now centers on parent dialog. This was accidentally overlooked in the last commit. --- .../src/javafx/scene/control/Dialogs.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/javafx-dialogs/src/javafx/scene/control/Dialogs.java b/javafx-dialogs/src/javafx/scene/control/Dialogs.java index 62643d9..62591fc 100644 --- a/javafx-dialogs/src/javafx/scene/control/Dialogs.java +++ b/javafx-dialogs/src/javafx/scene/control/Dialogs.java @@ -488,13 +488,21 @@ public DialogOptions getDefaultOptions() { } private static void centerToOwner(DialogTemplate template) { - final FXDialog dialog = template.getDialog(); + FXDialog dialog = template.getDialog(); Window window = dialog.getOwner(); + if(!centerToOwner(window, dialog)){ + template.getDialog().centerOnScreen(); + } + } + + private static boolean centerToOwner(Window window, FXDialog inDialog) { // get center of window final double windowCenterX = window.getX() + (window.getWidth() / 2); final double windowCenterY = window.getY() + (window.getHeight() / 2); + final FXDialog dialog = inDialog; + // verify if(!Double.isNaN(windowCenterX)){ // set a temp position @@ -505,13 +513,24 @@ private static void centerToOwner(DialogTemplate template) { Platform.runLater(new Runnable() { @Override public void run() { - dialog.setX(windowCenterX - (dialog.getWidth() / 2)); - dialog.setY(windowCenterY - (dialog.getHeight() / 2)); + double x = windowCenterX - (dialog.getWidth() / 2); + double y = windowCenterY - (dialog.getHeight() / 2); + + // we don't want the top left of the dialog to shoot off the screen + if(x < 0) + x = 0; + if(y < 0) + y = 0; + + dialog.setX(x); + dialog.setY(y); } }); + + return true; } else { - template.getDialog().centerOnScreen(); + return false; } } @@ -966,7 +985,9 @@ private List