diff options
author | Simon Rettberg | 2015-07-27 16:01:59 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-07-27 16:01:59 +0200 |
commit | 8d24acd9bdffcc5687bb0f7eb79e7206234ee445 (patch) | |
tree | 4eb99fcc36c44e6f3b4e725674705c5cff0b48f3 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java | |
parent | [client] One step forward and two steps back... (diff) | |
download | tutor-module-8d24acd9bdffcc5687bb0f7eb79e7206234ee445.tar.gz tutor-module-8d24acd9bdffcc5687bb0f7eb79e7206234ee445.tar.xz tutor-module-8d24acd9bdffcc5687bb0f7eb79e7206234ee445.zip |
[client] Transformed MainWindow
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 | 196 |
1 files changed, 60 insertions, 136 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 bcf2b738..9036f588 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -1,21 +1,24 @@ package org.openslx.dozmod.gui; -import java.lang.reflect.Constructor; +import java.awt.Dimension; +import java.awt.KeyEventDispatcher; +import java.awt.KeyboardFocusManager; +import java.awt.Window; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import javax.swing.BoxLayout; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; + 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.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -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.Shell; import org.openslx.dozmod.App; import org.openslx.dozmod.Config; import org.openslx.dozmod.gui.Gui.GuiCallable; @@ -36,7 +39,7 @@ public abstract class MainWindow { private final static Logger LOGGER = Logger.getLogger(MainWindow.class); - private static final Shell mainShell; + private static final JFrame mainShell; private static CompositePage currentPage; @@ -50,78 +53,28 @@ public abstract class MainWindow { * @param clazz */ public static void showPage(Class<? extends CompositePage> clazz) { - if (currentPage != null && currentPage.getLayoutData() != null) { - if (!currentPage.hide()) { + if (currentPage != null) { + if (!currentPage.requestHide()) { return; // Canceled by currently shown page } - ((GridData) currentPage.getLayoutData()).exclude = true; currentPage.setVisible(false); } currentPage = pages.get(clazz); if (currentPage == null) { - showMessageBox("Tried to show unknown page " + clazz.getSimpleName(), MessageType.ERROR, LOGGER, - null); + Gui.showMessageBox("Tried to show unknown page " + clazz.getSimpleName(), MessageType.ERROR, + LOGGER, null); Gui.exit(1); return; } // sets the starting preferred size. - currentPage.show(); - ((GridData) currentPage.getLayoutData()).exclude = false; + currentPage.requestShow(); currentPage.setVisible(true); - mainShell.layout(); - } - - /** - * - * @param clazz Class to open as a popup over the main window. - * MUST be a subclass of Composite. - * @param modal modal mode - other windows will be blocked until this popup - * is closed - * @param noclose don't allow closing the popup via the (X) in the title bar - * @return The composite that is opened as a popup, or <code>null</code> on - * error - */ - public static <T extends Composite> T openPopup(Class<T> clazz, boolean modal, boolean noclose) { - int style = SWT.TITLE | SWT.BORDER | SWT.RESIZE; - if (modal) - style |= SWT.APPLICATION_MODAL; - if (!noclose) - style |= SWT.CLOSE; - Shell dialogShell = Gui.newShell(mainShell, style); - // populate dialogShell - dialogShell.setLayout(new GridLayout(1, false)); - final T comp; - try { - Constructor<T> con = clazz.getConstructor(Shell.class); - comp = con.newInstance(dialogShell); - } catch (Exception e1) { - Gui.showMessageBox(mainShell, "Cannot show popup " + clazz.getName(), MessageType.DEBUG, LOGGER, - e1); - return null; - } - - if (noclose) { - // Add listener that will cancel a close request via the X. - // (Some platforms don't allow disabling it via style, so this is used to be safe) - dialogShell.addListener(SWT.Close, new Listener() { - @Override - public void handleEvent(Event event) { - event.doit = false; - } - }); - } - - dialogShell.layout(); - dialogShell.pack(); - Gui.limitShellSize(dialogShell); - Gui.centerShellOverShell(mainShell, dialogShell); - dialogShell.open(); - return comp; + mainShell.validate(); } - public static void centerShell(Shell shell) { + public static void centerShell(Window shell) { Gui.centerShellOverShell(mainShell, shell); } @@ -133,13 +86,14 @@ public abstract class MainWindow { */ static { // init SWT stuff - mainShell = Gui.newShell(SWT.SHELL_TRIM | SWT.CENTER); + mainShell = new JFrame("bwLehrstuhl"); + mainShell.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // Catch the close button (X) - mainShell.addListener(SWT.Close, new Listener() { - public void handleEvent(Event event) { + mainShell.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { MainWindow.askApplicationQuit(); - event.doit = false; } }); @@ -154,8 +108,7 @@ public abstract class MainWindow { return Gui.syncExec(new GuiCallable<Boolean>() { @Override public Boolean run() { - return Gui.showMessageBox(mainShell, THRIFT_CONNECTION_ERROR, - MessageType.ERROR_RETRY, LOGGER, t); + return Gui.showMessageBox(THRIFT_CONNECTION_ERROR, MessageType.ERROR_RETRY, LOGGER, t); } }); } @@ -168,7 +121,7 @@ public abstract class MainWindow { Gui.asyncExec(new Runnable() { @Override public void run() { - showMessageBox("Konnte Programmeinstellungen nicht speichern", MessageType.WARNING, + Gui.showMessageBox("Konnte Programmeinstellungen nicht speichern", MessageType.WARNING, LOGGER, t); } }); @@ -176,23 +129,22 @@ public abstract class MainWindow { }); // Global key listener - Gui.display.addFilter(SWT.KeyDown, new Listener() { - @Override - public void handleEvent(Event event) { - if (event.character == 17) { // Ctrl-Q = Quit + KeyboardFocusManager.getCurrentKeyboardFocusManager() + .addKeyEventDispatcher(new KeyEventDispatcher() { + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + if (event.getKeyChar() == 17) { // Ctrl-Q = Quit askApplicationQuit(); - event.doit = false; + event.consume(); } } }); createMenu(); - mainShell.setText("bwSuite"); - // Set layout for the mainshell, items added to the shell should get a gridData - mainShell.setLayout(new GridLayout(1, true)); - mainShell.setMinimumSize(850, 650); + mainShell.setLayout(new BoxLayout(mainShell, BoxLayout.PAGE_AXIS)); + mainShell.setMinimumSize(new Dimension(850, 650)); // register all pages of the main window registerPage(new MainMenuWindow(mainShell)); @@ -205,7 +157,6 @@ public abstract class MainWindow { Gui.centerShell(mainShell); Gui.limitShellSize(mainShell); - mainShell.open(); // here we can check for Session information if (Session.getSatelliteToken() != null) { @@ -216,7 +167,7 @@ public abstract class MainWindow { // Session resume probably failed, show login window if (Session.getSatelliteToken() == null) { // User did not login, show the login mask - openPopup(LoginWindow.class, true, true); + LoginWindow.open(); } } @@ -226,7 +177,7 @@ public abstract class MainWindow { */ protected static void askApplicationQuit() { // TODO: Only ask if an upload or download is running,, wizard is open etc.. - if (showMessageBox("Are you sure you want to quit?", MessageType.QUESTION_YESNO, null, null)) { + if (Gui.showMessageBox("Are you sure you want to quit?", MessageType.QUESTION_YESNO, null, null)) { QuickTimer.cancel(); Gui.exit(0); } @@ -242,75 +193,48 @@ public abstract class MainWindow { if (pages.containsKey(clazz)) throw new IllegalArgumentException("Page " + clazz.getSimpleName() + " already registered!"); pages.put(clazz, window); - GridData gd = new GridData(GridData.FILL, GridData.FILL, true, true); - gd.exclude = true; - window.setLayoutData(gd); window.setVisible(false); } private static void createMenu() { // the File menu button - 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() { + JMenuBar menuBar = new JMenuBar(); + mainShell.setJMenuBar(menuBar); + + JMenu cascadeFileMenu = new JMenu("&File"); + menuBar.add(cascadeFileMenu); + + JMenuItem exitItem = new JMenuItem("&Exit"); + exitItem.addMouseListener(new MouseAdapter() { @Override - public void widgetSelected(SelectionEvent e) { + public void mousePressed(MouseEvent arg0) { askApplicationQuit(); } }); // the About menu button - MenuItem cascadeAboutMenu = new MenuItem(menuBar, SWT.CASCADE); - cascadeAboutMenu.setText("&About"); - - Menu aboutMenu = new Menu(mainShell, SWT.DROP_DOWN); - cascadeAboutMenu.setMenu(aboutMenu); + JMenu cascadeAboutMenu = new JMenu("&About"); + menuBar.add(cascadeAboutMenu); - MenuItem disclaimerItem = new MenuItem(aboutMenu, SWT.PUSH); - disclaimerItem.setText("&Disclaimer"); - disclaimerItem.addSelectionListener(new SelectionAdapter() { + JMenuItem disclaimerItem = new JMenuItem("&Disclaimer"); + disclaimerItem.addMouseListener(new MouseAdapter() { @Override - public void widgetSelected(SelectionEvent e) { - MainWindow.openPopup(DisclaimerWindow.class, false, false); + public void mousePressed(MouseEvent arg0) { + DisclaimerWindow.open(false); } }); - MenuItem virtualizerNoticeItem = new MenuItem(aboutMenu, SWT.PUSH); - virtualizerNoticeItem.setText("&Virtualizer"); - virtualizerNoticeItem.addSelectionListener(new SelectionAdapter() { + JMenuItem virtualizerNoticeItem = new JMenuItem("&Virtualizer"); + virtualizerNoticeItem.addMouseListener(new MouseAdapter() { @Override - public void widgetSelected(SelectionEvent e) { - MainWindow.openPopup(VirtualizerNoticeWindow.class, false, false); + public void mousePressed(MouseEvent arg0) { + VirtualizerNoticeWindow.open(false); } }); - mainShell.setMenuBar(menuBar); - } - - /** - * Generic helper to show a message box to the user, and optionally log the - * message to the log file. The main window will be the parent of the - * message box. - * - * @param message Message to display. Can be multiline. - * @param messageType Type of message (warning, information) - * @param logger Logger instance to log to. Can be null. - * @param exception Exception related to this message. Can be null. - * @return true if OK, YES or RETRY was clicked, false for CANCEL or NO - */ - public static boolean showMessageBox(String message, MessageType messageType, Logger logger, - Throwable exception) { - return Gui.showMessageBox(mainShell, message, messageType, logger, exception); } public static void open() { - mainShell.open(); + mainShell.setVisible(true); } } |