diff --git a/client/src/main/java/envoy/client/data/shortcuts/EnvoyShortcutConfig.java b/client/src/main/java/envoy/client/data/shortcuts/EnvoyShortcutConfig.java index fe5db8f..14a110c 100644 --- a/client/src/main/java/envoy/client/data/shortcuts/EnvoyShortcutConfig.java +++ b/client/src/main/java/envoy/client/data/shortcuts/EnvoyShortcutConfig.java @@ -26,7 +26,8 @@ public class EnvoyShortcutConfig { public static void initializeEnvoyShortcuts() { final var instance = GlobalKeyShortcuts.getInstance(); - // Add the option to exit Linux-like with "Control" + "Q" or "Alt" + "F4" + // Add the option to exit with "Control" + "Q" or "Alt" + "F4" as offered by + // some desktop environments instance.add(new KeyCodeCombination(KeyCode.Q, KeyCombination.CONTROL_DOWN), ShutdownHelper::exit); // Add the option to logout using "Control"+"Shift"+"L" if not in login scene diff --git a/client/src/main/java/envoy/client/data/shortcuts/GlobalKeyShortcuts.java b/client/src/main/java/envoy/client/data/shortcuts/GlobalKeyShortcuts.java index b1f2e0b..c3643ee 100644 --- a/client/src/main/java/envoy/client/data/shortcuts/GlobalKeyShortcuts.java +++ b/client/src/main/java/envoy/client/data/shortcuts/GlobalKeyShortcuts.java @@ -1,64 +1,26 @@ package envoy.client.data.shortcuts; import java.util.*; -import java.util.Map.Entry; import javafx.scene.input.KeyCombination; import envoy.client.ui.SceneContext.SceneInfo; /** - * Contains all KeyBoardshotcuts used throughout the application. + * Contains all keyboard shortcuts used throughout the application. * * @author Leon Hofmeister * @since Envoy Client v0.3-beta */ public final class GlobalKeyShortcuts { - /** - * Helper class for the Entry interface. - * - * @author Leon Hofmeister - * @since Envoy Client v0.3-beta - */ - public final class KeyCombinationAction implements Entry { - - private final KeyCombination keys; - private final Runnable action; - - /** - * Creates a new {@code KeyCombinationAction}. - * - * @param keys the keys to press to perform the given action - * @param action the action to perform - * @since Envoy Client v0.3-beta - */ - public KeyCombinationAction(KeyCombination keys, Runnable action) { - if (keys == null || action == null) throw new NullPointerException("Cannot create key combination action"); - this.keys = keys; - this.action = action; - } - - @Override - public KeyCombination getKey() { return keys; } - - @Override - public Runnable getValue() { return action; } - - @Override - public Runnable setValue(Runnable none) { - throw new UnsupportedOperationException("Reassignment of keyboard shortcut actions is not supported"); - } - - } - - private final EnumMap> shortcuts = new EnumMap<>(SceneInfo.class); + private final EnumMap> shortcuts = new EnumMap<>(SceneInfo.class); private static GlobalKeyShortcuts instance = new GlobalKeyShortcuts(); private GlobalKeyShortcuts() { for (final var sceneInfo : SceneInfo.values()) - shortcuts.put(sceneInfo, new HashSet()); + shortcuts.put(sceneInfo, new HashMap()); } /** @@ -74,10 +36,7 @@ public final class GlobalKeyShortcuts { * @param action the action to perform * @since Envoy Client v0.3-beta */ - public void add(KeyCombination keys, Runnable action) { - final var keyCombinationAction = new KeyCombinationAction(keys, action); - shortcuts.values().forEach(collection -> collection.add(keyCombinationAction)); - } + public void add(KeyCombination keys, Runnable action) { shortcuts.values().forEach(collection -> collection.put(keys, action)); } /** * Adds the given keyboard shortcut and its action to all scenes that are not @@ -102,17 +61,16 @@ public final class GlobalKeyShortcuts { } // Adding the action to the remaining sceneInfos - final var keyCombinationAction = new KeyCombinationAction(keys, action); for (final var sceneInfo : include) - shortcuts.get(sceneInfo).add(keyCombinationAction); + shortcuts.get(sceneInfo).put(keys, action); } /** - * Returns all stored keyboard shortcuts for the given scene constant + * Returns all stored keyboard shortcuts for the given scene constant. * * @param sceneInfo the currently loading scene * @return all stored keyboard shortcuts for this scene * @since Envoy Client v0.3-beta */ - public Collection getKeyboardShortcuts(SceneInfo sceneInfo) { return shortcuts.get(sceneInfo); } + public Map getKeyboardShortcuts(SceneInfo sceneInfo) { return shortcuts.get(sceneInfo); } } diff --git a/client/src/main/java/envoy/client/data/shortcuts/KeyboardMapping.java b/client/src/main/java/envoy/client/data/shortcuts/KeyboardMapping.java index f98c055..4d56f8e 100644 --- a/client/src/main/java/envoy/client/data/shortcuts/KeyboardMapping.java +++ b/client/src/main/java/envoy/client/data/shortcuts/KeyboardMapping.java @@ -8,9 +8,9 @@ import envoy.client.ui.SceneContext; /** * Provides methods to set the keyboard shortcuts for a specific scene. - * Should only be implemented by Controllers of Scenes so that these methods can + * Should only be implemented by controllers of scenes so that these methods can * automatically be called inside {@link SceneContext} as soon - * as the underlying fxml file has been loaded. + * as the underlying FXML file has been loaded. * * @author Leon Hofmeister * @since Envoy Client v0.3-beta diff --git a/client/src/main/java/envoy/client/ui/SceneContext.java b/client/src/main/java/envoy/client/ui/SceneContext.java index eb790c4..70bb662 100644 --- a/client/src/main/java/envoy/client/ui/SceneContext.java +++ b/client/src/main/java/envoy/client/ui/SceneContext.java @@ -106,8 +106,7 @@ public final class SceneContext implements EventListener { stage.setScene(scene); // Supply the global custom keyboard shortcuts for that scene - for (final var shortcut : GlobalKeyShortcuts.getInstance().getKeyboardShortcuts(sceneInfo)) - scene.getAccelerators().put(shortcut.getKey(), shortcut.getValue()); + scene.getAccelerators().putAll(GlobalKeyShortcuts.getInstance().getKeyboardShortcuts(sceneInfo)); // Supply the scene specific keyboard shortcuts if (controller instanceof KeyboardMapping) scene.getAccelerators().putAll(((KeyboardMapping) controller).getKeyboardShortcuts()); diff --git a/client/src/main/java/envoy/client/ui/Startup.java b/client/src/main/java/envoy/client/ui/Startup.java index 391baa7..a93bf81 100644 --- a/client/src/main/java/envoy/client/ui/Startup.java +++ b/client/src/main/java/envoy/client/ui/Startup.java @@ -85,7 +85,7 @@ public final class Startup extends Application { stage.setTitle("Envoy"); stage.getIcons().add(IconUtil.loadIcon("envoy_logo")); - // Configure global shortcuts used + // Configure global shortcuts EnvoyShortcutConfig.initializeEnvoyShortcuts(); // Create scene context diff --git a/client/src/main/java/envoy/client/ui/controller/SettingsScene.java b/client/src/main/java/envoy/client/ui/controller/SettingsScene.java index 13f97e4..7a471e6 100644 --- a/client/src/main/java/envoy/client/ui/controller/SettingsScene.java +++ b/client/src/main/java/envoy/client/ui/controller/SettingsScene.java @@ -1,6 +1,6 @@ package envoy.client.ui.controller; -import java.util.*; +import java.util.Map; import javafx.fxml.FXML; import javafx.scene.control.*; @@ -45,8 +45,6 @@ public final class SettingsScene implements KeyboardMapping { @Override public Map getKeyboardShortcuts() { - final var map = new HashMap(); - map.put(new KeyCodeCombination(KeyCode.B, KeyCombination.CONTROL_DOWN), this::backButtonClicked); - return map; + return Map.of(new KeyCodeCombination(KeyCode.B, KeyCombination.CONTROL_DOWN), this::backButtonClicked); } }