Class KeyBindings
- java.lang.Object
-
- com.realtime.crossfire.jxclient.gui.keybindings.KeyBindings
-
public class KeyBindings extends java.lang.ObjectManages 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddKeyBindingAsKeyCode(@NotNull KeyEvent2 keyEvent, @NotNull CommandList cmdList, boolean isDefault)Adds a key binding for a key code/modifiers pair.voiddeleteKeyBindingAsKeyCode(@NotNull KeyEvent2 keyEvent)Removes a key binding for a key code/modifiers pair.@NotNull java.util.Collection<KeyBinding>getBindingsForPartialCommand(@NotNull java.lang.String command, boolean startOnly)Search bindings having a command text starting with the specified value.booleanhandleKeyPress(@NotNull KeyEvent2 e)Executes a "key press" event.voidloadKeyBindings()Loads the key bindings from the given file.voidparseKeyBinding(@NotNull java.lang.String line, boolean isDefault)Parses and add a key binding.voidsaveKeyBindings()Saves the key bindings to the given file.
-
-
-
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;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 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 bindingcmdList- the commands to associate to the key bindingisDefault- 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 InvalidKeyBindingExceptionParses 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
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 forstartOnly- if true only search the text at the start of the command, else anywhere.- Returns:
- the matching bindings
-
-