Class KeyBindings
java.lang.Object
com.realtime.crossfire.jxclient.gui.keybindings.KeyBindings
Manages a set of key bindings.
-
Constructor Summary
ConstructorsConstructorDescriptionKeyBindings(@Nullable Path fileVersion2, @Nullable Path fileVersion1, @NotNull GUICommandFactory guiCommandFactory) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddKeyBinding(@NotNull KeyEvent2 keyEvent, @NotNull CommandList cmdList, boolean isDefault) Adds a key binding for a key event.voiddeleteKeyBinding(@NotNull KeyEvent2 keyEvent) Removes a key binding for a key event.@NotNull Collection<KeyBinding>getBindings(@NotNull Predicate<KeyBinding> predicate) Returns all key bindings matching a given predicate.booleanhandleKeyPress(@NotNull KeyEvent2 e) Executes a "key press" event.voidLoads the key bindings from the given file.voidparseKeyBinding(@NotNull String line, boolean isDefault) Parses and add a key binding.voidSaves the key bindings to the given file.
-
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;nullto not load or savefileVersion1- the fallback file for loading the bindings iffileVersion2does not exist;nullto not loadguiCommandFactory- 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 bindingcmdList- the commands to associate to the key bindingisDefault- whether the key binding is a "default" binding which should not be saved
-
deleteKeyBinding
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 parseisDefault- whether the key binding is a "default" binding which should not be saved- Throws:
InvalidKeyBindingException- if the key binding is invalid
-
handleKeyPress
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
-