jwars.control
Class InputManager

public class InputManager
implements java.awt.event.KeyListener, java.awt.event.FocusListener, jwars.gui.TextParser
Contains a collection of commands, each of which may be invoked by means of a supplying its identifying String or, if a key is bound to that command, by pressing the appropriate key when a window which uses this WarController as a KeyListener has focus. That component should add this WarController as FocusListener as well. This is to ensure that commands which are meant to be repeated as long as the corresponding key is down will stop repeating when the component loses focus.
Field Detail

keyCommands

private jwars.control.InputManager$KeyTrackEvent[] keyCommands
The keycodes corresponding to standard keyboard input are all between 0 and 255, and thus we can let them be in an array of length 256

consoleCommands

private java.util.HashMap consoleCommands
Dictionary of registered events.

Constructor Detail

InputManager

public InputManager(jwars.event.SynchronizedQueue instantQueue)
Create a WarController using the specified queue manager.
Parameters:
qm - QueueManager

Method Detail

put

public void put(java.lang.String name,
                int keyCode,
                jwars.control.InputManager$KeyTrackEvent event)
Store and associate specified event with name and key code. The event will be executed when either name or key code are received through the parse and keyPressed methods of this WarController.
Parameters:
name - String
keyCode - int
event - Event

put

public void put(java.lang.String name,
                jwars.event.Event event)
Store and associate specified event with a name. The event will be executed when the name is received through the parse method of this WarController.
Parameters:
name - String
event - Event

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Fetch the command associated with the key code of argument event and schedule it for immediate execution
Parameters:
e - KeyEvent

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Ensures that the command corresponding to the code of the argument KeyEvent is no longer to be executed.
Parameters:
e - KeyEvent

parse

public java.lang.String parse(java.lang.String s)
Fetch the command associated with the argument String and schedule it for immediate execution, or, if no command is associated with arguement String, pass the String to a StringSerializer.
Parameters:
s - String

focusLost

public void focusLost(java.awt.event.FocusEvent e)
When losing focus, release keys
Parameters:
focusEvent - FocusEvent

setOut

public void setOut(java.io.PrintWriter out)
Sets the PrintWriter to which this WarController passes text which is received from a network. This funcionality may be moved to another class at some time.
Parameters:
out - PrintWriter