Class KeyBindings


  • public class KeyBindings
    extends java.lang.Object
    Manages a set of key bindings.
    • Constructor Summary

      Constructors 
      Constructor Description
      KeyBindings​(@Nullable java.nio.file.Path fileVersion2, @Nullable java.nio.file.Path fileVersion1, @NotNull GUICommandFactory guiCommandFactory)
      Creates a new instance.
    • Constructor Detail

      • KeyBindings

        public KeyBindings​(@Nullable
                           @Nullable java.nio.file.Path fileVersion2,
                           @Nullable
                           @Nullable java.nio.file.Path fileVersion1,
                           @NotNull
                           @NotNull GUICommandFactory guiCommandFactory)
        Creates a new instance.
        Parameters:
        fileVersion2 - the file for loading and saving the bindings; null to not load or save
        fileVersion1 - the fallback file for loading the bindings if fileVersion2 does not exist; null to not load
        guiCommandFactory - the gui command factory for creating commands
    • Method Detail

      • addKeyBindingAsKeyCode

        public void addKeyBindingAsKeyCode​(@NotNull
                                           @NotNull KeyEvent2 keyEvent,
                                           @NotNull
                                           @NotNull CommandList cmdList,
                                           boolean isDefault)
        Adds a key binding for a key code/modifiers pair.
        Parameters:
        keyEvent - the key event for the key binding
        cmdList - the commands to associate to the key binding
        isDefault - whether the key binding is a "default" binding which should not be saved
      • deleteKeyBindingAsKeyCode

        public void deleteKeyBindingAsKeyCode​(@NotNull
                                              @NotNull KeyEvent2 keyEvent)
        Removes a key binding for a key code/modifiers pair.
        Parameters:
        keyEvent - the key of the key binding
      • loadKeyBindings

        public void loadKeyBindings()
        Loads the key bindings from the given file. If the file cannot be loaded, a warning message is printed.
      • saveKeyBindings

        public void saveKeyBindings()
        Saves the key bindings to the given file. If the file cannot be written, a warning message is printed and the modified flag remains set.
      • parseKeyBinding

        public void parseKeyBinding​(@NotNull
                                    @NotNull java.lang.String line,
                                    boolean isDefault)
                             throws InvalidKeyBindingException
        Parses and add a key binding.
        Parameters:
        line - the key binding to parse
        isDefault - whether the key binding is a "default" binding which should not be saved
        Throws:
        InvalidKeyBindingException - if the key binding is invalid
      • handleKeyPress

        public boolean handleKeyPress​(@NotNull
                                      @NotNull KeyEvent2 e)
        Executes a "key press" event.
        Parameters:
        e - the event to execute
        Returns:
        whether a matching key binding was found
      • getBindingsForPartialCommand

        @NotNull
        public @NotNull java.util.Collection<KeyBinding> getBindingsForPartialCommand​(@NotNull
                                                                                      @NotNull java.lang.String command,
                                                                                      boolean startOnly)
        Search bindings having a command text starting with the specified value.
        Parameters:
        command - the text to search for
        startOnly - if true only search the text at the start of the command, else anywhere.
        Returns:
        the matching bindings