jigcell.compare.impl
Class Config

java.lang.Object
  extended by javax.swing.TransferHandler
      extended by jigcell.compare.impl.Transferer
          extended by jigcell.compare.impl.Config
All Implemented Interfaces:
java.awt.datatransfer.Transferable, java.io.Serializable

public class Config
extends Transferer

Controls the configuration of the Comparator and its various components. Any direct use of the configuration maps must be protected by properly acquiring the config lock.

This code is licensed under the DARPA BioCOMP Open Source License. See LICENSE for more details.

Author:
Nicholas Allen
See Also:
Serialized Form

Nested Class Summary
protected static class Config.ConfigDelegate
          Filters the temporary instance markers before persisting the configuration.
 
Field Summary
protected  EDU.oswego.cs.dl.util.concurrent.ReentrantWriterPreferenceReadWriteLock CONFIG_LOCK
          Lock for manipulating configuration data
protected  java.util.HashMap configs
          Map of marker-configurator pairs
static java.lang.String MARKER_UNIVERSAL
          Universal marker
static java.lang.String MARKER_UNIVERSALCLASS
          Universal class marker
static java.lang.String MARKER_UNIVERSALINSTANCE
          Universal instance marker
private static long markerCount
          Counter for unique instance markers
protected static java.lang.String TOKEN_LISTSEPARATOR
          Separator between two entries in a list
protected static java.lang.String TOKEN_SESSION
          Session token marker
protected  java.util.HashMap values
          Map of key-value pairs
 
Fields inherited from class jigcell.compare.impl.Transferer
CSV_FOOTER, CSV_LINEPOSTPEND, CSV_LINEPREPEND, CSV_LINESEPARATOR, HTML_FOOTER, HTML_HEADPOSTPEND, HTML_HEADPREPEND, HTML_HEADSEPARATOR, HTML_LINEPOSTPEND, HTML_LINEPREPEND, HTML_LINESEPARATOR
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, MOVE, NONE
 
Constructor Summary
Config()
          Creates a new configuration for a Comparator component.
 
Method Summary
static boolean convertToBoolean(java.lang.String value)
          Converts a configuration value to a boolean.
static boolean convertToBoolean(java.lang.String value, boolean fallback)
          Converts a configuration value to a boolean.
static java.lang.String convertToClassMarker(java.lang.Object instance)
          Converts a class or instance to a class canonical marker.
static java.awt.Color convertToColor(java.lang.String value)
          Converts a configuration value to a color.
static java.awt.Color convertToColor(java.lang.String value, java.awt.Color fallback)
          Converts a configuration value to a color.
static java.lang.String convertToInstanceMarker(java.lang.Object instance)
          Converts an instance to an instance canonical marker.
static long convertToInteger(java.lang.String value)
          Converts a configuration value to an integer.
static long convertToInteger(java.lang.String value, long fallback)
          Converts a configuration value to an integer.
static java.util.List convertToList(java.lang.String value)
          Converts a configuration value to a list.
static java.awt.Rectangle convertToRectangle(java.lang.String value)
          Converts a configuration value to a rectangle.
static java.lang.String createInstanceMarker()
          Creates a session unique instance marker.
static java.util.List createStandardMarkers(java.lang.Object instance)
          Creates the standard set of markers for an instance to match against: an instance and class marker.
 java.lang.String findValue(java.util.List markers, java.lang.String key)
          A value in this configurator or a subconfigurator.
 java.lang.String findValue(java.util.List markers, java.lang.String key, boolean searchUniversalInstance, boolean searchUniversalClass, boolean searchUniversal)
          A value in this configurator or one of its subconfigurators.
 java.lang.String findValue(java.util.List markers, java.lang.String key, boolean searchUniversalInstance, boolean searchUniversalClass, boolean searchUniversal, java.lang.String value)
          A value in this configurator or a subconfigurator.
 java.lang.String findValue(java.util.List markers, java.lang.String key, java.lang.String value)
          A value in this configurator or a subconfigurator.
 Config getConfig(java.lang.String marker)
          The config for a particular marker from this configurator.
 java.util.Map getConfigs()
          The mapping between markers and configurators.
 EDU.oswego.cs.dl.util.concurrent.ReadWriteLock getLock()
          The configuration lock.
 java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
          A transferable object for the given data flavor.
 java.lang.String getValue(java.lang.String key)
          The value for a particular key from this configurator.
 java.util.Map getValues()
          The mapping between keys and values.
 void importConfig(Config config)
          Copies the configuration information from another configurator.
 void removeConfig(java.lang.String marker)
          Removes a marker from this configurator.
 void removeValue(java.lang.String key)
          Removes a key from this configurator.
 void setConfig(java.lang.String marker, Config config)
          Sets the config for a particular marker in this configurator.
 void setConfigs(java.util.HashMap configs)
          Sets the mapping between markers and configurators.
 void setValue(java.lang.String key, boolean value)
          Sets the value for a particular key in this configurator to a boolean.
 void setValue(java.lang.String key, java.awt.Color value)
          Sets the value for a particular key in this configurator to a color.
 void setValue(java.lang.String key, java.util.List value)
          Sets the value for a particular key in this configurator to a list.
 void setValue(java.lang.String key, long value)
          Sets the value for a particular key in this configurator to an integer.
 void setValue(java.lang.String key, java.awt.Rectangle value)
          Sets the value for a particular key in this configurator to a rectangle.
 void setValue(java.lang.String key, java.lang.String value)
          Sets the value for a particular key in this configurator.
 void setValues(java.util.HashMap values)
          Sets the mapping between keys and values.
 
