jdk/src/share/classes/javax/swing/UIManager.java
author dmarkov
Wed, 16 Apr 2014 12:51:25 +0400
changeset 24184 4da2f6ec4dab
parent 22574 7f8ce0c8c20a
child 25201 4adc75e0c4e5
permissions -rw-r--r--
8032874: ArrayIndexOutOfBoundsException in JTable while clearing data in JTable Reviewed-by: alexp, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21278
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4199
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4199
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4199
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4199
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4199
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.KeyboardFocusManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.KeyEventPostProcessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.plaf.ComponentUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.border.Border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.event.SwingPropertyChangeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.awt.OSInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import java.lang.reflect.Method;
2492
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
    61
import java.util.HashMap;
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
    62
import sun.awt.AppContext;
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2658
diff changeset
    63
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * {@code UIManager} manages the current look and feel, the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * available look and feels, {@code PropertyChangeListeners} that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * are notified when the look and feel changes, look and feel defaults, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * convenience methods for obtaining various default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <h3>Specifying the look and feel</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * The look and feel can be specified in two distinct ways: by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * specifying the fully qualified name of the class for the look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * feel, or by creating an instance of {@code LookAndFeel} and passing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * it to {@code setLookAndFeel}. The following example illustrates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * setting the look and feel to the system look and feel:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * The following example illustrates setting the look and feel based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * class name:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *   UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * Once the look and feel has been changed it is imperative to invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * {@code updateUI} on all {@code JComponents}. The method {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * SwingUtilities#updateComponentTreeUI} makes it easy to apply {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * updateUI} to a containment hierarchy. Refer to it for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * details. The exact behavior of not invoking {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * updateUI} after changing the look and feel is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * unspecified. It is very possible to receive unexpected exceptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * painting problems, or worse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <h3>Default look and feel</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * The class used for the default look and feel is chosen in the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * manner:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *   <li>If the system property <code>swing.defaultlaf</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *       {@code non-null}, use its value as the default look and feel class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *       name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *   <li>If the {@link java.util.Properties} file <code>swing.properties</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *       exists and contains the key <code>swing.defaultlaf</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *       use its value as the default look and feel class name. The location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *       that is checked for <code>swing.properties</code> may vary depending
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   108
 *       upon the implementation of the Java platform. Typically the
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   109
 *       <code>swing.properties</code> file is located in the <code>lib</code>
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   110
 *       subdirectory of the Java installation directory.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *       Refer to the release notes of the implementation being used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *       further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *   <li>Otherwise use the cross platform look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <h3>Defaults</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * {@code UIManager} manages three sets of {@code UIDefaults}. In order, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *   <li>Developer defaults. With few exceptions Swing does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *       alter the developer defaults; these are intended to be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *       and used by the developer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *   <li>Look and feel defaults. The look and feel defaults are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *       supplied by the look and feel at the time it is installed as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *       current look and feel ({@code setLookAndFeel()} is invoked). The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *       look and feel defaults can be obtained using the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *       getLookAndFeelDefaults()} method.
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
   129
 *   <li>System defaults. The system defaults are provided by Swing.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * Invoking any of the various {@code get} methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * results in checking each of the defaults, in order, returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * the first {@code non-null} value. For example, invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * {@code UIManager.getString("Table.foreground")} results in first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * checking developer defaults. If the developer defaults contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * a value for {@code "Table.foreground"} it is returned, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * the look and feel defaults are checked, followed by the system defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * It's important to note that {@code getDefaults} returns a custom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * instance of {@code UIDefaults} with this resolution logic built into it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * For example, {@code UIManager.getDefaults().getString("Table.foreground")}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * is equivalent to {@code UIManager.getString("Table.foreground")}. Both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * resolve using the algorithm just described. In many places the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * documentation uses the word defaults to refer to the custom instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * of {@code UIDefaults} with the resolution logic as previously described.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * When the look and feel is changed, {@code UIManager} alters only the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * look and feel defaults; the developer and system defaults are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * altered by the {@code UIManager} in any way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * The set of defaults a particular look and feel supports is defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * and documented by that look and feel. In addition, each look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * feel, or {@code ComponentUI} provided by a look and feel, may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * access the defaults at different times in their life cycle. Some
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
   155
 * look and feels may aggressively look up defaults, so that changing a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * default may not have an effect after installing the look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * Other look and feels may lazily access defaults so that a change to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * the defaults may effect an existing look and feel. Finally, other look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * and feels might not configure themselves from the defaults table in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * any way. None-the-less it is usually the case that a look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * expects certain defaults, so that in general
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * a {@code ComponentUI} provided by one look and feel will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * work with another look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 15263
diff changeset
   170
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * @author Thomas Ball
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21278
diff changeset
   177
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
public class UIManager implements Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * This class defines the state managed by the <code>UIManager</code>.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Swing applications the fields in this class could just as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * be static members of <code>UIManager</code> however we give them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * "AppContext"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * scope instead so that applets (and potentially multiple lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * applications running in a single VM) have their own state. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * an applet can alter its look and feel, see <code>setLookAndFeel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Doing so has no affect on other applets (or the browser).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private static class LAFState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        Properties swingProps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        private UIDefaults[] tables = new UIDefaults[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        boolean initialized = false;
12661
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
   196
        boolean focusPolicyInitialized = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        MultiUIDefaults multiUIDefaults = new MultiUIDefaults(tables);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        LookAndFeel lookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        LookAndFeel multiLookAndFeel = null;
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   200
        Vector<LookAndFeel> auxLookAndFeels = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        SwingPropertyChangeSupport changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   203
        LookAndFeelInfo[] installedLAFs;
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   204
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        UIDefaults getLookAndFeelDefaults() { return tables[0]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        void setLookAndFeelDefaults(UIDefaults x) { tables[0] = x; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        UIDefaults getSystemDefaults() { return tables[1]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        void setSystemDefaults(UIDefaults x) { tables[1] = x; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         * Returns the SwingPropertyChangeSupport for the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * AppContext.  If <code>create</code> is a true, a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         * <code>SwingPropertyChangeSupport</code> will be returned, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         * <code>create</code> is false and this has not been invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         * with true, null will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        public synchronized SwingPropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                 getPropertyChangeSupport(boolean create) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            if (create && changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                changeSupport = new SwingPropertyChangeSupport(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                         UIManager.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            return changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /* Lock object used in place of class object for synchronization. (4187686)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    private static final Object classLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Return the <code>LAFState</code> object, lazily create one if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * All access to the <code>LAFState</code> fields is done via this method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * for example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *     getLAFState().initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    private static LAFState getLAFState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        LAFState rv = (LAFState)SwingUtilities.appContextGet(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                SwingUtilities2.LAF_STATE_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            synchronized (classLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                rv = (LAFState)SwingUtilities.appContextGet(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                        SwingUtilities2.LAF_STATE_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    SwingUtilities.appContextPut(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                            SwingUtilities2.LAF_STATE_KEY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                            (rv = new LAFState()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   261
    /* Keys used in the <code>swing.properties</code> properties file.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * See loadUserProperties(), initialize().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    private static final String defaultLAFKey = "swing.defaultlaf";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private static final String auxiliaryLAFsKey = "swing.auxiliarylaf";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    private static final String multiplexingLAFKey = "swing.plaf.multiplexinglaf";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    private static final String installedLAFsKey = "swing.installedlafs";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    private static final String disableMnemonicKey = "swing.disablenavaids";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   272
     * Return a <code>swing.properties</code> file key for the attribute of specified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * look and feel.  The attr is either "name" or "class", a typical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * key would be: "swing.installedlaf.windows.name"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private static String makeInstalledLAFKey(String laf, String attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return "swing.installedlaf." + laf + "." + attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   281
     * The location of the <code>swing.properties</code> property file is
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   282
     * implementation-specific.
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   283
     * It is typically located in the <code>lib</code> subdirectory of the Java
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   284
     * installation directory. This method returns a bogus filename
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   285
     * if <code>java.home</code> isn't defined.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    private static String makeSwingPropertiesFilename() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        String sep = File.separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // No need to wrap this in a doPrivileged as it's called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        // a doPrivileged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        String javaHome = System.getProperty("java.home");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (javaHome == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            javaHome = "<java.home undefined>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return javaHome + sep + "lib" + sep + "swing.properties";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Provides a little information about an installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * <code>LookAndFeel</code> for the sake of configuring a menu or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * for initial application set up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @see UIManager#getInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see LookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public static class LookAndFeelInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        private String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
         * Constructs a <code>UIManager</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
         * <code>LookAndFeelInfo</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
         * @param name      a <code>String</code> specifying the name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
         *                      the look and feel
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
   317
         * @param className a <code>String</code> specifying the name of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
         *                      the class that implements the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        public LookAndFeelInfo(String name, String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
         * Returns the name of the look and feel in a form suitable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         * for a menu or other presentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
         * @return a <code>String</code> containing the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         * @see LookAndFeel#getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
         * Returns the name of the class that implements this look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
         * @return the name of the class that implements this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         *              <code>LookAndFeel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
         * @see LookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        public String getClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * Returns a string that displays and identifies this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * object's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         * @return a <code>String</code> representation of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            return getClass().getName() + "[" + getName() + " " + getClassName() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * The default value of <code>installedLAFS</code> is used when no
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   359
     * <code>swing.properties</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * file is available or if the file doesn't contain a "swing.installedlafs"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @see #initializeInstalledLAFs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    private static LookAndFeelInfo[] installedLAFs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    static {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   368
        ArrayList<LookAndFeelInfo> iLAFs = new ArrayList<LookAndFeelInfo>(4);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        iLAFs.add(new LookAndFeelInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                      "Metal", "javax.swing.plaf.metal.MetalLookAndFeel"));
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2492
diff changeset
   371
        iLAFs.add(new LookAndFeelInfo(
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2492
diff changeset
   372
                      "Nimbus", "javax.swing.plaf.nimbus.NimbusLookAndFeel"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        iLAFs.add(new LookAndFeelInfo("CDE/Motif",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                  "com.sun.java.swing.plaf.motif.MotifLookAndFeel"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        // Only include windows on Windows boxs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        OSInfo.OSType osType = AccessController.doPrivileged(OSInfo.getOSTypeAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (osType == OSInfo.OSType.WINDOWS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            iLAFs.add(new LookAndFeelInfo("Windows",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                        "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (Toolkit.getDefaultToolkit().getDesktopProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    "win.xpstyle.themeActive") != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                iLAFs.add(new LookAndFeelInfo("Windows Classic",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                 "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   387
        else if (osType == OSInfo.OSType.MACOSX) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   388
            iLAFs.add(new LookAndFeelInfo("Mac OS X", "com.apple.laf.AquaLookAndFeel"));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   389
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            // GTK is not shipped on Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            iLAFs.add(new LookAndFeelInfo("GTK+",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                  "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   395
        installedLAFs = iLAFs.toArray(new LookAndFeelInfo[iLAFs.size()]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * Returns an array of {@code LookAndFeelInfo}s representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * {@code LookAndFeel} implementations currently available. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * <code>LookAndFeelInfo</code> objects can be used by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * application to construct a menu of look and feel options for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * the user, or to determine which look and feel to set at startup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * time. To avoid the penalty of creating numerous {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * LookAndFeel} objects, {@code LookAndFeelInfo} maintains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * class name of the {@code LookAndFeel} class, not the actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * {@code LookAndFeel} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * The following example illustrates setting the current look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * from an instance of {@code LookAndFeelInfo}:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *   UIManager.setLookAndFeel(info.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @return an array of <code>LookAndFeelInfo</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public static LookAndFeelInfo[] getInstalledLookAndFeels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        maybeInitialize();
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   421
        LookAndFeelInfo[] ilafs = getLAFState().installedLAFs;
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   422
        if (ilafs == null) {
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   423
            ilafs = installedLAFs;
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   424
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        LookAndFeelInfo[] rv = new LookAndFeelInfo[ilafs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        System.arraycopy(ilafs, 0, rv, 0, ilafs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Sets the set of available look and feels. While this method does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * not check to ensure all of the {@code LookAndFeelInfos} are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * {@code non-null}, it is strongly recommended that only {@code non-null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * values are supplied in the {@code infos} array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @param infos set of <code>LookAndFeelInfo</code> objects specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *        the available look and feels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @see #getInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @throws NullPointerException if {@code infos} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public static void setInstalledLookAndFeels(LookAndFeelInfo[] infos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    {
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   446
        maybeInitialize();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        LookAndFeelInfo[] newInfos = new LookAndFeelInfo[infos.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        System.arraycopy(infos, 0, newInfos, 0, infos.length);
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   449
        getLAFState().installedLAFs = newInfos;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Adds the specified look and feel to the set of available look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * and feels. While this method allows a {@code null} {@code info},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * it is strongly recommended that a {@code non-null} value be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @param info a <code>LookAndFeelInfo</code> object that names the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *          look and feel and identifies the class that implements it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @see #setInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public static void installLookAndFeel(LookAndFeelInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        LookAndFeelInfo[] infos = getInstalledLookAndFeels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        LookAndFeelInfo[] newInfos = new LookAndFeelInfo[infos.length + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        System.arraycopy(infos, 0, newInfos, 0, infos.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        newInfos[infos.length] = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        setInstalledLookAndFeels(newInfos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * Adds the specified look and feel to the set of available look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * and feels. While this method does not check the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * arguments in any way, it is strongly recommended that {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * non-null} values be supplied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * @param name descriptive name of the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @param className name of the class that implements the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @see #setInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public static void installLookAndFeel(String name, String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        installLookAndFeel(new LookAndFeelInfo(name, className));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * Returns the current look and feel or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @return current look and feel, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public static LookAndFeel getLookAndFeel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        maybeInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        return getLAFState().lookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Sets the current look and feel to {@code newLookAndFeel}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * If the current look and feel is {@code non-null} {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * uninitialize} is invoked on it. If {@code newLookAndFeel} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * {@code non-null}, {@code initialize} is invoked on it followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * by {@code getDefaults}. The defaults returned from {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * newLookAndFeel.getDefaults()} replace those of the defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * from the previous look and feel. If the {@code newLookAndFeel} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * {@code null}, the look and feel defaults are set to {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * A value of {@code null} can be used to set the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * to {@code null}. As the {@code LookAndFeel} is required for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * most of Swing to function, setting the {@code LookAndFeel} to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * {@code null} is strongly discouraged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * This is a JavaBeans bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @param newLookAndFeel {@code LookAndFeel} to install
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @throws UnsupportedLookAndFeelException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     *          {@code newLookAndFeel} is {@code non-null} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *          {@code newLookAndFeel.isSupportedLookAndFeel()} returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *          {@code false}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @see #getLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public static void setLookAndFeel(LookAndFeel newLookAndFeel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        throws UnsupportedLookAndFeelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        if ((newLookAndFeel != null) && !newLookAndFeel.isSupportedLookAndFeel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            String s = newLookAndFeel.toString() + " not supported on this platform";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            throw new UnsupportedLookAndFeelException(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        LAFState lafState = getLAFState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        LookAndFeel oldLookAndFeel = lafState.lookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        if (oldLookAndFeel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            oldLookAndFeel.uninitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        lafState.lookAndFeel = newLookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        if (newLookAndFeel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            sun.swing.DefaultLookup.setDefaultLookup(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            newLookAndFeel.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            lafState.setLookAndFeelDefaults(newLookAndFeel.getDefaults());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            lafState.setLookAndFeelDefaults(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        SwingPropertyChangeSupport changeSupport = lafState.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                                         getPropertyChangeSupport(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            changeSupport.firePropertyChange("lookAndFeel", oldLookAndFeel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                                             newLookAndFeel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * Loads the {@code LookAndFeel} specified by the given class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * name, using the current thread's context class loader, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * passes it to {@code setLookAndFeel(LookAndFeel)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @param className  a string specifying the name of the class that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *        the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @exception ClassNotFoundException if the <code>LookAndFeel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *           class could not be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @exception InstantiationException if a new instance of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *          couldn't be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @exception IllegalAccessException if the class or initializer isn't accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @exception UnsupportedLookAndFeelException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *          <code>lnf.isSupportedLookAndFeel()</code> is false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @throws ClassCastException if {@code className} does not identify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     *         a class that extends {@code LookAndFeel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    public static void setLookAndFeel(String className)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        throws ClassNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
               InstantiationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
               IllegalAccessException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
               UnsupportedLookAndFeelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        if ("javax.swing.plaf.metal.MetalLookAndFeel".equals(className)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            // Avoid reflection for the common case of metal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            Class lnfClass = SwingUtilities.loadSystemClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            setLookAndFeel((LookAndFeel)(lnfClass.newInstance()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * Returns the name of the <code>LookAndFeel</code> class that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * the native system look and feel if there is one, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * the name of the default cross platform <code>LookAndFeel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * class. This value can be overriden by setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * <code>swing.systemlaf</code> system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * @return the <code>String</code> of the <code>LookAndFeel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *          class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @see #getCrossPlatformLookAndFeelClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    public static String getSystemLookAndFeelClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        String systemLAF = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                             new GetPropertyAction("swing.systemlaf"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        if (systemLAF != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            return systemLAF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        OSInfo.OSType osType = AccessController.doPrivileged(OSInfo.getOSTypeAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        if (osType == OSInfo.OSType.WINDOWS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            String desktop = AccessController.doPrivileged(new GetPropertyAction("sun.desktop"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            Toolkit toolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            if ("gnome".equals(desktop) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    toolkit instanceof SunToolkit &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    ((SunToolkit) toolkit).isNativeGTKAvailable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                // May be set on Linux and Solaris boxs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                return "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   619
            if (osType == OSInfo.OSType.MACOSX) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   620
                if (toolkit.getClass() .getName()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   621
                                       .equals("sun.lwawt.macosx.LWCToolkit")) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   622
                    return "com.apple.laf.AquaLookAndFeel";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   623
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   624
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            if (osType == OSInfo.OSType.SOLARIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                return "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        return getCrossPlatformLookAndFeelClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * Returns the name of the <code>LookAndFeel</code> class that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * the default cross platform look and feel -- the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * Look and Feel (JLF).  This value can be overriden by setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * <code>swing.crossplatformlaf</code> system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @return  a string with the JLF implementation-class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * @see #getSystemLookAndFeelClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    public static String getCrossPlatformLookAndFeelClassName() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   644
        String laf = AccessController.doPrivileged(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                             new GetPropertyAction("swing.crossplatformlaf"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        if (laf != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            return laf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        return "javax.swing.plaf.metal.MetalLookAndFeel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * Returns the defaults. The returned defaults resolve using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * logic specified in the class documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @return a <code>UIDefaults</code> object containing the default values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    public static UIDefaults getDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        maybeInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        return getLAFState().multiUIDefaults;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * Returns a font from the defaults. If the value for {@code key} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * not a {@code Font}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @param key  an <code>Object</code> specifying the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * @return the <code>Font</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    public static Font getFont(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        return getDefaults().getFont(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * Returns a font from the defaults that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * for the given locale. If the value for {@code key} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * not a {@code Font}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @param key  an <code>Object</code> specifying the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @param l the <code>Locale</code> for which the font is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * @return the <code>Font</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    public static Font getFont(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        return getDefaults().getFont(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * Returns a color from the defaults. If the value for {@code key} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * not a {@code Color}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * @param key  an <code>Object</code> specifying the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @return the <code>Color</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    public static Color getColor(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        return getDefaults().getColor(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * Returns a color from the defaults that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * for the given locale. If the value for {@code key} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * not a {@code Color}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @param key  an <code>Object</code> specifying the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @param l the <code>Locale</code> for which the color is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @return the <code>Color</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    public static Color getColor(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        return getDefaults().getColor(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * Returns an <code>Icon</code> from the defaults. If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * {@code key} is not an {@code Icon}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * @param key  an <code>Object</code> specifying the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @return the <code>Icon</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    public static Icon getIcon(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        return getDefaults().getIcon(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * Returns an <code>Icon</code> from the defaults that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * for the given locale. If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * {@code key} is not an {@code Icon}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @param key  an <code>Object</code> specifying the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @param l the <code>Locale</code> for which the icon is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @return the <code>Icon</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    public static Icon getIcon(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        return getDefaults().getIcon(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * Returns a border from the defaults. If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * {@code key} is not a {@code Border}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * @param key  an <code>Object</code> specifying the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * @return the <code>Border</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    public static Border getBorder(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        return getDefaults().getBorder(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * Returns a border from the defaults that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * for the given locale.  If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * {@code key} is not a {@code Border}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * @param key  an <code>Object</code> specifying the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @param l the <code>Locale</code> for which the border is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * @return the <code>Border</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    public static Border getBorder(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        return getDefaults().getBorder(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * Returns a string from the defaults. If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * {@code key} is not a {@code String}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * @param key  an <code>Object</code> specifying the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * @return the <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    public static String getString(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        return getDefaults().getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * Returns a string from the defaults that is appropriate for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * given locale.  If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * {@code key} is not a {@code String}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * @param key  an <code>Object</code> specifying the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @param l the <code>Locale</code> for which the string is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @return the <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    public static String getString(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        return getDefaults().getString(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * Returns a string from the defaults that is appropriate for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * given locale.  If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * {@code key} is not a {@code String}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * @param key  an <code>Object</code> specifying the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @param c {@code Component} used to determine the locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     *          {@code null} implies the default locale as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *          returned by {@code Locale.getDefault()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * @return the <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    static String getString(Object key, Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        Locale l = (c == null) ? Locale.getDefault() : c.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        return getString(key, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * Returns an integer from the defaults. If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * {@code key} is not an {@code Integer}, or does not exist,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * {@code 0} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * @param key  an <code>Object</code> specifying the int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @return the int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    public static int getInt(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        return getDefaults().getInt(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * Returns an integer from the defaults that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * for the given locale. If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * {@code key} is not an {@code Integer}, or does not exist,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * {@code 0} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * @param key  an <code>Object</code> specifying the int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * @param l the <code>Locale</code> for which the int is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @return the int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    public static int getInt(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        return getDefaults().getInt(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * Returns a boolean from the defaults which is associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * the key value. If the key is not found or the key doesn't represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * a boolean value then {@code false} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * @param key  an <code>Object</code> specifying the key for the desired boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * @return the boolean value corresponding to the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    public static boolean getBoolean(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        return getDefaults().getBoolean(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * Returns a boolean from the defaults which is associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * the key value and the given <code>Locale</code>. If the key is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * found or the key doesn't represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * a boolean value then {@code false} will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @param key  an <code>Object</code> specifying the key for the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     *             boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * @param l the <code>Locale</code> for which the boolean is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @return the boolean value corresponding to the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    public static boolean getBoolean(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        return getDefaults().getBoolean(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * Returns an <code>Insets</code> object from the defaults. If the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * for {@code key} is not an {@code Insets}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * @param key  an <code>Object</code> specifying the <code>Insets</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * @return the <code>Insets</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    public static Insets getInsets(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        return getDefaults().getInsets(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * Returns an <code>Insets</code> object from the defaults that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * appropriate for the given locale. If the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * for {@code key} is not an {@code Insets}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * @param key  an <code>Object</code> specifying the <code>Insets</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * @param l the <code>Locale</code> for which the object is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * @return the <code>Insets</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    public static Insets getInsets(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        return getDefaults().getInsets(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * Returns a dimension from the defaults. If the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * for {@code key} is not a {@code Dimension}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * @param key  an <code>Object</code> specifying the dimension object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * @return the <code>Dimension</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    public static Dimension getDimension(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        return getDefaults().getDimension(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * Returns a dimension from the defaults that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * for the given locale. If the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * for {@code key} is not a {@code Dimension}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * @param key  an <code>Object</code> specifying the dimension object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * @param l the <code>Locale</code> for which the object is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * @return the <code>Dimension</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    public static Dimension getDimension(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        return getDefaults().getDimension(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * Returns an object from the defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * @param key  an <code>Object</code> specifying the desired object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * @return the <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    public static Object get(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        return getDefaults().get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * Returns an object from the defaults that is appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @param key  an <code>Object</code> specifying the desired object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @param l the <code>Locale</code> for which the object is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * @return the <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    public static Object get(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        return getDefaults().get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * Stores an object in the developer defaults. This is a cover method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * for {@code getDefaults().put(key, value)}. This only effects the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * developer defaults, not the system or look and feel defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * @param key    an <code>Object</code> specifying the retrieval key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * @param value  the <code>Object</code> to store; refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     *               {@code UIDefaults} for details on how {@code null} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     *               handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * @return the <code>Object</code> returned by {@link UIDefaults#put}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * @see UIDefaults#put
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    public static Object put(Object key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        return getDefaults().put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * Returns the appropriate {@code ComponentUI} implementation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * {@code target}. Typically, this is a cover for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * {@code getDefaults().getUI(target)}. However, if an auxiliary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * look and feel has been installed, this first invokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * {@code getUI(target)} on the multiplexing look and feel's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * defaults, and returns that value if it is {@code non-null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * @param target the <code>JComponent</code> to return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     *        {@code ComponentUI} for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * @return the <code>ComponentUI</code> object for {@code target}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * @throws NullPointerException if {@code target} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    public static ComponentUI getUI(JComponent target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        maybeInitialize();
12661
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1008
        maybeInitializeFocusPolicy(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        ComponentUI ui = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        LookAndFeel multiLAF = getLAFState().multiLookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        if (multiLAF != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            // This can return null if the multiplexing look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            // doesn't support a particular UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            ui = multiLAF.getDefaults().getUI(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        if (ui == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            ui = getDefaults().getUI(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        return ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * Returns the {@code UIDefaults} from the current look and feel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * that were obtained at the time the look and feel was installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * In general, developers should use the {@code UIDefaults} returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * {@code getDefaults()}. As the current look and feel may expect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * certain values to exist, altering the {@code UIDefaults} returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * from this method could have unexpected results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * @return <code>UIDefaults</code> from the current look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * @see #getDefaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * @see #setLookAndFeel(LookAndFeel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * @see LookAndFeel#getDefaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    public static UIDefaults getLookAndFeelDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        maybeInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        return getLAFState().getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * Finds the Multiplexing <code>LookAndFeel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    private static LookAndFeel getMultiLookAndFeel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        LookAndFeel multiLookAndFeel = getLAFState().multiLookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        if (multiLookAndFeel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            String defaultName = "javax.swing.plaf.multi.MultiLookAndFeel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            String className = getLAFState().swingProps.getProperty(multiplexingLAFKey, defaultName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                Class lnfClass = SwingUtilities.loadSystemClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                multiLookAndFeel = (LookAndFeel)lnfClass.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                System.err.println("UIManager: failed loading " + className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        return multiLookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * Adds a <code>LookAndFeel</code> to the list of auxiliary look and feels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * The auxiliary look and feels tell the multiplexing look and feel what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * other <code>LookAndFeel</code> classes for a component instance are to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * in addition to the default <code>LookAndFeel</code> class when creating a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * multiplexing UI.  The change will only take effect when a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * UI class is created or when the default look and feel is changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * on a component instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * <p>Note these are not the same as the installed look and feels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * @param laf the <code>LookAndFeel</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * @see #removeAuxiliaryLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * @see #getAuxiliaryLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * @see #getInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    static public void addAuxiliaryLookAndFeel(LookAndFeel laf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        maybeInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        if (!laf.isSupportedLookAndFeel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            // Ideally we would throw an exception here, but it's too late
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            // for that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        }
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1084
        Vector<LookAndFeel> v = getLAFState().auxLookAndFeels;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        if (v == null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1086
            v = new Vector<LookAndFeel>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        if (!v.contains(laf)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            v.addElement(laf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            laf.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            getLAFState().auxLookAndFeels = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            if (getLAFState().multiLookAndFeel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                getLAFState().multiLookAndFeel = getMultiLookAndFeel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * Removes a <code>LookAndFeel</code> from the list of auxiliary look and feels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * The auxiliary look and feels tell the multiplexing look and feel what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * other <code>LookAndFeel</code> classes for a component instance are to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * in addition to the default <code>LookAndFeel</code> class when creating a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * multiplexing UI.  The change will only take effect when a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * UI class is created or when the default look and feel is changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * on a component instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * <p>Note these are not the same as the installed look and feels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * @return true if the <code>LookAndFeel</code> was removed from the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * @see #removeAuxiliaryLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * @see #getAuxiliaryLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * @see #getInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    static public boolean removeAuxiliaryLookAndFeel(LookAndFeel laf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        maybeInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        boolean result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1120
        Vector<LookAndFeel> v = getLAFState().auxLookAndFeels;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        if ((v == null) || (v.size() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        result = v.removeElement(laf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        if (result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            if (v.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                getLAFState().auxLookAndFeels = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                getLAFState().multiLookAndFeel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                getLAFState().auxLookAndFeels = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        laf.uninitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * Returns the list of auxiliary look and feels (can be <code>null</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * The auxiliary look and feels tell the multiplexing look and feel what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * other <code>LookAndFeel</code> classes for a component instance are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * to be used in addition to the default LookAndFeel class when creating a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * multiplexing UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * <p>Note these are not the same as the installed look and feels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * @return list of auxiliary <code>LookAndFeel</code>s or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * @see #addAuxiliaryLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * @see #removeAuxiliaryLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * @see #getInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    static public LookAndFeel[] getAuxiliaryLookAndFeels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        maybeInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1156
        Vector<LookAndFeel> v = getLAFState().auxLookAndFeels;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        if ((v == null) || (v.size() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            LookAndFeel[] rv = new LookAndFeel[v.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            for (int i = 0; i < rv.length; i++) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1163
                rv[i] = v.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * Adds a <code>PropertyChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @param listener  the <code>PropertyChangeListener</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * @see java.beans.PropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    public static void addPropertyChangeListener(PropertyChangeListener listener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        synchronized (classLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            getLAFState().getPropertyChangeSupport(true).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                             addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * Removes a <code>PropertyChangeListener</code> from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * This removes a <code>PropertyChangeListener</code> that was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * @param listener  the <code>PropertyChangeListener</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * @see java.beans.PropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    public static void removePropertyChangeListener(PropertyChangeListener listener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        synchronized (classLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            getLAFState().getPropertyChangeSupport(true).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                          removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * Returns an array of all the <code>PropertyChangeListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * to this UIManager with addPropertyChangeListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * @return all of the <code>PropertyChangeListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    public static PropertyChangeListener[] getPropertyChangeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        synchronized(classLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            return getLAFState().getPropertyChangeSupport(true).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                      getPropertyChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    private static Properties loadSwingProperties()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        /* Don't bother checking for Swing properties if untrusted, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
         * there's no way to look them up without triggering SecurityExceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        if (UIManager.class.getClassLoader() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            return new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            final Properties props = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            java.security.AccessController.doPrivileged(
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1230
                new java.security.PrivilegedAction<Object>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                public Object run() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
  1232
                    OSInfo.OSType osType = AccessController.doPrivileged(OSInfo.getOSTypeAction());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
  1233
                    if (osType == OSInfo.OSType.MACOSX) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
  1234
                        props.put(defaultLAFKey, getSystemLookAndFeelClassName());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
  1235
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
  1236
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                        File file = new File(makeSwingPropertiesFilename());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                        if (file.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                            // InputStream has been buffered in Properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                            // class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                            FileInputStream ins = new FileInputStream(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                            props.load(ins);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                            ins.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                    catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                        // No such file, or file is otherwise non-readable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                    // Check whether any properties were overridden at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                    // command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                    checkProperty(props, defaultLAFKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                    checkProperty(props, auxiliaryLAFsKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                    checkProperty(props, multiplexingLAFKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                    checkProperty(props, installedLAFsKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                    checkProperty(props, disableMnemonicKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                    // Don't care about return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            return props;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    private static void checkProperty(Properties props, String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        // No need to do catch the SecurityException here, this runs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        // in a doPrivileged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        String value = System.getProperty(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            props.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    /**
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
  1278
     * If a <code>swing.properties</code> file exist and it has a
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
  1279
     * <code>swing.installedlafs</code> property
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * then initialize the <code>installedLAFs</code> field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * @see #getInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    private static void initializeInstalledLAFs(Properties swingProps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        String ilafsString = swingProps.getProperty(installedLAFsKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        if (ilafsString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        /* Create a vector that contains the value of the swing.installedlafs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
         * property.  For example given "swing.installedlafs=motif,windows"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
         * lafs = {"motif", "windows"}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
         */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1295
        Vector<String> lafs = new Vector<String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        StringTokenizer st = new StringTokenizer(ilafsString, ",", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
        while (st.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            lafs.addElement(st.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        /* Look up the name and class for each name in the "swing.installedlafs"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
         * list.  If they both exist then add a LookAndFeelInfo to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
         * the installedLafs array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
         */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1305
        Vector<LookAndFeelInfo> ilafs = new Vector<LookAndFeelInfo>(lafs.size());
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1306
        for (String laf : lafs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            String name = swingProps.getProperty(makeInstalledLAFKey(laf, "name"), laf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            String cls = swingProps.getProperty(makeInstalledLAFKey(laf, "class"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            if (cls != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                ilafs.addElement(new LookAndFeelInfo(name, cls));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
  1314
        LookAndFeelInfo[] installedLAFs = new LookAndFeelInfo[ilafs.size()];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        for(int i = 0; i < ilafs.size(); i++) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1316
            installedLAFs[i] = ilafs.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        }
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
  1318
        getLAFState().installedLAFs = installedLAFs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * If the user has specified a default look and feel, use that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     * Otherwise use the look and feel that's native to this platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * If this code is called after the application has explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * set it's look and feel, do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * @see #maybeInitialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    private static void initializeDefaultLAF(Properties swingProps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        if (getLAFState().lookAndFeel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
2492
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1336
        // Try to get default LAF from system property, then from AppContext
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1337
        // (6653395), then use cross-platform one by default.
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1338
        String lafName = null;
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1339
        HashMap lafData =
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1340
                (HashMap) AppContext.getAppContext().remove("swing.lafdata");
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1341
        if (lafData != null) {
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1342
            lafName = (String) lafData.remove("defaultlaf");
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1343
        }
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1344
        if (lafName == null) {
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1345
            lafName = getCrossPlatformLookAndFeelClassName();
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1346
        }
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1347
        lafName = swingProps.getProperty(defaultLAFKey, lafName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        try {
2492
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1350
            setLookAndFeel(lafName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        } catch (Exception e) {
2492
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1352
            throw new Error("Cannot load " + lafName);
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1353
        }
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1354
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1355
        // Set any properties passed through AppContext (6653395).
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1356
        if (lafData != null) {
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1357
            for (Object key: lafData.keySet()) {
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1358
                UIManager.put(key, lafData.get(key));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    private static void initializeAuxiliaryLAFs(Properties swingProps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        String auxLookAndFeelNames = swingProps.getProperty(auxiliaryLAFsKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        if (auxLookAndFeelNames == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1371
        Vector<LookAndFeel> auxLookAndFeels = new Vector<LookAndFeel>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        StringTokenizer p = new StringTokenizer(auxLookAndFeelNames,",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        String factoryName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        /* Try to load each LookAndFeel subclass in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        while (p.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            String className = p.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                Class lnfClass = SwingUtilities.loadSystemClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                LookAndFeel newLAF = (LookAndFeel)lnfClass.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                newLAF.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                auxLookAndFeels.addElement(newLAF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                System.err.println("UIManager: failed loading auxiliary look and feel " + className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        /* If there were problems and no auxiliary look and feels were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
         * loaded, make sure we reset auxLookAndFeels to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
         * Otherwise, we are going to use the MultiLookAndFeel to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
         * all component UI's, so we need to load it now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        if (auxLookAndFeels.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            auxLookAndFeels = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            getLAFState().multiLookAndFeel = getMultiLookAndFeel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
            if (getLAFState().multiLookAndFeel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                auxLookAndFeels = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
        getLAFState().auxLookAndFeels = auxLookAndFeels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
    private static void initializeSystemDefaults(Properties swingProps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
        getLAFState().swingProps = swingProps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * This method is called before any code that depends on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * <code>AppContext</code> specific LAFState object runs.  When the AppContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * corresponds to a set of applets it's possible for this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * to be re-entered, which is why we grab a lock before calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * initialize().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
    private static void maybeInitialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        synchronized (classLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
            if (!getLAFState().initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                getLAFState().initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
12661
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1432
    /*
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1433
     * Sets default swing focus traversal policy.
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1434
     */
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1435
    private static void maybeInitializeFocusPolicy(JComponent comp) {
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1436
        // Check for JRootPane which indicates that a swing toplevel
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1437
        // is coming, in which case a swing default focus policy
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1438
        // should be instatiated. See 7125044.
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1439
        if (comp instanceof JRootPane) {
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1440
            synchronized (classLock) {
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1441
                if (!getLAFState().focusPolicyInitialized) {
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1442
                    getLAFState().focusPolicyInitialized = true;
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1443
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1444
                    if (FocusManager.isFocusManagerEnabled()) {
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1445
                        KeyboardFocusManager.getCurrentKeyboardFocusManager().
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1446
                            setDefaultFocusTraversalPolicy(
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1447
                                new LayoutFocusTraversalPolicy());
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1448
                    }
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1449
                }
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1450
            }
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1451
        }
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1452
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * Only called by maybeInitialize().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    private static void initialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        Properties swingProps = loadSwingProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        initializeSystemDefaults(swingProps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        initializeDefaultLAF(swingProps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        initializeAuxiliaryLAFs(swingProps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        initializeInstalledLAFs(swingProps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        // Install Swing's PaintEventDispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            sun.awt.PaintEventDispatcher.setPaintEventDispatcher(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                                        new SwingPaintEventDispatcher());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        // Install a hook that will be invoked if no one consumes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        // KeyEvent.  If the source isn't a JComponent this will process
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        // key bindings, if the source is a JComponent it implies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        // processKeyEvent was already invoked and thus no need to process
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        // the bindings again, unless the Component is disabled, in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        // case KeyEvents will no longer be dispatched to it so that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        // handle it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                addKeyEventPostProcessor(new KeyEventPostProcessor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                    public boolean postProcessKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                        Component c = e.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                        if ((!(c instanceof JComponent) ||
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1482
                             (c != null && !c.isEnabled())) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                                JComponent.KeyboardState.shouldProcess(e) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                                SwingUtilities.processKeyBindings(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                });
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2658
diff changeset
  1491
        AWTAccessor.getComponentAccessor().
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2658
diff changeset
  1492
            setRequestFocusController(JComponent.focusController);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
}