|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
package sun.swing; |
|
|
|
import java.awt.Color; |
|
import java.awt.Insets; |
|
import javax.swing.*; |
|
import javax.swing.border.Border; |
|
import javax.swing.plaf.ComponentUI; |
|
import sun.awt.AppContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class DefaultLookup { |
|
|
|
|
|
*/ |
|
private static final Object DEFAULT_LOOKUP_KEY = new |
|
StringBuffer("DefaultLookup"); |
|
|
|
|
|
*/ |
|
private static Thread currentDefaultThread; |
|
|
|
|
|
*/ |
|
private static DefaultLookup currentDefaultLookup; |
|
|
|
|
|
|
|
*/ |
|
private static boolean isLookupSet; |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static void setDefaultLookup(DefaultLookup lookup) { |
|
synchronized(DefaultLookup.class) { |
|
if (!isLookupSet && lookup == null) { |
|
// Null was passed in, and no one has invoked setDefaultLookup |
|
|
|
return; |
|
} |
|
else if (lookup == null) { |
|
// null was passed in, but someone has invoked setDefaultLookup |
|
// with a non-null value, use an instance of DefautLookup |
|
|
|
lookup = new DefaultLookup(); |
|
} |
|
isLookupSet = true; |
|
AppContext.getAppContext().put(DEFAULT_LOOKUP_KEY, lookup); |
|
currentDefaultThread = Thread.currentThread(); |
|
currentDefaultLookup = lookup; |
|
} |
|
} |
|
|
|
public static Object get(JComponent c, ComponentUI ui, String key) { |
|
boolean lookupSet; |
|
synchronized(DefaultLookup.class) { |
|
lookupSet = isLookupSet; |
|
} |
|
if (!lookupSet) { |
|
|
|
return UIManager.get(key, c.getLocale()); |
|
} |
|
Thread thisThread = Thread.currentThread(); |
|
DefaultLookup lookup; |
|
synchronized(DefaultLookup.class) { |
|
// See if we've already cached the DefaultLookup for this thread, |
|
|
|
if (thisThread == currentDefaultThread) { |
|
|
|
lookup = currentDefaultLookup; |
|
} |
|
else { |
|
|
|
lookup = (DefaultLookup)AppContext.getAppContext().get( |
|
DEFAULT_LOOKUP_KEY); |
|
if (lookup == null) { |
|
// Fallback to DefaultLookup, which will redirect to the |
|
|
|
lookup = new DefaultLookup(); |
|
AppContext.getAppContext().put(DEFAULT_LOOKUP_KEY, lookup); |
|
} |
|
|
|
currentDefaultThread = thisThread; |
|
currentDefaultLookup = lookup; |
|
} |
|
} |
|
return lookup.getDefault(c, ui, key); |
|
} |
|
|
|
// |
|
// The following are convenience method that all use getDefault. |
|
|
|
public static int getInt(JComponent c, ComponentUI ui, String key, |
|
int defaultValue) { |
|
Object iValue = get(c, ui, key); |
|
|
|
if (iValue == null || !(iValue instanceof Number)) { |
|
return defaultValue; |
|
} |
|
return ((Number)iValue).intValue(); |
|
} |
|
|
|
public static int getInt(JComponent c, ComponentUI ui, String key) { |
|
return getInt(c, ui, key, -1); |
|
} |
|
|
|
public static Insets getInsets(JComponent c, ComponentUI ui, String key, |
|
Insets defaultValue) { |
|
Object iValue = get(c, ui, key); |
|
|
|
if (iValue == null || !(iValue instanceof Insets)) { |
|
return defaultValue; |
|
} |
|
return (Insets)iValue; |
|
} |
|
|
|
public static Insets getInsets(JComponent c, ComponentUI ui, String key) { |
|
return getInsets(c, ui, key, null); |
|
} |
|
|
|
public static boolean getBoolean(JComponent c, ComponentUI ui, String key, |
|
boolean defaultValue) { |
|
Object iValue = get(c, ui, key); |
|
|
|
if (iValue == null || !(iValue instanceof Boolean)) { |
|
return defaultValue; |
|
} |
|
return ((Boolean)iValue).booleanValue(); |
|
} |
|
|
|
public static boolean getBoolean(JComponent c, ComponentUI ui, String key) { |
|
return getBoolean(c, ui, key, false); |
|
} |
|
|
|
public static Color getColor(JComponent c, ComponentUI ui, String key, |
|
Color defaultValue) { |
|
Object iValue = get(c, ui, key); |
|
|
|
if (iValue == null || !(iValue instanceof Color)) { |
|
return defaultValue; |
|
} |
|
return (Color)iValue; |
|
} |
|
|
|
public static Color getColor(JComponent c, ComponentUI ui, String key) { |
|
return getColor(c, ui, key, null); |
|
} |
|
|
|
public static Icon getIcon(JComponent c, ComponentUI ui, String key, |
|
Icon defaultValue) { |
|
Object iValue = get(c, ui, key); |
|
if (iValue == null || !(iValue instanceof Icon)) { |
|
return defaultValue; |
|
} |
|
return (Icon)iValue; |
|
} |
|
|
|
public static Icon getIcon(JComponent c, ComponentUI ui, String key) { |
|
return getIcon(c, ui, key, null); |
|
} |
|
|
|
public static Border getBorder(JComponent c, ComponentUI ui, String key, |
|
Border defaultValue) { |
|
Object iValue = get(c, ui, key); |
|
if (iValue == null || !(iValue instanceof Border)) { |
|
return defaultValue; |
|
} |
|
return (Border)iValue; |
|
} |
|
|
|
public static Border getBorder(JComponent c, ComponentUI ui, String key) { |
|
return getBorder(c, ui, key, null); |
|
} |
|
|
|
public Object getDefault(JComponent c, ComponentUI ui, String key) { |
|
|
|
return UIManager.get(key, c.getLocale()); |
|
} |
|
} |