org.jvnet.substance.utils
Class SubstanceHighlightManager

java.lang.Object
  extended by org.jvnet.substance.utils.SubstanceHighlightManager

public class SubstanceHighlightManager
extends java.lang.Object

This class is used to decide whether the a highlight theme should be applied on a specific component.

At runtime, the manager is populated from META-INF/substance.highlight.properties resources found in classpath. This allows providing additional application-specific components to be registered to use highlight theme. Each such resource should contain a list of fully qualified class names, one class name per line. The class name may be a "leaf" class (such as JToggleButton), or can be a parent class / interface (such as ListCellRenderer). In the later case, the highlight theme will be used on all classes that extend such class / implement such interface.

In addition, the toUseHighlightTheme(Component) API can be used to register additional application-specific components.

Author:
Kirill Grouchnikov

Field Summary
protected  java.util.Set<java.lang.Class<?>> cache
          Contains Class instances.
protected static SubstanceHighlightManager instance
          The singleton instance.
protected  java.util.Set<java.lang.Class<?>> useHighlightThemeOn
          Contains Class instances.
 
Method Summary
 void addToUseHighlightTheme(java.lang.Class<?> clazz)
          Adds the specified class to the set of components that should use highlight theme.
 void addToUseHighlightTheme(java.lang.String className)
          Adds the specified class name to the set of components that should use highlight theme.
static SubstanceHighlightManager getInstance()
          Returns the singleton instance.
 void populate()
          Populates the useHighlightThemeOn set.
protected  void populateFrom(java.net.URL url)
          Populates the useHighlightThemeOn set from the specific URL resource.
 boolean toUseHighlightTheme(java.awt.Component comp)
          Returns indication whether the specified component should use highlight theme.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

useHighlightThemeOn

protected java.util.Set<java.lang.Class<?>> useHighlightThemeOn
Contains Class instances. If a class instance is in this set, all components of this class (directly, via extension or via inheritance) will use highlight theme.


cache

protected java.util.Set<java.lang.Class<?>> cache
Contains Class instances. This serves as a cache to speed up the subsequent processing.

See Also:
toUseHighlightTheme(Component)

instance

protected static SubstanceHighlightManager instance
The singleton instance.

Method Detail

getInstance

public static SubstanceHighlightManager getInstance()
Returns the singleton instance.

Returns:
The singleton instance.

populate

public void populate()
Populates the useHighlightThemeOn set. The classpath is scanned for all resources that match the name META-INF/substance.highlight.properties.

See Also:
populateFrom(URL)

populateFrom

protected void populateFrom(java.net.URL url)
Populates the useHighlightThemeOn set from the specific URL resource. The resource should contain a list of fully qualified class names, one class name per line. The class name may be a "leaf" class (such as JToggleButton), or can be a parent class / interface (such as ListCellRenderer). In the later case, the highlight theme will be used on all classes that extend such class / implement such interface.

Parameters:
url - Resource URL.

addToUseHighlightTheme

public void addToUseHighlightTheme(java.lang.Class<?> clazz)
Adds the specified class to the set of components that should use highlight theme.

Parameters:
clazz - Component class.

addToUseHighlightTheme

public void addToUseHighlightTheme(java.lang.String className)
Adds the specified class name to the set of components that should use highlight theme.

Parameters:
className - Component class name.

toUseHighlightTheme

public boolean toUseHighlightTheme(java.awt.Component comp)
Returns indication whether the specified component should use highlight theme. The component hierarchy is scanned from the component up. At each stage, the current ascendant is checked against all entries in the useHighlightThemeOn set. If the class of the current ascendant matches one of the entries, true is returned. Otherwise, false is returned (no ascendant found matching any of the entries in the useHighlightThemeOn set).

The implementation uses the cache tp speed up the processing. When a component class is determined to use highlight theme, its class is put in this cache. The implementation first consults this cache - if the component class is found, true is returned. Otherwise, the above algorithm is performed.

Parameters:
comp - Component.
Returns:
true if the specified component should use highlight theme, false otherwise.