/* * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing; import java.awt.Component; import java.awt.Font; import java.awt.Color; import java.awt.Insets; import java.awt.Dimension; import java.awt.KeyboardFocusManager; import java.awt.KeyEventPostProcessor; import java.awt.Toolkit; import java.awt.event.KeyEvent; import java.security.AccessController; import javax.swing.plaf.ComponentUI; import javax.swing.border.Border; import javax.swing.event.SwingPropertyChangeSupport; import java.beans.PropertyChangeListener; import java.io.Serializable; import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; import java.util.Properties; import java.util.StringTokenizer; import java.util.Vector; import java.util.Locale; import sun.awt.SunToolkit; import sun.awt.OSInfo; import sun.security.action.GetPropertyAction; import sun.swing.SwingUtilities2; import java.lang.reflect.Method; import java.util.HashMap; import sun.awt.AppContext; import sun.awt.AWTAccessor; /** * {@code UIManager} manages the current look and feel, the set of * available look and feels, {@code PropertyChangeListeners} that * are notified when the look and feel changes, look and feel defaults, and * convenience methods for obtaining various default values. * *
* UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); ** The following example illustrates setting the look and feel based on * class name: *
* UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); ** Once the look and feel has been changed it is imperative to invoke * {@code updateUI} on all {@code JComponents}. The method {@link * SwingUtilities#updateComponentTreeUI} makes it easy to apply {@code * updateUI} to a containment hierarchy. Refer to it for * details. The exact behavior of not invoking {@code * updateUI} after changing the look and feel is * unspecified. It is very possible to receive unexpected exceptions, * painting problems, or worse. * *
swing.defaultlaf
is
* {@code non-null}, use its value as the default look and feel class
* name.
* swing.properties
* exists and contains the key swing.defaultlaf
,
* use its value as the default look and feel class name. The location
* that is checked for swing.properties
may vary depending
* upon the implementation of the Java platform. In Sun's implementation
* the location is ${java.home}/lib/swing.properties
.
* Refer to the release notes of the implementation being used for
* further details.
* * It's important to note that {@code getDefaults} returns a custom * instance of {@code UIDefaults} with this resolution logic built into it. * For example, {@code UIManager.getDefaults().getString("Table.foreground")} * is equivalent to {@code UIManager.getString("Table.foreground")}. Both * resolve using the algorithm just described. In many places the * documentation uses the word defaults to refer to the custom instance * of {@code UIDefaults} with the resolution logic as previously described. *
* When the look and feel is changed, {@code UIManager} alters only the * look and feel defaults; the developer and system defaults are not * altered by the {@code UIManager} in any way. *
* The set of defaults a particular look and feel supports is defined * and documented by that look and feel. In addition, each look and * feel, or {@code ComponentUI} provided by a look and feel, may * access the defaults at different times in their life cycle. Some * look and feels may agressively look up defaults, so that changing a * default may not have an effect after installing the look and feel. * Other look and feels may lazily access defaults so that a change to * the defaults may effect an existing look and feel. Finally, other look * and feels might not configure themselves from the defaults table in * any way. None-the-less it is usually the case that a look and feel * expects certain defaults, so that in general * a {@code ComponentUI} provided by one look and feel will not * work with another look and feel. *
* Warning:
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeansTM
* has been added to the
* The following example illustrates setting the current look and feel
* from an instance of {@code LookAndFeelInfo}:
*
* A value of {@code null} can be used to set the look and feel
* to {@code null}. As the {@code LookAndFeel} is required for
* most of Swing to function, setting the {@code LookAndFeel} to
* {@code null} is strongly discouraged.
*
* This is a JavaBeans bound property.
*
* @param newLookAndFeel {@code LookAndFeel} to install
* @throws UnsupportedLookAndFeelException if
* {@code newLookAndFeel} is {@code non-null} and
* {@code newLookAndFeel.isSupportedLookAndFeel()} returns
* {@code false}
* @see #getLookAndFeel
*/
public static void setLookAndFeel(LookAndFeel newLookAndFeel)
throws UnsupportedLookAndFeelException
{
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);
}
}
/**
* Loads the {@code LookAndFeel} specified by the given class
* name, using the current thread's context class loader, and
* passes it to {@code setLookAndFeel(LookAndFeel)}.
*
* @param className a string specifying the name of the class that implements
* the look and feel
* @exception ClassNotFoundException if the
* In general, developers should use the {@code UIDefaults} returned from
* {@code getDefaults()}. As the current look and feel may expect
* certain values to exist, altering the {@code UIDefaults} returned
* from this method could have unexpected results.
*
* @return Note these are not the same as the installed look and feels.
*
* @param laf the Note these are not the same as the installed look and feels.
* @return true if the Note these are not the same as the installed look and feels.
*
* @return list of auxiliary java.beans
package.
* Please see {@link java.beans.XMLEncoder}.
*
* @author Thomas Ball
* @author Hans Muller
*/
public class UIManager implements Serializable
{
/**
* This class defines the state managed by the UIManager
. For
* Swing applications the fields in this class could just as well
* be static members of UIManager
however we give them
* "AppContext"
* scope instead so that applets (and potentially multiple lightweight
* applications running in a single VM) have their own state. For example,
* an applet can alter its look and feel, see setLookAndFeel
.
* Doing so has no affect on other applets (or the browser).
*/
private static class LAFState
{
Properties swingProps;
private UIDefaults[] tables = new UIDefaults[2];
boolean initialized = false;
boolean focusPolicyInitialized = false;
MultiUIDefaults multiUIDefaults = new MultiUIDefaults(tables);
LookAndFeel lookAndFeel;
LookAndFeel multiLookAndFeel = null;
Vectorcreate
is a true, a non-null
* SwingPropertyChangeSupport
will be returned, if
* create
is false and this has not been invoked
* with true, null will be returned.
*/
public synchronized SwingPropertyChangeSupport
getPropertyChangeSupport(boolean create) {
if (create && changeSupport == null) {
changeSupport = new SwingPropertyChangeSupport(
UIManager.class);
}
return changeSupport;
}
}
/* Lock object used in place of class object for synchronization. (4187686)
*/
private static final Object classLock = new Object();
/**
* 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;
*
*/
private static LAFState getLAFState() {
LAFState rv = (LAFState)SwingUtilities.appContextGet(
SwingUtilities2.LAF_STATE_KEY);
if (rv == null) {
synchronized (classLock) {
rv = (LAFState)SwingUtilities.appContextGet(
SwingUtilities2.LAF_STATE_KEY);
if (rv == null) {
SwingUtilities.appContextPut(
SwingUtilities2.LAF_STATE_KEY,
(rv = new LAFState()));
}
}
}
return rv;
}
/* Keys used for the properties file in LookAndFeel
for the sake of configuring a menu or
* for initial application set up.
*
* @see UIManager#getInstalledLookAndFeels
* @see LookAndFeel
*/
public static class LookAndFeelInfo {
private String name;
private String className;
/**
* Constructs a UIManager
s
* LookAndFeelInfo
object.
*
* @param name a String
specifying the name of
* the look and feel
* @param className a String
specifiying the name of
* the class that implements the look and feel
*/
public LookAndFeelInfo(String name, String className) {
this.name = name;
this.className = className;
}
/**
* Returns the name of the look and feel in a form suitable
* for a menu or other presentation
* @return a String
containing the name
* @see LookAndFeel#getName
*/
public String getName() {
return name;
}
/**
* Returns the name of the class that implements this look and feel.
* @return the name of the class that implements this
* LookAndFeel
* @see LookAndFeel
*/
public String getClassName() {
return className;
}
/**
* Returns a string that displays and identifies this
* object's properties.
*
* @return a String
representation of this object
*/
public String toString() {
return getClass().getName() + "[" + getName() + " " + getClassName() + "]";
}
}
/**
* The default value of installedLAFS
is used when no
* swing.properties
* file is available or if the file doesn't contain a "swing.installedlafs"
* property.
*
* @see #initializeInstalledLAFs
*/
private static LookAndFeelInfo[] installedLAFs;
static {
ArrayListLookAndFeelInfo
objects can be used by an
* application to construct a menu of look and feel options for
* the user, or to determine which look and feel to set at startup
* time. To avoid the penalty of creating numerous {@code
* LookAndFeel} objects, {@code LookAndFeelInfo} maintains the
* class name of the {@code LookAndFeel} class, not the actual
* {@code LookAndFeel} instance.
*
* UIManager.setLookAndFeel(info.getClassName());
*
*
* @return an array of LookAndFeelInfo
objects
* @see #setLookAndFeel
*/
public static LookAndFeelInfo[] getInstalledLookAndFeels() {
maybeInitialize();
LookAndFeelInfo[] ilafs = getLAFState().installedLAFs;
if (ilafs == null) {
ilafs = installedLAFs;
}
LookAndFeelInfo[] rv = new LookAndFeelInfo[ilafs.length];
System.arraycopy(ilafs, 0, rv, 0, ilafs.length);
return rv;
}
/**
* Sets the set of available look and feels. While this method does
* not check to ensure all of the {@code LookAndFeelInfos} are
* {@code non-null}, it is strongly recommended that only {@code non-null}
* values are supplied in the {@code infos} array.
*
* @param infos set of LookAndFeelInfo
objects specifying
* the available look and feels
*
* @see #getInstalledLookAndFeels
* @throws NullPointerException if {@code infos} is {@code null}
*/
public static void setInstalledLookAndFeels(LookAndFeelInfo[] infos)
throws SecurityException
{
maybeInitialize();
LookAndFeelInfo[] newInfos = new LookAndFeelInfo[infos.length];
System.arraycopy(infos, 0, newInfos, 0, infos.length);
getLAFState().installedLAFs = newInfos;
}
/**
* Adds the specified look and feel to the set of available look
* and feels. While this method allows a {@code null} {@code info},
* it is strongly recommended that a {@code non-null} value be used.
*
* @param info a LookAndFeelInfo
object that names the
* look and feel and identifies the class that implements it
* @see #setInstalledLookAndFeels
*/
public static void installLookAndFeel(LookAndFeelInfo info) {
LookAndFeelInfo[] infos = getInstalledLookAndFeels();
LookAndFeelInfo[] newInfos = new LookAndFeelInfo[infos.length + 1];
System.arraycopy(infos, 0, newInfos, 0, infos.length);
newInfos[infos.length] = info;
setInstalledLookAndFeels(newInfos);
}
/**
* Adds the specified look and feel to the set of available look
* and feels. While this method does not check the
* arguments in any way, it is strongly recommended that {@code
* non-null} values be supplied.
*
* @param name descriptive name of the look and feel
* @param className name of the class that implements the look and feel
* @see #setInstalledLookAndFeels
*/
public static void installLookAndFeel(String name, String className) {
installLookAndFeel(new LookAndFeelInfo(name, className));
}
/**
* Returns the current look and feel or null
.
*
* @return current look and feel, or null
* @see #setLookAndFeel
*/
public static LookAndFeel getLookAndFeel() {
maybeInitialize();
return getLAFState().lookAndFeel;
}
/**
* Sets the current look and feel to {@code newLookAndFeel}.
* If the current look and feel is {@code non-null} {@code
* uninitialize} is invoked on it. If {@code newLookAndFeel} is
* {@code non-null}, {@code initialize} is invoked on it followed
* by {@code getDefaults}. The defaults returned from {@code
* newLookAndFeel.getDefaults()} replace those of the defaults
* from the previous look and feel. If the {@code newLookAndFeel} is
* {@code null}, the look and feel defaults are set to {@code null}.
* LookAndFeel
* class could not be found
* @exception InstantiationException if a new instance of the class
* couldn't be created
* @exception IllegalAccessException if the class or initializer isn't accessible
* @exception UnsupportedLookAndFeelException if
* lnf.isSupportedLookAndFeel()
is false
* @throws ClassCastException if {@code className} does not identify
* a class that extends {@code LookAndFeel}
*/
public static void setLookAndFeel(String className)
throws ClassNotFoundException,
InstantiationException,
IllegalAccessException,
UnsupportedLookAndFeelException
{
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()));
}
}
/**
* Returns the name of the LookAndFeel
class that implements
* the native system look and feel if there is one, otherwise
* the name of the default cross platform LookAndFeel
* class. This value can be overriden by setting the
* swing.systemlaf
system property.
*
* @return the String
of the LookAndFeel
* class
*
* @see #setLookAndFeel
* @see #getCrossPlatformLookAndFeelClassName
*/
public static String getSystemLookAndFeelClassName() {
String systemLAF = AccessController.doPrivileged(
new GetPropertyAction("swing.systemlaf"));
if (systemLAF != null) {
return systemLAF;
}
OSInfo.OSType osType = AccessController.doPrivileged(OSInfo.getOSTypeAction());
if (osType == OSInfo.OSType.WINDOWS) {
return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
} else {
String desktop = AccessController.doPrivileged(new GetPropertyAction("sun.desktop"));
Toolkit toolkit = Toolkit.getDefaultToolkit();
if ("gnome".equals(desktop) &&
toolkit instanceof SunToolkit &&
((SunToolkit) toolkit).isNativeGTKAvailable()) {
// May be set on Linux and Solaris boxs.
return "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
}
if (osType == OSInfo.OSType.MACOSX) {
if (toolkit.getClass() .getName()
.equals("sun.lwawt.macosx.LWCToolkit")) {
return "com.apple.laf.AquaLookAndFeel";
}
}
if (osType == OSInfo.OSType.SOLARIS) {
return "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
}
}
return getCrossPlatformLookAndFeelClassName();
}
/**
* Returns the name of the LookAndFeel
class that implements
* the default cross platform look and feel -- the Java
* Look and Feel (JLF). This value can be overriden by setting the
* swing.crossplatformlaf
system property.
*
* @return a string with the JLF implementation-class
* @see #setLookAndFeel
* @see #getSystemLookAndFeelClassName
*/
public static String getCrossPlatformLookAndFeelClassName() {
String laf = AccessController.doPrivileged(
new GetPropertyAction("swing.crossplatformlaf"));
if (laf != null) {
return laf;
}
return "javax.swing.plaf.metal.MetalLookAndFeel";
}
/**
* Returns the defaults. The returned defaults resolve using the
* logic specified in the class documentation.
*
* @return a UIDefaults
object containing the default values
*/
public static UIDefaults getDefaults() {
maybeInitialize();
return getLAFState().multiUIDefaults;
}
/**
* Returns a font from the defaults. If the value for {@code key} is
* not a {@code Font}, {@code null} is returned.
*
* @param key an Object
specifying the font
* @return the Font
object
* @throws NullPointerException if {@code key} is {@code null}
*/
public static Font getFont(Object key) {
return getDefaults().getFont(key);
}
/**
* Returns a font from the defaults that is appropriate
* for the given locale. If the value for {@code key} is
* not a {@code Font}, {@code null} is returned.
*
* @param key an Object
specifying the font
* @param l the Locale
for which the font is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the Font
object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
public static Font getFont(Object key, Locale l) {
return getDefaults().getFont(key,l);
}
/**
* Returns a color from the defaults. If the value for {@code key} is
* not a {@code Color}, {@code null} is returned.
*
* @param key an Object
specifying the color
* @return the Color
object
* @throws NullPointerException if {@code key} is {@code null}
*/
public static Color getColor(Object key) {
return getDefaults().getColor(key);
}
/**
* Returns a color from the defaults that is appropriate
* for the given locale. If the value for {@code key} is
* not a {@code Color}, {@code null} is returned.
*
* @param key an Object
specifying the color
* @param l the Locale
for which the color is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the Color
object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
public static Color getColor(Object key, Locale l) {
return getDefaults().getColor(key,l);
}
/**
* Returns an Icon
from the defaults. If the value for
* {@code key} is not an {@code Icon}, {@code null} is returned.
*
* @param key an Object
specifying the icon
* @return the Icon
object
* @throws NullPointerException if {@code key} is {@code null}
*/
public static Icon getIcon(Object key) {
return getDefaults().getIcon(key);
}
/**
* Returns an Icon
from the defaults that is appropriate
* for the given locale. If the value for
* {@code key} is not an {@code Icon}, {@code null} is returned.
*
* @param key an Object
specifying the icon
* @param l the Locale
for which the icon is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the Icon
object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
public static Icon getIcon(Object key, Locale l) {
return getDefaults().getIcon(key,l);
}
/**
* Returns a border from the defaults. If the value for
* {@code key} is not a {@code Border}, {@code null} is returned.
*
* @param key an Object
specifying the border
* @return the Border
object
* @throws NullPointerException if {@code key} is {@code null}
*/
public static Border getBorder(Object key) {
return getDefaults().getBorder(key);
}
/**
* Returns a border from the defaults that is appropriate
* for the given locale. If the value for
* {@code key} is not a {@code Border}, {@code null} is returned.
*
* @param key an Object
specifying the border
* @param l the Locale
for which the border is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the Border
object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
public static Border getBorder(Object key, Locale l) {
return getDefaults().getBorder(key,l);
}
/**
* Returns a string from the defaults. If the value for
* {@code key} is not a {@code String}, {@code null} is returned.
*
* @param key an Object
specifying the string
* @return the String
* @throws NullPointerException if {@code key} is {@code null}
*/
public static String getString(Object key) {
return getDefaults().getString(key);
}
/**
* Returns a string from the defaults that is appropriate for the
* given locale. If the value for
* {@code key} is not a {@code String}, {@code null} is returned.
*
* @param key an Object
specifying the string
* @param l the Locale
for which the string is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the String
* @since 1.4
* @throws NullPointerException if {@code key} is {@code null}
*/
public static String getString(Object key, Locale l) {
return getDefaults().getString(key,l);
}
/**
* Returns a string from the defaults that is appropriate for the
* given locale. If the value for
* {@code key} is not a {@code String}, {@code null} is returned.
*
* @param key an Object
specifying the string
* @param c {@code Component} used to determine the locale;
* {@code null} implies the default locale as
* returned by {@code Locale.getDefault()}
* @return the String
* @throws NullPointerException if {@code key} is {@code null}
*/
static String getString(Object key, Component c) {
Locale l = (c == null) ? Locale.getDefault() : c.getLocale();
return getString(key, l);
}
/**
* Returns an integer from the defaults. If the value for
* {@code key} is not an {@code Integer}, or does not exist,
* {@code 0} is returned.
*
* @param key an Object
specifying the int
* @return the int
* @throws NullPointerException if {@code key} is {@code null}
*/
public static int getInt(Object key) {
return getDefaults().getInt(key);
}
/**
* Returns an integer from the defaults that is appropriate
* for the given locale. If the value for
* {@code key} is not an {@code Integer}, or does not exist,
* {@code 0} is returned.
*
* @param key an Object
specifying the int
* @param l the Locale
for which the int is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the int
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
public static int getInt(Object key, Locale l) {
return getDefaults().getInt(key,l);
}
/**
* Returns a boolean from the defaults which is associated with
* the key value. If the key is not found or the key doesn't represent
* a boolean value then {@code false} is returned.
*
* @param key an Object
specifying the key for the desired boolean value
* @return the boolean value corresponding to the key
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
public static boolean getBoolean(Object key) {
return getDefaults().getBoolean(key);
}
/**
* Returns a boolean from the defaults 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 {@code false} will be returned.
*
* @param key an Object
specifying the key for the desired
* boolean value
* @param l the Locale
for which the boolean is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the boolean value corresponding to the key
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
public static boolean getBoolean(Object key, Locale l) {
return getDefaults().getBoolean(key,l);
}
/**
* Returns an Insets
object from the defaults. If the value
* for {@code key} is not an {@code Insets}, {@code null} is returned.
*
* @param key an Object
specifying the Insets
object
* @return the Insets
object
* @throws NullPointerException if {@code key} is {@code null}
*/
public static Insets getInsets(Object key) {
return getDefaults().getInsets(key);
}
/**
* Returns an Insets
object from the defaults that is
* appropriate for the given locale. If the value
* for {@code key} is not an {@code Insets}, {@code null} is returned.
*
* @param key an Object
specifying the Insets
object
* @param l the Locale
for which the object is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the Insets
object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
public static Insets getInsets(Object key, Locale l) {
return getDefaults().getInsets(key,l);
}
/**
* Returns a dimension from the defaults. If the value
* for {@code key} is not a {@code Dimension}, {@code null} is returned.
*
* @param key an Object
specifying the dimension object
* @return the Dimension
object
* @throws NullPointerException if {@code key} is {@code null}
*/
public static Dimension getDimension(Object key) {
return getDefaults().getDimension(key);
}
/**
* Returns a dimension from the defaults that is appropriate
* for the given locale. If the value
* for {@code key} is not a {@code Dimension}, {@code null} is returned.
*
* @param key an Object
specifying the dimension object
* @param l the Locale
for which the object is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the Dimension
object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
public static Dimension getDimension(Object key, Locale l) {
return getDefaults().getDimension(key,l);
}
/**
* Returns an object from the defaults.
*
* @param key an Object
specifying the desired object
* @return the Object
* @throws NullPointerException if {@code key} is {@code null}
*/
public static Object get(Object key) {
return getDefaults().get(key);
}
/**
* Returns an object from the defaults that is appropriate for
* the given locale.
*
* @param key an Object
specifying the desired object
* @param l the Locale
for which the object is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the Object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
public static Object get(Object key, Locale l) {
return getDefaults().get(key,l);
}
/**
* Stores an object in the developer defaults. This is a cover method
* for {@code getDefaults().put(key, value)}. This only effects the
* developer defaults, not the system or look and feel defaults.
*
* @param key an Object
specifying the retrieval key
* @param value the Object
to store; refer to
* {@code UIDefaults} for details on how {@code null} is
* handled
* @return the Object
returned by {@link UIDefaults#put}
* @throws NullPointerException if {@code key} is {@code null}
* @see UIDefaults#put
*/
public static Object put(Object key, Object value) {
return getDefaults().put(key, value);
}
/**
* Returns the appropriate {@code ComponentUI} implementation for
* {@code target}. Typically, this is a cover for
* {@code getDefaults().getUI(target)}. However, if an auxiliary
* look and feel has been installed, this first invokes
* {@code getUI(target)} on the multiplexing look and feel's
* defaults, and returns that value if it is {@code non-null}.
*
* @param target the JComponent
to return the
* {@code ComponentUI} for
* @return the ComponentUI
object for {@code target}
* @throws NullPointerException if {@code target} is {@code null}
* @see UIDefaults#getUI
*/
public static ComponentUI getUI(JComponent target) {
maybeInitialize();
maybeInitializeFocusPolicy(target);
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;
}
/**
* Returns the {@code UIDefaults} from the current look and feel,
* that were obtained at the time the look and feel was installed.
* UIDefaults
from the current look and feel
* @see #getDefaults
* @see #setLookAndFeel(LookAndFeel)
* @see LookAndFeel#getDefaults
*/
public static UIDefaults getLookAndFeelDefaults() {
maybeInitialize();
return getLAFState().getLookAndFeelDefaults();
}
/**
* Finds the Multiplexing LookAndFeel
.
*/
private static LookAndFeel getMultiLookAndFeel() {
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;
}
/**
* 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.
* LookAndFeel
object
* @see #removeAuxiliaryLookAndFeel
* @see #setLookAndFeel
* @see #getAuxiliaryLookAndFeels
* @see #getInstalledLookAndFeels
*/
static public void addAuxiliaryLookAndFeel(LookAndFeel laf) {
maybeInitialize();
if (!laf.isSupportedLookAndFeel()) {
// Ideally we would throw an exception here, but it's too late
// for that.
return;
}
VectorLookAndFeel
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.
* LookAndFeel
was removed from the list
* @see #removeAuxiliaryLookAndFeel
* @see #getAuxiliaryLookAndFeels
* @see #setLookAndFeel
* @see #getInstalledLookAndFeels
*/
static public boolean removeAuxiliaryLookAndFeel(LookAndFeel laf) {
maybeInitialize();
boolean result;
Vectornull
).
* 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.
* LookAndFeel
s or null
* @see #addAuxiliaryLookAndFeel
* @see #removeAuxiliaryLookAndFeel
* @see #setLookAndFeel
* @see #getInstalledLookAndFeels
*/
static public LookAndFeel[] getAuxiliaryLookAndFeels() {
maybeInitialize();
VectorPropertyChangeListener
to the listener list.
* The listener is registered for all properties.
*
* @param listener the PropertyChangeListener
to be added
* @see java.beans.PropertyChangeSupport
*/
public static void addPropertyChangeListener(PropertyChangeListener listener)
{
synchronized (classLock) {
getLAFState().getPropertyChangeSupport(true).
addPropertyChangeListener(listener);
}
}
/**
* Removes a PropertyChangeListener
from the listener list.
* This removes a PropertyChangeListener
that was registered
* for all properties.
*
* @param listener the PropertyChangeListener
to be removed
* @see java.beans.PropertyChangeSupport
*/
public static void removePropertyChangeListener(PropertyChangeListener listener)
{
synchronized (classLock) {
getLAFState().getPropertyChangeSupport(true).
removePropertyChangeListener(listener);
}
}
/**
* Returns an array of all the PropertyChangeListener
s added
* to this UIManager with addPropertyChangeListener().
*
* @return all of the PropertyChangeListener
s added or an empty
* array if no listeners have been added
* @since 1.4
*/
public static PropertyChangeListener[] getPropertyChangeListeners() {
synchronized(classLock) {
return getLAFState().getPropertyChangeSupport(true).
getPropertyChangeListeners();
}
}
private static 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