From d23140ea4818d74dab73c5265e68e2d3127ef40d Mon Sep 17 00:00:00 2001 From: Tobias Kellner Date: Mon, 12 Oct 2015 04:44:28 +0200 Subject: Center input dialog on main window --- .../main/java/at/asit/pdfover/gui/controls/InputDialog.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/InputDialog.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/InputDialog.java index 80c967a6..88cf9e87 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/InputDialog.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/InputDialog.java @@ -19,6 +19,7 @@ package at.asit.pdfover.gui.controls; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -96,12 +97,18 @@ public class InputDialog extends org.eclipse.swt.widgets.Dialog { * @return the input */ public String open() { - Shell shell = new Shell(getParent(), getStyle()); + Shell parent = getParent(); + Shell shell = new Shell(parent, getStyle()); shell.setText(getText()); createContents(shell); shell.pack(); shell.open(); - Display display = getParent().getDisplay(); + Display display = parent.getDisplay(); + Rectangle bounds = parent.getBounds(); + Rectangle main = shell.getBounds(); + shell.setLocation( + bounds.x + (bounds.width - main.width) / 2, + bounds.y + (bounds.height - main.height) / 2); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); -- cgit v1.2.3