com.miginfocom.theme
Class Theme

java.lang.Object
  extended by com.miginfocom.theme.Theme
Direct Known Subclasses:
CalendarTheme

public abstract class Theme
extends java.lang.Object

A abstract base class for all themes. Contains the basic funtionality. To make a custom theme you have to:

  1. Set the capabilities for every key, or its folder key if a whole folder has the same capabilities.
  2. Set the default value for every key.
  3. Call transferDefaultsToTheme() to set the keys for the theme from the default/initial values.
That's it. Any theme that follows these rules will be editable in the ThemeEditor.

In order to make subclasses serializable to XML via the default JavaBeans XMLEncoder/decoder, all properties (I.e. the state of the theme) must be stored with putValue(String, Object) or putAll(java.util.Map). All values that doens't already have a Persistence delegate (many Java classes, such as Color and Border do) must have a PersistenceDelegate registered with IOUtil.setDelegate(Class, java.beans.PersistenceDelegate).


Field Summary
protected static PropertyCapability CAP_BASIC_STROKE
          A static capability to use from whereever place since it is immutable.
protected static PropertyCapability CAP_BOOLEAN
          A static capability to use from whereever place since it is immutable.
protected static PropertyCapability CAP_BORDER
          A static capability to use from whereever place since it is immutable.
protected static PropertyCapability CAP_COLOR
          A static capability to use from whereever place since it is immutable.
protected static PropertyCapability CAP_DIMENSION
          A static capability to use from whereever place since it is immutable.
protected static PropertyCapability CAP_FONT
          A static capability to use from whereever place since it is immutable.
protected static PropertyCapability CAP_INSETS
          A static capability to use from whereever place since it is immutable.
protected static PropertyCapability CAP_NULL
          A static capability to use from whatever place since it is immutable.
protected static PropertyCapability CAP_PAINT
          A static capability to use from whereever place since it is immutable.
protected static PropertyCapability CAP_STRING
          A static capability to use from whereever place since it is immutable.
protected static java.util.HashSet deprecatedKeys
          A set of keys that are now deprecated and thus if they are in the theme file but don't have any property capabilities, they are silently ignored.
static char FOLDER_CHAR
           
protected static int INITIAL_MAP_SIZE
          Default initial size of the created hash maps.
static char LIST_CHAR
           
protected  int modifiedCount
          Everytime a value, or list of values, in the theme changes, this value is also changed (increased by one).
static java.lang.String MULTI_KEY_PROP_NAME
          A property key name used when there are multiple keys changed and they arn't all tracked separately
static int VALIDATE_MODE_LENIENT
          Denotes validation of keys when getting/putting keys/values, but before throwing a ValidateException try to fallback on the default value for the key, if available, and if that works only send a note to System.err.
static int VALIDATE_MODE_NONE
          Denotes no validation of keys when getting/putting keys/values.
static int VALIDATE_MODE_STRICT
          Denotes strict validation of keys when getting/putting keys/values.
static boolean validateDefaults
          If defaults are to be validated when they are set.
 
Constructor Summary
protected Theme()
           
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Adds a listener that is notified of all changes to the theme.
 void addPropertyChangeListener(java.beans.PropertyChangeListener l, boolean asWeakRef)
          Adds a listener that is notified of all changes to the theme.
 int addToList(java.lang.String listKey, int index, java.lang.Object value)
          Adds/inserts a value to a list.
 int addToList(java.lang.String lKey, java.lang.Object value)
          Adds a value to the end of a list.
static void assertIsFolderKey(java.lang.String key)
          Throws an exception if key isn't a folder key and MigUtil.DEBUG == true.
static java.lang.String assertIsListKey(java.lang.String key)
          Throws an exception if key isn't a list key and == true.
static void assertIsNotFolderKey(java.lang.String key)
          Throws an exception if key is a folder key and == true.
 boolean equals(java.lang.Object o)
          Returns true if the class type is same and the properties are the same.
 void firePropertyChangeEvent(java.beans.PropertyChangeEvent e)
          Fires a change event to all registerd listeners if change events isn't ignored.
Also always adds one to modifiedCount
 boolean getBool(java.lang.String key)
          Returns a property as Boolean.
Note! If the key is null false will be returned.
 java.lang.Boolean getBoolean(java.lang.String key)
          Returns a property as Boolean
 javax.swing.border.Border getBorder(java.lang.String key)
          Returns a property as Border
 java.awt.Color getColor(java.lang.String key)
          Returns a property as Color
 java.lang.Object getDefaultValue(java.lang.String key, boolean useDefObjForLink)
          Returns the default value of a key for a specific default theme.
