From 2b57f9240540a2d26913f2f96c38918fe9004e79 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:07:45 +0000 Subject: Center window if possible Note: not tested git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@147 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../src/main/java/at/asit/pdfover/gui/MainWindow.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'pdf-over-gui/src/main') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java index 7b57d46d..c109f6bd 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java @@ -21,17 +21,20 @@ import java.util.EnumMap; import java.util.Map; import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTError; import org.eclipse.swt.custom.StackLayout; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -171,6 +174,18 @@ public class MainWindow { protected void createContents() { this.shell = new Shell(); getShell().setSize(1024, 768); + try { + Display display = new Display(); + Monitor primary = display.getPrimaryMonitor(); + Rectangle bounds = primary.getBounds(); + Rectangle main = this.shell.getBounds(); + this.shell.setLocation( + bounds.x + (bounds.width - main.width) / 2, + bounds.y + (bounds.height - main.height) / 2); + } + catch (SWTError e) { + log.debug("Cannot get display", e); //$NON-NLS-1$ + } getShell().setText(Messages.getString("main.title")); //$NON-NLS-1$ ImageData data = new ImageData(this.getClass().getResourceAsStream("/icons/icon.png"));//$NON-NLS-1$ -- cgit v1.2.3