diff options
Diffstat (limited to 'dozentenmodul/src/main/java/gui/GuiManager.java')
-rw-r--r-- | dozentenmodul/src/main/java/gui/GuiManager.java | 87 |
1 files changed, 70 insertions, 17 deletions
diff --git a/dozentenmodul/src/main/java/gui/GuiManager.java b/dozentenmodul/src/main/java/gui/GuiManager.java index 41d5c711..d3904238 100644 --- a/dozentenmodul/src/main/java/gui/GuiManager.java +++ b/dozentenmodul/src/main/java/gui/GuiManager.java @@ -1,31 +1,84 @@ package gui; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; public abstract class GuiManager { + static Shell mainShell; + static Composite contentComposite; + static Display display; - private static Display _display; - private static Shell _mainShell; - private static Shell _containerShell; + /** + * Add a new composite with content to the main Shell + * @param The composite to add, should be a GUI + */ + public static void addContent( Composite contentComposite ){ + removeContent(); + + GuiManager.contentComposite = contentComposite; + mainShell.layout(); + + } + + /** + * Remove the current content of the main shell + */ + private static void removeContent() { + if(contentComposite != null) { + GuiManager.contentComposite.dispose(); + + } + System.out.println(mainShell.toString()); + } + + + public static Display getDisplay(){ + return display; + } + public static void initGui() { - // init display, shell - _display = new Display(); - _mainShell = new Shell(_display); + display = new Display(); + mainShell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER); + + Menu menuBar = new Menu(mainShell, SWT.BAR); + MenuItem cascadeFileMenu = new MenuItem(menuBar, SWT.CASCADE); + cascadeFileMenu.setText("&File"); + + Menu fileMenu = new Menu(mainShell, SWT.DROP_DOWN); + cascadeFileMenu.setMenu(fileMenu); + + MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH); + exitItem.setText("&Exit"); + exitItem.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + mainShell.getDisplay().dispose(); + System.exit(0); + } + }); + + mainShell.setText("Dozmod"); + mainShell.setMenuBar(menuBar); + mainShell.setLayout(new FillLayout()); + + addContent(new gui.core.LoginComposite(mainShell)); + - // add static gui elements - _containerShell = _mainShell; + mainShell.pack(); + mainShell.open(); - // pack (aka size widgets) and open - _mainShell.pack(); - _mainShell.open(); - // main loop - while (!_mainShell.isDisposed()) { - if (!_display.readAndDispatch()) - _display.sleep(); + while (!mainShell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); } - _display.dispose(); } -}
\ No newline at end of file +} |