java.lang.Object
com.realtime.crossfire.jxclient.gui.keybindings.KeyBindings

public class KeyBindings extends Object
Manages a set of key bindings.
  • Constructor Details

    • KeyBindings

      public KeyBindings(@Nullable @Nullable Path fileVersion2, @Nullable @Nullable 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 Details

    • addKeyBinding

      public void addKeyBinding(@NotNull @NotNull KeyEvent2 keyEvent, @NotNull @NotNull CommandList cmdList, boolean isDefault)
      Adds a key binding for a key event.
      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
    • deleteKeyBinding

      public void deleteKeyBinding(@NotNull @NotNull KeyEvent2 keyEvent)
      Removes a key binding for a key event.
      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 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
    • getBindings

      @NotNull public @NotNull Collection<KeyBinding> getBindings(@NotNull @NotNull Predicate<KeyBinding> predicate)
      Returns all key bindings matching a given predicate.
      Parameters:
      predicate - the predicate for selecting keybindings
      Returns:
      the matching bindings