Methods inherited from class jigcell.compare.impl.Transferer
addExtension, addFlavor, createCSVTable, createFormattedTable, createHTMLTable, getExceptionRecorder, getExpectedClasses, getExpectedClasses, getExpectedClasses, getFlavors, getFlavors, getPreferredExtensions, getPreferredExtensions, getTransferClass, getTransferDataFlavors, getTransferFlavor, isDataFlavorSupported, transfer
 
Methods inherited from class javax.swing.TransferHandler
canImport, createTransferable, exportAsDrag, exportDone, exportToClipboard, getCopyAction, getCutAction, getPasteAction, getSourceActions, getVisualRepresentation, importData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MARKER_UNIVERSALINSTANCE

public static final java.lang.String MARKER_UNIVERSALINSTANCE
Universal instance marker

See Also:
Constant Field Values

MARKER_UNIVERSALCLASS

public static final java.lang.String MARKER_UNIVERSALCLASS
Universal class marker

See Also:
Constant Field Values

MARKER_UNIVERSAL

public static final java.lang.String MARKER_UNIVERSAL
Universal marker

See Also:
Constant Field Values

TOKEN_LISTSEPARATOR

protected static final java.lang.String TOKEN_LISTSEPARATOR
Separator between two entries in a list

See Also:
Constant Field Values

TOKEN_SESSION

protected static final java.lang.String TOKEN_SESSION
Session token marker

See Also:
Constant Field Values

markerCount

private static long markerCount
Counter for unique instance markers


configs

protected java.util.HashMap configs
Map of marker-configurator pairs


values

protected java.util.HashMap values
Map of key-value pairs


CONFIG_LOCK

protected final EDU.oswego.cs.dl.util.concurrent.ReentrantWriterPreferenceReadWriteLock CONFIG_LOCK
Lock for manipulating configuration data

Constructor Detail

Config

public Config()
Creates a new configuration for a Comparator component.

Method Detail

convertToBoolean

public static boolean convertToBoolean(java.lang.String value)
Converts a configuration value to a boolean. If the configuration value cannot be converted, an exception is thrown.

Parameters:
value - Configuration value

convertToBoolean

public static boolean convertToBoolean(java.lang.String value,
                                       boolean fallback)
Converts a configuration value to a boolean. If the configuration value cannot be converted, the default is returned.

Parameters:
value - Configuration value
fallback - Default value

convertToClassMarker

public static java.lang.String convertToClassMarker(java.lang.Object instance)
Converts a class or instance to a class canonical marker.

Parameters:
instance - Instance

convertToColor

public static java.awt.Color convertToColor(java.lang.String value)
Converts a configuration value to a color. If the configuration value cannot be converted, an exception is thrown.

Parameters:
value - Configuration value

convertToColor

public static java.awt.Color convertToColor(java.lang.String value,
                                            java.awt.Color fallback)
Converts a configuration value to a color. If the configuration value cannot be converted, the default is returned.

Parameters:
value - Configuration value
fallback - Default value

convertToInstanceMarker

public static java.lang.String convertToInstanceMarker(java.lang.Object instance)
Converts an instance to an instance canonical marker.

Parameters:
instance - Instance

convertToInteger

public static long convertToInteger(java.lang.String value)
Converts a configuration value to an integer. If the configuration value cannot be converted, an exception is thrown.

Parameters:
value - Configuration value

convertToInteger

public static long convertToInteger(java.lang.String value,
                                    long fallback)
Converts a configuration value to an integer. If the configuration value cannot be converted, the default is returned.

Parameters:
value - Configuration value
fallback - Default value

convertToList

public static java.util.List convertToList(java.lang.String value)
Converts a configuration value to a list. If the configuration value cannot be converted, an empty list is returned.

Parameters:
value - Configuration value

convertToRectangle

public static java.awt.Rectangle convertToRectangle(java.lang.String value)
Converts a configuration value to a rectangle. If the configuration value cannot be converted, an exception is thrown.

Parameters:
value - Configuration value

createInstanceMarker

public static java.lang.String createInstanceMarker()
Creates a session unique instance marker.


