diff options
author | Simon Rettberg | 2015-07-10 14:58:08 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-07-10 14:58:08 +0200 |
commit | b1298643908e80a5bd4763d1e2b13aa9992d5048 (patch) | |
tree | 43066b3cf826db0a19eed9a5112dd7072866b7f4 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java | |
parent | [client] close popups a bit safer (diff) | |
download | tutor-module-b1298643908e80a5bd4763d1e2b13aa9992d5048.tar.gz tutor-module-b1298643908e80a5bd4763d1e2b13aa9992d5048.tar.xz tutor-module-b1298643908e80a5bd4763d1e2b13aa9992d5048.zip |
[client] More refactoring, introduce a Gui helper class (again)
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java index 72b19293..c8ba577f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -6,18 +6,16 @@ import org.apache.log4j.Logger; 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.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.MessageBox; -import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; +import org.openslx.dozmod.gui.helper.Gui; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.window.DisclaimerWindow; import org.openslx.dozmod.gui.window.LoginWindow; @@ -33,7 +31,6 @@ public abstract class MainWindow { private static final Shell mainShell; private static Composite contentComposite; - private static final Display display; private static final String THRIFT_CONNECTION_ERROR = "Lost connection to the masterserver. Do you want to retry?"; @@ -44,7 +41,8 @@ public abstract class MainWindow { */ public static void setContent(Composite contentComposite) { - if (contentComposite == null) return; + if (contentComposite == null) + return; if (MainWindow.contentComposite != null) MainWindow.contentComposite.dispose(); @@ -57,7 +55,7 @@ public abstract class MainWindow { /** * @param clazz Class to open as a popup over the main window. - * MUST be a subclass of Composite. + * MUST be a subclass of Composite. */ public static void openPopup(Class<? extends Composite> clazz, boolean modal) { Shell dialogShell = new Shell(mainShell, SWT.DIALOG_TRIM | (modal ? SWT.APPLICATION_MODAL : 0)); @@ -75,20 +73,19 @@ public abstract class MainWindow { dialogShell.layout(); dialogShell.pack(); + Gui.limitShellSize(dialogShell); dialogShell.open(); } /** - * @return The instance of SWT display currently in use + * Initialises the GUI by creating the main window, adding the menu and + * creating the login mask as the first content window. + * Further sets up the global thrift error callback to catch any + * connection errors during the communication with the servers. */ - public static Display getDisplay() { - return display; - } - static { // init SWT stuff - display = new Display(); - mainShell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER); + mainShell = new Shell(Gui.display, SWT.SHELL_TRIM | SWT.CENTER); // Set up thrift error message displaying ThriftManager.setErrorCallback(new ErrorCallback() { @@ -101,7 +98,7 @@ public abstract class MainWindow { }); // Global key listener - display.addFilter(SWT.KeyDown, new Listener() { + Gui.display.addFilter(SWT.KeyDown, new Listener() { @Override public void handleEvent(Event event) { if (event.character == 17) // Ctrl-Q = Quit @@ -121,14 +118,8 @@ public abstract class MainWindow { setContent(new MainMenuWindow(mainShell)); // center the window on the primary monitor - Monitor primary = display.getPrimaryMonitor(); - Rectangle bounds = primary.getBounds(); - Rectangle rect = mainShell.getBounds(); + Gui.centerShell(mainShell); - int x = bounds.x + (bounds.width - rect.width) / 2; - int y = bounds.y + (bounds.height - rect.height) / 2; - - mainShell.setLocation(x, y); mainShell.open(); // here we can check for Session information @@ -139,15 +130,12 @@ public abstract class MainWindow { } /** - * Initialises the GUI by creating the main window, adding the menu and - * creating the login mask as the first content window. - * Further sets up the global thrift error callback to catch any - * connection errors during the communication with the servers. + * Run the GUI mainloop as long as the main window exists. */ public static void mainloop() { while (!mainShell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); + if (!Gui.display.readAndDispatch()) + Gui.display.sleep(); } } |