static java.beans.PersistenceDelegate getDelegateInstance()
          Returns the persistence delegate for this object.
 java.awt.Dimension getDimension(java.lang.String key)
          Returns a property as a Dimension
protected static PropertyCapability getDoubleCap(double min, double max, double step)
          A convenience method for getting a bounded Double capability.
 java.lang.Float getFloat(java.lang.String key)
          Returns a property as Float
protected static PropertyCapability getFloatCap(float min, float max, float step)
          A convenience method for getting a bounded Float capability.
 java.awt.Font getFont(java.lang.String key)
          Returns a property as Font
 java.lang.Object getFromList(java.lang.String listKey, int index)
          Returns a value in a list.
 java.awt.Insets getInsets(java.lang.String key)
          Returns a property as Insets
 int getInt(java.lang.String key)
          Returns a property as an int.
 java.lang.Integer getInteger(java.lang.String key)
          Returns a property as an Integer
protected static PropertyCapability getIntegerCap(int min, int max, int step)
          A convenience method for getting a bounded Integer capability.
 java.util.Iterator getKeyIterator()
          Returns a new Iterator that can be used to iterator over the keys.
 ThemeKeyLink getLink(java.lang.String key)
          Return the link in stead of the linked object as getValue(String) would.
 java.util.List getList(java.lang.String listKey, boolean removeNullElements)
          Returns a list of objects.
 java.lang.Long getLong(java.lang.String key)
          Returns a property as a Long
protected static PropertyCapability getLongCap(long min, long max, long step)
          A convenience method for getting a bounded Long capability.
 int getModifiedCount()
          Returns the an counter that is increased every time a property value is changed.
 java.lang.Number getNumber(java.lang.String key)
          Returns a property as Number
 java.awt.Paint getPaint(java.lang.String key)
          Returns a property as Paint (Color is a Paint)
 PropertyCapability[] getPropertyCapabilities(java.lang.String key)
          Returns the capabilities that the property can have.
 java.util.HashMap getPropertyMap()
          Return the property map that contains all key/value mapping for this theme.
 java.lang.String getString(java.lang.String key)
          Returns a property as String
 java.awt.Stroke getStroke(java.lang.String key)
          Returns a property as Stroke
 int getValidateMode()
          Returns the validate mode for the theme.
 java.lang.Object getValue(java.lang.String key)
          Returns a property as Object.
static boolean isFolderKey(java.lang.String key)
          Returns if the key is a folder key.
 boolean isKeysConnectable(java.lang.String key1, java.lang.String key2)
          Returns if the two key can be linked.
 boolean isLinked(java.lang.String key)
          Returnb if the key is really a link to another key.
static boolean isListKey(java.lang.String key)
          Returns if the key is a list key.
 int moveListKey(java.lang.String listKey, int index, int delta)
          Moves the list key upp or down delta number of steps in the list.
 void putAll(java.util.Map map)
          Overridden to only fire change event after added all.
 java.lang.Object putValue(java.lang.String key, int value)
          Convenience method that wraps the int in a new integer and calls putValue(String, Object)
 java.lang.Object putValue(java.lang.String key, java.lang.Object value)
          Overridden to validate objects if that feature is turned on.
 java.util.List removeAllFromList(java.lang.String listKey)
          Removes all values from the list.
 java.lang.Object removeFromList(java.lang.String listKey, int index)
          Removes a value from a list key.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Removes a listener.
static void removePropertyChangeListener(java.lang.String themeContext, java.beans.PropertyChangeListener l)
          Removes a listener IF a theme exists for the themeContext.
 void resetToDefaults()
          Reset the theme to default values.
protected  void setDefaultValue(java.lang.String key, java.lang.Object value)
          Convenience method for putting a property in the defProps HashMap.
protected  void setDefaultValue(java.lang.String folderKey, java.lang.String[][] subKeys, java.lang.Object[] values)
          Convenience method for putting a number of props in the defProps HashMap.
protected  void setDefaultValue(java.lang.String folderKey, java.lang.String[] subKeys, java.lang.Object value)
          Convenience method for putting default properties in the defProps HashMap.
protected  void setDefaultValue(java.lang.String folderKey, java.lang.String[] subKeys, java.lang.Object[] values)
          Convenience method for putting a number of props in the defProps HashMap.
protected  void setDefaultValueAsList(java.lang.String listKey, java.lang.Object[] values)
          Convenience method for putting a number of props in the defProps HashMap for a list key.
protected  void setDefaultValueAsList(java.lang.String folderKey, java.lang.String[][] subListKeys, java.lang.Object[] values)
          Convenience method for putting a number of props in the defProps HashMap for a list key.
