org.jvnet.lafwidget
Class LafWidgetRepository

java.lang.Object
  extended by org.jvnet.lafwidget.LafWidgetRepository

public class LafWidgetRepository
extends java.lang.Object

Repository of LAF widgets.

Author:
Kirill Grouchnikov

Nested Class Summary
protected static class LafWidgetRepository.LafWidgetClassInfo
          Information on a single class.
 
Field Summary
protected  FadeIgnoreManager fadeIgnoreManager
          Manages the components that ignore animations.
protected  boolean isCustomLafSupportSet
          Indicates whether the currently registered LAF support is custom (not LafWidgetSupport).
protected  LafWidgetSupport lafSupport
          Currently registered LAF support.
protected static LafWidgetRepository repository
          Singleton instance.
protected  java.util.Map<java.lang.Class<?>,java.util.Set<LafWidgetRepository.LafWidgetClassInfo>> widgets
          All registered widgets.
 
Method Summary
 FadeIgnoreManager getFadeIgnoreManager()
          Retrieves the manager for components that ignore animations.
static java.util.ResourceBundle getLabelBundle()
          Retrieves the current label bundle.
static java.util.ResourceBundle getLabelBundle(java.util.Locale locale)
          Retrieves the label bundle for the specified locale.
 LafWidgetSupport getLafSupport()
          Returns the currently set LAF support.
 java.util.Set<LafWidget> getMatchingWidgets(javax.swing.JComponent jcomp)
          Returns a set of widgets that match the specified component.
static LafWidgetRepository getRepository()
          Returns the widget repository.
 void populate()
          Populates the widget repository.
protected  void populateFrom(java.net.URL url)
          Populates the repository from the specified URL.
 void registerWidget(java.lang.String widgetClassName, java.lang.Class<?> supportedClass, boolean isExact)
          Registers a new widget for the specified UI class.
 void registerWidget(java.lang.String widgetClassName, java.util.List<java.lang.Class<?>> supportedClasses)
          Registers a new widget for the specified UI classes.
static void resetLabelBundle()
          Resets the current label bundle.
static void setLabelBundleClassLoader(java.lang.ClassLoader labelBundleClassLoader)
          Sets the class loader for LABEL_BUNDLE.
 void setLafSupport(LafWidgetSupport lafSupport)
          Sets LAF support.
 void unsetLafSupport()
          Unsets custom LAF support and reverts to the base LAF support.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

widgets

protected java.util.Map<java.lang.Class<?>,java.util.Set<LafWidgetRepository.LafWidgetClassInfo>> widgets
All registered widgets. Key is Class in the UI component hierarchy, value is a Set of fully-qualified widget class names.


lafSupport

protected LafWidgetSupport lafSupport
Currently registered LAF support.


isCustomLafSupportSet

protected boolean isCustomLafSupportSet
Indicates whether the currently registered LAF support is custom (not LafWidgetSupport).


fadeIgnoreManager

protected FadeIgnoreManager fadeIgnoreManager
Manages the components that ignore animations.


repository

protected static LafWidgetRepository repository
Singleton instance.

Method Detail

getRepository

public static LafWidgetRepository getRepository()
Returns the widget repository.

Returns:
Widget repository.

populateFrom

protected void populateFrom(java.net.URL url)
Populates the repository from the specified URL. The URL should point to a properties file, the key being the fully-qualified class name of the widget implementation, the value being semicolon-separated fully-qualified class names of classes in UI component hierarchy. Sample property file:
             org.jvnet.lafwidget.text.PasswordStrengthCheckerWidget = javax.swing.JPasswordField
             org.jvnet.lafwidget.text.LockBorderWidget = javax.swing.text.JTextComponent;javax.swing.JComboBox
 

Parameters:
url - URL that points to a properties file.

populate

public void populate()
Populates the widget repository. The classpath is scanned for all resources that match the name META-INF/lafwidget.properties.

See Also:
populateFrom(URL)

registerWidget

public void registerWidget(java.lang.String widgetClassName,
                           java.util.List<java.lang.Class<?>> supportedClasses)
Registers a new widget for the specified UI classes. The list should contain Class instances.

Parameters:
widgetClassName - Full-qualified class name for the widget.
supportedClasses - Classes supported by the widget.

registerWidget

public void registerWidget(java.lang.String widgetClassName,
                           java.lang.Class<?> supportedClass,
                           boolean isExact)
Registers a new widget for the specified UI class.

Parameters:
widgetClassName - Full-qualified class name for the widget.
supportedClass - Class supported by the widget.
isExact - if true, the widget will be available only for the components of the specified class. If false, the widget be available for the components of the specified class and all its descendants (as defined in the Class.isAssignableFrom(Class)).

getMatchingWidgets

public java.util.Set<LafWidget> getMatchingWidgets(javax.swing.JComponent jcomp)
Returns a set of widgets that match the specified component. The component hierarchy is scanned bottom-up and all matching widget classes are used to instantiate new instance of widgets. In case the isCustomLafSupportSet is false, only widgets that return false in LafWidget.requiresCustomLafSupport() are returned.

Parameters:
jcomp - UI component.
Returns:
Set of widgets that match the specified component.

setLafSupport

public void setLafSupport(LafWidgetSupport lafSupport)
Sets LAF support.

Parameters:
lafSupport - LAF support.
Throws:
java.lang.IllegalArgumentException - If the LAF support is null.

unsetLafSupport

public void unsetLafSupport()
Unsets custom LAF support and reverts to the base LAF support.


getLafSupport

public LafWidgetSupport getLafSupport()
Returns the currently set LAF support. The result is guaranteed to be non-null.

Returns:
Currently set non-null LAF support.

getLabelBundle

public static java.util.ResourceBundle getLabelBundle()
Retrieves the current label bundle.

Returns:
The current label bundle.
See Also:
resetLabelBundle()

getLabelBundle

public static java.util.ResourceBundle getLabelBundle(java.util.Locale locale)
Retrieves the label bundle for the specified locale.

Parameters:
locale - Locale.
Returns:
The label bundle for the specified locale.

resetLabelBundle

public static void resetLabelBundle()
Resets the current label bundle. Useful when the application changes Locale at runtime.

See Also:
getLabelBundle()

setLabelBundleClassLoader

public static void setLabelBundleClassLoader(java.lang.ClassLoader labelBundleClassLoader)
Sets the class loader for LABEL_BUNDLE.

Parameters:
labelBundleClassLoader - Class loader for LABEL_BUNDLE.
Since:
version 1.1

getFadeIgnoreManager

public FadeIgnoreManager getFadeIgnoreManager()
Retrieves the manager for components that ignore animations.

Returns:
The manager for components that ignore animations.