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
This commit is contained in:
angryziber 2006-12-30 13:08:12 +00:00
parent 1b2037e3a5
commit 589f28df97

View File

@ -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();
}