protected  void setDefaultValueAsList(java.lang.String folderKey, java.lang.String[] subListKeys, java.lang.Object[] values)
          Convenience method for putting a number of props in the defProps HashMap for a list key.
 boolean setIgnorePropertyChangeEvents(boolean b)
          Sets if PropertyChangeEvent's should be fired.
 java.lang.Object setInList(java.lang.String listKey, int index, java.lang.Object value)
          Sets a value in a list.
 java.util.List setList(java.lang.String listKey, java.lang.Object[] values)
          Sets a value in a list.
protected  void setPropertyCapabilities(java.lang.String key, PropertyCapability pc)
          Sets property capabilities for a key that only has one capability.
protected  void setPropertyCapabilities(java.lang.String key, PropertyCapability[] pc)
          Sets property capabilities for a key.
protected  void setPropertyCapabilities(java.lang.String key, PropertyCapability pc1, PropertyCapability pc2)
          Sets property capabilities for a key that has two capabilities.
protected  void setPropertyCapabilities(java.lang.String key, PropertyCapability pc1, PropertyCapability pc2, PropertyCapability pc3)
          Sets property capabilities for a key that has three capabilities.
protected  void setPropertyCapabilities(java.lang.String key, PropertyCapability pc1, PropertyCapability pc2, PropertyCapability pc3, PropertyCapability pc4)
          Sets property capabilities for a key that has four capabilities.
protected  void setPropertyCapabilities(java.lang.String folderKey, java.lang.String[][] subKeys, PropertyCapability[] pc)
          Sets property capabilities for a number of keys.
protected  void setPropertyCapabilities(java.lang.String folderKey, java.lang.String[] subKeys, PropertyCapability[] pc)
          Sets property capabilities for a number of keys.
 void setPropertyMap(java.util.HashMap map)
          Set the property map to use.
 int setValidateMode(int mode)
          Sets the validate mode for the theme.
protected  void transferDefaultsToTheme()
          Transfer all key/values from the defaults in the default value map to the property map.
 void validate(java.lang.String key, java.lang.Object value)
          Validates the key in the correct mode.
protected  void validateAllowDefault(java.lang.String key, java.lang.Object value)
          Calls validateDontAllowDefault(java.lang.String, java.lang.Object) for the key/value pair.
protected  void validateDontAllowDefault(java.lang.String key, java.lang.Object value)
          Validates the value of the key against the current PropertyCapability for that key.
 void validateTheme(boolean removeFaultyKeys)
          Validates the theme against the current PropertyCapability.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

validateDefaults

public static final boolean validateDefaults
If defaults are to be validated when they are set. Usually switched on in deub mode and off in production since it consumes a few CPU cycles to validate every default value.

See Also:
Constant Field Values

INITIAL_MAP_SIZE

protected static int INITIAL_MAP_SIZE
Default initial size of the created hash maps.


VALIDATE_MODE_NONE

public static final int VALIDATE_MODE_NONE
Denotes no validation of keys when getting/putting keys/values.

See Also:
Constant Field Values

VALIDATE_MODE_LENIENT

public static final int VALIDATE_MODE_LENIENT
Denotes validation of keys when getting/putting keys/values, but before throwing a ValidateException try to fallback on the default value for the key, if available, and if that works only send a note to System.err.

See Also:
Constant Field Values

VALIDATE_MODE_STRICT

public static final int VALIDATE_MODE_STRICT
Denotes strict validation of keys when getting/putting keys/values. Throws a ValidateException for any illegal values that are not validated ok by any of the registered PropertyCapability for that key.

See Also:
Constant Field Values

FOLDER_CHAR

public static final char FOLDER_CHAR
See Also:
Constant Field Values

LIST_CHAR

public static final char LIST_CHAR
See Also:
Constant Field Values

deprecatedKeys

protected static java.util.HashSet deprecatedKeys
A set of keys that are now deprecated and thus if they are in the theme file but don't have any property capabilities, they are silently ignored.


modifiedCount

protected transient int modifiedCount
Everytime a value, or list of values, in the theme changes, this value is also changed (increased by one). This can be used for a theme-change-check to implement a fast caching of defaults in local objects. Starts with 0.


CAP_NULL

protected static final PropertyCapability CAP_NULL
A static capability to use from whatever place since it is immutable. Denotes the capability to set the key to null.


CAP_BORDER

protected static final PropertyCapability CAP_BORDER
A static capability to use from whereever place since it is immutable. Denotes the capability to set the key to any typer of Border.


CAP_BASIC_STROKE

protected static final PropertyCapability CAP_BASIC_STROKE
A static capability to use from whereever place since it is immutable. Denotes the capability to set the key to a BasicStroke.


CAP_COLOR

