Package org.pushingpixels.lafwidget
Class LafWidgetRepository
- java.lang.Object
-
- org.pushingpixels.lafwidget.LafWidgetRepository
-
public class LafWidgetRepository extends Object
Repository of LAF widgets.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classLafWidgetRepository.LafWidgetClassInfoInformation on a single class.
-
Field Summary
Fields Modifier and Type Field Description protected booleanisCustomLafSupportSetIndicates whether the currently registered LAF support is custom (notLafWidgetSupport).protected LafWidgetSupportlafSupportCurrently registered LAF support.protected static LafWidgetRepositoryrepositorySingleton instance.protected Set<String>widgetClassesToIgnoreContains fully qualified class names of widgets that should not be installed on any components.protected Map<Class<?>,Set<LafWidgetRepository.LafWidgetClassInfo>>widgetsAll registered widgets.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddToIgnoreWidgets(String widgetClassName)Marks widget with the specified class name to never be installed on any components.static ResourceBundlegetLabelBundle()Retrieves the current label bundle.static ResourceBundlegetLabelBundle(Locale locale)Retrieves the label bundle for the specified locale.LafWidgetSupportgetLafSupport()Returns the currently set LAF support.Set<LafWidget>getMatchingWidgets(JComponent jcomp)Returns a set of widgets that match the specified component.static LafWidgetRepositorygetRepository()Returns the widget repository.voidpopulate()Populates the widget repository.protected voidpopulateFrom(URL url)Populates the repository from the specified URL.voidregisterWidget(String widgetClassName, Class<?> supportedClass, boolean isExact)Registers a new widget for the specified UI class.voidregisterWidget(String widgetClassName, List<Class<?>> supportedClasses)Registers a new widget for the specified UI classes.static voidresetLabelBundle()Resets the current label bundle.static voidsetLabelBundleClassLoader(ClassLoader labelBundleClassLoader)Sets the class loader forLABEL_BUNDLE.voidsetLafSupport(LafWidgetSupport lafSupport)Sets LAF support.voidunsetLafSupport()Unsets custom LAF support and reverts to the base LAF support.
-
-
-
Field Detail
-
widgets
protected Map<Class<?>,Set<LafWidgetRepository.LafWidgetClassInfo>> widgets
-
widgetClassesToIgnore
protected Set<String> widgetClassesToIgnore
Contains fully qualified class names of widgets that should not be installed on any components.
-
lafSupport
protected LafWidgetSupport lafSupport
Currently registered LAF support.
-
isCustomLafSupportSet
protected boolean isCustomLafSupportSet
Indicates whether the currently registered LAF support is custom (notLafWidgetSupport).
-
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(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.pushingpixels.lafwidget.text.PasswordStrengthCheckerWidget = javax.swing.JPasswordField org.pushingpixels.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 nameMETA-INF/lafwidget.properties.- See Also:
populateFrom(URL)
-
registerWidget
public void registerWidget(String widgetClassName, List<Class<?>> supportedClasses)
Registers a new widget for the specified UI classes. The list should containClassinstances.- Parameters:
widgetClassName- Full-qualified class name for the widget.supportedClasses- Classes supported by the widget.
-
registerWidget
public void registerWidget(String widgetClassName, 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- iftrue, the widget will be available only for the components of the specified class. Iffalse, the widget be available for the components of the specified class and all its descendants (as defined in theClass.isAssignableFrom(Class)).
-
getMatchingWidgets
public Set<LafWidget> getMatchingWidgets(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 theisCustomLafSupportSetisfalse, only widgets that returnfalseinLafWidget.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:
IllegalArgumentException- If the LAF support isnull.
-
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-
nullLAF support.
-
getLabelBundle
public static ResourceBundle getLabelBundle()
Retrieves the current label bundle.- Returns:
- The current label bundle.
- See Also:
resetLabelBundle()
-
getLabelBundle
public static ResourceBundle getLabelBundle(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(ClassLoader labelBundleClassLoader)
Sets the class loader forLABEL_BUNDLE.- Parameters:
labelBundleClassLoader- Class loader forLABEL_BUNDLE.- Since:
- version 1.1
-
addToIgnoreWidgets
public void addToIgnoreWidgets(String widgetClassName)
Marks widget with the specified class name to never be installed on any components.- Parameters:
widgetClassName- Fully qualified widget class name.
-
-