diff options
| author | Simon Rettberg | 2015-08-07 19:00:14 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2015-08-07 19:00:14 +0200 |
| commit | f688a4a1f888030155b20331c83e36d5c4958bf3 (patch) | |
| tree | d8b7785fd205a7d4f081c881cce004e63359e7c5 /dozentenmodul/src/main/java | |
| parent | [client] More work in ImageDetailsWindow (diff) | |
| download | tutor-module-f688a4a1f888030155b20331c83e36d5c4958bf3.tar.gz tutor-module-f688a4a1f888030155b20331c83e36d5c4958bf3.tar.xz tutor-module-f688a4a1f888030155b20331c83e36d5c4958bf3.zip | |
[client] Add UiFeedback interface for top level windows
Diffstat (limited to 'dozentenmodul/src/main/java')
3 files changed, 51 insertions, 3 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 295cf413..600f6a1e 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -34,6 +34,7 @@ import org.openslx.dozmod.gui.activity.UploadPanel; import org.openslx.dozmod.gui.helper.CompositePage; import org.openslx.dozmod.gui.helper.DebugWindow; import org.openslx.dozmod.gui.helper.MessageType; +import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.gui.window.DisclaimerWindow; import org.openslx.dozmod.gui.window.ImageListWindow; import org.openslx.dozmod.gui.window.LectureListWindow; @@ -170,12 +171,20 @@ public abstract class MainWindow { KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent event) { - if (event.getKeyChar() == 17) { // Ctrl-Q = Quit - if (!isQuitQuestionOpen) { + int type = event.getID(); + int code = event.getKeyChar(); + if (code == 17) { // Ctrl-Q = Quit + if (type == KeyEvent.KEY_RELEASED && !isQuitQuestionOpen) { isQuitQuestionOpen = true; askApplicationQuit(); } event.consume(); + } else if (code == 27 && type == KeyEvent.KEY_PRESSED) { + Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); + if (window instanceof UiFeedback) { + ((UiFeedback) window).escapePressed(); + event.consume(); + } } return event.isConsumed(); } @@ -248,6 +257,12 @@ public abstract class MainWindow { break; } } + if (!open) { + Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); + if (window instanceof UiFeedback) { + open = ((UiFeedback) window).wantConfirmQuit(); + } + } if (!open || Gui.showMessageBox(mainWindow, "Are you sure you want to quit?", MessageType.QUESTION_YESNO, null, null)) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/UiFeedback.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/UiFeedback.java new file mode 100644 index 00000000..f7216692 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/UiFeedback.java @@ -0,0 +1,20 @@ +package org.openslx.dozmod.gui.helper; + +public interface UiFeedback { + + /** + * If this window wants to prevent the user from closing the application, + * it should return true. This makes the application ask the user to confirm + * quitting. + * + * @return true to ask the user for confirmation + */ + public boolean wantConfirmQuit(); + + /** + * Called if the user pressed the ESC key and the window currently has + * the focus. + */ + public void escapePressed(); + +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java index 30e86f37..a1cda92f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java @@ -19,6 +19,7 @@ import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.MainWindow; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.helper.PopupMenu; +import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.gui.window.layout.ImageDetailsWindowLayout; import org.openslx.dozmod.permissions.ImagePerms; import org.openslx.dozmod.thrift.MetaDataCache; @@ -30,7 +31,7 @@ import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; @SuppressWarnings("serial") -public class ImageDetailsWindow extends ImageDetailsWindowLayout { +public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFeedback { private static final Logger LOGGER = Logger.getLogger(ImageDetailsWindow.class); @@ -229,4 +230,16 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout { win.setImage(imageBaseId); } + @Override + public boolean wantConfirmQuit() { + // Maybe return true if the user changed one of the fields, but not really a priority + return false; + } + + @Override + public void escapePressed() { + // Also ask if applicable + this.dispose(); + } + } |
