UIManager.java revision 2362
0N/A/*
2362N/A * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing;
0N/A
0N/Aimport java.awt.Component;
893N/Aimport java.awt.Font;
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Insets;
0N/Aimport java.awt.Dimension;
0N/Aimport java.awt.KeyboardFocusManager;
0N/Aimport java.awt.KeyEventPostProcessor;
0N/Aimport java.awt.Toolkit;
0N/A
0N/Aimport java.awt.event.KeyEvent;
0N/A
0N/Aimport java.security.AccessController;
0N/A
0N/Aimport javax.swing.plaf.ComponentUI;
0N/Aimport javax.swing.border.Border;
0N/A
0N/Aimport javax.swing.event.SwingPropertyChangeSupport;
0N/Aimport java.beans.PropertyChangeListener;
0N/A
0N/Aimport java.io.Serializable;
0N/Aimport java.io.File;
0N/Aimport java.io.FileInputStream;
0N/A
0N/Aimport java.util.ArrayList;
0N/Aimport java.util.Properties;
0N/Aimport java.util.StringTokenizer;
0N/Aimport java.util.Vector;
0N/Aimport java.util.Locale;
0N/A
0N/Aimport sun.awt.SunToolkit;
0N/Aimport sun.awt.OSInfo;
0N/Aimport sun.security.action.GetPropertyAction;
0N/Aimport sun.swing.SwingUtilities2;
0N/Aimport java.lang.reflect.Method;
0N/Aimport java.util.HashMap;
0N/Aimport sun.awt.AppContext;
0N/Aimport sun.awt.AWTAccessor;
0N/A
0N/A
0N/A/**
0N/A * {@code UIManager} manages the current look and feel, the set of
0N/A * available look and feels, {@code PropertyChangeListeners} that
0N/A * are notified when the look and feel changes, look and feel defaults, and
0N/A * convenience methods for obtaining various default values.
0N/A *
0N/A * <h3>Specifying the look and feel</h3>
0N/A *
0N/A * The look and feel can be specified in two distinct ways: by
0N/A * specifying the fully qualified name of the class for the look and
0N/A * feel, or by creating an instance of {@code LookAndFeel} and passing
0N/A * it to {@code setLookAndFeel}. The following example illustrates
0N/A * setting the look and feel to the system look and feel:
0N/A * <pre>
0N/A * UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
0N/A * </pre>
0N/A * The following example illustrates setting the look and feel based on
0N/A * class name:
0N/A * <pre>
0N/A * UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
0N/A * </pre>
0N/A * Once the look and feel has been changed it is imperative to invoke
0N/A * {@code updateUI} on all {@code JComponents}. The method {@link
0N/A * SwingUtilities#updateComponentTreeUI} makes it easy to apply {@code
0N/A * updateUI} to a containment hierarchy. Refer to it for
0N/A * details. The exact behavior of not invoking {@code
0N/A * updateUI} after changing the look and feel is
0N/A * unspecified. It is very possible to receive unexpected exceptions,
0N/A * painting problems, or worse.
0N/A *
0N/A * <h3>Default look and feel</h3>
0N/A *
0N/A * The class used for the default look and feel is chosen in the following
0N/A * manner:
0N/A * <ol>
0N/A * <li>If the system property <code>swing.defaultlaf</code> is
0N/A * {@code non-null}, use its value as the default look and feel class
0N/A * name.
0N/A * <li>If the {@link java.util.Properties} file <code>swing.properties</code>
0N/A * exists and contains the key <code>swing.defaultlaf</code>,
0N/A * use its value as the default look and feel class name. The location
0N/A * that is checked for <code>swing.properties</code> may vary depending
0N/A * upon the implementation of the Java platform. In Sun's implementation
0N/A * the location is <code>${java.home}/lib/swing.properties</code>.
0N/A * Refer to the release notes of the implementation being used for
0N/A * further details.
0N/A * <li>Otherwise use the cross platform look and feel.
0N/A * </ol>
0N/A *
0N/A * <h3>Defaults</h3>
0N/A *
0N/A * {@code UIManager} manages three sets of {@code UIDefaults}. In order, they
0N/A * are:
0N/A * <ol>
0N/A * <li>Developer defaults. With few exceptions Swing does not
0N/A * alter the developer defaults; these are intended to be modified
0N/A * and used by the developer.
0N/A * <li>Look and feel defaults. The look and feel defaults are
0N/A * supplied by the look and feel at the time it is installed as the
0N/A * current look and feel ({@code setLookAndFeel()} is invoked). The
0N/A * look and feel defaults can be obtained using the {@code
0N/A * getLookAndFeelDefaults()} method.
0N/A * <li>Sytem defaults. The system defaults are provided by Swing.
0N/A * </ol>
0N/A * Invoking any of the various {@code get} methods
0N/A * results in checking each of the defaults, in order, returning
0N/A * the first {@code non-null} value. For example, invoking
0N/A * {@code UIManager.getString("Table.foreground")} results in first
0N/A * checking developer defaults. If the developer defaults contain
0N/A * a value for {@code "Table.foreground"} it is returned, otherwise
0N/A * the look and feel defaults are checked, followed by the system defaults.
0N/A * <p>
0N/A * It's important to note that {@code getDefaults} returns a custom
0N/A * instance of {@code UIDefaults} with this resolution logic built into it.
0N/A * For example, {@code UIManager.getDefaults().getString("Table.foreground")}
0N/A * is equivalent to {@code UIManager.getString("Table.foreground")}. Both
0N/A * resolve using the algorithm just described. In many places the
0N/A * documentation uses the word defaults to refer to the custom instance
0N/A * of {@code UIDefaults} with the resolution logic as previously described.
0N/A * <p>
0N/A * When the look and feel is changed, {@code UIManager} alters only the
0N/A * look and feel defaults; the developer and system defaults are not
0N/A * altered by the {@code UIManager} in any way.
0N/A * <p>
0N/A * The set of defaults a particular look and feel supports is defined
0N/A * and documented by that look and feel. In addition, each look and
0N/A * feel, or {@code ComponentUI} provided by a look and feel, may
0N/A * access the defaults at different times in their life cycle. Some
0N/A * look and feels may agressively look up defaults, so that changing a
0N/A * default may not have an effect after installing the look and feel.
0N/A * Other look and feels may lazily access defaults so that a change to
0N/A * the defaults may effect an existing look and feel. Finally, other look
0N/A * and feels might not configure themselves from the defaults table in
0N/A * any way. None-the-less it is usually the case that a look and feel
0N/A * expects certain defaults, so that in general
0N/A * a {@code ComponentUI} provided by one look and feel will not
0N/A * work with another look and feel.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @author Thomas Ball
0N/A * @author Hans Muller
0N/A */
0N/Apublic class UIManager implements Serializable
0N/A{
0N/A /**
0N/A * This class defines the state managed by the <code>UIManager</code>. For
0N/A * Swing applications the fields in this class could just as well
0N/A * be static members of <code>UIManager</code> however we give them
0N/A * "AppContext"
0N/A * scope instead so that applets (and potentially multiple lightweight
0N/A * applications running in a single VM) have their own state. For example,
0N/A * an applet can alter its look and feel, see <code>setLookAndFeel</code>.
0N/A * Doing so has no affect on other applets (or the browser).
0N/A */
0N/A private static class LAFState
0N/A {
0N/A Properties swingProps;
0N/A private UIDefaults[] tables = new UIDefaults[2];
0N/A
0N/A boolean initialized = false;
0N/A MultiUIDefaults multiUIDefaults = new MultiUIDefaults(tables);
0N/A LookAndFeel lookAndFeel;
0N/A LookAndFeel multiLookAndFeel = null;
0N/A Vector<LookAndFeel> auxLookAndFeels = null;
0N/A SwingPropertyChangeSupport changeSupport;
0N/A
0N/A LookAndFeelInfo[] installedLAFs;
0N/A
0N/A UIDefaults getLookAndFeelDefaults() { return tables[0]; }
0N/A void setLookAndFeelDefaults(UIDefaults x) { tables[0] = x; }
0N/A
0N/A UIDefaults getSystemDefaults() { return tables[1]; }
0N/A void setSystemDefaults(UIDefaults x) { tables[1] = x; }
0N/A
0N/A /**
0N/A * Returns the SwingPropertyChangeSupport for the current
0N/A * AppContext. If <code>create</code> is a true, a non-null
0N/A * <code>SwingPropertyChangeSupport</code> will be returned, if
0N/A * <code>create</code> is false and this has not been invoked
0N/A * with true, null will be returned.
0N/A */
0N/A public synchronized SwingPropertyChangeSupport
0N/A getPropertyChangeSupport(boolean create) {
0N/A if (create && changeSupport == null) {
0N/A changeSupport = new SwingPropertyChangeSupport(
0N/A UIManager.class);
0N/A }
0N/A return changeSupport;
0N/A }
0N/A }
0N/A
0N/A
0N/A
0N/A
0N/A /* Lock object used in place of class object for synchronization. (4187686)
0N/A */
0N/A private static final Object classLock = new Object();
0N/A
0N/A /**
0N/A * Return the <code>LAFState</code> object, lazily create one if necessary.
0N/A * All access to the <code>LAFState</code> fields is done via this method,
0N/A * for example:
0N/A * <pre>
0N/A * getLAFState().initialized = true;
0N/A * </pre>
0N/A */
0N/A private static LAFState getLAFState() {
0N/A LAFState rv = (LAFState)SwingUtilities.appContextGet(
0N/A SwingUtilities2.LAF_STATE_KEY);
0N/A if (rv == null) {
0N/A synchronized (classLock) {
0N/A rv = (LAFState)SwingUtilities.appContextGet(
0N/A SwingUtilities2.LAF_STATE_KEY);
0N/A if (rv == null) {
0N/A SwingUtilities.appContextPut(
0N/A SwingUtilities2.LAF_STATE_KEY,
0N/A (rv = new LAFState()));
0N/A }
0N/A }
0N/A }
0N/A return rv;
0N/A }
0N/A
0N/A
0N/A /* Keys used for the properties file in <java.home>/lib/swing.properties.
0N/A * See loadUserProperties(), initialize().
0N/A */
0N/A
0N/A private static final String defaultLAFKey = "swing.defaultlaf";
0N/A private static final String auxiliaryLAFsKey = "swing.auxiliarylaf";
0N/A private static final String multiplexingLAFKey = "swing.plaf.multiplexinglaf";
0N/A private static final String installedLAFsKey = "swing.installedlafs";
0N/A private static final String disableMnemonicKey = "swing.disablenavaids";
0N/A
0N/A /**
0N/A * Return a swing.properties file key for the attribute of specified
0N/A * look and feel. The attr is either "name" or "class", a typical
0N/A * key would be: "swing.installedlaf.windows.name"
0N/A */
0N/A private static String makeInstalledLAFKey(String laf, String attr) {
0N/A return "swing.installedlaf." + laf + "." + attr;
0N/A }
0N/A
0N/A /**
0N/A * The filename for swing.properties is a path like this (Unix version):
0N/A * <java.home>/lib/swing.properties. This method returns a bogus
0N/A * filename if java.home isn't defined.
0N/A */
0N/A private static String makeSwingPropertiesFilename() {
0N/A String sep = File.separator;
0N/A // No need to wrap this in a doPrivileged as it's called from
0N/A // a doPrivileged.
0N/A String javaHome = System.getProperty("java.home");
0N/A if (javaHome == null) {
0N/A javaHome = "<java.home undefined>";
0N/A }
0N/A return javaHome + sep + "lib" + sep + "swing.properties";
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Provides a little information about an installed
0N/A * <code>LookAndFeel</code> for the sake of configuring a menu or
0N/A * for initial application set up.
0N/A *
0N/A * @see UIManager#getInstalledLookAndFeels
0N/A * @see LookAndFeel
0N/A */
0N/A public static class LookAndFeelInfo {
0N/A private String name;
0N/A private String className;
0N/A
0N/A /**
0N/A * Constructs a <code>UIManager</code>s
0N/A * <code>LookAndFeelInfo</code> object.
0N/A *
0N/A * @param name a <code>String</code> specifying the name of
0N/A * the look and feel
0N/A * @param className a <code>String</code> specifiying the name of
0N/A * the class that implements the look and feel
0N/A */
0N/A public LookAndFeelInfo(String name, String className) {
0N/A this.name = name;
0N/A this.className = className;
0N/A }
0N/A
0N/A /**
0N/A * Returns the name of the look and feel in a form suitable
0N/A * for a menu or other presentation
0N/A * @return a <code>String</code> containing the name
0N/A * @see LookAndFeel#getName
0N/A */
0N/A public String getName() {
0N/A return name;
0N/A }
0N/A
0N/A /**
0N/A * Returns the name of the class that implements this look and feel.
0N/A * @return the name of the class that implements this
0N/A * <code>LookAndFeel</code>
0N/A * @see LookAndFeel
0N/A */
0N/A public String getClassName() {
0N/A return className;
0N/A }
0N/A
0N/A /**
0N/A * Returns a string that displays and identifies this
0N/A * object's properties.
0N/A *
0N/A * @return a <code>String</code> representation of this object
0N/A */
2574N/A public String toString() {
0N/A return getClass().getName() + "[" + getName() + " " + getClassName() + "]";
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * The default value of <code>installedLAFS</code> is used when no
0N/A * swing.properties
0N/A * file is available or if the file doesn't contain a "swing.installedlafs"
0N/A * property.
0N/A *
0N/A * @see #initializeInstalledLAFs
0N/A */
0N/A private static LookAndFeelInfo[] installedLAFs;
0N/A
0N/A static {
0N/A ArrayList<LookAndFeelInfo> iLAFs = new ArrayList<LookAndFeelInfo>(4);
0N/A iLAFs.add(new LookAndFeelInfo(
0N/A "Metal", "javax.swing.plaf.metal.MetalLookAndFeel"));
0N/A iLAFs.add(new LookAndFeelInfo(
0N/A "Nimbus", "javax.swing.plaf.nimbus.NimbusLookAndFeel"));
0N/A iLAFs.add(new LookAndFeelInfo("CDE/Motif",
0N/A "com.sun.java.swing.plaf.motif.MotifLookAndFeel"));
0N/A
0N/A // Only include windows on Windows boxs.
0N/A OSInfo.OSType osType = AccessController.doPrivileged(OSInfo.getOSTypeAction());
0N/A if (osType == OSInfo.OSType.WINDOWS) {
0N/A iLAFs.add(new LookAndFeelInfo("Windows",
0N/A "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"));
0N/A if (Toolkit.getDefaultToolkit().getDesktopProperty(
0N/A "win.xpstyle.themeActive") != null) {
0N/A iLAFs.add(new LookAndFeelInfo("Windows Classic",
0N/A "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"));
0N/A }
0N/A }
0N/A else {
0N/A // GTK is not shipped on Windows.
0N/A iLAFs.add(new LookAndFeelInfo("GTK+",
0N/A "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"));
0N/A }
0N/A installedLAFs = iLAFs.toArray(new LookAndFeelInfo[iLAFs.size()]);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns an array of {@code LookAndFeelInfo}s representing the
0N/A * {@code LookAndFeel} implementations currently available. The
0N/A * <code>LookAndFeelInfo</code> objects can be used by an
0N/A * application to construct a menu of look and feel options for
0N/A * the user, or to determine which look and feel to set at startup
0N/A * time. To avoid the penalty of creating numerous {@code
0N/A * LookAndFeel} objects, {@code LookAndFeelInfo} maintains the
0N/A * class name of the {@code LookAndFeel} class, not the actual
0N/A * {@code LookAndFeel} instance.
0N/A * <p>
0N/A * The following example illustrates setting the current look and feel
0N/A * from an instance of {@code LookAndFeelInfo}:
0N/A * <pre>
0N/A * UIManager.setLookAndFeel(info.getClassName());
0N/A * </pre>
0N/A *
0N/A * @return an array of <code>LookAndFeelInfo</code> objects
0N/A * @see #setLookAndFeel
0N/A */
0N/A public static LookAndFeelInfo[] getInstalledLookAndFeels() {
0N/A maybeInitialize();
0N/A LookAndFeelInfo[] ilafs = getLAFState().installedLAFs;
0N/A if (ilafs == null) {
0N/A ilafs = installedLAFs;
0N/A }
0N/A LookAndFeelInfo[] rv = new LookAndFeelInfo[ilafs.length];
0N/A System.arraycopy(ilafs, 0, rv, 0, ilafs.length);
0N/A return rv;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the set of available look and feels. While this method does
0N/A * not check to ensure all of the {@code LookAndFeelInfos} are
0N/A * {@code non-null}, it is strongly recommended that only {@code non-null}
0N/A * values are supplied in the {@code infos} array.
0N/A *
0N/A * @param infos set of <code>LookAndFeelInfo</code> objects specifying
0N/A * the available look and feels
0N/A *
0N/A * @see #getInstalledLookAndFeels
0N/A * @throws NullPointerException if {@code infos} is {@code null}
0N/A */
0N/A public static void setInstalledLookAndFeels(LookAndFeelInfo[] infos)
0N/A throws SecurityException
0N/A {
0N/A maybeInitialize();
0N/A LookAndFeelInfo[] newInfos = new LookAndFeelInfo[infos.length];
0N/A System.arraycopy(infos, 0, newInfos, 0, infos.length);
0N/A getLAFState().installedLAFs = newInfos;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Adds the specified look and feel to the set of available look
0N/A * and feels. While this method allows a {@code null} {@code info},
0N/A * it is strongly recommended that a {@code non-null} value be used.
0N/A *
0N/A * @param info a <code>LookAndFeelInfo</code> object that names the
0N/A * look and feel and identifies the class that implements it
0N/A * @see #setInstalledLookAndFeels
0N/A */
0N/A public static void installLookAndFeel(LookAndFeelInfo info) {
0N/A LookAndFeelInfo[] infos = getInstalledLookAndFeels();
0N/A LookAndFeelInfo[] newInfos = new LookAndFeelInfo[infos.length + 1];
0N/A System.arraycopy(infos, 0, newInfos, 0, infos.length);
0N/A newInfos[infos.length] = info;
0N/A setInstalledLookAndFeels(newInfos);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Adds the specified look and feel to the set of available look
0N/A * and feels. While this method does not check the
0N/A * arguments in any way, it is strongly recommended that {@code
0N/A * non-null} values be supplied.
0N/A *
0N/A * @param name descriptive name of the look and feel
0N/A * @param className name of the class that implements the look and feel
0N/A * @see #setInstalledLookAndFeels
0N/A */
0N/A public static void installLookAndFeel(String name, String className) {
0N/A installLookAndFeel(new LookAndFeelInfo(name, className));
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the current look and feel or <code>null</code>.
0N/A *
0N/A * @return current look and feel, or <code>null</code>
0N/A * @see #setLookAndFeel
0N/A */
0N/A public static LookAndFeel getLookAndFeel() {
0N/A maybeInitialize();
0N/A return getLAFState().lookAndFeel;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the current look and feel to {@code newLookAndFeel}.
0N/A * If the current look and feel is {@code non-null} {@code
0N/A * uninitialize} is invoked on it. If {@code newLookAndFeel} is
0N/A * {@code non-null}, {@code initialize} is invoked on it followed
0N/A * by {@code getDefaults}. The defaults returned from {@code
0N/A * newLookAndFeel.getDefaults()} replace those of the defaults
0N/A * from the previous look and feel. If the {@code newLookAndFeel} is
0N/A * {@code null}, the look and feel defaults are set to {@code null}.
0N/A * <p>
0N/A * A value of {@code null} can be used to set the look and feel
0N/A * to {@code null}. As the {@code LookAndFeel} is required for
0N/A * most of Swing to function, setting the {@code LookAndFeel} to
0N/A * {@code null} is strongly discouraged.
0N/A * <p>
0N/A * This is a JavaBeans bound property.
0N/A *
0N/A * @param newLookAndFeel {@code LookAndFeel} to install
0N/A * @throws UnsupportedLookAndFeelException if
0N/A * {@code newLookAndFeel} is {@code non-null} and
0N/A * {@code newLookAndFeel.isSupportedLookAndFeel()} returns
0N/A * {@code false}
0N/A * @see #getLookAndFeel
0N/A */
0N/A public static void setLookAndFeel(LookAndFeel newLookAndFeel)
0N/A throws UnsupportedLookAndFeelException
0N/A {
0N/A if ((newLookAndFeel != null) && !newLookAndFeel.isSupportedLookAndFeel()) {
0N/A String s = newLookAndFeel.toString() + " not supported on this platform";
0N/A throw new UnsupportedLookAndFeelException(s);
0N/A }
0N/A
0N/A LAFState lafState = getLAFState();
0N/A LookAndFeel oldLookAndFeel = lafState.lookAndFeel;
0N/A if (oldLookAndFeel != null) {
0N/A oldLookAndFeel.uninitialize();
0N/A }
0N/A
0N/A lafState.lookAndFeel = newLookAndFeel;
0N/A if (newLookAndFeel != null) {
0N/A sun.swing.DefaultLookup.setDefaultLookup(null);
0N/A newLookAndFeel.initialize();
0N/A lafState.setLookAndFeelDefaults(newLookAndFeel.getDefaults());
0N/A }
0N/A else {
0N/A lafState.setLookAndFeelDefaults(null);
0N/A }
0N/A
0N/A SwingPropertyChangeSupport changeSupport = lafState.
0N/A getPropertyChangeSupport(false);
0N/A if (changeSupport != null) {
0N/A changeSupport.firePropertyChange("lookAndFeel", oldLookAndFeel,
0N/A newLookAndFeel);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Loads the {@code LookAndFeel} specified by the given class
0N/A * name, using the current thread's context class loader, and
0N/A * passes it to {@code setLookAndFeel(LookAndFeel)}.
0N/A *
0N/A * @param className a string specifying the name of the class that implements
0N/A * the look and feel
0N/A * @exception ClassNotFoundException if the <code>LookAndFeel</code>
0N/A * class could not be found
0N/A * @exception InstantiationException if a new instance of the class
0N/A * couldn't be created
0N/A * @exception IllegalAccessException if the class or initializer isn't accessible
0N/A * @exception UnsupportedLookAndFeelException if
0N/A * <code>lnf.isSupportedLookAndFeel()</code> is false
0N/A * @throws ClassCastException if {@code className} does not identify
0N/A * a class that extends {@code LookAndFeel}
0N/A */
0N/A public static void setLookAndFeel(String className)
0N/A throws ClassNotFoundException,
0N/A InstantiationException,
0N/A IllegalAccessException,
0N/A UnsupportedLookAndFeelException
0N/A {
0N/A if ("javax.swing.plaf.metal.MetalLookAndFeel".equals(className)) {
0N/A // Avoid reflection for the common case of metal.
0N/A setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
0N/A }
0N/A else {
0N/A Class lnfClass = SwingUtilities.loadSystemClass(className);
0N/A setLookAndFeel((LookAndFeel)(lnfClass.newInstance()));
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the name of the <code>LookAndFeel</code> class that implements
0N/A * the native system look and feel if there is one, otherwise
0N/A * the name of the default cross platform <code>LookAndFeel</code>
0N/A * class. This value can be overriden by setting the
2700N/A * <code>swing.systemlaf</code> system property.
0N/A *
0N/A * @return the <code>String</code> of the <code>LookAndFeel</code>
0N/A * class
0N/A *
0N/A * @see #setLookAndFeel
0N/A * @see #getCrossPlatformLookAndFeelClassName
0N/A */
0N/A public static String getSystemLookAndFeelClassName() {
0N/A String systemLAF = AccessController.doPrivileged(
0N/A new GetPropertyAction("swing.systemlaf"));
0N/A if (systemLAF != null) {
0N/A return systemLAF;
0N/A }
0N/A OSInfo.OSType osType = AccessController.doPrivileged(OSInfo.getOSTypeAction());
0N/A if (osType == OSInfo.OSType.WINDOWS) {
0N/A return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
0N/A } else {
0N/A String desktop = AccessController.doPrivileged(new GetPropertyAction("sun.desktop"));
0N/A Toolkit toolkit = Toolkit.getDefaultToolkit();
0N/A if ("gnome".equals(desktop) &&
0N/A toolkit instanceof SunToolkit &&
0N/A ((SunToolkit) toolkit).isNativeGTKAvailable()) {
0N/A // May be set on Linux and Solaris boxs.
0N/A return "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
0N/A }
0N/A if (osType == OSInfo.OSType.SOLARIS) {
0N/A return "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
0N/A }
0N/A }
0N/A return getCrossPlatformLookAndFeelClassName();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the name of the <code>LookAndFeel</code> class that implements
0N/A * the default cross platform look and feel -- the Java
0N/A * Look and Feel (JLF). This value can be overriden by setting the
0N/A * <code>swing.crossplatformlaf</code> system property.
0N/A *
0N/A * @return a string with the JLF implementation-class
0N/A * @see #setLookAndFeel
0N/A * @see #getSystemLookAndFeelClassName
0N/A */
0N/A public static String getCrossPlatformLookAndFeelClassName() {
0N/A String laf = AccessController.doPrivileged(
0N/A new GetPropertyAction("swing.crossplatformlaf"));
0N/A if (laf != null) {
0N/A return laf;
0N/A }
0N/A return "javax.swing.plaf.metal.MetalLookAndFeel";
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the defaults. The returned defaults resolve using the
0N/A * logic specified in the class documentation.
0N/A *
0N/A * @return a <code>UIDefaults</code> object containing the default values
0N/A */
0N/A public static UIDefaults getDefaults() {
0N/A maybeInitialize();
0N/A return getLAFState().multiUIDefaults;
0N/A }
0N/A
0N/A /**
0N/A * Returns a font from the defaults. If the value for {@code key} is
0N/A * not a {@code Font}, {@code null} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the font
0N/A * @return the <code>Font</code> object
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A */
0N/A public static Font getFont(Object key) {
0N/A return getDefaults().getFont(key);
0N/A }
0N/A
0N/A /**
0N/A * Returns a font from the defaults that is appropriate
0N/A * for the given locale. If the value for {@code key} is
0N/A * not a {@code Font}, {@code null} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the font
0N/A * @param l the <code>Locale</code> for which the font is desired; refer
0N/A * to {@code UIDefaults} for details on how a {@code null}
0N/A * {@code Locale} is handled
0N/A * @return the <code>Font</code> object
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A * @since 1.4
0N/A */
0N/A public static Font getFont(Object key, Locale l) {
0N/A return getDefaults().getFont(key,l);
893N/A }
893N/A
893N/A /**
893N/A * Returns a color from the defaults. If the value for {@code key} is
893N/A * not a {@code Color}, {@code null} is returned.
893N/A *
893N/A * @param key an <code>Object</code> specifying the color
893N/A * @return the <code>Color</code> object
893N/A * @throws NullPointerException if {@code key} is {@code null}
893N/A */
893N/A public static Color getColor(Object key) {
893N/A return getDefaults().getColor(key);
893N/A }
893N/A
893N/A /**
1319N/A * Returns a color from the defaults that is appropriate
893N/A * for the given locale. If the value for {@code key} is
893N/A * not a {@code Color}, {@code null} is returned.
893N/A *
893N/A * @param key an <code>Object</code> specifying the color
893N/A * @param l the <code>Locale</code> for which the color is desired; refer
893N/A * to {@code UIDefaults} for details on how a {@code null}
893N/A * {@code Locale} is handled
893N/A * @return the <code>Color</code> object
893N/A * @throws NullPointerException if {@code key} is {@code null}
893N/A * @since 1.4
893N/A */
893N/A public static Color getColor(Object key, Locale l) {
893N/A return getDefaults().getColor(key,l);
893N/A }
893N/A
893N/A /**
893N/A * Returns an <code>Icon</code> from the defaults. If the value for
893N/A * {@code key} is not an {@code Icon}, {@code null} is returned.
893N/A *
893N/A * @param key an <code>Object</code> specifying the icon
893N/A * @return the <code>Icon</code> object
1319N/A * @throws NullPointerException if {@code key} is {@code null}
893N/A */
893N/A public static Icon getIcon(Object key) {
893N/A return getDefaults().getIcon(key);
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>Icon</code> from the defaults that is appropriate
0N/A * for the given locale. If the value for
0N/A * {@code key} is not an {@code Icon}, {@code null} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the icon
0N/A * @param l the <code>Locale</code> for which the icon is desired; refer
0N/A * to {@code UIDefaults} for details on how a {@code null}
0N/A * {@code Locale} is handled
0N/A * @return the <code>Icon</code> object
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A * @since 1.4
0N/A */
0N/A public static Icon getIcon(Object key, Locale l) {
0N/A return getDefaults().getIcon(key,l);
0N/A }
0N/A
0N/A /**
0N/A * Returns a border from the defaults. If the value for
0N/A * {@code key} is not a {@code Border}, {@code null} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the border
0N/A * @return the <code>Border</code> object
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A */
0N/A public static Border getBorder(Object key) {
0N/A return getDefaults().getBorder(key);
0N/A }
0N/A
0N/A /**
0N/A * Returns a border from the defaults that is appropriate
0N/A * for the given locale. If the value for
0N/A * {@code key} is not a {@code Border}, {@code null} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the border
0N/A * @param l the <code>Locale</code> for which the border is desired; refer
0N/A * to {@code UIDefaults} for details on how a {@code null}
0N/A * {@code Locale} is handled
0N/A * @return the <code>Border</code> object
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A * @since 1.4
0N/A */
0N/A public static Border getBorder(Object key, Locale l) {
0N/A return getDefaults().getBorder(key,l);
0N/A }
0N/A
0N/A /**
0N/A * Returns a string from the defaults. If the value for
0N/A * {@code key} is not a {@code String}, {@code null} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the string
0N/A * @return the <code>String</code>
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A */
0N/A public static String getString(Object key) {
0N/A return getDefaults().getString(key);
0N/A }
0N/A
0N/A /**
0N/A * Returns a string from the defaults that is appropriate for the
0N/A * given locale. If the value for
0N/A * {@code key} is not a {@code String}, {@code null} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the string
0N/A * @param l the <code>Locale</code> for which the string is desired; refer
0N/A * to {@code UIDefaults} for details on how a {@code null}
0N/A * {@code Locale} is handled
0N/A * @return the <code>String</code>
0N/A * @since 1.4
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A */
0N/A public static String getString(Object key, Locale l) {
0N/A return getDefaults().getString(key,l);
0N/A }
0N/A
0N/A /**
0N/A * Returns a string from the defaults that is appropriate for the
0N/A * given locale. If the value for
0N/A * {@code key} is not a {@code String}, {@code null} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the string
0N/A * @param c {@code Component} used to determine the locale;
0N/A * {@code null} implies the default locale as
0N/A * returned by {@code Locale.getDefault()}
0N/A * @return the <code>String</code>
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A */
0N/A static String getString(Object key, Component c) {
0N/A Locale l = (c == null) ? Locale.getDefault() : c.getLocale();
0N/A return getString(key, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an integer from the defaults. If the value for
0N/A * {@code key} is not an {@code Integer}, or does not exist,
0N/A * {@code 0} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the int
0N/A * @return the int
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A */
0N/A public static int getInt(Object key) {
0N/A return getDefaults().getInt(key);
0N/A }
0N/A
0N/A /**
0N/A * Returns an integer from the defaults that is appropriate
0N/A * for the given locale. If the value for
0N/A * {@code key} is not an {@code Integer}, or does not exist,
0N/A * {@code 0} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the int
0N/A * @param l the <code>Locale</code> for which the int is desired; refer
0N/A * to {@code UIDefaults} for details on how a {@code null}
0N/A * {@code Locale} is handled
0N/A * @return the int
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A * @since 1.4
0N/A */
0N/A public static int getInt(Object key, Locale l) {
0N/A return getDefaults().getInt(key,l);
0N/A }
0N/A
0N/A /**
0N/A * Returns a boolean from the defaults which is associated with
0N/A * the key value. If the key is not found or the key doesn't represent
0N/A * a boolean value then {@code false} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the key for the desired boolean value
0N/A * @return the boolean value corresponding to the key
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A * @since 1.4
0N/A */
0N/A public static boolean getBoolean(Object key) {
0N/A return getDefaults().getBoolean(key);
0N/A }
0N/A
0N/A /**
0N/A * Returns a boolean from the defaults which is associated with
0N/A * the key value and the given <code>Locale</code>. If the key is not
0N/A * found or the key doesn't represent
0N/A * a boolean value then {@code false} will be returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the key for the desired
0N/A * boolean value
0N/A * @param l the <code>Locale</code> for which the boolean is desired; refer
0N/A * to {@code UIDefaults} for details on how a {@code null}
0N/A * {@code Locale} is handled
0N/A * @return the boolean value corresponding to the key
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A * @since 1.4
0N/A */
0N/A public static boolean getBoolean(Object key, Locale l) {
0N/A return getDefaults().getBoolean(key,l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>Insets</code> object from the defaults. If the value
0N/A * for {@code key} is not an {@code Insets}, {@code null} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the <code>Insets</code> object
0N/A * @return the <code>Insets</code> object
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A */
0N/A public static Insets getInsets(Object key) {
0N/A return getDefaults().getInsets(key);
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>Insets</code> object from the defaults that is
0N/A * appropriate for the given locale. If the value
0N/A * for {@code key} is not an {@code Insets}, {@code null} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the <code>Insets</code> object
0N/A * @param l the <code>Locale</code> for which the object is desired; refer
0N/A * to {@code UIDefaults} for details on how a {@code null}
0N/A * {@code Locale} is handled
0N/A * @return the <code>Insets</code> object
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A * @since 1.4
0N/A */
0N/A public static Insets getInsets(Object key, Locale l) {
0N/A return getDefaults().getInsets(key,l);
0N/A }
0N/A
0N/A /**
0N/A * Returns a dimension from the defaults. If the value
0N/A * for {@code key} is not a {@code Dimension}, {@code null} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the dimension object
0N/A * @return the <code>Dimension</code> object
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A */
0N/A public static Dimension getDimension(Object key) {
0N/A return getDefaults().getDimension(key);
0N/A }
0N/A
0N/A /**
0N/A * Returns a dimension from the defaults that is appropriate
0N/A * for the given locale. If the value
0N/A * for {@code key} is not a {@code Dimension}, {@code null} is returned.
0N/A *
0N/A * @param key an <code>Object</code> specifying the dimension object
0N/A * @param l the <code>Locale</code> for which the object is desired; refer
0N/A * to {@code UIDefaults} for details on how a {@code null}
0N/A * {@code Locale} is handled
0N/A * @return the <code>Dimension</code> object
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A * @since 1.4
0N/A */
0N/A public static Dimension getDimension(Object key, Locale l) {
0N/A return getDefaults().getDimension(key,l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an object from the defaults.
0N/A *
0N/A * @param key an <code>Object</code> specifying the desired object
0N/A * @return the <code>Object</code>
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A */
0N/A public static Object get(Object key) {
0N/A return getDefaults().get(key);
0N/A }
0N/A
0N/A /**
0N/A * Returns an object from the defaults that is appropriate for
0N/A * the given locale.
0N/A *
0N/A * @param key an <code>Object</code> specifying the desired object
0N/A * @param l the <code>Locale</code> for which the object is desired; refer
0N/A * to {@code UIDefaults} for details on how a {@code null}
0N/A * {@code Locale} is handled
0N/A * @return the <code>Object</code>
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A * @since 1.4
0N/A */
0N/A public static Object get(Object key, Locale l) {
0N/A return getDefaults().get(key,l);
0N/A }
0N/A
0N/A /**
0N/A * Stores an object in the developer defaults. This is a cover method
0N/A * for {@code getDefaults().put(key, value)}. This only effects the
0N/A * developer defaults, not the system or look and feel defaults.
0N/A *
0N/A * @param key an <code>Object</code> specifying the retrieval key
0N/A * @param value the <code>Object</code> to store; refer to
0N/A * {@code UIDefaults} for details on how {@code null} is
0N/A * handled
0N/A * @return the <code>Object</code> returned by {@link UIDefaults#put}
0N/A * @throws NullPointerException if {@code key} is {@code null}
0N/A * @see UIDefaults#put
0N/A */
0N/A public static Object put(Object key, Object value) {
0N/A return getDefaults().put(key, value);
0N/A }
0N/A
0N/A /**
0N/A * Returns the appropriate {@code ComponentUI} implementation for
0N/A * {@code target}. Typically, this is a cover for
0N/A * {@code getDefaults().getUI(target)}. However, if an auxiliary
0N/A * look and feel has been installed, this first invokes
0N/A * {@code getUI(target)} on the multiplexing look and feel's
0N/A * defaults, and returns that value if it is {@code non-null}.
0N/A *
0N/A * @param target the <code>JComponent</code> to return the
0N/A * {@code ComponentUI} for
0N/A * @return the <code>ComponentUI</code> object for {@code target}
0N/A * @throws NullPointerException if {@code target} is {@code null}
0N/A * @see UIDefaults#getUI
0N/A */
0N/A public static ComponentUI getUI(JComponent target) {
0N/A maybeInitialize();
0N/A ComponentUI ui = null;
0N/A LookAndFeel multiLAF = getLAFState().multiLookAndFeel;
0N/A if (multiLAF != null) {
0N/A // This can return null if the multiplexing look and feel
0N/A // doesn't support a particular UI.
0N/A ui = multiLAF.getDefaults().getUI(target);
0N/A }
0N/A if (ui == null) {
0N/A ui = getDefaults().getUI(target);
0N/A }
0N/A return ui;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the {@code UIDefaults} from the current look and feel,
0N/A * that were obtained at the time the look and feel was installed.
0N/A * <p>
0N/A * In general, developers should use the {@code UIDefaults} returned from
0N/A * {@code getDefaults()}. As the current look and feel may expect
0N/A * certain values to exist, altering the {@code UIDefaults} returned
0N/A * from this method could have unexpected results.
0N/A *
0N/A * @return <code>UIDefaults</code> from the current look and feel
0N/A * @see #getDefaults
0N/A * @see #setLookAndFeel(LookAndFeel)
0N/A * @see LookAndFeel#getDefaults
0N/A */
0N/A public static UIDefaults getLookAndFeelDefaults() {
0N/A maybeInitialize();
0N/A return getLAFState().getLookAndFeelDefaults();
0N/A }
0N/A
0N/A /**
0N/A * Finds the Multiplexing <code>LookAndFeel</code>.
0N/A */
0N/A private static LookAndFeel getMultiLookAndFeel() {
0N/A LookAndFeel multiLookAndFeel = getLAFState().multiLookAndFeel;
0N/A if (multiLookAndFeel == null) {
0N/A String defaultName = "javax.swing.plaf.multi.MultiLookAndFeel";
0N/A String className = getLAFState().swingProps.getProperty(multiplexingLAFKey, defaultName);
0N/A try {
0N/A Class lnfClass = SwingUtilities.loadSystemClass(className);
0N/A multiLookAndFeel = (LookAndFeel)lnfClass.newInstance();
0N/A } catch (Exception exc) {
0N/A System.err.println("UIManager: failed loading " + className);
0N/A }
0N/A }
0N/A return multiLookAndFeel;
0N/A }
0N/A
0N/A /**
0N/A * Adds a <code>LookAndFeel</code> to the list of auxiliary look and feels.
0N/A * The auxiliary look and feels tell the multiplexing look and feel what
0N/A * other <code>LookAndFeel</code> classes for a component instance are to be used
0N/A * in addition to the default <code>LookAndFeel</code> class when creating a
0N/A * multiplexing UI. The change will only take effect when a new
0N/A * UI class is created or when the default look and feel is changed
0N/A * on a component instance.
0N/A * <p>Note these are not the same as the installed look and feels.
0N/A *
0N/A * @param laf the <code>LookAndFeel</code> object
0N/A * @see #removeAuxiliaryLookAndFeel
0N/A * @see #setLookAndFeel
0N/A * @see #getAuxiliaryLookAndFeels
0N/A * @see #getInstalledLookAndFeels
0N/A */
0N/A static public void addAuxiliaryLookAndFeel(LookAndFeel laf) {
0N/A maybeInitialize();
0N/A
0N/A if (!laf.isSupportedLookAndFeel()) {
0N/A // Ideally we would throw an exception here, but it's too late
0N/A // for that.
0N/A return;
0N/A }
0N/A Vector<LookAndFeel> v = getLAFState().auxLookAndFeels;
0N/A if (v == null) {
0N/A v = new Vector<LookAndFeel>();
0N/A }
0N/A
0N/A if (!v.contains(laf)) {
0N/A v.addElement(laf);
0N/A laf.initialize();
0N/A getLAFState().auxLookAndFeels = v;
0N/A
0N/A if (getLAFState().multiLookAndFeel == null) {
0N/A getLAFState().multiLookAndFeel = getMultiLookAndFeel();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes a <code>LookAndFeel</code> from the list of auxiliary look and feels.
0N/A * The auxiliary look and feels tell the multiplexing look and feel what
0N/A * other <code>LookAndFeel</code> classes for a component instance are to be used
0N/A * in addition to the default <code>LookAndFeel</code> class when creating a
0N/A * multiplexing UI. The change will only take effect when a new
0N/A * UI class is created or when the default look and feel is changed
0N/A * on a component instance.
0N/A * <p>Note these are not the same as the installed look and feels.
0N/A * @return true if the <code>LookAndFeel</code> was removed from the list
0N/A * @see #removeAuxiliaryLookAndFeel
0N/A * @see #getAuxiliaryLookAndFeels
0N/A * @see #setLookAndFeel
0N/A * @see #getInstalledLookAndFeels
0N/A */
0N/A static public boolean removeAuxiliaryLookAndFeel(LookAndFeel laf) {
0N/A maybeInitialize();
0N/A
0N/A boolean result;
0N/A
0N/A Vector<LookAndFeel> v = getLAFState().auxLookAndFeels;
0N/A if ((v == null) || (v.size() == 0)) {
0N/A return false;
0N/A }
0N/A
0N/A result = v.removeElement(laf);
0N/A if (result) {
0N/A if (v.size() == 0) {
0N/A getLAFState().auxLookAndFeels = null;
0N/A getLAFState().multiLookAndFeel = null;
0N/A } else {
0N/A getLAFState().auxLookAndFeels = v;
0N/A }
0N/A }
0N/A laf.uninitialize();
0N/A
0N/A return result;
0N/A }
0N/A
0N/A /**
0N/A * Returns the list of auxiliary look and feels (can be <code>null</code>).
0N/A * The auxiliary look and feels tell the multiplexing look and feel what
0N/A * other <code>LookAndFeel</code> classes for a component instance are
0N/A * to be used in addition to the default LookAndFeel class when creating a
0N/A * multiplexing UI.
0N/A * <p>Note these are not the same as the installed look and feels.
0N/A *
0N/A * @return list of auxiliary <code>LookAndFeel</code>s or <code>null</code>
0N/A * @see #addAuxiliaryLookAndFeel
0N/A * @see #removeAuxiliaryLookAndFeel
0N/A * @see #setLookAndFeel
0N/A * @see #getInstalledLookAndFeels
0N/A */
0N/A static public LookAndFeel[] getAuxiliaryLookAndFeels() {
0N/A maybeInitialize();
0N/A
0N/A Vector<LookAndFeel> v = getLAFState().auxLookAndFeels;
0N/A if ((v == null) || (v.size() == 0)) {
0N/A return null;
0N/A }
0N/A else {
0N/A LookAndFeel[] rv = new LookAndFeel[v.size()];
0N/A for (int i = 0; i < rv.length; i++) {
0N/A rv[i] = v.elementAt(i);
0N/A }
0N/A return rv;
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Adds a <code>PropertyChangeListener</code> to the listener list.
0N/A * The listener is registered for all properties.
0N/A *
0N/A * @param listener the <code>PropertyChangeListener</code> to be added
0N/A * @see java.beans.PropertyChangeSupport
0N/A */
0N/A public static void addPropertyChangeListener(PropertyChangeListener listener)
0N/A {
0N/A synchronized (classLock) {
0N/A getLAFState().getPropertyChangeSupport(true).
0N/A addPropertyChangeListener(listener);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Removes a <code>PropertyChangeListener</code> from the listener list.
0N/A * This removes a <code>PropertyChangeListener</code> that was registered
0N/A * for all properties.
0N/A *
0N/A * @param listener the <code>PropertyChangeListener</code> to be removed
0N/A * @see java.beans.PropertyChangeSupport
0N/A */
0N/A public static void removePropertyChangeListener(PropertyChangeListener listener)
0N/A {
0N/A synchronized (classLock) {
0N/A getLAFState().getPropertyChangeSupport(true).
0N/A removePropertyChangeListener(listener);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns an array of all the <code>PropertyChangeListener</code>s added
0N/A * to this UIManager with addPropertyChangeListener().
0N/A *
0N/A * @return all of the <code>PropertyChangeListener</code>s added or an empty
0N/A * array if no listeners have been added
0N/A * @since 1.4
0N/A */
0N/A public static PropertyChangeListener[] getPropertyChangeListeners() {
0N/A synchronized(classLock) {
0N/A return getLAFState().getPropertyChangeSupport(true).
0N/A getPropertyChangeListeners();
0N/A }
0N/A }
0N/A
0N/A private static Properties loadSwingProperties()
0N/A {
0N/A /* Don't bother checking for Swing properties if untrusted, as
0N/A * there's no way to look them up without triggering SecurityExceptions.
0N/A */
0N/A if (UIManager.class.getClassLoader() != null) {
0N/A return new Properties();
0N/A }
0N/A else {
0N/A final Properties props = new Properties();
0N/A
0N/A java.security.AccessController.doPrivileged(
0N/A new java.security.PrivilegedAction<Object>() {
0N/A public Object run() {
0N/A try {
0N/A File file = new File(makeSwingPropertiesFilename());
0N/A
0N/A if (file.exists()) {
0N/A // InputStream has been buffered in Properties
0N/A // class
0N/A FileInputStream ins = new FileInputStream(file);
0N/A props.load(ins);
0N/A ins.close();
0N/A }
0N/A }
0N/A catch (Exception e) {
0N/A // No such file, or file is otherwise non-readable.
0N/A }
0N/A
0N/A // Check whether any properties were overridden at the
0N/A // command line.
0N/A checkProperty(props, defaultLAFKey);
0N/A checkProperty(props, auxiliaryLAFsKey);
0N/A checkProperty(props, multiplexingLAFKey);
0N/A checkProperty(props, installedLAFsKey);
0N/A checkProperty(props, disableMnemonicKey);
0N/A // Don't care about return value.
0N/A return null;
0N/A }
0N/A });
0N/A return props;
0N/A }
0N/A }
0N/A
0N/A private static void checkProperty(Properties props, String key) {
0N/A // No need to do catch the SecurityException here, this runs
0N/A // in a doPrivileged.
0N/A String value = System.getProperty(key);
0N/A if (value != null) {
0N/A props.put(key, value);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * If a swing.properties file exist and it has a swing.installedlafs property
0N/A * then initialize the <code>installedLAFs</code> field.
0N/A *
0N/A * @see #getInstalledLookAndFeels
0N/A */
0N/A private static void initializeInstalledLAFs(Properties swingProps)
0N/A {
0N/A String ilafsString = swingProps.getProperty(installedLAFsKey);
0N/A if (ilafsString == null) {
0N/A return;
0N/A }
0N/A
0N/A /* Create a vector that contains the value of the swing.installedlafs
0N/A * property. For example given "swing.installedlafs=motif,windows"
0N/A * lafs = {"motif", "windows"}.
0N/A */
0N/A Vector<String> lafs = new Vector<String>();
0N/A StringTokenizer st = new StringTokenizer(ilafsString, ",", false);
0N/A while (st.hasMoreTokens()) {
0N/A lafs.addElement(st.nextToken());
0N/A }
0N/A
0N/A /* Look up the name and class for each name in the "swing.installedlafs"
0N/A * list. If they both exist then add a LookAndFeelInfo to
0N/A * the installedLafs array.
0N/A */
0N/A Vector<LookAndFeelInfo> ilafs = new Vector<LookAndFeelInfo>(lafs.size());
0N/A for (String laf : lafs) {
0N/A String name = swingProps.getProperty(makeInstalledLAFKey(laf, "name"), laf);
0N/A String cls = swingProps.getProperty(makeInstalledLAFKey(laf, "class"));
0N/A if (cls != null) {
0N/A ilafs.addElement(new LookAndFeelInfo(name, cls));
0N/A }
0N/A }
0N/A
0N/A LookAndFeelInfo[] installedLAFs = new LookAndFeelInfo[ilafs.size()];
0N/A for(int i = 0; i < ilafs.size(); i++) {
0N/A installedLAFs[i] = ilafs.elementAt(i);
0N/A }
0N/A getLAFState().installedLAFs = installedLAFs;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * If the user has specified a default look and feel, use that.
0N/A * Otherwise use the look and feel that's native to this platform.
0N/A * If this code is called after the application has explicitly
0N/A * set it's look and feel, do nothing.
0N/A *
0N/A * @see #maybeInitialize
0N/A */
0N/A private static void initializeDefaultLAF(Properties swingProps)
0N/A {
0N/A if (getLAFState().lookAndFeel != null) {
0N/A return;
0N/A }
0N/A
0N/A // Try to get default LAF from system property, then from AppContext
0N/A // (6653395), then use cross-platform one by default.
0N/A String lafName = null;
0N/A HashMap lafData =
0N/A (HashMap) AppContext.getAppContext().remove("swing.lafdata");
0N/A if (lafData != null) {
0N/A lafName = (String) lafData.remove("defaultlaf");
0N/A }
0N/A if (lafName == null) {
0N/A lafName = getCrossPlatformLookAndFeelClassName();
0N/A }
0N/A lafName = swingProps.getProperty(defaultLAFKey, lafName);
0N/A
0N/A try {
0N/A setLookAndFeel(lafName);
0N/A } catch (Exception e) {
0N/A throw new Error("Cannot load " + lafName);
0N/A }
0N/A
0N/A // Set any properties passed through AppContext (6653395).
0N/A if (lafData != null) {
0N/A for (Object key: lafData.keySet()) {
0N/A UIManager.put(key, lafData.get(key));
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A private static void initializeAuxiliaryLAFs(Properties swingProps)
0N/A {
0N/A String auxLookAndFeelNames = swingProps.getProperty(auxiliaryLAFsKey);
0N/A if (auxLookAndFeelNames == null) {
0N/A return;
0N/A }
0N/A
0N/A Vector<LookAndFeel> auxLookAndFeels = new Vector<LookAndFeel>();
0N/A
0N/A StringTokenizer p = new StringTokenizer(auxLookAndFeelNames,",");
0N/A String factoryName;
0N/A
0N/A /* Try to load each LookAndFeel subclass in the list.
0N/A */
0N/A
0N/A while (p.hasMoreTokens()) {
0N/A String className = p.nextToken();
0N/A try {
0N/A Class lnfClass = SwingUtilities.loadSystemClass(className);
0N/A LookAndFeel newLAF = (LookAndFeel)lnfClass.newInstance();
0N/A newLAF.initialize();
0N/A auxLookAndFeels.addElement(newLAF);
0N/A }
0N/A catch (Exception e) {
0N/A System.err.println("UIManager: failed loading auxiliary look and feel " + className);
0N/A }
0N/A }
0N/A
0N/A /* If there were problems and no auxiliary look and feels were
0N/A * loaded, make sure we reset auxLookAndFeels to null.
0N/A * Otherwise, we are going to use the MultiLookAndFeel to get
0N/A * all component UI's, so we need to load it now.
0N/A */
0N/A if (auxLookAndFeels.size() == 0) {
0N/A auxLookAndFeels = null;
0N/A }
0N/A else {
0N/A getLAFState().multiLookAndFeel = getMultiLookAndFeel();
0N/A if (getLAFState().multiLookAndFeel == null) {
0N/A auxLookAndFeels = null;
0N/A }
0N/A }
0N/A
0N/A getLAFState().auxLookAndFeels = auxLookAndFeels;
0N/A }
0N/A
0N/A
0N/A private static void initializeSystemDefaults(Properties swingProps) {
0N/A getLAFState().swingProps = swingProps;
0N/A }
0N/A
0N/A
0N/A /*
0N/A * This method is called before any code that depends on the
0N/A * <code>AppContext</code> specific LAFState object runs. When the AppContext
0N/A * corresponds to a set of applets it's possible for this method
0N/A * to be re-entered, which is why we grab a lock before calling
0N/A * initialize().
0N/A */
0N/A private static void maybeInitialize() {
0N/A synchronized (classLock) {
0N/A if (!getLAFState().initialized) {
0N/A getLAFState().initialized = true;
0N/A initialize();
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /*
0N/A * Only called by maybeInitialize().
0N/A */
0N/A private static void initialize() {
0N/A Properties swingProps = loadSwingProperties();
0N/A initializeSystemDefaults(swingProps);
0N/A initializeDefaultLAF(swingProps);
0N/A initializeAuxiliaryLAFs(swingProps);
0N/A initializeInstalledLAFs(swingProps);
0N/A
0N/A // Enable the Swing default LayoutManager.
0N/A String toolkitName = Toolkit.getDefaultToolkit().getClass().getName();
0N/A // don't set default policy if this is XAWT.
0N/A if (!"sun.awt.X11.XToolkit".equals(toolkitName)) {
0N/A if (FocusManager.isFocusManagerEnabled()) {
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A setDefaultFocusTraversalPolicy(
0N/A new LayoutFocusTraversalPolicy());
0N/A }
0N/A }
0N/A
0N/A // Install Swing's PaintEventDispatcher
0N/A if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) {
0N/A sun.awt.PaintEventDispatcher.setPaintEventDispatcher(
0N/A new SwingPaintEventDispatcher());
0N/A }
0N/A // Install a hook that will be invoked if no one consumes the
0N/A // KeyEvent. If the source isn't a JComponent this will process
0N/A // key bindings, if the source is a JComponent it implies that
0N/A // processKeyEvent was already invoked and thus no need to process
0N/A // the bindings again, unless the Component is disabled, in which
0N/A // case KeyEvents will no longer be dispatched to it so that we
0N/A // handle it here.
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A addKeyEventPostProcessor(new KeyEventPostProcessor() {
0N/A public boolean postProcessKeyEvent(KeyEvent e) {
0N/A Component c = e.getComponent();
0N/A
0N/A if ((!(c instanceof JComponent) ||
0N/A (c != null && !c.isEnabled())) &&
0N/A JComponent.KeyboardState.shouldProcess(e) &&
0N/A SwingUtilities.processKeyBindings(e)) {
0N/A e.consume();
0N/A return true;
0N/A }
0N/A return false;
0N/A }
0N/A });
0N/A AWTAccessor.getComponentAccessor().
0N/A setRequestFocusController(JComponent.focusController);
0N/A }
0N/A}
0N/A