// get all the defaults from UIManager.getDefaults() and put them
// into the compiledDefaults
compileDefaults(compiledDefaults, UIManager.getDefaults());
// This second statement pulls defaults from the laf defaults
UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults();
compileDefaults(compiledDefaults, lafDefaults);
// if it has not already been done, add a listener to both
// UIManager.getDefaults() and UIManager.getLookAndFeelDefaults().
PropertyChangeListener pcl = (PropertyChangeListener)
ctx.get("NimbusStyle.defaults.pcl");
// if pcl is null, then it has not yet been registered with
// the UIManager defaults for this app context
if (pcl == null) {
// create a PCL which will simply clear out the compiled
// defaults from the app context, causing it to be recomputed
// on subsequent passes
pcl = new DefaultsListener();
// add the PCL to both defaults tables that we pay attention
// to, so that if the UIDefaults are updated, then the
// precompiled defaults will be cleared from the app context
// and recomputed on subsequent passes
UIManager.getDefaults().addPropertyChangeListener(pcl);
UIManager.getLookAndFeelDefaults().addPropertyChangeListener(pcl);
// save the PCL to the app context as a marker indicating
// that the PCL has been registered so we don't end up adding
// more than one listener to the UIDefaults tables.
ctx.put("NimbusStyle.defaults.pcl", pcl);
}
// store the defaults for reuse
ctx.put("NimbusStyle.defaults", compiledDefaults);
}
TreeMap<String, Object> defaults = compiledDefaults.get(prefix);
// inspect the client properties for the key "Nimbus.Overrides". If the
// value is an instance of UIDefaults, then these defaults are used
// in place of, or in addition to, the defaults in UIManager.
if (component != null) {
Object o = component.getClientProperty("Nimbus.Overrides");
if (o instanceof UIDefaults) {
Object i = component.getClientProperty(
"Nimbus.Overrides.InheritDefaults");
boolean inherit = i instanceof Boolean ? (Boolean)i : true;
UIDefaults d = (UIDefaults)o;
TreeMap<String, Object> map = new TreeMap<String, Object>();
for (Object obj : d.keySet()) {
if (obj instanceof String) {
String key = (String)obj;
if (key.startsWith(prefix)) {
map.put(key, d.get(key));
}
}
}
if (inherit) {
defaults.putAll(map);