chooser
Enum Persistence

java.lang.Object
  extended by java.lang.Enum<Persistence>
      extended by chooser.Persistence
All Implemented Interfaces:
Serializable, Comparable<Persistence>

public enum Persistence
extends Enum<Persistence>

Convenience methods providing a quick means of loading and saving keybindings. None preserve disabled mappings. The formats provided are as follows:
SERIAL_HASH- Serialized hash map of bindings. Ordering is preserved if available.
SERIAL_INPUT- Serialized input map of bindings.
PROPERTIES_PAIR- Persistence provided by java.util.Properties using plain text key/value pairs.
PROPERTIES_XML- Persistence provided by java.util.Properties using its XML format.

Version:
September 21, 2007
Author:
Damian Johnson (atagar1@gmail.com)

Enum Constant Summary
PROPERTIES_PAIRS
           
PROPERTIES_XML
           
SERIAL_HASH
           
SERIAL_INPUT
           
 
Method Summary
static Persistence fromString(String str)
          Returns the enum representation of a string.
 String getOutput(Map<KeyStroke,String> bindings)
          Provides the textual output of what this persistence format would save given a set of bindings.
 LinkedHashMap<KeyStroke,String> load(InputStream input)
          Attempts to load this type of persistent keystroke map from a given stream.
 LinkedHashMap<KeyStroke,String> load(String path)
          Attempts to load this type of persistent keystroke map from a given path.
 void save(OutputStream output, Map<KeyStroke,String> bindings)
          Writes the persistent state of the bindings to an output stream.
 void save(String path, Map<KeyStroke,String> bindings)
          Writes the persistent state of the bindings to a file.
 String toString()
           
static Persistence valueOf(String name)
          Returns the enum constant of this type with the specified name.
static Persistence[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
compareTo, equals, getDeclaringClass, hashCode, name, ordinal, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

SERIAL_HASH

public static final Persistence SERIAL_HASH

SERIAL_INPUT

public static final Persistence SERIAL_INPUT

PROPERTIES_PAIRS

public static final Persistence PROPERTIES_PAIRS

PROPERTIES_XML

public static final Persistence PROPERTIES_XML
Method Detail

values

public static Persistence[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (Persistence c : Persistence.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static Persistence valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

fromString

public static Persistence fromString(String str)
Returns the enum representation of a string. This is case sensitive.

Parameters:
str - toString representation of this enum
Returns:
enum associated with a string
Throws:
IllegalArgumentException - if argument is not represented by this enum.

load

public LinkedHashMap<KeyStroke,String> load(String path)
                                     throws IOException,
                                            ParseException
Attempts to load this type of persistent keystroke map from a given path. This is unable to parse any null content.

Parameters:
path - absolute path to resource to be loaded
Returns:
keybinding map reflecting file contents
Throws:
IOException - if unable to load resource
ParseException - if unable to parse content

load

public LinkedHashMap<KeyStroke,String> load(InputStream input)
                                     throws IOException,
                                            ParseException
Attempts to load this type of persistent keystroke map from a given stream. This is unable to parse any null content.

Parameters:
input - source of keybindings to be parsed
Returns:
keybinding map reflecting file contents
Throws:
IOException - if unable to load resource
ParseException - if unable to parse content

save

public void save(OutputStream output,
                 Map<KeyStroke,String> bindings)
          throws IOException
Writes the persistent state of the bindings to an output stream.

Parameters:
output - stream where persistent state should be written
bindings - keybindings to be saved
Throws:
IOException - if unable to save bindings
UnsupportedOperationException - if any keys or values of the binding are null

save

public void save(String path,
                 Map<KeyStroke,String> bindings)
          throws IOException
Writes the persistent state of the bindings to a file.

Parameters:
path - absolute path to where bindings should be saved
bindings - keybindings to be saved
Throws:
IOException - if unable to save bindings
UnsupportedOperationException - if any keys or values of the binding are null

getOutput

public String getOutput(Map<KeyStroke,String> bindings)
Provides the textual output of what this persistence format would save given a set of bindings. This silently fails, returning null if unable to generate output from bindings.

Parameters:
bindings - bindings for which to generate saved output
Returns:
string reflecting what would be saved by this persistence format

toString

public String toString()
Overrides:
toString in class Enum<Persistence>