public class KeyBindings
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.io.File |
file
The file for saving the bindings;
null to not save. |
private GUICommandFactory |
guiCommandFactory
The
GUICommandFactory for creating commands. |
private java.util.Collection<KeyBinding> |
keybindings
The active key bindings.
|
private KeyCodeMap |
keyCodeMap
The key code map to use.
|
private boolean |
modified
Whether the contents of
keybindings have been modified from the
last saved state. |
Constructor and Description |
---|
KeyBindings(java.io.File file,
GUICommandFactory guiCommandFactory)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
private void |
addKeyBinding(KeyBinding keyBinding)
Adds (or replace) a key binding.
|
void |
addKeyBindingAsKeyChar(char keyChar,
CommandList cmdList,
boolean isDefault)
Adds a key binding for a key character.
|
void |
addKeyBindingAsKeyCode(KeyEvent2 keyEvent,
CommandList cmdList,
boolean isDefault)
Adds a key binding for a key code/modifiers pair.
|
private void |
deleteKeyBinding(KeyBinding keyBinding)
Removes a key binding.
|
void |
deleteKeyBindingAsKeyCode(KeyEvent2 keyEvent)
Removes a key binding for a key code/modifiers pair.
|
private static void |
executeKeyBinding(KeyBinding keyBinding)
Executes a
KeyBinding instance. |
java.util.Collection<KeyBinding> |
getBindingsForPartialCommand(java.lang.String command,
boolean startOnly)
Search bindings having a command text starting with the specified value.
|
java.io.File |
getFile()
Returns the file for saving the bindings;
null to not save. |
private KeyBinding |
getKeyBindingAsKeyChar(char keyChar)
Finds a key binding associated to a key character.
|
private KeyBinding |
getKeyBindingAsKeyCode(KeyEvent2 keyEvent)
Finds a key binding associated to a key code/modifiers pair.
|
boolean |
handleKeyPress(KeyEvent2 e)
Executes a "key press" event.
|
void |
loadKeyBindings()
Loads the key bindings from the given file.
|
void |
parseKeyBinding(java.lang.String line,
boolean isDefault)
Parses and add a key binding.
|
void |
saveKeyBindings()
Saves the key bindings to the given file.
|
@Nullable private final java.io.File file
null
to not save.@NotNull private final GUICommandFactory guiCommandFactory
GUICommandFactory
for creating commands.@NotNull private final java.util.Collection<KeyBinding> keybindings
@Nullable private KeyCodeMap keyCodeMap
null
until first use.private boolean modified
keybindings
have been modified from the
last saved state.public KeyBindings(@Nullable java.io.File file, @NotNull GUICommandFactory guiCommandFactory)
file
- the file for saving the bindings; null
to not saveguiCommandFactory
- the gui command factory for creating commandsprivate void addKeyBinding(@NotNull KeyBinding keyBinding)
keyBinding
- the key bindingpublic void addKeyBindingAsKeyChar(char keyChar, @NotNull CommandList cmdList, boolean isDefault)
keyChar
- the key character 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 addKeyBindingAsKeyCode(@NotNull KeyEvent2 keyEvent, @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 savedprivate void deleteKeyBinding(@Nullable KeyBinding keyBinding)
keyBinding
- the key binding; may be null
public void deleteKeyBindingAsKeyCode(@NotNull KeyEvent2 keyEvent)
keyEvent
- the key of the key bindingprivate static void executeKeyBinding(@NotNull KeyBinding keyBinding)
KeyBinding
instance.keyBinding
- the key binding to execute; may be null
@NotNull public java.util.Collection<KeyBinding> getBindingsForPartialCommand(@NotNull java.lang.String command, boolean startOnly)
command
- the text to search forstartOnly
- if true only search the text at the start of the
command, else anywhere.@Nullable public java.io.File getFile()
null
to not save.@Nullable private KeyBinding getKeyBindingAsKeyChar(char keyChar)
keyChar
- the key character to look upnull
if no key binding is associated@Nullable private KeyBinding getKeyBindingAsKeyCode(KeyEvent2 keyEvent)
keyEvent
- the key to look upnull
if no key binding is associatedpublic boolean handleKeyPress(@NotNull KeyEvent2 e)
e
- the event to executepublic void loadKeyBindings() throws java.io.IOException
java.io.IOException
- if the file cannot be readpublic void parseKeyBinding(@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 void saveKeyBindings() throws java.io.IOException
java.io.IOException
- if the file cannot be written