de.matthiasmann.twl
Class InputMap

java.lang.Object
  extended by de.matthiasmann.twl.InputMap

public final class InputMap
extends java.lang.Object

A immutable InputMap class. It maps key strokes to action names.


Method Summary
 InputMap addKeyStroke(KeyStroke keyStroke)
          Creates a new InputMap containing both the current and the new KeyStroke.
 InputMap addKeyStrokes(InputMap map)
          Creates a new InputMap containing both the current and the new KeyStrokes from another InputMap.
 InputMap addKeyStrokes(java.util.LinkedHashSet<KeyStroke> newKeyStrokes)
          Creates a new InputMap containing both the current and the new KeyStrokes.
static InputMap empty()
          Returns an empty input mapping
 KeyStroke[] getKeyStrokes()
          Returns all key strokes in this InputMap.
 java.lang.String mapEvent(Event event)
          Maps the given key event to an action.
static InputMap parse(java.net.URL url)
          Parses a stand alone <inputMapDef> XML file
static java.util.LinkedHashSet<KeyStroke> parseBody(XMLParser xmlp)
          Parses the child elemets of the current XML tag as input map.
 InputMap removeKeyStrokes(java.util.Set<KeyStroke> keyStrokes)
          Remove key strokes from this mapping
 void writeXML(java.io.OutputStream os)
          Writes this input map into a XML file which can be parsed by parse(java.net.URL).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

mapEvent

public java.lang.String mapEvent(Event event)
Maps the given key event to an action.

Parameters:
event - the key event
Returns:
the action or null if no mapping was found

addKeyStrokes

public InputMap addKeyStrokes(java.util.LinkedHashSet<KeyStroke> newKeyStrokes)
Creates a new InputMap containing both the current and the new KeyStrokes. If the new key strokes contain already mapped key strokes then the new mappings will replace the old mappings.

Parameters:
newKeyStrokes - the new key strokes.
Returns:
the InputMap containing the resulting mapping

addKeyStrokes

public InputMap addKeyStrokes(InputMap map)
Creates a new InputMap containing both the current and the new KeyStrokes from another InputMap. If the new key strokes contain already mapped key strokes then the new mappings will replace the old mappings.

Parameters:
map - the other InputMap containing the new key strokes.
Returns:
the InputMap containing the resulting mapping

addKeyStroke

public InputMap addKeyStroke(KeyStroke keyStroke)
Creates a new InputMap containing both the current and the new KeyStroke. If the specified key stroke is already mapped then the new mapping will replace the old mapping.

Parameters:
keyStroke - the new key stroke.
Returns:
the InputMap containing the resulting mapping

removeKeyStrokes

public InputMap removeKeyStrokes(java.util.Set<KeyStroke> keyStrokes)
Remove key strokes from this mapping

Parameters:
keyStrokes - the key strokes to remove
Returns:
the InputMap containing the resulting mapping

getKeyStrokes

public KeyStroke[] getKeyStrokes()
Returns all key strokes in this InputMap.

Returns:
all key strokes in this InputMap.

empty

public static InputMap empty()
Returns an empty input mapping

Returns:
an empty input mapping

parse

public static InputMap parse(java.net.URL url)
                      throws java.io.IOException
Parses a stand alone <inputMapDef> XML file

Parameters:
url - the URL ton the XML file
Returns:
the parsed key strokes
Throws:
java.io.IOException - if an IO related error occured

writeXML

public void writeXML(java.io.OutputStream os)
              throws java.io.IOException
Writes this input map into a XML file which can be parsed by parse(java.net.URL). The encoding is UTF8

Parameters:
os - the output where the XML will be written to
Throws:
java.io.IOException - if an IO error occured
See Also:
parse(java.net.URL)

parseBody

public static java.util.LinkedHashSet<KeyStroke> parseBody(XMLParser xmlp)
                                                    throws org.xmlpull.v1.XmlPullParserException,
                                                           java.io.IOException
Parses the child elemets of the current XML tag as input map. This method is only public so that it can be called from ThemeManager.

Parameters:
xmlp - the XML parser
Returns:
the found key strokes
Throws:
org.xmlpull.v1.XmlPullParserException - if a parser error occured
java.io.IOException - if an IO error occured