From 589f28df97fa789403ce26053a0eb7a52bb53e5d Mon Sep 17 00:00:00 2001 From: angryziber Date: Sat, 30 Dec 2006 13:08:12 +0000 Subject: [PATCH] center dialog boxes, this is needed on Windows git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@90 375186e5-ef17-0410-b0b6-91563547dcda --- .../net/azib/ipscan/gui/AbstractModalDialog.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ipscan/src/net/azib/ipscan/gui/AbstractModalDialog.java b/ipscan/src/net/azib/ipscan/gui/AbstractModalDialog.java index a2992d5f..f074bfb2 100755 --- a/ipscan/src/net/azib/ipscan/gui/AbstractModalDialog.java +++ b/ipscan/src/net/azib/ipscan/gui/AbstractModalDialog.java @@ -3,6 +3,7 @@ */ package net.azib.ipscan.gui; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.List; @@ -19,12 +20,24 @@ public abstract class AbstractModalDialog { protected Shell shell = null; public void open() { + // center dialog box according to the parent window + Rectangle parentBounds = shell.getParent().getBounds(); + Rectangle childBounds = shell.getBounds(); + int x = parentBounds.x + (parentBounds.width - childBounds.width) / 2; + int y = parentBounds.y + (parentBounds.height - childBounds.height) / 2; + shell.setLocation(x, y); + + // open the dialog box shell.open(); + + // create a separate event loop Display display = Display.getCurrent(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } + + // destroy the window shell.dispose(); }