java.lang.Objectcom.realtime.crossfire.jxclient.gui.keybindings.KeyBindings
public class KeyBindings
Manages a set of key bindings.
| Field Summary | |
|---|---|
private CommandCallback |
commandCallback
The CommandCallback to use. |
private Commands |
commands
The commands instance for executing commands. |
private java.io.File |
file
The file for saving the bindings; null to not save. |
private java.util.Collection<KeyBinding> |
keybindings
The active key bindings. |
private KeyCodeMap |
keyCodeMap
The key code map to use. |
private Macros |
macros
The Macros instance to use. |
private boolean |
modified
Whether the contents of keybindings have been modified from the
last saved state. |
| Constructor Summary | |
|---|---|
KeyBindings(java.io.File file,
Commands commands,
CommandCallback commandCallback,
Macros macros)
Creates a new instance. |
|
| Method Summary | |
|---|---|
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(int keyCode,
int modifiers,
CommandList cmdList,
boolean isDefault)
Adds a key binding for a key code/modifiers pair. |
private void |
deleteKeyBinding(KeyBinding keyBinding)
Removes a key binding. |
void |
deleteKeyBindingAsKeyChar(char keyChar)
Removes a key binding for a key character. |
void |
deleteKeyBindingAsKeyCode(int keyCode,
int modifiers)
Removes a key binding for a key code/modifiers pair. |
private static boolean |
executeKeyBinding(KeyBinding keyBinding)
Executes a KeyBinding instance. |
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(int keyCode,
int modifiers)
Finds a key binding associated to a key code/modifiers pair. |
boolean |
handleKeyPress(java.awt.event.KeyEvent e)
Executes a "key press" event. |
boolean |
handleKeyTyped(java.awt.event.KeyEvent e)
Executes a "key typed" 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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
@NotNull private final CommandCallback commandCallback
CommandCallback to use.
@NotNull private final Commands commands
@Nullable private final java.io.File file
null to not save.
@NotNull private final java.util.Collection<KeyBinding> keybindings
@Nullable private KeyCodeMap keyCodeMap
null until first use.
@NotNull private final Macros macros
Macros instance to use.
private boolean modified
keybindings have been modified from the
last saved state.
| Constructor Detail |
|---|
public KeyBindings(@Nullable
java.io.File file,
@NotNull
Commands commands,
@NotNull
CommandCallback commandCallback,
@NotNull
Macros macros)
file - the file for saving the bindings; null to not
savecommands - the commands instance for executing commandscommandCallback - the command callback to usemacros - the macros instance to use| Method Detail |
|---|
private void addKeyBinding(@NotNull
KeyBinding keyBinding)
keyBinding - the key binding
public 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 saved
public void addKeyBindingAsKeyCode(int keyCode,
int modifiers,
@NotNull
CommandList cmdList,
boolean isDefault)
keyCode - the key code for the key bindingmodifiers - the modifiers 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
private void deleteKeyBinding(@Nullable
KeyBinding keyBinding)
keyBinding - the key binding; may be nullpublic void deleteKeyBindingAsKeyChar(char keyChar)
keyChar - the key character of the key binding
public void deleteKeyBindingAsKeyCode(int keyCode,
int modifiers)
keyCode - the key code of the key bindingmodifiers - the modifiers of the key binding
private static boolean executeKeyBinding(@Nullable
KeyBinding keyBinding)
KeyBinding instance.
keyBinding - the key binding to execute; may be null
keyBinding is not null@Nullable public java.io.File getFile()
null to not save.
@Nullable private KeyBinding getKeyBindingAsKeyChar(char keyChar)
keyChar - the key character to look up
null if no key binding is
associated
@Nullable
private KeyBinding getKeyBindingAsKeyCode(int keyCode,
int modifiers)
keyCode - the key code to look upmodifiers - the modifiers to look up
null if no key binding is
associated
public boolean handleKeyPress(@NotNull
java.awt.event.KeyEvent e)
e - the event to execute
public boolean handleKeyTyped(@NotNull
java.awt.event.KeyEvent e)
e - the event to execute
public void loadKeyBindings()
throws java.io.IOException
java.io.IOException - if the file cannot be read
public 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 saved
InvalidKeyBindingException - if the key binding is invalid
public void saveKeyBindings()
throws java.io.IOException
java.io.IOException - if the file cannot be written