Methods Summary |
---|
public static void | addAuxiliaryLookAndFeel(javax.swing.LookAndFeel laf)Adds a LookAndFeel to the list of auxiliary look and feels.
The auxiliary look and feels tell the multiplexing look and feel what
other LookAndFeel classes for a component instance are to be used
in addition to the default LookAndFeel class when creating a
multiplexing UI. The change will only take effect when a new
UI class is created or when the default look and feel is changed
on a component instance.
Note these are not the same as the installed look and feels.
maybeInitialize();
if (!laf.isSupportedLookAndFeel()) {
// Ideally we would throw an exception here, but it's too late
// for that.
return;
}
Vector v = getLAFState().auxLookAndFeels;
if (v == null) {
v = new Vector();
}
if (!v.contains(laf)) {
v.addElement(laf);
laf.initialize();
getLAFState().auxLookAndFeels = v;
if (getLAFState().multiLookAndFeel == null) {
getLAFState().multiLookAndFeel = getMultiLookAndFeel();
}
}
|
public static void | addPropertyChangeListener(java.beans.PropertyChangeListener listener)Adds a PropertyChangeListener to the listener list.
The listener is registered for all properties.
synchronized (classLock) {
getLAFState().getPropertyChangeSupport(true).
addPropertyChangeListener(listener);
}
|
private static void | checkProperty(java.util.Properties props, java.lang.String key)
// No need to do catch the SecurityException here, this runs
// in a doPrivileged.
String value = System.getProperty(key);
if (value != null) {
props.put(key, value);
}
|
public static java.lang.Object | get(java.lang.Object key)Returns an object from the defaults table.
return getDefaults().get(key);
|
public static java.lang.Object | get(java.lang.Object key, java.util.Locale l)Returns an object from the defaults table that is appropriate for
the given locale.
return getDefaults().get(key,l);
|
public static javax.swing.LookAndFeel[] | getAuxiliaryLookAndFeels()Returns the list of auxiliary look and feels (can be null ).
The auxiliary look and feels tell the multiplexing look and feel what
other LookAndFeel classes for a component instance are
to be used in addition to the default LookAndFeel class when creating a
multiplexing UI.
Note these are not the same as the installed look and feels.
maybeInitialize();
Vector v = getLAFState().auxLookAndFeels;
if ((v == null) || (v.size() == 0)) {
return null;
}
else {
LookAndFeel[] rv = new LookAndFeel[v.size()];
for (int i = 0; i < rv.length; i++) {
rv[i] = (LookAndFeel)v.elementAt(i);
}
return rv;
}
|
public static boolean | getBoolean(java.lang.Object key)Returns a boolean from the defaults table which is associated with
the key value. If the key is not found or the key doesn't represent
a boolean value then false will be returned.
return getDefaults().getBoolean(key);
|
public static boolean | getBoolean(java.lang.Object key, java.util.Locale l)Returns a boolean from the defaults table which is associated with
the key value and the given Locale . If the key is not
found or the key doesn't represent
a boolean value then false will be returned.
return getDefaults().getBoolean(key,l);
|
public static javax.swing.border.Border | getBorder(java.lang.Object key)Returns a border from the defaults table.
return getDefaults().getBorder(key);
|
public static javax.swing.border.Border | getBorder(java.lang.Object key, java.util.Locale l)Returns a border from the defaults table that is appropriate
for the given locale.
return getDefaults().getBorder(key,l);
|
public static java.awt.Color | getColor(java.lang.Object key)Returns a drawing color from the defaults table.
return getDefaults().getColor(key);
|
public static java.awt.Color | getColor(java.lang.Object key, java.util.Locale l)Returns a drawing color from the defaults table that is appropriate
for the given locale.
return getDefaults().getColor(key,l);
|
public static java.lang.String | getCrossPlatformLookAndFeelClassName()Returns the name of the LookAndFeel class that implements
the default cross platform look and feel -- the Java
Look and Feel (JLF). If the system property
swing.crossplatformlaf has been
defined, its value will be returned.
String laf = (String)AccessController.doPrivileged(
new GetPropertyAction("swing.crossplatformlaf"));
if (laf != null) {
return laf;
}
return "javax.swing.plaf.metal.MetalLookAndFeel";
|
public static javax.swing.UIDefaults | getDefaults()Returns the default values for this look and feel.
maybeInitialize();
return getLAFState().multiUIDefaults;
|
public static java.awt.Dimension | getDimension(java.lang.Object key)Returns a dimension from the defaults table.
return getDefaults().getDimension(key);
|
public static java.awt.Dimension | getDimension(java.lang.Object key, java.util.Locale l)Returns a dimension from the defaults table that is appropriate
for the given locale.
return getDefaults().getDimension(key,l);
|
public static java.awt.Font | getFont(java.lang.Object key)Returns a drawing font from the defaults table.
return getDefaults().getFont(key);
|
public static java.awt.Font | getFont(java.lang.Object key, java.util.Locale l)Returns a drawing font from the defaults table that is appropriate
for the given locale.
return getDefaults().getFont(key,l);
|
public static javax.swing.Icon | getIcon(java.lang.Object key)Returns an Icon from the defaults table.
return getDefaults().getIcon(key);
|
public static javax.swing.Icon | getIcon(java.lang.Object key, java.util.Locale l)Returns an Icon from the defaults table that is appropriate
for the given locale.
return getDefaults().getIcon(key,l);
|
public static java.awt.Insets | getInsets(java.lang.Object key)Returns an Insets object from the defaults table.
return getDefaults().getInsets(key);
|
public static java.awt.Insets | getInsets(java.lang.Object key, java.util.Locale l)Returns an Insets object from the defaults table that is
appropriate for the given locale.
return getDefaults().getInsets(key,l);
|
public static javax.swing.UIManager$LookAndFeelInfo[] | getInstalledLookAndFeels()Returns an array of objects that provide some information about the
LookAndFeel implementations that have been installed with this
software development kit. The LookAndFeel info objects can
used by an application to construct a menu of look and feel options for
the user or to set the look and feel at start up time. Note that
we do not return the LookAndFeel classes themselves here to
avoid the cost of unnecessarily loading them.
Given a LookAndFeelInfo object one can set the current
look and feel like this:
UIManager.setLookAndFeel(info.getClassName());
ArrayList iLAFs = new ArrayList(4);
iLAFs.add(new LookAndFeelInfo(
"Metal", "javax.swing.plaf.metal.MetalLookAndFeel"));
iLAFs.add(new LookAndFeelInfo("CDE/Motif",
"com.sun.java.swing.plaf.motif.MotifLookAndFeel"));
// Only include windows on Windows boxs.
String osName = (String)AccessController.doPrivileged(
new GetPropertyAction("os.name"));
if (osName != null && osName.indexOf("Windows") != -1) {
iLAFs.add(new LookAndFeelInfo("Windows",
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"));
if (Toolkit.getDefaultToolkit().getDesktopProperty(
"win.xpstyle.themeActive") != null) {
iLAFs.add(new LookAndFeelInfo("Windows Classic",
"com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"));
}
}
else {
// GTK is not shipped on Windows.
iLAFs.add(new LookAndFeelInfo("GTK+",
"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"));
}
installedLAFs = (LookAndFeelInfo[])iLAFs.toArray(
new LookAndFeelInfo[iLAFs.size()]);
maybeInitialize();
LookAndFeelInfo[] ilafs = installedLAFs;
LookAndFeelInfo[] rv = new LookAndFeelInfo[ilafs.length];
System.arraycopy(ilafs, 0, rv, 0, ilafs.length);
return rv;
|
public static int | getInt(java.lang.Object key)Returns an integer from the defaults table.
return getDefaults().getInt(key);
|
public static int | getInt(java.lang.Object key, java.util.Locale l)Returns an integer from the defaults table that is appropriate
for the given locale.
return getDefaults().getInt(key,l);
|
static int | getInt(java.lang.Object key, int defaultValue)Returns an integer from the defaults table. If key does
not map to a valid Integer , or can not be convered from
a String to an integer, default is
returned.
Object value = UIManager.get(key);
if (value instanceof Integer) {
return ((Integer)value).intValue();
}
if (value instanceof String) {
try {
return Integer.parseInt((String)value);
} catch (NumberFormatException nfe) {}
}
return defaultValue;
|
private static javax.swing.UIManager$LAFState | getLAFState()Return the LAFState object, lazily create one if necessary.
All access to the LAFState fields is done via this method,
for example:
getLAFState().initialized = true;
// First check whether we're running on the same thread as
// the last request.
Thread thisThread = Thread.currentThread();
if (thisThread == currentLAFStateThread) {
return currentLAFState;
}
LAFState rv = (LAFState)SwingUtilities.appContextGet(lafStateACKey);
if (rv == null) {
synchronized (classLock) {
rv = (LAFState)SwingUtilities.appContextGet(lafStateACKey);
if (rv == null) {
SwingUtilities.appContextPut(lafStateACKey,
(rv = new LAFState()));
}
}
}
currentLAFStateThread = thisThread;
currentLAFState = rv;
return rv;
|
public static javax.swing.LookAndFeel | getLookAndFeel()Returns the current default look and feel or null .
maybeInitialize();
return getLAFState().lookAndFeel;
|
public static javax.swing.UIDefaults | getLookAndFeelDefaults()Returns the default values for this look and feel.
maybeInitialize();
return getLAFState().getLookAndFeelDefaults();
|
private static javax.swing.LookAndFeel | getMultiLookAndFeel()Finds the Multiplexing LookAndFeel .
LookAndFeel multiLookAndFeel = getLAFState().multiLookAndFeel;
if (multiLookAndFeel == null) {
String defaultName = "javax.swing.plaf.multi.MultiLookAndFeel";
String className = getLAFState().swingProps.getProperty(multiplexingLAFKey, defaultName);
try {
Class lnfClass = SwingUtilities.loadSystemClass(className);
multiLookAndFeel = (LookAndFeel)lnfClass.newInstance();
} catch (Exception exc) {
System.err.println("UIManager: failed loading " + className);
}
}
return multiLookAndFeel;
|
public static java.beans.PropertyChangeListener[] | getPropertyChangeListeners()Returns an array of all the PropertyChangeListener s added
to this UIManager with addPropertyChangeListener().
synchronized(classLock) {
return getLAFState().getPropertyChangeSupport(true).
getPropertyChangeListeners();
}
|
public static java.lang.String | getString(java.lang.Object key)Returns a string from the defaults table.
return getDefaults().getString(key);
|
public static java.lang.String | getString(java.lang.Object key, java.util.Locale l)Returns a string from the defaults table that is appropriate for the
given locale.
return getDefaults().getString(key,l);
|
static java.lang.String | getString(java.lang.Object key, java.awt.Component c)Returns a string from the defaults table that is appropriate for the
given locale.
Locale l = (c == null) ? Locale.getDefault() : c.getLocale();
return getString(key, l);
|
public static java.lang.String | getSystemLookAndFeelClassName()Returns the name of the LookAndFeel class that implements
the native systems look and feel if there is one, otherwise
the name of the default cross platform LookAndFeel
class. If the system property swing.systemlaf has been
defined, its value will be returned.
String systemLAF = (String)AccessController.doPrivileged(
new GetPropertyAction("swing.systemlaf"));
if (systemLAF != null) {
return systemLAF;
}
String osName = (String)AccessController.doPrivileged(
new GetPropertyAction("os.name"));
if (osName != null) {
if (osName.indexOf("Windows") != -1) {
return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
}
else {
String desktop = (String)AccessController.doPrivileged(
new GetPropertyAction("sun.desktop"));
if ("gnome".equals(desktop)) {
// May be set on Linux and Solaris boxs.
return "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
}
if ((osName.indexOf("Solaris") != -1) ||
(osName.indexOf("SunOS") != -1)) {
return "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
}
}
}
return getCrossPlatformLookAndFeelClassName();
|
public static javax.swing.plaf.ComponentUI | getUI(javax.swing.JComponent target)Returns the L&F object that renders the target component.
maybeInitialize();
ComponentUI ui = null;
LookAndFeel multiLAF = getLAFState().multiLookAndFeel;
if (multiLAF != null) {
// This can return null if the multiplexing look and feel
// doesn't support a particular UI.
ui = multiLAF.getDefaults().getUI(target);
}
if (ui == null) {
ui = getDefaults().getUI(target);
}
return ui;
|
private static void | initialize()
Properties swingProps = loadSwingProperties();
initializeSystemDefaults(swingProps);
initializeDefaultLAF(swingProps);
initializeAuxiliaryLAFs(swingProps);
initializeInstalledLAFs(swingProps);
// Enable the Swing default LayoutManager.
String toolkitName = Toolkit.getDefaultToolkit().getClass().getName();
// don't set default policy if this is XAWT.
if (!"sun.awt.X11.XToolkit".equals(toolkitName)) {
if (FocusManager.isFocusManagerEnabled()) {
KeyboardFocusManager.getCurrentKeyboardFocusManager().
setDefaultFocusTraversalPolicy(
new LayoutFocusTraversalPolicy());
}
}
// Install a hook that will be invoked if no one consumes the
// KeyEvent. If the source isn't a JComponent this will process
// key bindings, if the source is a JComponent it implies that
// processKeyEvent was already invoked and thus no need to process
// the bindings again, unless the Component is disabled, in which
// case KeyEvents will no longer be dispatched to it so that we
// handle it here.
KeyboardFocusManager.getCurrentKeyboardFocusManager().
addKeyEventPostProcessor(new KeyEventPostProcessor() {
public boolean postProcessKeyEvent(KeyEvent e) {
Component c = e.getComponent();
if ((!(c instanceof JComponent) ||
(c != null && !((JComponent)c).isEnabled())) &&
JComponent.KeyboardState.shouldProcess(e) &&
SwingUtilities.processKeyBindings(e)) {
e.consume();
return true;
}
return false;
}
});
|
private static void | initializeAuxiliaryLAFs(java.util.Properties swingProps)
String auxLookAndFeelNames = swingProps.getProperty(auxiliaryLAFsKey);
if (auxLookAndFeelNames == null) {
return;
}
Vector auxLookAndFeels = new Vector();
StringTokenizer p = new StringTokenizer(auxLookAndFeelNames,",");
String factoryName;
/* Try to load each LookAndFeel subclass in the list.
*/
while (p.hasMoreTokens()) {
String className = p.nextToken();
try {
Class lnfClass = SwingUtilities.loadSystemClass(className);
LookAndFeel newLAF = (LookAndFeel)lnfClass.newInstance();
newLAF.initialize();
auxLookAndFeels.addElement(newLAF);
}
catch (Exception e) {
System.err.println("UIManager: failed loading auxiliary look and feel " + className);
}
}
/* If there were problems and no auxiliary look and feels were
* loaded, make sure we reset auxLookAndFeels to null.
* Otherwise, we are going to use the MultiLookAndFeel to get
* all component UI's, so we need to load it now.
*/
if (auxLookAndFeels.size() == 0) {
auxLookAndFeels = null;
}
else {
getLAFState().multiLookAndFeel = getMultiLookAndFeel();
if (getLAFState().multiLookAndFeel == null) {
auxLookAndFeels = null;
}
}
getLAFState().auxLookAndFeels = auxLookAndFeels;
|
private static void | initializeDefaultLAF(java.util.Properties swingProps)If the user has specified a default look and feel, use that.
Otherwise use the look and feel that's native to this platform.
If this code is called after the application has explicitly
set it's look and feel, do nothing.
if (getLAFState().lookAndFeel != null) {
return;
}
String metalLnf = getCrossPlatformLookAndFeelClassName();
String lnfDefault = metalLnf;
String lnfName = "<undefined>" ;
try {
lnfName = swingProps.getProperty(defaultLAFKey, lnfDefault);
setLookAndFeel(lnfName);
} catch (Exception e) {
try {
lnfName = swingProps.getProperty(defaultLAFKey, metalLnf);
setLookAndFeel(lnfName);
} catch (Exception e2) {
throw new Error("can't load " + lnfName);
}
}
|
private static void | initializeInstalledLAFs(java.util.Properties swingProps)If a swing.properties file exist and it has a swing.installedlafs property
then initialize the installedLAFs field.
String ilafsString = swingProps.getProperty(installedLAFsKey);
if (ilafsString == null) {
return;
}
/* Create a vector that contains the value of the swing.installedlafs
* property. For example given "swing.installedlafs=motif,windows"
* lafs = {"motif", "windows"}.
*/
Vector lafs = new Vector();
StringTokenizer st = new StringTokenizer(ilafsString, ",", false);
while (st.hasMoreTokens()) {
lafs.addElement(st.nextToken());
}
/* Look up the name and class for each name in the "swing.installedlafs"
* list. If they both exist then add a LookAndFeelInfo to
* the installedLafs array.
*/
Vector ilafs = new Vector(lafs.size());
for(int i = 0; i < lafs.size(); i++) {
String laf = (String)lafs.elementAt(i);
String name = swingProps.getProperty(makeInstalledLAFKey(laf, "name"), laf);
String cls = swingProps.getProperty(makeInstalledLAFKey(laf, "class"));
if (cls != null) {
ilafs.addElement(new LookAndFeelInfo(name, cls));
}
}
installedLAFs = new LookAndFeelInfo[ilafs.size()];
for(int i = 0; i < ilafs.size(); i++) {
installedLAFs[i] = (LookAndFeelInfo)(ilafs.elementAt(i));
}
|
private static void | initializeSystemDefaults(java.util.Properties swingProps)
getLAFState().swingProps = swingProps;
|
public static void | installLookAndFeel(javax.swing.UIManager$LookAndFeelInfo info)Adds the specified look and feel to the current array and
then calls {@link #setInstalledLookAndFeels}.
LookAndFeelInfo[] infos = getInstalledLookAndFeels();
LookAndFeelInfo[] newInfos = new LookAndFeelInfo[infos.length + 1];
System.arraycopy(infos, 0, newInfos, 0, infos.length);
newInfos[infos.length] = info;
setInstalledLookAndFeels(newInfos);
|
public static void | installLookAndFeel(java.lang.String name, java.lang.String className)Creates a new look and feel and adds it to the current array.
Then calls {@link #setInstalledLookAndFeels}.
installLookAndFeel(new LookAndFeelInfo(name, className));
|
private static java.util.Properties | loadSwingProperties()
/* Don't bother checking for Swing properties if untrusted, as
* there's no way to look them up without triggering SecurityExceptions.
*/
if (UIManager.class.getClassLoader() != null) {
return new Properties();
}
else {
final Properties props = new Properties();
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
try {
File file = new File(makeSwingPropertiesFilename());
if (file.exists()) {
// InputStream has been buffered in Properties
// class
FileInputStream ins = new FileInputStream(file);
props.load(ins);
ins.close();
}
}
catch (Exception e) {
// No such file, or file is otherwise non-readable.
}
// Check whether any properties were overridden at the
// command line.
checkProperty(props, defaultLAFKey);
checkProperty(props, auxiliaryLAFsKey);
checkProperty(props, multiplexingLAFKey);
checkProperty(props, installedLAFsKey);
checkProperty(props, disableMnemonicKey);
// Don't care about return value.
return null;
}
});
return props;
}
|
private static java.lang.String | makeInstalledLAFKey(java.lang.String laf, java.lang.String attr)Return a swing.properties file key for the attribute of specified
look and feel. The attr is either "name" or "class", a typical
key would be: "swing.installedlaf.windows.name"
return "swing.installedlaf." + laf + "." + attr;
|
private static java.lang.String | makeSwingPropertiesFilename()The filename for swing.properties is a path like this (Unix version):
/lib/swing.properties. This method returns a bogus
filename if java.home isn't defined.
String sep = File.separator;
// No need to wrap this in a doPrivileged as it's called from
// a doPrivileged.
String javaHome = System.getProperty("java.home");
if (javaHome == null) {
javaHome = "<java.home undefined>";
}
return javaHome + sep + "lib" + sep + "swing.properties";
|
private static void | maybeInitialize()
synchronized (classLock) {
if (!getLAFState().initialized) {
getLAFState().initialized = true;
initialize();
}
}
|
public static java.lang.Object | put(java.lang.Object key, java.lang.Object value)Stores an object in the defaults table.
return getDefaults().put(key, value);
|
public static boolean | removeAuxiliaryLookAndFeel(javax.swing.LookAndFeel laf)Removes a LookAndFeel from the list of auxiliary look and feels.
The auxiliary look and feels tell the multiplexing look and feel what
other LookAndFeel classes for a component instance are to be used
in addition to the default LookAndFeel class when creating a
multiplexing UI. The change will only take effect when a new
UI class is created or when the default look and feel is changed
on a component instance.
Note these are not the same as the installed look and feels.
maybeInitialize();
boolean result;
Vector v = getLAFState().auxLookAndFeels;
if ((v == null) || (v.size() == 0)) {
return false;
}
result = v.removeElement(laf);
if (result) {
if (v.size() == 0) {
getLAFState().auxLookAndFeels = null;
getLAFState().multiLookAndFeel = null;
} else {
getLAFState().auxLookAndFeels = v;
}
}
laf.uninitialize();
return result;
|
public static void | removePropertyChangeListener(java.beans.PropertyChangeListener listener)Removes a PropertyChangeListener from the listener list.
This removes a PropertyChangeListener that was registered
for all properties.
synchronized (classLock) {
getLAFState().getPropertyChangeSupport(true).
removePropertyChangeListener(listener);
}
|
public static void | setInstalledLookAndFeels(javax.swing.UIManager$LookAndFeelInfo[] infos)Replaces the current array of installed LookAndFeelInfos .
LookAndFeelInfo[] newInfos = new LookAndFeelInfo[infos.length];
System.arraycopy(infos, 0, newInfos, 0, infos.length);
installedLAFs = newInfos;
|
public static void | setLookAndFeel(java.lang.String className)Sets the current default look and feel using a class name.
if ("javax.swing.plaf.metal.MetalLookAndFeel".equals(className)) {
// Avoid reflection for the common case of metal.
setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
}
else {
Class lnfClass = SwingUtilities.loadSystemClass(className);
setLookAndFeel((LookAndFeel)(lnfClass.newInstance()));
}
|
public static void | setLookAndFeel(javax.swing.LookAndFeel newLookAndFeel)Sets the current default look and feel using a
LookAndFeel object.
This is a JavaBeans bound property.
if ((newLookAndFeel != null) && !newLookAndFeel.isSupportedLookAndFeel()) {
String s = newLookAndFeel.toString() + " not supported on this platform";
throw new UnsupportedLookAndFeelException(s);
}
LAFState lafState = getLAFState();
LookAndFeel oldLookAndFeel = lafState.lookAndFeel;
if (oldLookAndFeel != null) {
oldLookAndFeel.uninitialize();
}
lafState.lookAndFeel = newLookAndFeel;
if (newLookAndFeel != null) {
sun.swing.DefaultLookup.setDefaultLookup(null);
newLookAndFeel.initialize();
lafState.setLookAndFeelDefaults(newLookAndFeel.getDefaults());
}
else {
lafState.setLookAndFeelDefaults(null);
}
SwingPropertyChangeSupport changeSupport = lafState.
getPropertyChangeSupport(false);
if (changeSupport != null) {
changeSupport.firePropertyChange("lookAndFeel", oldLookAndFeel,
newLookAndFeel);
}
|