com.realtime.crossfire.jxclient.window
Class KeybindingsManager

java.lang.Object
  extended by com.realtime.crossfire.jxclient.window.KeybindingsManager

public class KeybindingsManager
extends java.lang.Object

Manages key bindings.


Field Summary
private  KeyBindings characterKeyBindings
          The key bindings for the current user.
private  CommandCallback commandCallback
          The CommandCallback to use.
private  Commands commands
          The commands instance to use.
private  KeyBindings keyBindings
          The global key bindings.
private  KeyBindingState keyBindingState
          The current key binding state.
private  Macros macros
          The Macros instance to use.
 
Constructor Summary
KeybindingsManager(Commands commands, CommandCallback commandCallback, Macros macros)
          Creates a new instance.
 
Method Summary
 boolean createKeyBinding(boolean perCharacter, CommandList cmdList)
          Starts creating a new key binding.
 boolean escPressed()
          Processes a pressed ESC key.
private  KeyBindings getKeyBindings(boolean perCharacter)
          Returns the active key bindings.
 boolean handleKeyPress(java.awt.event.KeyEvent e)
          Processes a key pressed event.
 boolean handleKeyTyped(java.awt.event.KeyEvent e)
          Processes a key typed event.
 boolean keyPressed(int keyCode, int modifiers)
          Processes a key pressed event.
 boolean keyReleased()
          Processes a key released event.
 boolean keyTyped(char keyChar)
          Processes a key typed event.
 void loadKeybindings()
          Loads the key bindings from the backing file.
 void loadPerCharacterBindings(java.lang.CharSequence hostname, java.lang.CharSequence character)
          Loads the per-character key bindings.
 boolean removeKeyBinding(boolean perCharacter)
          Starts to remove a key binding.
 void saveKeybindings()
          Saves the key bindings to the backing file.
 void unloadPerCharacterBindings()
          Unloads (clears and saves) the per-character key bindings.
 boolean windowClosing()
          Should be called when the main window is closing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

characterKeyBindings

@Nullable
private KeyBindings characterKeyBindings
The key bindings for the current user. Set to null if no user is logged in.


commandCallback

@NotNull
private final CommandCallback commandCallback
The CommandCallback to use.


commands

@NotNull
private final Commands commands
The commands instance to use.


keyBindings

@NotNull
private final KeyBindings keyBindings
The global key bindings.


keyBindingState

@Nullable
private KeyBindingState keyBindingState
The current key binding state. Set to null if no key binding dialog is active.


macros

@NotNull
private final Macros macros
The Macros instance to use.

Constructor Detail

KeybindingsManager

public KeybindingsManager(@NotNull
                          Commands commands,
                          @NotNull
                          CommandCallback commandCallback,
                          @NotNull
                          Macros macros)
Creates a new instance.

Parameters:
commands - the commands instance to use
commandCallback - the command callback to use
macros - the macros instance to use
Method Detail

createKeyBinding

public boolean createKeyBinding(boolean perCharacter,
                                @NotNull
                                CommandList cmdList)
Starts creating a new key binding.

Parameters:
perCharacter - whether a per-character key bindings should be created
cmdList - the commands for the key binding
Returns:
whether the key bindings dialog should be opened

escPressed

public boolean escPressed()
Processes a pressed ESC key.

Returns:
whether the event has been consumed and the key bindings dialog should be closed

getKeyBindings

@Nullable
private KeyBindings getKeyBindings(boolean perCharacter)
Returns the active key bindings.

Parameters:
perCharacter - if set, return the per-character key bindings; else return the global bindings
Returns:
the key bindings or null if no per-character bindings exist because no character is logged in

handleKeyPress

public boolean handleKeyPress(@NotNull
                              java.awt.event.KeyEvent e)
Processes a key pressed event.

Parameters:
e - the key event
Returns:
whether the event has been consumed

handleKeyTyped

public boolean handleKeyTyped(@NotNull
                              java.awt.event.KeyEvent e)
Processes a key typed event.

Parameters:
e - the key event
Returns:
whether the event has been consumed

keyPressed

public boolean keyPressed(int keyCode,
                          int modifiers)
Processes a key pressed event.

Parameters:
keyCode - the character code of the key event
modifiers - the modifiers of the key event
Returns:
whether the event has been consumed

keyReleased

public boolean keyReleased()
Processes a key released event.

Returns:
whether the event has been consumed

keyTyped

public boolean keyTyped(char keyChar)
Processes a key typed event.

Parameters:
keyChar - the character information of the key event
Returns:
whether the event has been consumed

loadKeybindings

public void loadKeybindings()
Loads the key bindings from the backing file.


loadPerCharacterBindings

public void loadPerCharacterBindings(@NotNull
                                     java.lang.CharSequence hostname,
                                     @NotNull
                                     java.lang.CharSequence character)
Loads the per-character key bindings. This function should be called when a character logs in.

Parameters:
hostname - the character's hostname
character - the character's name

removeKeyBinding

public boolean removeKeyBinding(boolean perCharacter)
Starts to remove a key binding.

Parameters:
perCharacter - whether a per-character key binding should be removed
Returns:
whether the key bindings dialog should be opened

saveKeybindings

public void saveKeybindings()
Saves the key bindings to the backing file.


unloadPerCharacterBindings

public void unloadPerCharacterBindings()
Unloads (clears and saves) the per-character key bindings. This function should be called when a character logs out.


windowClosing

public boolean windowClosing()
Should be called when the main window is closing.

Returns:
whether the key bindings dialog should be closed