UIManager.java revision 1086
/*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* {@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.
*
* <h3>Specifying the look and feel</h3>
*
* The look and feel can be specified in two distinct ways: by
* specifying the fully qualified name of the class for the look and
* feel, or by creating an instance of {@code LookAndFeel} and passing
* it to {@code setLookAndFeel}. The following example illustrates
* setting the look and feel to the system look and feel:
* <pre>
* UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
* </pre>
* The following example illustrates setting the look and feel based on
* class name:
* <pre>
* UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
* </pre>
* 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.
*
* <h3>Default look and feel</h3>
*
* The class used for the default look and feel is chosen in the following
* manner:
* <ol>
* <li>If the system property <code>swing.defaultlaf</code> is
* {@code non-null}, use its value as the default look and feel class
* name.
* <li>If the {@link java.util.Properties} file <code>swing.properties</code>
* exists and contains the key <code>swing.defaultlaf</code>,
* use its value as the default look and feel class name. The location
* that is checked for <code>swing.properties</code> may vary depending
* upon the implementation of the Java platform. In Sun's implementation
* the location is <code>${java.home}/lib/swing.properties</code>.
* Refer to the release notes of the implementation being used for
* further details.
* <li>Otherwise use the cross platform look and feel.
* </ol>
*
* <h3>Defaults</h3>
*
* {@code UIManager} manages three sets of {@code UIDefaults}. In order, they
* are:
* <ol>
* <li>Developer defaults. With few exceptions Swing does not
* alter the developer defaults; these are intended to be modified
* and used by the developer.
* <li>Look and feel defaults. The look and feel defaults are
* supplied by the look and feel at the time it is installed as the
* current look and feel ({@code setLookAndFeel()} is invoked). The
* look and feel defaults can be obtained using the {@code
* getLookAndFeelDefaults()} method.
* <li>Sytem defaults. The system defaults are provided by Swing.
* </ol>
* Invoking any of the various {@code get} methods
* results in checking each of the defaults, in order, returning
* the first {@code non-null} value. For example, invoking
* {@code UIManager.getString("Table.foreground")} results in first
* checking developer defaults. If the developer defaults contain
* a value for {@code "Table.foreground"} it is returned, otherwise
* the look and feel defaults are checked, followed by the system defaults.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* <strong>Warning:</strong>
* 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 JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> 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 <code>UIManager</code>. For
* Swing applications the fields in this class could just as well
* be static members of <code>UIManager</code> 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 <code>setLookAndFeel</code>.
* Doing so has no affect on other applets (or the browser).
*/
private static class LAFState
{
boolean initialized = false;
/**
* Returns the SwingPropertyChangeSupport for the current
* AppContext. If <code>create</code> is a true, a non-null
* <code>SwingPropertyChangeSupport</code> will be returned, if
* <code>create</code> is false and this has not been invoked
* with true, null will be returned.
*/
public synchronized SwingPropertyChangeSupport
getPropertyChangeSupport(boolean create) {
UIManager.class);
}
return changeSupport;
}
}
/* Lock object used in place of class object for synchronization. (4187686)
*/
/* Cache the last referenced LAFState to improve performance
* when accessing it. The cache is based on last thread rather
* than last AppContext because of the cost of looking up the
* AppContext each time. Since most Swing UI work is on the
* EventDispatchThread, this hits often enough to justify the
* overhead. (4193032)
*/
/**
* Return the <code>LAFState</code> object, lazily create one if necessary.
* All access to the <code>LAFState</code> fields is done via this method,
* for example:
* <pre>
* getLAFState().initialized = true;
* </pre>
*/
private static LAFState getLAFState() {
// First check whether we're running on the same thread as
// the last request.
if (thisThread == currentLAFStateThread) {
return currentLAFState;
}
synchronized (classLock) {
}
}
}
return rv;
}
/* Keys used for the properties file in <java.home>/lib/swing.properties.
* See loadUserProperties(), initialize().
*/
/**
* 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"
*/
}
/**
* The filename for swing.properties is a path like this (Unix version):
* <java.home>/lib/swing.properties. This method returns a bogus
* filename if java.home isn't defined.
*/
private static String makeSwingPropertiesFilename() {
// No need to wrap this in a doPrivileged as it's called from
// a doPrivileged.
javaHome = "<java.home undefined>";
}
}
/**
* Provides a little information about an installed
* <code>LookAndFeel</code> for the sake of configuring a menu or
* for initial application set up.
*
* @see UIManager#getInstalledLookAndFeels
* @see LookAndFeel
*/
public static class LookAndFeelInfo {
/**
* Constructs a <code>UIManager</code>s
* <code>LookAndFeelInfo</code> object.
*
* @param name a <code>String</code> specifying the name of
* the look and feel
* @param className a <code>String</code> specifiying the name of
* the class that implements the look and feel
*/
}
/**
* Returns the name of the look and feel in a form suitable
* for a menu or other presentation
* @return a <code>String</code> containing the name
* @see LookAndFeel#getName
*/
return name;
}
/**
* Returns the name of the class that implements this look and feel.
* @return the name of the class that implements this
* <code>LookAndFeel</code>
* @see LookAndFeel
*/
public String getClassName() {
return className;
}
/**
* Returns a string that displays and identifies this
* object's properties.
*
* @return a <code>String</code> representation of this object
*/
}
}
/**
* The default value of <code>installedLAFS</code> is used when no
* file is available or if the file doesn't contain a "swing.installedlafs"
* property.
*
* @see #initializeInstalledLAFs
*/
private static LookAndFeelInfo[] installedLAFs;
static {
"Metal", "javax.swing.plaf.metal.MetalLookAndFeel"));
"com.sun.java.swing.plaf.motif.MotifLookAndFeel"));
// Only include windows on Windows boxs.
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"));
"win.xpstyle.themeActive") != null) {
"com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"));
}
}
else {
// GTK is not shipped on Windows.
"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"));
}
}
/**
* Returns an array of {@code LookAndFeelInfo}s representing the
* {@code LookAndFeel} implementations currently available. The
* <code>LookAndFeelInfo</code> 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.
* <p>
* The following example illustrates setting the current look and feel
* from an instance of {@code LookAndFeelInfo}:
* <pre>
* UIManager.setLookAndFeel(info.getClassName());
* </pre>
*
* @return an array of <code>LookAndFeelInfo</code> objects
* @see #setLookAndFeel
*/
public static LookAndFeelInfo[] getInstalledLookAndFeels() {
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 <code>LookAndFeelInfo</code> objects specifying
* the available look and feels
*
* @see #getInstalledLookAndFeels
* @throws NullPointerException if {@code infos} is {@code null}
*/
throws SecurityException
{
}
/**
* 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 <code>LookAndFeelInfo</code> object that names the
* look and feel and identifies the class that implements it
* @see #setInstalledLookAndFeels
*/
}
/**
* 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
*/
}
/**
* Returns the current look and feel or <code>null</code>.
*
* @return current look and feel, or <code>null</code>
* @see #setLookAndFeel
*/
public static LookAndFeel getLookAndFeel() {
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}.
* <p>
* 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.
* <p>
* 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
*/
{
throw new UnsupportedLookAndFeelException(s);
}
if (oldLookAndFeel != null) {
}
if (newLookAndFeel != null) {
}
else {
}
getPropertyChangeSupport(false);
if (changeSupport != null) {
}
}
/**
* 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 <code>LookAndFeel</code>
* 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
* <code>lnf.isSupportedLookAndFeel()</code> is false
* @throws ClassCastException if {@code className} does not identify
* a class that extends {@code LookAndFeel}
*/
throws ClassNotFoundException,
{
// Avoid reflection for the common case of metal.
}
else {
}
}
/**
* Returns the name of the <code>LookAndFeel</code> class that implements
* the native system look and feel if there is one, otherwise
* the name of the default cross platform <code>LookAndFeel</code>
* class. This value can be overriden by setting the
* <code>swing.systemlaf</code> system property.
*
* @return the <code>String</code> of the <code>LookAndFeel</code>
* class
*
* @see #setLookAndFeel
* @see #getCrossPlatformLookAndFeelClassName
*/
public static String getSystemLookAndFeelClassName() {
new GetPropertyAction("swing.systemlaf"));
return systemLAF;
}
return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
} else {
toolkit instanceof SunToolkit &&
// May be set on Linux and Solaris boxs.
return "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
}
return "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
}
}
return getCrossPlatformLookAndFeelClassName();
}
/**
* Returns the name of the <code>LookAndFeel</code> class that implements
* the default cross platform look and feel -- the Java
* Look and Feel (JLF). This value can be overriden by setting the
* <code>swing.crossplatformlaf</code> system property.
*
* @return a string with the JLF implementation-class
* @see #setLookAndFeel
* @see #getSystemLookAndFeelClassName
*/
public static String getCrossPlatformLookAndFeelClassName() {
new GetPropertyAction("swing.crossplatformlaf"));
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 <code>UIDefaults</code> object containing the default values
*/
public static UIDefaults getDefaults() {
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 <code>Object</code> specifying the font
* @return the <code>Font</code> object
* @throws NullPointerException if {@code key} is {@code null}
*/
}
/**
* 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 <code>Object</code> specifying the font
* @param l the <code>Locale</code> for which the font is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the <code>Font</code> object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
}
/**
* Returns a color from the defaults. If the value for {@code key} is
* not a {@code Color}, {@code null} is returned.
*
* @param key an <code>Object</code> specifying the color
* @return the <code>Color</code> object
* @throws NullPointerException if {@code key} is {@code null}
*/
}
/**
* 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 <code>Object</code> specifying the color
* @param l the <code>Locale</code> for which the color is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the <code>Color</code> object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
}
/**
* Returns an <code>Icon</code> from the defaults. If the value for
* {@code key} is not an {@code Icon}, {@code null} is returned.
*
* @param key an <code>Object</code> specifying the icon
* @return the <code>Icon</code> object
* @throws NullPointerException if {@code key} is {@code null}
*/
}
/**
* Returns an <code>Icon</code> 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 <code>Object</code> specifying the icon
* @param l the <code>Locale</code> for which the icon is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the <code>Icon</code> object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
}
/**
* Returns a border from the defaults. If the value for
* {@code key} is not a {@code Border}, {@code null} is returned.
*
* @param key an <code>Object</code> specifying the border
* @return the <code>Border</code> object
* @throws NullPointerException if {@code key} is {@code null}
*/
}
/**
* 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 <code>Object</code> specifying the border
* @param l the <code>Locale</code> for which the border is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the <code>Border</code> object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
}
/**
* Returns a string from the defaults. If the value for
* {@code key} is not a {@code String}, {@code null} is returned.
*
* @param key an <code>Object</code> specifying the string
* @return the <code>String</code>
* @throws NullPointerException if {@code key} is {@code null}
*/
}
/**
* 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 <code>Object</code> specifying the string
* @param l the <code>Locale</code> for which the string is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the <code>String</code>
* @since 1.4
* @throws NullPointerException if {@code key} is {@code null}
*/
}
/**
* 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 <code>Object</code> 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 <code>String</code>
* @throws NullPointerException if {@code key} is {@code null}
*/
}
/**
* 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 <code>Object</code> specifying the int
* @return the int
* @throws NullPointerException if {@code key} is {@code null}
*/
}
/**
* 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 <code>Object</code> specifying the int
* @param l the <code>Locale</code> 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
*/
}
/**
* 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 <code>Object</code> 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
*/
}
/**
* Returns a boolean from the defaults which is associated with
* the key value and the given <code>Locale</code>. If the key is not
* found or the key doesn't represent
* a boolean value then {@code false} will be returned.
*
* @param key an <code>Object</code> specifying the key for the desired
* boolean value
* @param l the <code>Locale</code> 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
*/
}
/**
* Returns an <code>Insets</code> object from the defaults. If the value
* for {@code key} is not an {@code Insets}, {@code null} is returned.
*
* @param key an <code>Object</code> specifying the <code>Insets</code> object
* @return the <code>Insets</code> object
* @throws NullPointerException if {@code key} is {@code null}
*/
}
/**
* Returns an <code>Insets</code> 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 <code>Object</code> specifying the <code>Insets</code> object
* @param l the <code>Locale</code> for which the object is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the <code>Insets</code> object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
}
/**
* Returns a dimension from the defaults. If the value
* for {@code key} is not a {@code Dimension}, {@code null} is returned.
*
* @param key an <code>Object</code> specifying the dimension object
* @return the <code>Dimension</code> object
* @throws NullPointerException if {@code key} is {@code null}
*/
}
/**
* 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 <code>Object</code> specifying the dimension object
* @param l the <code>Locale</code> for which the object is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the <code>Dimension</code> object
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
}
/**
* Returns an object from the defaults.
*
* @param key an <code>Object</code> specifying the desired object
* @return the <code>Object</code>
* @throws NullPointerException if {@code key} is {@code null}
*/
}
/**
* Returns an object from the defaults that is appropriate for
* the given locale.
*
* @param key an <code>Object</code> specifying the desired object
* @param l the <code>Locale</code> for which the object is desired; refer
* to {@code UIDefaults} for details on how a {@code null}
* {@code Locale} is handled
* @return the <code>Object</code>
* @throws NullPointerException if {@code key} is {@code null}
* @since 1.4
*/
}
/**
* 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 <code>Object</code> specifying the retrieval key
* @param value the <code>Object</code> to store; refer to
* {@code UIDefaults} for details on how {@code null} is
* handled
* @return the <code>Object</code> returned by {@link UIDefaults#put}
* @throws NullPointerException if {@code key} is {@code null}
* @see UIDefaults#put
*/
}
/**
* 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 <code>JComponent</code> to return the
* {@code ComponentUI} for
* @return the <code>ComponentUI</code> object for {@code target}
* @throws NullPointerException if {@code target} is {@code null}
* @see UIDefaults#getUI
*/
// This can return null if the multiplexing look and feel
// doesn't support a particular UI.
}
}
return ui;
}
/**
* Returns the {@code UIDefaults} from the current look and feel,
* that were obtained at the time the look and feel was installed.
* <p>
* 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 <code>UIDefaults</code> from the current look and feel
* @see #getDefaults
* @see #setLookAndFeel(LookAndFeel)
* @see LookAndFeel#getDefaults
*/
public static UIDefaults getLookAndFeelDefaults() {
return getLAFState().getLookAndFeelDefaults();
}
/**
* Finds the Multiplexing <code>LookAndFeel</code>.
*/
private static LookAndFeel getMultiLookAndFeel() {
if (multiLookAndFeel == null) {
try {
}
}
return multiLookAndFeel;
}
/**
* Adds a <code>LookAndFeel</code> to the list of auxiliary look and feels.
* The auxiliary look and feels tell the multiplexing look and feel what
* other <code>LookAndFeel</code> classes for a component instance are to be used
* in addition to the default <code>LookAndFeel</code> 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.
* <p>Note these are not the same as the installed look and feels.
*
* @param laf the <code>LookAndFeel</code> object
* @see #removeAuxiliaryLookAndFeel
* @see #setLookAndFeel
* @see #getAuxiliaryLookAndFeels
* @see #getInstalledLookAndFeels
*/
if (!laf.isSupportedLookAndFeel()) {
// Ideally we would throw an exception here, but it's too late
// for that.
return;
}
if (v == null) {
v = new Vector<LookAndFeel>();
}
v.addElement(laf);
laf.initialize();
getLAFState().auxLookAndFeels = v;
}
}
}
/**
* Removes a <code>LookAndFeel</code> from the list of auxiliary look and feels.
* The auxiliary look and feels tell the multiplexing look and feel what
* other <code>LookAndFeel</code> classes for a component instance are to be used
* in addition to the default <code>LookAndFeel</code> 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.
* <p>Note these are not the same as the installed look and feels.
* @return true if the <code>LookAndFeel</code> was removed from the list
* @see #removeAuxiliaryLookAndFeel
* @see #getAuxiliaryLookAndFeels
* @see #setLookAndFeel
* @see #getInstalledLookAndFeels
*/
boolean result;
return false;
}
if (result) {
if (v.size() == 0) {
} else {
getLAFState().auxLookAndFeels = v;
}
}
laf.uninitialize();
return result;
}
/**
* Returns the list of auxiliary look and feels (can be <code>null</code>).
* The auxiliary look and feels tell the multiplexing look and feel what
* other <code>LookAndFeel</code> classes for a component instance are
* to be used in addition to the default LookAndFeel class when creating a
* multiplexing UI.
* <p>Note these are not the same as the installed look and feels.
*
* @return list of auxiliary <code>LookAndFeel</code>s or <code>null</code>
* @see #addAuxiliaryLookAndFeel
* @see #removeAuxiliaryLookAndFeel
* @see #setLookAndFeel
* @see #getInstalledLookAndFeels
*/
static public LookAndFeel[] getAuxiliaryLookAndFeels() {
return null;
}
else {
}
return rv;
}
}
/**
* Adds a <code>PropertyChangeListener</code> to the listener list.
* The listener is registered for all properties.
*
* @param listener the <code>PropertyChangeListener</code> to be added
* @see java.beans.PropertyChangeSupport
*/
{
synchronized (classLock) {
getLAFState().getPropertyChangeSupport(true).
}
}
/**
* Removes a <code>PropertyChangeListener</code> from the listener list.
* This removes a <code>PropertyChangeListener</code> that was registered
* for all properties.
*
* @param listener the <code>PropertyChangeListener</code> to be removed
* @see java.beans.PropertyChangeSupport
*/
{
synchronized (classLock) {
getLAFState().getPropertyChangeSupport(true).
}
}
/**
* Returns an array of all the <code>PropertyChangeListener</code>s added
* to this UIManager with addPropertyChangeListener().
*
* @return all of the <code>PropertyChangeListener</code>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).
}
}
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.
*/
return new Properties();
}
else {
try {
// InputStream has been buffered in Properties
// class
}
}
catch (Exception e) {
// No such file, or file is otherwise non-readable.
}
// Check whether any properties were overridden at the
// command line.
// Don't care about return value.
return null;
}
});
return props;
}
}
// No need to do catch the SecurityException here, this runs
// in a doPrivileged.
}
}
/**
* If a swing.properties file exist and it has a swing.installedlafs property
* then initialize the <code>installedLAFs</code> field.
*
* @see #getInstalledLookAndFeels
*/
{
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"}.
*/
while (st.hasMoreTokens()) {
}
/* 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.
*/
}
}
}
}
/**
* 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.
*
* @see #maybeInitialize
*/
{
return;
}
// Try to get default LAF from system property, then from AppContext
// (6653395), then use cross-platform one by default.
}
}
try {
} catch (Exception e) {
}
// Set any properties passed through AppContext (6653395).
}
}
}
{
if (auxLookAndFeelNames == null) {
return;
}
/* Try to load each LookAndFeel subclass in the list.
*/
while (p.hasMoreTokens()) {
try {
newLAF.initialize();
}
catch (Exception e) {
}
}
/* 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.
*/
}
else {
}
}
}
}
/*
* This method is called before any code that depends on the
* <code>AppContext</code> specific LAFState object runs. When the AppContext
* corresponds to a set of applets it's possible for this method
* to be re-entered, which is why we grab a lock before calling
* initialize().
*/
private static void maybeInitialize() {
synchronized (classLock) {
if (!getLAFState().initialized) {
getLAFState().initialized = true;
initialize();
}
}
}
/*
* Only called by maybeInitialize().
*/
private static void initialize() {
// Enable the Swing default LayoutManager.
// don't set default policy if this is XAWT.
if (FocusManager.isFocusManagerEnabled()) {
new LayoutFocusTraversalPolicy());
}
}
// Install Swing's PaintEventDispatcher
new SwingPaintEventDispatcher());
}
// 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.
public boolean postProcessKeyEvent(KeyEvent e) {
Component c = e.getComponent();
if ((!(c instanceof JComponent) ||
e.consume();
return true;
}
return false;
}
});
try {
method.setAccessible(true);
return method;
}
});
} catch (Exception e) {
// perhaps we should log this
assert false;
}
}
}