public class KeyBindings
extends java.lang.Object
Constructor and Description |
---|
KeyBindings(@Nullable java.nio.file.Path fileVersion2,
@Nullable java.nio.file.Path fileVersion1,
@NotNull GUICommandFactory guiCommandFactory)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addKeyBinding(@NotNull KeyEvent2 keyEvent,
@NotNull CommandList cmdList,
boolean isDefault)
Adds a key binding for a key event.
|
void |
deleteKeyBinding(@NotNull KeyEvent2 keyEvent)
Removes a key binding for a key event.
|
@NotNull java.util.Collection<KeyBinding> |
getBindings(@NotNull java.util.function.Predicate<KeyBinding> predicate)
Returns all key bindings matching a given predicate.
|
boolean |
handleKeyPress(@NotNull KeyEvent2 e)
Executes a "key press" event.
|
void |
loadKeyBindings()
Loads the key bindings from the given file.
|
void |
parseKeyBinding(@NotNull java.lang.String line,
boolean isDefault)
Parses and add a key binding.
|
void |
saveKeyBindings()
Saves the key bindings to the given file.
|
public KeyBindings(@Nullable @Nullable java.nio.file.Path fileVersion2, @Nullable @Nullable java.nio.file.Path fileVersion1, @NotNull @NotNull GUICommandFactory guiCommandFactory)
fileVersion2
- the file for loading and saving the bindings;
null
to not load or savefileVersion1
- the fallback file for loading the bindings if
fileVersion2
does not exist; null
to not loadguiCommandFactory
- the gui command factory for creating commandspublic void addKeyBinding(@NotNull @NotNull KeyEvent2 keyEvent, @NotNull @NotNull CommandList cmdList, boolean isDefault)
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 savedpublic void deleteKeyBinding(@NotNull @NotNull KeyEvent2 keyEvent)
keyEvent
- the key of the key bindingpublic void loadKeyBindings()
public void saveKeyBindings()
public void parseKeyBinding(@NotNull @NotNull java.lang.String line, boolean isDefault) throws InvalidKeyBindingException
line
- the key binding to parseisDefault
- whether the key binding is a "default" binding which
should not be savedInvalidKeyBindingException
- if the key binding is invalidpublic boolean handleKeyPress(@NotNull @NotNull KeyEvent2 e)
e
- the event to execute@NotNull public @NotNull java.util.Collection<KeyBinding> getBindings(@NotNull @NotNull java.util.function.Predicate<KeyBinding> predicate)
predicate
- the predicate for selecting keybindings