| A simple mechanism for guaranteeing the presence of a value in UIDefaults.
Some look and feels (GTK/Synth) don't necessarily provide these colors,
resulting in null pointer exceptions. Since we want to make it easy to
write maintainable components, it is preferable to centralize guaranteeing
the value here, rather than have the codebase littered with null tests and
fallbacks for null colors.
It will either take on the existing value if present, or used the passed
value if not present. If passed an array of UIManager keys, it will try
them in order, and use the first value that returns non-null from
UIManager.get() .
Usage:
UIManager.put (new GuaranteedValue("controlShadow", Color.LIGHT_GRAY));
or
UIManager.put (new GuaranteedValue(new String[] {"Tree.foreground",
List.foreground", "textText"}, Color.BLACK));
It can also be used to ensure a value matches another value, with a fallback
if it is not present:
UIManager.put("TextArea.font", new GuaranteedValue ("Label.font", new Font("Dialog", Font.PLAIN, 11)))
author: Tim Boudreau |