protected static final PropertyCapability CAP_COLOR
A static capability to use from whereever place since it is immutable. Denotes the capability to set the key to a Color.


CAP_STRING

protected static final PropertyCapability CAP_STRING
A static capability to use from whereever place since it is immutable. Denotes the capability to set the key to a String.


CAP_BOOLEAN

protected static final PropertyCapability CAP_BOOLEAN
A static capability to use from whereever place since it is immutable. Denotes the capability to set the key to a Boolean.


CAP_FONT

protected static final PropertyCapability CAP_FONT
A static capability to use from whereever place since it is immutable. Denotes the capability to set the key to a Font.


CAP_INSETS

protected static final PropertyCapability CAP_INSETS
A static capability to use from whereever place since it is immutable. Denotes the capability to set the key to a Insets object.


CAP_DIMENSION

protected static final PropertyCapability CAP_DIMENSION
A static capability to use from whereever place since it is immutable. Denotes the capability to set the key to a Dimension object.


CAP_PAINT

protected static final PropertyCapability CAP_PAINT
A static capability to use from whereever place since it is immutable. Denotes the capability to set the key to a Paint object.


MULTI_KEY_PROP_NAME

public static final java.lang.String MULTI_KEY_PROP_NAME
A property key name used when there are multiple keys changed and they arn't all tracked separately

See Also:
Constant Field Values
Constructor Detail

Theme

protected Theme()
Method Detail

getIntegerCap

protected static final PropertyCapability getIntegerCap(int min,
                                                        int max,
                                                        int step)
A convenience method for getting a bounded Integer capability.

Parameters:
min - The minimum accepted value.
max - The maximum accepted value.
step - The step size used by the theme editor. Not used for actual validation.
Returns:
A capability object, never null.

getLongCap

protected static final PropertyCapability getLongCap(long min,
                                                     long max,
                                                     long step)
A convenience method for getting a bounded Long capability.

Parameters:
min - The minimum accepted value.
max - The maximum accepted value.
step - The step size used by the theme editor. Not used for actual validation.
Returns:
A capability object, never null.

getFloatCap

protected static final PropertyCapability getFloatCap(float min,
                                                      float max,
                                                      float step)
A convenience method for getting a bounded Float capability.

Parameters:
min - The minimum accepted value.
max - The maximum accepted value.
step - The step size used by the theme editor. Not used for actual validation.
Returns:
A capability object, never null.

getDoubleCap

protected static final PropertyCapability getDoubleCap(double min,
                                                       double max,
                                                       double step)
A convenience method for getting a bounded Double capability.

Parameters:
min - The minimum accepted value.
max - The maximum accepted value.
step - The step size used by the theme editor. Not used for actual validation.
Returns:
A capability object, never null.

getPropertyMap

public java.util.HashMap getPropertyMap()
Return the property map that contains all key/value mapping for this theme. The returned map is a clone, but the values themselves are not cloned.

Returns:
The property map.

setPropertyMap

public void setPropertyMap(java.util.HashMap map)
Set the property map to use. Adds the properties via putAll(java.util.Map)

Parameters:
map - the Map to add. not null.

getKeyIterator

public java.util.Iterator getKeyIterator()
Returns a new Iterator that can be used to iterator over the keys.

Returns:
The iterator. Never null.

resetToDefaults

public void resetToDefaults()
Reset the theme to default values.


transferDefaultsToTheme

protected void transferDefaultsToTheme()
Transfer all key/values from the defaults in the default value map to the property map. Usually only done at initialization.


getDefaultValue

public java.lang.Object getDefaultValue(java.lang.String key,
                                        boolean useDefObjForLink)
Returns the default value of a key for a specific default theme. If no default value exists null is returned.

Parameters:
key - The key to return the default value for. Use the key + subKey if there are sub-keys.
useDefObjForLink - If true the default object for the link is returned rather than the link object itself. This is used to be able to "break" a link in a controlled way, since the key/value that the link point to must be a valid value for key as well.
Returns:
The default value of a key for a specific default theme or null if no default value exist or the default value IS null.

getModifiedCount

public int getModifiedCount()
Returns the an counter that is increased every time a property value is changed. Can be used for fast checks if a theme has changed since some earlier point in time.

Returns:
The modified count.

validateTheme

public void validateTheme(boolean removeFaultyKeys)
Validates the theme against the current PropertyCapability. Does nothing if validation is turned off. Throws ValidateException if one or more key/values doen't meet the capabilities.

Parameters:
removeFaultyKeys - If true keys which property arn't validated ok are removed and no exception are thrown.
See Also:
setValidateMode(int)

validate

public void validate(java.lang.String key,
                     java.lang.Object value)
