jdk/src/java.desktop/share/classes/javax/swing/UIManager.java
author chegar
Wed, 03 Dec 2014 14:22:58 +0000
changeset 27565 729f9700483a
parent 25859 3317bb8137f4
child 28231 b608ffcaed74
permissions -rw-r--r--
8049367: Modular Run-Time Images Reviewed-by: chegar, dfuchs, ihse, joehw, mullan, psandoz, wetmore Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, bradford.wetmore@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, james.laskey@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com, sundararajan.athijegannathan@oracle.com
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
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   109
 *       <code>swing.properties</code> file is located in the <code>conf</code>
15263
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
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 22574
diff changeset
   176
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21278
diff changeset
   178
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
public class UIManager implements Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * This class defines the state managed by the <code>UIManager</code>.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Swing applications the fields in this class could just as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * be static members of <code>UIManager</code> however we give them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * "AppContext"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * scope instead so that applets (and potentially multiple lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * applications running in a single VM) have their own state. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * an applet can alter its look and feel, see <code>setLookAndFeel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Doing so has no affect on other applets (or the browser).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private static class LAFState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        Properties swingProps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        private UIDefaults[] tables = new UIDefaults[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        boolean initialized = false;
12661
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
   197
        boolean focusPolicyInitialized = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        MultiUIDefaults multiUIDefaults = new MultiUIDefaults(tables);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        LookAndFeel lookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        LookAndFeel multiLookAndFeel = null;
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   201
        Vector<LookAndFeel> auxLookAndFeels = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        SwingPropertyChangeSupport changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   204
        LookAndFeelInfo[] installedLAFs;
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   205
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        UIDefaults getLookAndFeelDefaults() { return tables[0]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        void setLookAndFeelDefaults(UIDefaults x) { tables[0] = x; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        UIDefaults getSystemDefaults() { return tables[1]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        void setSystemDefaults(UIDefaults x) { tables[1] = x; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * Returns the SwingPropertyChangeSupport for the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         * AppContext.  If <code>create</code> is a true, a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         * <code>SwingPropertyChangeSupport</code> will be returned, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         * <code>create</code> is false and this has not been invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         * with true, null will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        public synchronized SwingPropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                 getPropertyChangeSupport(boolean create) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            if (create && changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                changeSupport = new SwingPropertyChangeSupport(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                         UIManager.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            return changeSupport;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /* Lock object used in place of class object for synchronization. (4187686)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    private static final Object classLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Return the <code>LAFState</code> object, lazily create one if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * All access to the <code>LAFState</code> fields is done via this method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * for example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *     getLAFState().initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    private static LAFState getLAFState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        LAFState rv = (LAFState)SwingUtilities.appContextGet(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                SwingUtilities2.LAF_STATE_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            synchronized (classLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                rv = (LAFState)SwingUtilities.appContextGet(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                        SwingUtilities2.LAF_STATE_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    SwingUtilities.appContextPut(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                            SwingUtilities2.LAF_STATE_KEY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                            (rv = new LAFState()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   262
    /* Keys used in the <code>swing.properties</code> properties file.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * See loadUserProperties(), initialize().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private static final String defaultLAFKey = "swing.defaultlaf";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    private static final String auxiliaryLAFsKey = "swing.auxiliarylaf";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    private static final String multiplexingLAFKey = "swing.plaf.multiplexinglaf";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    private static final String installedLAFsKey = "swing.installedlafs";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private static final String disableMnemonicKey = "swing.disablenavaids";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   273
     * Return a <code>swing.properties</code> file key for the attribute of specified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * look and feel.  The attr is either "name" or "class", a typical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * key would be: "swing.installedlaf.windows.name"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private static String makeInstalledLAFKey(String laf, String attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return "swing.installedlaf." + laf + "." + attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   282
     * 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
   283
     * implementation-specific.
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   284
     * It is typically located in the <code>conf</code> subdirectory of the Java
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
   285
     * 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
   286
     * if <code>java.home</code> isn't defined.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private static String makeSwingPropertiesFilename() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        String sep = File.separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        // No need to wrap this in a doPrivileged as it's called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        // a doPrivileged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        String javaHome = System.getProperty("java.home");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (javaHome == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            javaHome = "<java.home undefined>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   296
        return javaHome + sep + "conf" + sep + "swing.properties";
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Provides a little information about an installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <code>LookAndFeel</code> for the sake of configuring a menu or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * for initial application set up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see UIManager#getInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @see LookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public static class LookAndFeelInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        private String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
         * Constructs a <code>UIManager</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
         * <code>LookAndFeelInfo</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
         * @param name      a <code>String</code> specifying the name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
         *                      the look and feel
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
   318
         * @param className a <code>String</code> specifying the name of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
         *                      the class that implements the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        public LookAndFeelInfo(String name, String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         * Returns the name of the look and feel in a form suitable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
         * for a menu or other presentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         * @return a <code>String</code> containing the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
         * @see LookAndFeel#getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
         * Returns the name of the class that implements this look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         * @return the name of the class that implements this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
         *              <code>LookAndFeel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
         * @see LookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        public String getClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * Returns a string that displays and identifies this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         * object's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         * @return a <code>String</code> representation of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            return getClass().getName() + "[" + getName() + " " + getClassName() + "]";
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * 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
   360
     * <code>swing.properties</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * file is available or if the file doesn't contain a "swing.installedlafs"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @see #initializeInstalledLAFs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    private static LookAndFeelInfo[] installedLAFs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    static {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   369
        ArrayList<LookAndFeelInfo> iLAFs = new ArrayList<LookAndFeelInfo>(4);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        iLAFs.add(new LookAndFeelInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                      "Metal", "javax.swing.plaf.metal.MetalLookAndFeel"));
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2492
diff changeset
   372
        iLAFs.add(new LookAndFeelInfo(
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2492
diff changeset
   373
                      "Nimbus", "javax.swing.plaf.nimbus.NimbusLookAndFeel"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        iLAFs.add(new LookAndFeelInfo("CDE/Motif",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                  "com.sun.java.swing.plaf.motif.MotifLookAndFeel"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        // Only include windows on Windows boxs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        OSInfo.OSType osType = AccessController.doPrivileged(OSInfo.getOSTypeAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (osType == OSInfo.OSType.WINDOWS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            iLAFs.add(new LookAndFeelInfo("Windows",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                        "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            if (Toolkit.getDefaultToolkit().getDesktopProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    "win.xpstyle.themeActive") != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                iLAFs.add(new LookAndFeelInfo("Windows Classic",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                 "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   388
        else if (osType == OSInfo.OSType.MACOSX) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   389
            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
   390
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            // GTK is not shipped on Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            iLAFs.add(new LookAndFeelInfo("GTK+",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                  "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   396
        installedLAFs = iLAFs.toArray(new LookAndFeelInfo[iLAFs.size()]);
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * Returns an array of {@code LookAndFeelInfo}s representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * {@code LookAndFeel} implementations currently available. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * <code>LookAndFeelInfo</code> objects can be used by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * application to construct a menu of look and feel options for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * the user, or to determine which look and feel to set at startup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * time. To avoid the penalty of creating numerous {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * LookAndFeel} objects, {@code LookAndFeelInfo} maintains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * class name of the {@code LookAndFeel} class, not the actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * {@code LookAndFeel} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * The following example illustrates setting the current look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * from an instance of {@code LookAndFeelInfo}:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *   UIManager.setLookAndFeel(info.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @return an array of <code>LookAndFeelInfo</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public static LookAndFeelInfo[] getInstalledLookAndFeels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        maybeInitialize();
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   422
        LookAndFeelInfo[] ilafs = getLAFState().installedLAFs;
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   423
        if (ilafs == null) {
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   424
            ilafs = installedLAFs;
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   425
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        LookAndFeelInfo[] rv = new LookAndFeelInfo[ilafs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        System.arraycopy(ilafs, 0, rv, 0, ilafs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return rv;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * Sets the set of available look and feels. While this method does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * not check to ensure all of the {@code LookAndFeelInfos} are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * {@code non-null}, it is strongly recommended that only {@code non-null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * values are supplied in the {@code infos} array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @param infos set of <code>LookAndFeelInfo</code> objects specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *        the available look and feels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @see #getInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @throws NullPointerException if {@code infos} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public static void setInstalledLookAndFeels(LookAndFeelInfo[] infos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    {
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   447
        maybeInitialize();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        LookAndFeelInfo[] newInfos = new LookAndFeelInfo[infos.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        System.arraycopy(infos, 0, newInfos, 0, infos.length);
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
   450
        getLAFState().installedLAFs = newInfos;
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Adds the specified look and feel to the set of available look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * and feels. While this method allows a {@code null} {@code info},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * it is strongly recommended that a {@code non-null} value be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @param info a <code>LookAndFeelInfo</code> object that names the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *          look and feel and identifies the class that implements it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @see #setInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    public static void installLookAndFeel(LookAndFeelInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        LookAndFeelInfo[] infos = getInstalledLookAndFeels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        LookAndFeelInfo[] newInfos = new LookAndFeelInfo[infos.length + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        System.arraycopy(infos, 0, newInfos, 0, infos.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        newInfos[infos.length] = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        setInstalledLookAndFeels(newInfos);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * Adds the specified look and feel to the set of available look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * and feels. While this method does not check the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * arguments in any way, it is strongly recommended that {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * non-null} values be supplied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @param name descriptive name of the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @param className name of the class that implements the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @see #setInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public static void installLookAndFeel(String name, String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        installLookAndFeel(new LookAndFeelInfo(name, className));
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * Returns the current look and feel or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @return current look and feel, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    public static LookAndFeel getLookAndFeel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        maybeInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        return getLAFState().lookAndFeel;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Sets the current look and feel to {@code newLookAndFeel}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * If the current look and feel is {@code non-null} {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * uninitialize} is invoked on it. If {@code newLookAndFeel} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * {@code non-null}, {@code initialize} is invoked on it followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * by {@code getDefaults}. The defaults returned from {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * newLookAndFeel.getDefaults()} replace those of the defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * from the previous look and feel. If the {@code newLookAndFeel} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * {@code null}, the look and feel defaults are set to {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * A value of {@code null} can be used to set the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * to {@code null}. As the {@code LookAndFeel} is required for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * most of Swing to function, setting the {@code LookAndFeel} to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * {@code null} is strongly discouraged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * This is a JavaBeans bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @param newLookAndFeel {@code LookAndFeel} to install
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @throws UnsupportedLookAndFeelException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *          {@code newLookAndFeel} is {@code non-null} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *          {@code newLookAndFeel.isSupportedLookAndFeel()} returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *          {@code false}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @see #getLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public static void setLookAndFeel(LookAndFeel newLookAndFeel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        throws UnsupportedLookAndFeelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        if ((newLookAndFeel != null) && !newLookAndFeel.isSupportedLookAndFeel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            String s = newLookAndFeel.toString() + " not supported on this platform";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            throw new UnsupportedLookAndFeelException(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        LAFState lafState = getLAFState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        LookAndFeel oldLookAndFeel = lafState.lookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        if (oldLookAndFeel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            oldLookAndFeel.uninitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        lafState.lookAndFeel = newLookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        if (newLookAndFeel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            sun.swing.DefaultLookup.setDefaultLookup(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            newLookAndFeel.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            lafState.setLookAndFeelDefaults(newLookAndFeel.getDefaults());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            lafState.setLookAndFeelDefaults(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        SwingPropertyChangeSupport changeSupport = lafState.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                         getPropertyChangeSupport(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            changeSupport.firePropertyChange("lookAndFeel", oldLookAndFeel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                                             newLookAndFeel);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * Loads the {@code LookAndFeel} specified by the given class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * name, using the current thread's context class loader, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * passes it to {@code setLookAndFeel(LookAndFeel)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @param className  a string specifying the name of the class that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *        the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @exception ClassNotFoundException if the <code>LookAndFeel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *           class could not be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @exception InstantiationException if a new instance of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *          couldn't be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @exception IllegalAccessException if the class or initializer isn't accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @exception UnsupportedLookAndFeelException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *          <code>lnf.isSupportedLookAndFeel()</code> is false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @throws ClassCastException if {@code className} does not identify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *         a class that extends {@code LookAndFeel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public static void setLookAndFeel(String className)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        throws ClassNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
               InstantiationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
               IllegalAccessException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
               UnsupportedLookAndFeelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        if ("javax.swing.plaf.metal.MetalLookAndFeel".equals(className)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            // Avoid reflection for the common case of metal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        else {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   584
            Class<?> lnfClass = SwingUtilities.loadSystemClass(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            setLookAndFeel((LookAndFeel)(lnfClass.newInstance()));
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * Returns the name of the <code>LookAndFeel</code> class that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * the native system look and feel if there is one, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * the name of the default cross platform <code>LookAndFeel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * class. This value can be overriden by setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <code>swing.systemlaf</code> system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @return the <code>String</code> of the <code>LookAndFeel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *          class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @see #getCrossPlatformLookAndFeelClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public static String getSystemLookAndFeelClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        String systemLAF = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                             new GetPropertyAction("swing.systemlaf"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        if (systemLAF != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            return systemLAF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        OSInfo.OSType osType = AccessController.doPrivileged(OSInfo.getOSTypeAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (osType == OSInfo.OSType.WINDOWS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            String desktop = AccessController.doPrivileged(new GetPropertyAction("sun.desktop"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            Toolkit toolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if ("gnome".equals(desktop) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    toolkit instanceof SunToolkit &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    ((SunToolkit) toolkit).isNativeGTKAvailable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                // May be set on Linux and Solaris boxs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                return "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   620
            if (osType == OSInfo.OSType.MACOSX) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   621
                if (toolkit.getClass() .getName()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   622
                                       .equals("sun.lwawt.macosx.LWCToolkit")) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   623
                    return "com.apple.laf.AquaLookAndFeel";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   624
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   625
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            if (osType == OSInfo.OSType.SOLARIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                return "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        return getCrossPlatformLookAndFeelClassName();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Returns the name of the <code>LookAndFeel</code> class that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * the default cross platform look and feel -- the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * Look and Feel (JLF).  This value can be overriden by setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * <code>swing.crossplatformlaf</code> system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @return  a string with the JLF implementation-class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @see #getSystemLookAndFeelClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    public static String getCrossPlatformLookAndFeelClassName() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   645
        String laf = AccessController.doPrivileged(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                             new GetPropertyAction("swing.crossplatformlaf"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        if (laf != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            return laf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        return "javax.swing.plaf.metal.MetalLookAndFeel";
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * Returns the defaults. The returned defaults resolve using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * logic specified in the class documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * @return a <code>UIDefaults</code> object containing the default values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    public static UIDefaults getDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        maybeInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        return getLAFState().multiUIDefaults;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * Returns a font from the defaults. If the value for {@code key} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * not a {@code Font}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * @param key  an <code>Object</code> specifying the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @return the <code>Font</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    public static Font getFont(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        return getDefaults().getFont(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Returns a font from the defaults that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * for the given locale. If the value for {@code key} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * not a {@code Font}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @param key  an <code>Object</code> specifying the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @param l the <code>Locale</code> for which the font is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @return the <code>Font</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    public static Font getFont(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        return getDefaults().getFont(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * Returns a color from the defaults. If the value for {@code key} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * not a {@code Color}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @param key  an <code>Object</code> specifying the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @return the <code>Color</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    public static Color getColor(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        return getDefaults().getColor(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * Returns a color from the defaults that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * for the given locale. If the value for {@code key} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * not a {@code Color}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @param key  an <code>Object</code> specifying the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @param l the <code>Locale</code> for which the color is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * @return the <code>Color</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    public static Color getColor(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        return getDefaults().getColor(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * Returns an <code>Icon</code> from the defaults. If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * {@code key} is not an {@code Icon}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @param key  an <code>Object</code> specifying the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * @return the <code>Icon</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    public static Icon getIcon(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        return getDefaults().getIcon(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * Returns an <code>Icon</code> from the defaults that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * for the given locale. If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * {@code key} is not an {@code Icon}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @param key  an <code>Object</code> specifying the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * @param l the <code>Locale</code> for which the icon is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @return the <code>Icon</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    public static Icon getIcon(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        return getDefaults().getIcon(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * Returns a border from the defaults. If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * {@code key} is not a {@code Border}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * @param key  an <code>Object</code> specifying the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * @return the <code>Border</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    public static Border getBorder(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        return getDefaults().getBorder(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * Returns a border from the defaults that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * for the given locale.  If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * {@code key} is not a {@code Border}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @param key  an <code>Object</code> specifying the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * @param l the <code>Locale</code> for which the border is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * @return the <code>Border</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    public static Border getBorder(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        return getDefaults().getBorder(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * Returns a string from the defaults. If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * {@code key} is not a {@code String}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * @param key  an <code>Object</code> specifying the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * @return the <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    public static String getString(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        return getDefaults().getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * Returns a string from the defaults that is appropriate for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * given locale.  If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * {@code key} is not a {@code String}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @param key  an <code>Object</code> specifying the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * @param l the <code>Locale</code> for which the string is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @return the <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    public static String getString(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        return getDefaults().getString(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * Returns a string from the defaults that is appropriate for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * given locale.  If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * {@code key} is not a {@code String}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @param key  an <code>Object</code> specifying the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @param c {@code Component} used to determine the locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *          {@code null} implies the default locale as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     *          returned by {@code Locale.getDefault()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * @return the <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    static String getString(Object key, Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        Locale l = (c == null) ? Locale.getDefault() : c.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        return getString(key, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * Returns an integer from the defaults. If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * {@code key} is not an {@code Integer}, or does not exist,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * {@code 0} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @param key  an <code>Object</code> specifying the int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * @return the int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    public static int getInt(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        return getDefaults().getInt(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * Returns an integer from the defaults that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * for the given locale. If the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * {@code key} is not an {@code Integer}, or does not exist,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * {@code 0} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * @param key  an <code>Object</code> specifying the int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @param l the <code>Locale</code> for which the int is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * @return the int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    public static int getInt(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        return getDefaults().getInt(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * Returns a boolean from the defaults which is associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * the key value. If the key is not found or the key doesn't represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * a boolean value then {@code false} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * @param key  an <code>Object</code> specifying the key for the desired boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * @return the boolean value corresponding to the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    public static boolean getBoolean(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        return getDefaults().getBoolean(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * Returns a boolean from the defaults which is associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * the key value and the given <code>Locale</code>. If the key is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * found or the key doesn't represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * a boolean value then {@code false} will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * @param key  an <code>Object</code> specifying the key for the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     *             boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @param l the <code>Locale</code> for which the boolean is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @return the boolean value corresponding to the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    public static boolean getBoolean(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        return getDefaults().getBoolean(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * Returns an <code>Insets</code> object from the defaults. If the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * for {@code key} is not an {@code Insets}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * @param key  an <code>Object</code> specifying the <code>Insets</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * @return the <code>Insets</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    public static Insets getInsets(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        return getDefaults().getInsets(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * Returns an <code>Insets</code> object from the defaults that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * appropriate for the given locale. If the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * for {@code key} is not an {@code Insets}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * @param key  an <code>Object</code> specifying the <code>Insets</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * @param l the <code>Locale</code> for which the object is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * @return the <code>Insets</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    public static Insets getInsets(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        return getDefaults().getInsets(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * Returns a dimension from the defaults. If the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * for {@code key} is not a {@code Dimension}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * @param key  an <code>Object</code> specifying the dimension object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * @return the <code>Dimension</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    public static Dimension getDimension(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        return getDefaults().getDimension(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * Returns a dimension from the defaults that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * for the given locale. If the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * for {@code key} is not a {@code Dimension}, {@code null} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * @param key  an <code>Object</code> specifying the dimension object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * @param l the <code>Locale</code> for which the object is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * @return the <code>Dimension</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    public static Dimension getDimension(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        return getDefaults().getDimension(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * Returns an object from the defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * @param key  an <code>Object</code> specifying the desired object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * @return the <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    public static Object get(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        return getDefaults().get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * Returns an object from the defaults that is appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @param key  an <code>Object</code> specifying the desired object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * @param l the <code>Locale</code> for which the object is desired; refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     *        to {@code UIDefaults} for details on how a {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     *        {@code Locale} is handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * @return the <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    public static Object get(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        return getDefaults().get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * Stores an object in the developer defaults. This is a cover method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * for {@code getDefaults().put(key, value)}. This only effects the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * developer defaults, not the system or look and feel defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * @param key    an <code>Object</code> specifying the retrieval key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * @param value  the <code>Object</code> to store; refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     *               {@code UIDefaults} for details on how {@code null} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     *               handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * @return the <code>Object</code> returned by {@link UIDefaults#put}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * @throws NullPointerException if {@code key} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * @see UIDefaults#put
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    public static Object put(Object key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        return getDefaults().put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * Returns the appropriate {@code ComponentUI} implementation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * {@code target}. Typically, this is a cover for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * {@code getDefaults().getUI(target)}. However, if an auxiliary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * look and feel has been installed, this first invokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * {@code getUI(target)} on the multiplexing look and feel's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * defaults, and returns that value if it is {@code non-null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * @param target the <code>JComponent</code> to return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     *        {@code ComponentUI} for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * @return the <code>ComponentUI</code> object for {@code target}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * @throws NullPointerException if {@code target} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    public static ComponentUI getUI(JComponent target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        maybeInitialize();
12661
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1009
        maybeInitializeFocusPolicy(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        ComponentUI ui = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        LookAndFeel multiLAF = getLAFState().multiLookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        if (multiLAF != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            // This can return null if the multiplexing look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            // doesn't support a particular UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            ui = multiLAF.getDefaults().getUI(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        if (ui == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            ui = getDefaults().getUI(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        return ui;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * Returns the {@code UIDefaults} from the current look and feel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * that were obtained at the time the look and feel was installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * In general, developers should use the {@code UIDefaults} returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * {@code getDefaults()}. As the current look and feel may expect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * certain values to exist, altering the {@code UIDefaults} returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * from this method could have unexpected results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * @return <code>UIDefaults</code> from the current look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * @see #getDefaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * @see #setLookAndFeel(LookAndFeel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * @see LookAndFeel#getDefaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    public static UIDefaults getLookAndFeelDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        maybeInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        return getLAFState().getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * Finds the Multiplexing <code>LookAndFeel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    private static LookAndFeel getMultiLookAndFeel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        LookAndFeel multiLookAndFeel = getLAFState().multiLookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        if (multiLookAndFeel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            String defaultName = "javax.swing.plaf.multi.MultiLookAndFeel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            String className = getLAFState().swingProps.getProperty(multiplexingLAFKey, defaultName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            try {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  1052
                Class<?> lnfClass = SwingUtilities.loadSystemClass(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                multiLookAndFeel = (LookAndFeel)lnfClass.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                System.err.println("UIManager: failed loading " + className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        return multiLookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * Adds a <code>LookAndFeel</code> to the list of auxiliary look and feels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * The auxiliary look and feels tell the multiplexing look and feel what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * other <code>LookAndFeel</code> classes for a component instance are to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * in addition to the default <code>LookAndFeel</code> class when creating a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * multiplexing UI.  The change will only take effect when a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * UI class is created or when the default look and feel is changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * on a component instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * <p>Note these are not the same as the installed look and feels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * @param laf the <code>LookAndFeel</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * @see #removeAuxiliaryLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * @see #getAuxiliaryLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * @see #getInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    static public void addAuxiliaryLookAndFeel(LookAndFeel laf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        maybeInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        if (!laf.isSupportedLookAndFeel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            // Ideally we would throw an exception here, but it's too late
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            // for that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1085
        Vector<LookAndFeel> v = getLAFState().auxLookAndFeels;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        if (v == null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1087
            v = new Vector<LookAndFeel>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        if (!v.contains(laf)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            v.addElement(laf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            laf.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            getLAFState().auxLookAndFeels = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            if (getLAFState().multiLookAndFeel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                getLAFState().multiLookAndFeel = getMultiLookAndFeel();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * Removes a <code>LookAndFeel</code> from the list of auxiliary look and feels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * The auxiliary look and feels tell the multiplexing look and feel what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * other <code>LookAndFeel</code> classes for a component instance are to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * in addition to the default <code>LookAndFeel</code> class when creating a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * multiplexing UI.  The change will only take effect when a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * UI class is created or when the default look and feel is changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * on a component instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * <p>Note these are not the same as the installed look and feels.
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1110
     *
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1111
     * @param laf the {@code LookAndFeel} to be removed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * @return true if the <code>LookAndFeel</code> was removed from the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * @see #removeAuxiliaryLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * @see #getAuxiliaryLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * @see #getInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    static public boolean removeAuxiliaryLookAndFeel(LookAndFeel laf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        maybeInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        boolean result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1123
        Vector<LookAndFeel> v = getLAFState().auxLookAndFeels;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        if ((v == null) || (v.size() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        result = v.removeElement(laf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        if (result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            if (v.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                getLAFState().auxLookAndFeels = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                getLAFState().multiLookAndFeel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                getLAFState().auxLookAndFeels = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        laf.uninitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * Returns the list of auxiliary look and feels (can be <code>null</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * The auxiliary look and feels tell the multiplexing look and feel what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * other <code>LookAndFeel</code> classes for a component instance are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * to be used in addition to the default LookAndFeel class when creating a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * multiplexing UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * <p>Note these are not the same as the installed look and feels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * @return list of auxiliary <code>LookAndFeel</code>s or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * @see #addAuxiliaryLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * @see #removeAuxiliaryLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * @see #setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * @see #getInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    static public LookAndFeel[] getAuxiliaryLookAndFeels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        maybeInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1159
        Vector<LookAndFeel> v = getLAFState().auxLookAndFeels;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        if ((v == null) || (v.size() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            LookAndFeel[] rv = new LookAndFeel[v.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            for (int i = 0; i < rv.length; i++) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1166
                rv[i] = v.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * Adds a <code>PropertyChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * @param listener  the <code>PropertyChangeListener</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * @see java.beans.PropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    public static void addPropertyChangeListener(PropertyChangeListener listener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        synchronized (classLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            getLAFState().getPropertyChangeSupport(true).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                             addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * Removes a <code>PropertyChangeListener</code> from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * This removes a <code>PropertyChangeListener</code> that was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * @param listener  the <code>PropertyChangeListener</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * @see java.beans.PropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    public static void removePropertyChangeListener(PropertyChangeListener listener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        synchronized (classLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            getLAFState().getPropertyChangeSupport(true).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                          removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * Returns an array of all the <code>PropertyChangeListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * to this UIManager with addPropertyChangeListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * @return all of the <code>PropertyChangeListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
    public static PropertyChangeListener[] getPropertyChangeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        synchronized(classLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            return getLAFState().getPropertyChangeSupport(true).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                      getPropertyChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    private static Properties loadSwingProperties()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        /* Don't bother checking for Swing properties if untrusted, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
         * there's no way to look them up without triggering SecurityExceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        if (UIManager.class.getClassLoader() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            return new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            final Properties props = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            java.security.AccessController.doPrivileged(
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1233
                new java.security.PrivilegedAction<Object>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                public Object run() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
  1235
                    OSInfo.OSType osType = AccessController.doPrivileged(OSInfo.getOSTypeAction());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
  1236
                    if (osType == OSInfo.OSType.MACOSX) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
  1237
                        props.put(defaultLAFKey, getSystemLookAndFeelClassName());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
  1238
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
  1239
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                        File file = new File(makeSwingPropertiesFilename());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                        if (file.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                            // InputStream has been buffered in Properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                            // class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                            FileInputStream ins = new FileInputStream(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                            props.load(ins);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                            ins.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                    catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                        // No such file, or file is otherwise non-readable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                    // Check whether any properties were overridden at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                    // command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                    checkProperty(props, defaultLAFKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                    checkProperty(props, auxiliaryLAFsKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                    checkProperty(props, multiplexingLAFKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                    checkProperty(props, installedLAFsKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                    checkProperty(props, disableMnemonicKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                    // Don't care about return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            return props;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    private static void checkProperty(Properties props, String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        // No need to do catch the SecurityException here, this runs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        // in a doPrivileged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        String value = System.getProperty(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            props.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    /**
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 12661
diff changeset
  1281
     * 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
  1282
     * <code>swing.installedlafs</code> property
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     * then initialize the <code>installedLAFs</code> field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * @see #getInstalledLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    private static void initializeInstalledLAFs(Properties swingProps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        String ilafsString = swingProps.getProperty(installedLAFsKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        if (ilafsString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        /* Create a vector that contains the value of the swing.installedlafs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
         * property.  For example given "swing.installedlafs=motif,windows"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
         * lafs = {"motif", "windows"}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
         */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1298
        Vector<String> lafs = new Vector<String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        StringTokenizer st = new StringTokenizer(ilafsString, ",", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        while (st.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            lafs.addElement(st.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        /* Look up the name and class for each name in the "swing.installedlafs"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
         * list.  If they both exist then add a LookAndFeelInfo to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
         * the installedLafs array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
         */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1308
        Vector<LookAndFeelInfo> ilafs = new Vector<LookAndFeelInfo>(lafs.size());
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1309
        for (String laf : lafs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            String name = swingProps.getProperty(makeInstalledLAFKey(laf, "name"), laf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            String cls = swingProps.getProperty(makeInstalledLAFKey(laf, "class"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            if (cls != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                ilafs.addElement(new LookAndFeelInfo(name, cls));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
  1317
        LookAndFeelInfo[] installedLAFs = new LookAndFeelInfo[ilafs.size()];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        for(int i = 0; i < ilafs.size(); i++) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1319
            installedLAFs[i] = ilafs.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        }
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 3084
diff changeset
  1321
        getLAFState().installedLAFs = installedLAFs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * If the user has specified a default look and feel, use that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     * Otherwise use the look and feel that's native to this platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * If this code is called after the application has explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * set it's look and feel, do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     * @see #maybeInitialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    private static void initializeDefaultLAF(Properties swingProps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        if (getLAFState().lookAndFeel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
2492
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1339
        // 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
  1340
        // (6653395), then use cross-platform one by default.
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1341
        String lafName = null;
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  1342
        @SuppressWarnings("unchecked")
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  1343
        HashMap<Object, String> lafData =
2492
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1344
                (HashMap) AppContext.getAppContext().remove("swing.lafdata");
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1345
        if (lafData != null) {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  1346
            lafName = lafData.remove("defaultlaf");
2492
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1347
        }
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1348
        if (lafName == null) {
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1349
            lafName = getCrossPlatformLookAndFeelClassName();
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1350
        }
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1351
        lafName = swingProps.getProperty(defaultLAFKey, lafName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        try {
2492
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1354
            setLookAndFeel(lafName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        } catch (Exception e) {
2492
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1356
            throw new Error("Cannot load " + lafName);
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1357
        }
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1358
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1359
        // Set any properties passed through AppContext (6653395).
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1360
        if (lafData != null) {
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1361
            for (Object key: lafData.keySet()) {
0ea97f5e5746 6653395: Default LAF is set to CrossPlatformLookAndFeel not SystemLookAndFeel
peterz
parents: 1639
diff changeset
  1362
                UIManager.put(key, lafData.get(key));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    private static void initializeAuxiliaryLAFs(Properties swingProps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        String auxLookAndFeelNames = swingProps.getProperty(auxiliaryLAFsKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        if (auxLookAndFeelNames == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1375
        Vector<LookAndFeel> auxLookAndFeels = new Vector<LookAndFeel>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        StringTokenizer p = new StringTokenizer(auxLookAndFeelNames,",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        String factoryName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        /* Try to load each LookAndFeel subclass in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        while (p.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
            String className = p.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            try {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  1386
                Class<?> lnfClass = SwingUtilities.loadSystemClass(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                LookAndFeel newLAF = (LookAndFeel)lnfClass.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                newLAF.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                auxLookAndFeels.addElement(newLAF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                System.err.println("UIManager: failed loading auxiliary look and feel " + className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        /* If there were problems and no auxiliary look and feels were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
         * loaded, make sure we reset auxLookAndFeels to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
         * Otherwise, we are going to use the MultiLookAndFeel to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
         * all component UI's, so we need to load it now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        if (auxLookAndFeels.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
            auxLookAndFeels = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            getLAFState().multiLookAndFeel = getMultiLookAndFeel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            if (getLAFState().multiLookAndFeel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                auxLookAndFeels = null;
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
        getLAFState().auxLookAndFeels = auxLookAndFeels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
    private static void initializeSystemDefaults(Properties swingProps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        getLAFState().swingProps = swingProps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * This method is called before any code that depends on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * <code>AppContext</code> specific LAFState object runs.  When the AppContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * corresponds to a set of applets it's possible for this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * to be re-entered, which is why we grab a lock before calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * initialize().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    private static void maybeInitialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        synchronized (classLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            if (!getLAFState().initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                getLAFState().initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
12661
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1436
    /*
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1437
     * 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
  1438
     */
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1439
    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
  1440
        // 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
  1441
        // 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
  1442
        // should be instatiated. See 7125044.
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1443
        if (comp instanceof JRootPane) {
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1444
            synchronized (classLock) {
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1445
                if (!getLAFState().focusPolicyInitialized) {
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1446
                    getLAFState().focusPolicyInitialized = true;
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1447
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1448
                    if (FocusManager.isFocusManagerEnabled()) {
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1449
                        KeyboardFocusManager.getCurrentKeyboardFocusManager().
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1450
                            setDefaultFocusTraversalPolicy(
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1451
                                new LayoutFocusTraversalPolicy());
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1452
                    }
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1453
                }
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1454
            }
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1455
        }
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12047
diff changeset
  1456
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     * Only called by maybeInitialize().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
    private static void initialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        Properties swingProps = loadSwingProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        initializeSystemDefaults(swingProps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        initializeDefaultLAF(swingProps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        initializeAuxiliaryLAFs(swingProps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        initializeInstalledLAFs(swingProps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        // Install Swing's PaintEventDispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            sun.awt.PaintEventDispatcher.setPaintEventDispatcher(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                                        new SwingPaintEventDispatcher());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        // Install a hook that will be invoked if no one consumes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        // KeyEvent.  If the source isn't a JComponent this will process
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        // key bindings, if the source is a JComponent it implies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        // processKeyEvent was already invoked and thus no need to process
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        // the bindings again, unless the Component is disabled, in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        // case KeyEvents will no longer be dispatched to it so that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        // handle it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                addKeyEventPostProcessor(new KeyEventPostProcessor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                    public boolean postProcessKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                        Component c = e.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                        if ((!(c instanceof JComponent) ||
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1486
                             (c != null && !c.isEnabled())) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                                JComponent.KeyboardState.shouldProcess(e) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                                SwingUtilities.processKeyBindings(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                });
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2658
diff changeset
  1495
        AWTAccessor.getComponentAccessor().
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2658
diff changeset
  1496
            setRequestFocusController(JComponent.focusController);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
}