createStandardMarkers

public static java.util.List createStandardMarkers(java.lang.Object instance)
Creates the standard set of markers for an instance to match against: an instance and class marker.

Parameters:
instance - Instance to match against

findValue

public java.lang.String findValue(java.util.List markers,
                                  java.lang.String key)
A value in this configurator or a subconfigurator.

Parameters:
markers - Marker list
key - Key
See Also:
findValue(java.util.List,java.lang.String,boolean,boolean,boolean)

findValue

public java.lang.String findValue(java.util.List markers,
                                  java.lang.String key,
                                  java.lang.String value)
A value in this configurator or a subconfigurator. If no value was found, the default is returned.

Parameters:
markers - Marker list
key - Key
value - Default value
See Also:
findValue(java.util.List,java.lang.String,boolean,boolean,boolean)

findValue

public java.lang.String findValue(java.util.List markers,
                                  java.lang.String key,
                                  boolean searchUniversalInstance,
                                  boolean searchUniversalClass,
                                  boolean searchUniversal)
A value in this configurator or one of its subconfigurators. Matching order is subconfigurators with matching marker from first given marker to last given marker, subconfigurator with universal instance marker (optional), subconfigurator with universal class marker (optional), subconfigurator with universal marker (optional), then this configurator. First located match is returned.

Parameters:
markers - Marker list
key - Key
searchUniversalInstance - Search subconfigurators with universal instance marker
searchUniversalClass - Search subconfigurators with universal class marker
searchUniversal - Search subconfigurators with universal marker

findValue

public java.lang.String findValue(java.util.List markers,
                                  java.lang.String key,
                                  boolean searchUniversalInstance,
                                  boolean searchUniversalClass,
                                  boolean searchUniversal,
                                  java.lang.String value)
A value in this configurator or a subconfigurator. If no value was found, the default is returned.

Parameters:
markers - Marker list
key - Key
searchUniversalInstance - Search subconfigurators with universal instance marker
searchUniversalClass - Search subconfigurators with universal class marker
searchUniversal - Search subconfigurators with universal marker
value - Default value
See Also:
findValue(java.util.List,java.lang.String,boolean,boolean,boolean)

getConfig

public Config getConfig(java.lang.String marker)
The config for a particular marker from this configurator.

Parameters:
marker - Marker

getConfigs

public java.util.Map getConfigs()
The mapping between markers and configurators.


getLock

public EDU.oswego.cs.dl.util.concurrent.ReadWriteLock getLock()
The configuration lock.


getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
                                 throws java.awt.datatransfer.UnsupportedFlavorException,
                                        java.io.IOException
A transferable object for the given data flavor.

Specified by:
getTransferData in interface java.awt.datatransfer.Transferable
Overrides:
getTransferData in class Transferer
Parameters:
flavor - Flavor
Throws:
java.awt.datatransfer.UnsupportedFlavorException
java.io.IOException

getValue

public java.lang.String getValue(java.lang.String key)
The value for a particular key from this configurator.

Parameters:
key - Key

getValues

public java.util.Map getValues()
The mapping between keys and values.


importConfig

public void importConfig(Config config)
Copies the configuration information from another configurator.

Parameters:
config - Configurator to copy from

removeConfig

public void removeConfig(java.lang.String marker)
Removes a marker from this configurator.

Parameters:
marker - Marker

removeValue

public void removeValue(java.lang.String key)
Removes a key from this configurator.

Parameters:
key - Key

setConfig

public void setConfig(java.lang.String marker,
                      Config config)
Sets the config for a particular marker in this configurator.

Parameters:
marker - Marker
config - Config

setConfigs

public void setConfigs(java.util.HashMap configs)
Sets the mapping between markers and configurators.

Parameters:
configs - Mapping

setValue

public void setValue(java.lang.String key,
                     boolean value)
Sets the value for a particular key in this configurator to a boolean.

Parameters:
key - Key
value - Value

setValue

public void setValue(java.lang.String key,
                     java.awt.Color value)
Sets the value for a particular key in this configurator to a color.

Parameters:
key - Key
value - Value

setValue

public void setValue(java.lang.String key,
                     long value)
Sets the value for a particular key in this configurator to an integer.

Parameters:
key - Key
value - Value

setValue

public void setValue(java.lang.String key,
                     java.util.List value)
Sets the value for a particular key in this configurator to a list.

Parameters:
key - Key
value - Value

setValue

public void setValue(java.lang.String key,
                     java.awt.Rectangle value)
Sets the value for a particular key in this configurator to a rectangle.

Parameters:
key - Key
value - Value

setValue

public void setValue(java.lang.String key,
                     java.lang.String value)
Sets the value for a particular key in this configurator.

Parameters:
key - Key
value - Value

setValues

public void setValues(java.util.HashMap values)
Sets the mapping between keys and values.

Parameters:
values - Mapping