Validates the key in the correct mode. Either does nothing, calls validateAllowDefault(String, Object) or calls validateDontAllowDefault(String, Object).

Parameters:
key - The key to check the value for. Ca be a list key (ends with #) but then value must be a List or null.
value - The value to check if is can be enterd as a value for 'key'. can be a List if key is a lisst key.

validateAllowDefault

protected void validateAllowDefault(java.lang.String key,
                                    java.lang.Object value)
Calls validateDontAllowDefault(java.lang.String, java.lang.Object) for the key/value pair. If that fails tries to put the default value for the key instead and if that succeeds it's ok. If not, the original ValidateException if thrown.

Parameters:
key - The key to check the value for. Ca be a list key (ends with #) but then value must be a List or null.
value - The value to check if is can be enterd as a value for 'key'. can be a List if key is a lisst key.

validateDontAllowDefault

protected void validateDontAllowDefault(java.lang.String key,
                                        java.lang.Object value)
Validates the value of the key against the current PropertyCapability for that key. Throws a ValidateException if the key wasn't validated ok. If validate mode is set to false no validation is done.

Parameters:
key - The key to check the value for. Ca be a list key (ends with #) but then value must be a List or null.
value - The value to check if is can be enterd as a value for 'key'. can be a List if key is a lisst key.

getPropertyCapabilities

public PropertyCapability[] getPropertyCapabilities(java.lang.String key)
Returns the capabilities that the property can have.

If no capabilities are found for the exact key (which may be a folder key) the folder keys above are checked in turn.

Parameters:
key - The key of the property to return the capabilities for.
Returns:
The capabilities. Can be null and of length 0.

setPropertyCapabilities

protected final void setPropertyCapabilities(java.lang.String key,
                                             PropertyCapability pc)
Sets property capabilities for a key that only has one capability. Convenience method.

Parameters:
key - The key to set capabilities for
pc - The only propertyCapabilities for this key

setPropertyCapabilities

protected final void setPropertyCapabilities(java.lang.String key,
                                             PropertyCapability pc1,
                                             PropertyCapability pc2)
Sets property capabilities for a key that has two capabilities. Convenience method.

Parameters:
key - The key to set capabilities for
pc1 - The first propertyCapabilities for this key. Not null
pc2 - The second propertyCapabilities for this key. Not null
See Also:
(String, PropertyCapability[])

setPropertyCapabilities

protected final void setPropertyCapabilities(java.lang.String key,
                                             PropertyCapability pc1,
                                             PropertyCapability pc2,
                                             PropertyCapability pc3)
Sets property capabilities for a key that has three capabilities. Convenience method.

Parameters:
key - The key to set capabilities for
pc1 - The first propertyCapabilities for this key. Not null
pc2 - The second propertyCapabilities for this key. Not null
pc3 - The third propertyCapabilities for this key. Not null
See Also:
(String, PropertyCapability[])

setPropertyCapabilities

protected final void setPropertyCapabilities(java.lang.String key,
                                             PropertyCapability pc1,
                                             PropertyCapability pc2,
                                             PropertyCapability pc3,
                                             PropertyCapability pc4)
Sets property capabilities for a key that has four capabilities. Convenience method.

Parameters:
key - The key to set capabilities for
pc1 - The first propertyCapabilities for this key. Not null
pc2 - The second propertyCapabilities for this key. Not null
pc3 - The third propertyCapabilities for this key. Not null
pc4 - The fourth propertyCapabilities for this key. Not null
See Also:
(String, PropertyCapability[])

setPropertyCapabilities

protected final void setPropertyCapabilities(java.lang.String key,
                                             PropertyCapability[] pc)
Sets property capabilities for a key.

Parameters:
key - The key to set capabilities for
pc - The propertyCapabilities for this key. can be null but elements should not be null.

setPropertyCapabilities

protected final void setPropertyCapabilities(java.lang.String folderKey,
                                             java.lang.String[][] subKeys,
                                             PropertyCapability[] pc)
Sets property capabilities for a number of keys.

Parameters:
folderKey - The key to set capabilities for
subKeys - The key-ends to add to key. Not null or any elements null or of length 0.
Will be flattened. See MigUtil.flatten(String[][]).
pc - The propertyCapabilities for this key. can be null but elements should not be null.

setPropertyCapabilities

protected final void setPropertyCapabilities(java.lang.String folderKey,
                                             java.lang.String[] subKeys,
                                             PropertyCapability[] pc)
Sets property capabilities for a number of keys.

Parameters:
folderKey - The key to set capabilities for
subKeys - Will be added to key.
pc - The propertyCapabilities for this key. can be null but elements should not be null.

setDefaultValue

protected final void setDefaultValue(java.lang.String key,
                                     java.lang.Object value)
Convenience method for putting a property in the defProps HashMap.

Parameters:
key - The key, SHOULD NOT end with a "/".
value - What to put as a default value for the key.
See Also:
validateDefaults

setDefaultValue

protected final void setDefaultValue(java.lang.String folderKey,
                                     java.lang.String[] subKeys,
                                     java.lang.Object value)
Convenience method for putting default properties in the defProps HashMap.

Parameters:
folderKey - The main key, ends with a "/"
subKeys - The keys-ends to add to key. Not null.
value - What to put as a default value for the key.
See Also:
validateDefaults

setDefaultValue

protected final void setDefaultValue(java.lang.String folderKey,
                                     java.lang.String[] subKeys,
                                     java.lang.Object[] values)
Convenience method for putting a number of props in the defProps HashMap.

Parameters:
folderKey - The main key, ends with a "/"
subKeys - The key-ends to add to key. Not null.
values - What to put as a default value for the keys, respectively. Not null. If element count < subKeys.length the last element is used as value for the remaining keys.
See Also:
validateDefaults

setDefaultValue

protected final void setDefaultValue(java.lang.String folderKey,
                                     java.lang.String[][] subKeys,
                                     java.lang.Object[] values)
Convenience method for putting a number of props in the defProps HashMap.

Parameters:
folderKey - The main key, ends with a "/"
subKeys - The key-ends to add to key. Not null or any elements null or of length 0.
Will be flattened. See MigUtil.flatten(String[][]).
values - What to put as a default value for the keys, respectively. Not null. If element count < subKeys.length the last element is used as value for the remaining keys.
See Also:
validateDefaults

setDefaultValueAsList

protected final void setDefaultValueAsList(java.lang.String listKey,
                                           java.lang.Object[] values)
Convenience method for putting a number of props in the defProps HashMap for a list key.

Parameters:
listKey - The key, ends with a "#".
values - The value list. Can be null.
See Also:
validateDefaults

setDefaultValueAsList

protected final void setDefaultValueAsList(java.lang.String folderKey,
                                           java.lang.String[] subListKeys,
                                           java.lang.Object[] values)
Convenience method for putting a number of props in the defProps HashMap for a list key.

Parameters:
folderKey - The folder key, ends with a "/".
subListKeys - The sub keys, ends with a "#". The value element index will be added to this key before calling setDefaultValue(String, Object)
values - The value list. Can be null.
See Also:
validateDefaults

setDefaultValueAsList

protected final void setDefaultValueAsList(java.lang.String folderKey,
                                           java.lang.String[][] subListKeys,
                                           java.lang.Object[] values)
Convenience method for putting a number of props in the defProps HashMap for a list key.

Parameters:
folderKey - The folder key, ends with a "/".
subListKeys - The key-ends to add to folderKey. Not null or any elements null or of length 0.
Will be flattened. See MigUtil.flatten(String[][]).
values - The value list. Can be null.
See Also:
validateDefaults

putValue

public java.lang.Object putValue(java.lang.String key,
                                 int value)
Convenience method that wraps the int in a new integer and calls putValue(String, Object)

Parameters:
key - The key.
value - The value to store under the key.
Returns:
The old value under key.

putValue

public java.lang.Object putValue(java.lang.String key,
                                 java.lang.Object value)
Overridden to validate objects if that feature is turned on. If validation is turned on every value entered is validated and an ValidateException is thrown if the value isn't met by any of the key's capabilities.

Parameters:
key - The key.
value - The value to store under the key.
Returns:
The old value under key.
See Also:
validateDontAllowDefault(java.lang.String, java.lang.Object), setPropertyCapabilities(java.lang.String, com.miginfocom.theme.PropertyCapability)

putAll

public void putAll(java.util.Map map)
Overridden to only fire change event after added all. Call putValue(String, Object) directly to fire events for every property change. If validation is on all key/value pairs are validated first and if all passes the validation the are added. A ValidateException will be thrown if any of the keys aren't validated ok.

Parameters:
map - The map to add. Not null and all keys must be Strings.

isListKey

public static final boolean isListKey(java.lang.String key)
Returns if the key is a list key. (Ends with a hash (#))

Parameters:
key - The key to check. Not null.
Returns:
If the key is a list key.

isFolderKey

public static final boolean isFolderKey(java.lang.String key)
Returns if the key is a folder key. (Ends with a slash (/))

Parameters:
key - The key to check. Not null.
Returns:
If the key is a folder key.

assertIsListKey

public static final java.lang.String assertIsListKey(java.lang.String key)
Throws an exception if key isn't a list key and == true.

Parameters:
key - The key. Not null
Returns:
key as convenience. To use this method as "filter".

assertIsFolderKey

public static final void assertIsFolderKey(java.lang.String key)
Throws an exception if key isn't a folder key and MigUtil.DEBUG == true.

Parameters:
key - The key. Not null

assertIsNotFolderKey

public static final void assertIsNotFolderKey(java.lang.String key)
Throws an exception if key is a folder key and == true.

Parameters:
key - The key. Not null

isLinked

public boolean isLinked(java.lang.String key)
Returnb if the key is really a link to another key.

Parameters:
key - The key to test. Not null.
Returns:
If the key is really a link to another key.

getLink

public ThemeKeyLink getLink(java.lang.String key)
Return the link in stead of the linked object as getValue(String) would. Return null if the key does not store a ThemeKeyLink.

Returns:
The link or null.

isKeysConnectable

public boolean isKeysConnectable(java.lang.String key1,
                                 java.lang.String key2)
Returns if the two key can be linked. They must have the exact same capabilities for this to be true.

Parameters:
key1 - One key. Must be a String.
key2 - Another key. Must be a String.
Returns:
If the two key can be linked.

getValue

public java.lang.Object getValue(java.lang.String key)
Returns a property as Object. Overridden to possibly validate that there is such a key.

Parameters:
key - The key that uniquely identifies a property (without a subkey). Not null and must be a String.
Returns:
A property as Object

getList

public java.util.List getList(java.lang.String listKey,
                              boolean removeNullElements)
Returns a list of objects. The list returned MIGHT be the live list in the theme. The list must not be changed.

Parameters:
listKey - The key that should end with a hash (#) and therefore be a collection if values.
removeNullElements - If true a new list will be returned with null elements removed, if there are null elements.
Returns:
A list with all keys in the collection, will be RandomAccess list. Not null but can be of length 0.
See Also:
addToList(String, int, Object), getFromList(String, int), removeFromList(String, int), setInList(String, int, Object)

addToList

public int addToList(java.lang.String lKey,
                     java.lang.Object value)
Adds a value to the end of a list. Creates list if no elements at lKey.

Parameters:
lKey - The key that should end with a hash (#) and therefore be a collection if values.
value - The value to add. May be null.
Returns:
The index of the value that was added.

addToList

public int addToList(java.lang.String listKey,
                     int index,
                     java.lang.Object value)
Adds/inserts a value to a list. Creates list if no elements at lKey.

Parameters:
listKey - The key that should end with a hash (#) and therefore be a collection if values.
index - The index. If > size will be added last.
value - The value to add. May be null.
Returns:
The index of the value that was added.

getFromList

public java.lang.Object getFromList(java.lang.String listKey,
                                    int index)
Returns a value in a list. Element must exist.

Parameters:
listKey - The key that should end with a hash (#) and therefore be a collection if values.
index - The index. Must be < the size of the list.
Returns:
The value. May be null if that was stored at index.

setInList

public java.lang.Object setInList(java.lang.String listKey,
                                  int index,
                                  java.lang.Object value)
Sets a value in a list. Element must exist.

Parameters:
listKey - The key that should end with a hash (#) and therefore be a collection if values.
index - The index. Must be < the size of the list.
value - The value to set. May be null.
Returns:
The old value. May be null if that was stored at index.

setList

public java.util.List setList(java.lang.String listKey,
                              java.lang.Object[] values)
Sets a value in a list. Element must exist.

Parameters:
listKey - The key that should end with a hash (#) and therefore be a collection if values.
values - The values to set. May be null which are same as length 0.
Returns:
The old list. May be null if there was no list added to the key.

removeFromList

public java.lang.Object removeFromList(java.lang.String listKey,
                                       int index)
Removes a value from a list key.

Parameters:
listKey - The key that should end with a hash (#) and therefore be a collection if values.
index - The index to remove. Must exists or an exception will be thrown.
Returns:
The removed value. May be null if that was stored at index.

removeAllFromList

public java.util.List removeAllFromList(java.lang.String listKey)
Removes all values from the list.

Parameters:
listKey - The key that should end with a hash (#) and therefore be a collection if values.
Returns:
The removed list. May be null if there was no list added to the key.

moveListKey

public int moveListKey(java.lang.String listKey,
                       int index,
                       int delta)
Moves the list key upp or down delta number of steps in the list.

Parameters:
listKey - The key that should end with a hash (#) and therefore be a collection if values.
index - The index to move. Must exists or an exception will be thrown.
Returns:
The new index of the key.

getString

public java.lang.String getString(java.lang.String key)
Returns a property as String

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as String

getColor

public java.awt.Color getColor(java.lang.String key)
Returns a property as Color

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Color

getStroke

public java.awt.Stroke getStroke(java.lang.String key)
Returns a property as Stroke

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Stroke

getInteger

public java.lang.Integer getInteger(java.lang.String key)
Returns a property as an Integer

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Integer

getLong

public java.lang.Long getLong(java.lang.String key)
Returns a property as a Long

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Long

getDimension

public java.awt.Dimension getDimension(java.lang.String key)
Returns a property as a Dimension

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Integer

getInt

public int getInt(java.lang.String key)
Returns a property as an int.
NOTE! If the key has stored null 0 will be returned!

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Integer

getFloat

public java.lang.Float getFloat(java.lang.String key)
Returns a property as Float

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Float

getNumber

public java.lang.Number getNumber(java.lang.String key)
Returns a property as Number

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Number

getFont

public java.awt.Font getFont(java.lang.String key)
Returns a property as Font

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Font

getBool

public boolean getBool(java.lang.String key)
Returns a property as Boolean.
Note! If the key is null false will be returned.

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Boolean

getBoolean

public java.lang.Boolean getBoolean(java.lang.String key)
Returns a property as Boolean

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Boolean

getBorder

public javax.swing.border.Border getBorder(java.lang.String key)
Returns a property as Border

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Border

getPaint

public java.awt.Paint getPaint(java.lang.String key)
Returns a property as Paint (Color is a Paint)

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Paint (Color is a Paint)

getInsets

public java.awt.Insets getInsets(java.lang.String key)
Returns a property as Insets

Parameters:
key - The key that uniquely identifies a property (without a subkey)
Returns:
a property as Insets

setValidateMode

public int setValidateMode(int mode)
Sets the validate mode for the theme. See VALIDATE_MODE_NONE, VALIDATE_MODE_LENIENT and VALIDATE_MODE_STRICT for an explanation of the different modes.

Parameters:
mode - The new mode. E.g. VALIDATE_MODE_LENIENT
Returns:
The old state. For resetting later.

getValidateMode

public int getValidateMode()
Returns the validate mode for the theme. See VALIDATE_MODE_NONE, VALIDATE_MODE_LENIENT and VALIDATE_MODE_STRICT for an explanation of the different modes.

Returns:
The current validate mode. E.g. VALIDATE_MODE_LENIENT

removePropertyChangeListener

public static void removePropertyChangeListener(java.lang.String themeContext,
                                                java.beans.PropertyChangeListener l)
Removes a listener IF a theme exists for the themeContext.

Parameters:
themeContext - Them context used to get the theme.
l - the listener

setIgnorePropertyChangeEvents

public boolean setIgnorePropertyChangeEvents(boolean b)
Sets if PropertyChangeEvent's should be fired. Can be set to false if batch updates will occur for instance.
Use with caution though since one never know who's listening.

Parameters:
b - true or false...
Returns:
The old value.

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds a listener that is notified of all changes to the theme. The property name will be the key name or if multiple keys are updated MULTI_KEY_PROP_NAME. Old value and new value will contain the values. or if multiple values null and null.

Parameters:
l - The listener. Not null.

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l,
                                      boolean asWeakRef)
Adds a listener that is notified of all changes to the theme. The property name will be the key name or if multiple keys are updated MULTI_KEY_PROP_NAME. Old value and new value will contain the values. or if multiple values null and null.

Parameters:
l - The listener. Not null.
asWeakRef - If the listener should be added wrapped in a WeakReference. This defers memory leak problems since the garbage collector can collect the listener if it is only referenced from this list.
Note! This (weak reference) can not be used with listeners that doesn't have another real (a.k.a Strong) reference to it, as for instance an annonymous inner class. If one such listener is added it will be removed almost immediately by the garbage collector.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes a listener.

Parameters:
l - the listener

firePropertyChangeEvent

public void firePropertyChangeEvent(java.beans.PropertyChangeEvent e)
Fires a change event to all registerd listeners if change events isn't ignored.
Also always adds one to modifiedCount

See Also:
setIgnorePropertyChangeEvents(boolean), MULTI_KEY_PROP_NAME

equals

public boolean equals(java.lang.Object o)
Returns true if the class type is same and the properties are the same.

Overrides:
equals in class java.lang.Object
Parameters:
o - The object (Theme) to compare to. If null false is returned.
Returns:
IF the themes contains the same key/value pairs
See Also:
AbstractMap.equals(Object)

getDelegateInstance

public static java.beans.PersistenceDelegate getDelegateInstance()
Returns the persistence delegate for this object. See XMLEncoder and PersistenceDelegate.

Returns:
The only persistence delegate.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.