jdk/src/share/classes/javax/swing/LookAndFeel.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8380 9b9f901a909d
child 20451 4cedf4e1560a
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8380
diff changeset
     2
 * Copyright (c) 1997, 2011, 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: 3084
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: 3084
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: 3084
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3084
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3084
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.InputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.SystemColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Toolkit;
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2
diff changeset
    35
import sun.awt.SunToolkit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.swing.DefaultLayoutStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.swing.ImageIconUIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * {@code LookAndFeel}, as the name implies, encapsulates a look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * feel. Beyond installing a look and feel most developers never need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * interact directly with {@code LookAndFeel}. In general only developers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * creating a custom look and feel need to concern themselves with this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Swing is built upon the foundation that each {@code JComponent}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * subclass has an implementation of a specific {@code ComponentUI}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * subclass. The {@code ComponentUI} is often referred to as "the ui",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * "component ui", or "look and feel delegate". The {@code ComponentUI}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * subclass is responsible for providing the look and feel specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * functionality of the component. For example, {@code JTree} requires
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * an implementation of the {@code ComponentUI} subclass {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * TreeUI}. The implementation of the specific {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * ComponentUI} subclass is provided by the {@code LookAndFeel}. Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * {@code JComponent} subclass identifies the {@code ComponentUI}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * subclass it requires by way of the {@code JComponent} method {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * getUIClassID}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Each {@code LookAndFeel} implementation must provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * an implementation of the appropriate {@code ComponentUI} subclass by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * specifying a value for each of Swing's ui class ids in the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * UIDefaults} object returned from {@code getDefaults}. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * {@code BasicLookAndFeel} uses {@code BasicTreeUI} as the concrete
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * implementation for {@code TreeUI}. This is accomplished by {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * BasicLookAndFeel} providing the key-value pair {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * "TreeUI"-"javax.swing.plaf.basic.BasicTreeUI"}, in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * {@code UIDefaults} returned from {@code getDefaults}. Refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * {@link UIDefaults#getUI(JComponent)} for defails on how the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * of the {@code ComponentUI} subclass is obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * When a {@code LookAndFeel} is installed the {@code UIManager} does
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * not check that an entry exists for all ui class ids. As such,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * random exceptions will occur if the current look and feel has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * provided a value for a particular ui class id and an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * the {@code JComponent} subclass is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <h2>Recommendations for Look and Feels</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * As noted in {@code UIManager} each {@code LookAndFeel} has the opportunity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * to provide a set of defaults that are layered in with developer and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * system defaults. Some of Swing's components require the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * to provide a specific set of defaults. These are documented in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * classes that require the specific default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <h3><a name="#defaultRecommendation">ComponentUIs and defaults</a></h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * All {@code ComponentUIs} typically need to set various properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * on the {@code JComponent} the {@code ComponentUI} is providing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * look and feel for. This is typically done when the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * ComponentUI} is installed on the {@code JComponent}. Setting a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * property should only be done if the developer has not set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * property. For non-primitive values it is recommended that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * {@code ComponentUI} only change the property on the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * JComponent} if the current value is {@code null} or implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * {@code UIResource}. If the current value is {@code null} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * implements {@code UIResource} it indicates the property has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * been set by the developer, and the ui is free to change it.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * example, {@code BasicButtonUI.installDefaults} only changes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * font on the {@code JButton} if the return value from {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * button.getFont()} is {@code null} or implements {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * UIResource}. On the other hand if {@code button.getFont()} returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * a {@code non-null} value that did not implement {@code UIResource}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * then {@code BasicButtonUI.installDefaults} would not change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * {@code JButton}'s font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * For primitive values, such as {@code opaque}, the method {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * installProperty} should be invoked.  {@code installProperty} only changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * the correspoding property if the value has not been changed by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * developer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * {@code ComponentUI} implementations should use the various install methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * provided by this class as they handle the necessary checking and install
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * the property using the recommended guidelines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <h3><a name="exceptions"></a>Exceptions</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * All of the install methods provided by {@code LookAndFeel} need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * access the defaults if the value of the property being changed is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * {@code null} or a {@code UIResource}. For example, installing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * font does the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *   JComponent c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *   Font font = c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *   if (font == null || (font instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *       c.setFont(UIManager.getFont("fontKey"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * If the font is {@code null} or a {@code UIResource}, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * defaults table is queried with the key {@code fontKey}. All of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * {@code UIDefault's} get methods throw a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * NullPointerException} if passed in {@code null}. As such, unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * otherwise noted each of the various install methods of {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * LookAndFeel} throw a {@code NullPointerException} if the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * value is {@code null} or a {@code UIResource} and the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * defaults key is {@code null}. In addition, unless otherwise specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * all of the {@code install} methods throw a {@code NullPointerException} if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * a {@code null} component is passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * @author Tom Ball
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
public abstract class LookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Convenience method for setting a component's foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * and background color properties with values from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * defaults.  The properties are only set if the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * value is either {@code null} or a {@code UIResource}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param c component to set the colors on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param defaultBgName key for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param defaultFgName key for the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @see #installColorsAndFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @see UIManager#getColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @throws NullPointerException as described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *         <a href="#exceptions">exceptions</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public static void installColors(JComponent c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                     String defaultBgName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                     String defaultFgName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        Color bg = c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (bg == null || bg instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            c.setBackground(UIManager.getColor(defaultBgName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        Color fg = c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (fg == null || fg instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            c.setForeground(UIManager.getColor(defaultFgName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Convenience method for setting a component's foreground,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * background and font properties with values from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * defaults.  The properties are only set if the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * value is either {@code null} or a {@code UIResource}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param c component set to the colors and font on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param defaultBgName key for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param defaultFgName key for the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @param defaultFontName key for the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @throws NullPointerException as described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *         <a href="#exceptions">exceptions</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @see #installColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @see UIManager#getColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @see UIManager#getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public static void installColorsAndFont(JComponent c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                         String defaultBgName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                         String defaultFgName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                                         String defaultFontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        Font f = c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (f == null || f instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            c.setFont(UIManager.getFont(defaultFontName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        installColors(c, defaultBgName, defaultFgName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Convenience method for setting a component's border property with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * a value from the defaults. The border is only set if the border is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * {@code null} or an instance of {@code UIResource}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param c component to set the border on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param defaultBorderName key specifying the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @throws NullPointerException as described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *         <a href="#exceptions">exceptions</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public static void installBorder(JComponent c, String defaultBorderName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        Border b = c.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (b == null || b instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            c.setBorder(UIManager.getBorder(defaultBorderName));
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Convenience method for uninstalling a border. If the border of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * the component is a {@code UIResource}, it is set to {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @param c component to uninstall the border on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @throws NullPointerException if {@code c} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public static void uninstallBorder(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (c.getBorder() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            c.setBorder(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Convenience method for installing a property with the specified name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * and value on a component if that property has not already been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * by the developer.  This method is intended to be used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * ui delegate instances that need to specify a default value for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * property of primitive type (boolean, int, ..), but do not wish
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * to override a value set by the client.  Since primitive property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * values cannot be wrapped with the {@code UIResource} marker, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * uses private state to determine whether the property has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * by the client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @throws IllegalArgumentException if the specified property is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *         one which can be set using this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @throws ClassCastException if the property value has not been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *         by the developer and the type does not match the property's type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @throws NullPointerException if {@code c} is {@code null}, or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *         named property has not been set by the developer and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *         {@code propertyValue} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param c target component to set the property on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param propertyName name of the property to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param propertyValue value of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public static void installProperty(JComponent c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                       String propertyName, Object propertyValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        // this is a special case because the JPasswordField's ancestor heirarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        // includes a class outside of javax.swing, thus we cannot call setUIProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        // directly.
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2
diff changeset
   275
        if (SunToolkit.isInstanceOf(c, "javax.swing.JPasswordField")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            if (!((JPasswordField)c).customSetUIProperty(propertyName, propertyValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                c.setUIProperty(propertyName, propertyValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            c.setUIProperty(propertyName, propertyValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Convenience method for building an array of {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * KeyBindings}. While this method is not deprecated, developers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * should instead use {@code ActionMap} and {@code InputMap} for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * supplying key bindings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * This method returns an array of {@code KeyBindings}, one for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * alternating {@code key-action} pair in {@code keyBindingList}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * A {@code key} can either be a {@code String} in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * specified by the <code>KeyStroke.getKeyStroke</code> method, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * a {@code KeyStroke}. The {@code action} part of the pair is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * {@code String} that corresponds to the name of the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Action}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * The following example illustrates creating a {@code KeyBinding} array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * from six alternating {@code key-action} pairs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *  JTextComponent.KeyBinding[] multilineBindings = makeKeyBindings( new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *          "UP", DefaultEditorKit.upAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *        "DOWN", DefaultEditorKit.downAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *     "PAGE_UP", DefaultEditorKit.pageUpAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *   "PAGE_DOWN", DefaultEditorKit.pageDownAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *       "ENTER", DefaultEditorKit.insertBreakAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *         "TAB", DefaultEditorKit.insertTabAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *  });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * If {@code keyBindingList's} length is odd, the last element is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Supplying a {@code null} value for either the {@code key} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * {@code action} part of the {@code key-action} pair results in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * creating a {@code KeyBinding} with the corresponding value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * {@code null}. As other parts of Swing's expect {@code non-null} values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * in a {@code KeyBinding}, you should avoid supplying {@code null} as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * either the {@code key} or {@code action} part of the {@code key-action}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * pair.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @param keyBindingList an array of {@code key-action} pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @return an array of {@code KeyBindings}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @throws NullPointerException if {@code keyBindingList} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @throws ClassCastException if the {@code key} part of the pair is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *         not a {@code KeyStroke} or {@code String}, or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *         {@code action} part of the pair is not a {@code String}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @see ActionMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @see InputMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @see KeyStroke#getKeyStroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public static JTextComponent.KeyBinding[] makeKeyBindings(Object[] keyBindingList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        JTextComponent.KeyBinding[] rv = new JTextComponent.KeyBinding[keyBindingList.length / 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
8380
9b9f901a909d 6474153: LookAndFeel.makeKeyBindings(...) doesn't ignore last element in keyBindingList with odd size
alexp
parents: 5506
diff changeset
   335
        for(int i = 0; i < rv.length; i ++) {
9b9f901a909d 6474153: LookAndFeel.makeKeyBindings(...) doesn't ignore last element in keyBindingList with odd size
alexp
parents: 5506
diff changeset
   336
            Object o = keyBindingList[2 * i];
9b9f901a909d 6474153: LookAndFeel.makeKeyBindings(...) doesn't ignore last element in keyBindingList with odd size
alexp
parents: 5506
diff changeset
   337
            KeyStroke keystroke = (o instanceof KeyStroke)
9b9f901a909d 6474153: LookAndFeel.makeKeyBindings(...) doesn't ignore last element in keyBindingList with odd size
alexp
parents: 5506
diff changeset
   338
                ? (KeyStroke) o
9b9f901a909d 6474153: LookAndFeel.makeKeyBindings(...) doesn't ignore last element in keyBindingList with odd size
alexp
parents: 5506
diff changeset
   339
                : KeyStroke.getKeyStroke((String) o);
9b9f901a909d 6474153: LookAndFeel.makeKeyBindings(...) doesn't ignore last element in keyBindingList with odd size
alexp
parents: 5506
diff changeset
   340
            String action = (String) keyBindingList[2 * i + 1];
9b9f901a909d 6474153: LookAndFeel.makeKeyBindings(...) doesn't ignore last element in keyBindingList with odd size
alexp
parents: 5506
diff changeset
   341
            rv[i] = new JTextComponent.KeyBinding(keystroke, action);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Creates a {@code InputMapUIResource} from <code>keys</code>. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * a convenience method for creating a new {@code InputMapUIResource},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * invoking {@code loadKeyBindings(map, keys)}, and returning the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * {@code InputMapUIResource}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @param keys alternating pairs of {@code keystroke-action key}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *        pairs as described in {@link #loadKeyBindings}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @return newly created and populated {@code InputMapUIResource}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @see #loadKeyBindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    public static InputMap makeInputMap(Object[] keys) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        InputMap retMap = new InputMapUIResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        loadKeyBindings(retMap, keys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        return retMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * Creates a {@code ComponentInputMapUIResource} from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * <code>keys</code>. This is a convenience method for creating a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * new {@code ComponentInputMapUIResource}, invoking {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * loadKeyBindings(map, keys)}, and returning the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * ComponentInputMapUIResource}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @param c component to create the {@code ComponentInputMapUIResource}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *          with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @param keys alternating pairs of {@code keystroke-action key}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *        pairs as described in {@link #loadKeyBindings}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @return newly created and populated {@code InputMapUIResource}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @throws IllegalArgumentException if {@code c} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @see #loadKeyBindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @see ComponentInputMapUIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public static ComponentInputMap makeComponentInputMap(JComponent c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                                                          Object[] keys) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        ComponentInputMap retMap = new ComponentInputMapUIResource(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        loadKeyBindings(retMap, keys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return retMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * Populates an {@code InputMap} with the specified bindings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * The bindings are supplied as a list of alternating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * {@code keystroke-action key} pairs. The {@code keystroke} is either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * an instance of {@code KeyStroke}, or a {@code String}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * that identifies the {@code KeyStroke} for the binding. Refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * to {@code KeyStroke.getKeyStroke(String)} for the specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * format. The {@code action key} part of the pair is the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * registered in the {@code InputMap} for the {@code KeyStroke}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * The following illustrates loading an {@code InputMap} with two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * {@code key-action} pairs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *   LookAndFeel.loadKeyBindings(inputMap, new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *     "control X", "cut",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *     "control V", "paste"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *   });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * Supplying a {@code null} list of bindings ({@code keys}) does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * change {@code retMap} in any way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * Specifying a {@code null} {@code action key} results in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * removing the {@code keystroke's} entry from the {@code InputMap}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * A {@code null} {@code keystroke} is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @param retMap {@code InputMap} to add the {@code key-action}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *               pairs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @param keys bindings to add to {@code retMap}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @throws NullPointerException if {@code keys} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *         {@code non-null}, not empty, and {@code retMap} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *         {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @see KeyStroke#getKeyStroke(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @see InputMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public static void loadKeyBindings(InputMap retMap, Object[] keys) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if (keys != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            for (int counter = 0, maxCounter = keys.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                 counter < maxCounter; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                Object keyStrokeO = keys[counter++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                KeyStroke ks = (keyStrokeO instanceof KeyStroke) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                (KeyStroke)keyStrokeO :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                                KeyStroke.getKeyStroke((String)keyStrokeO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                retMap.put(ks, keys[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Creates and returns a {@code UIDefault.LazyValue} that loads an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * image. The returned value is an implementation of {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * UIDefaults.LazyValue}. When {@code createValue} is invoked on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * the returned object, the image is loaded. If the image is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * non-null}, it is then wrapped in an {@code Icon} that implements {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * UIResource}. The image is loaded using {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * Class.getResourceAsStream(gifFile)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * This method does not check the arguments in any way. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * strongly recommended that {@code non-null} values are supplied else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * exceptions may occur when {@code createValue} is invoked on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * returned object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @param baseClass {@code Class} used to load the resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @param gifFile path to the image to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @return a {@code UIDefaults.LazyValue}; when resolved the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *         {@code LazyValue} loads the specified image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @see UIDefaults.LazyValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @see Icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @see Class#getResourceAsStream(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public static Object makeIcon(final Class<?> baseClass, final String gifFile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return SwingUtilities2.makeIcon(baseClass, baseClass, gifFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * Returns the <code>LayoutStyle</code> for this look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * and feel.  This never returns {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * You generally don't use the <code>LayoutStyle</code> from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * the look and feel, instead use the <code>LayoutStyle</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * method <code>getInstance</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @see LayoutStyle#getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @return the <code>LayoutStyle</code> for this look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public LayoutStyle getLayoutStyle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return DefaultLayoutStyle.getInstance();
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
     * Invoked when the user attempts an invalid operation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * such as pasting into an uneditable <code>JTextField</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * that has focus. The default implementation beeps. Subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * that wish different behavior should override this and provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * the additional feedback.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @param component the <code>Component</code> the error occurred in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *                  may be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *                  indicating the error condition is not directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *                  associated with a <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    public void provideErrorFeedback(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        Toolkit toolkit = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if (component != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            toolkit = component.getToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            toolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        toolkit.beep();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    } // provideErrorFeedback()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Returns the value of the specified system desktop property by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * invoking <code>Toolkit.getDefaultToolkit().getDesktopProperty()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * If the value of the specified property is {@code null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * {@code fallbackValue} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @param systemPropertyName the name of the system desktop property being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @param fallbackValue the object to be returned as the value if the system value is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @return the current value of the desktop property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @see java.awt.Toolkit#getDesktopProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public static Object getDesktopPropertyValue(String systemPropertyName, Object fallbackValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        Object value = Toolkit.getDefaultToolkit().getDesktopProperty(systemPropertyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            return fallbackValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        } else if (value instanceof Color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            return new ColorUIResource((Color)value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        } else if (value instanceof Font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            return new FontUIResource((Font)value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Returns an <code>Icon</code> with a disabled appearance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * This method is used to generate a disabled <code>Icon</code> when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * one has not been specified.  For example, if you create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * <code>JButton</code> and only specify an <code>Icon</code> via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <code>setIcon</code> this method will be called to generate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * disabled <code>Icon</code>. If {@code null} is passed as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * <code>icon</code> this method returns {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * Some look and feels might not render the disabled {@code Icon}, in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * case they will ignore this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @param component {@code JComponent} that will display the {@code Icon},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *         may be {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @param icon {@code Icon} to generate the disabled icon from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @return disabled {@code Icon}, or {@code null} if a suitable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     *         {@code Icon} can not be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    public Icon getDisabledIcon(JComponent component, Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (icon instanceof ImageIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            return new ImageIconUIResource(GrayFilter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                   createDisabledImage(((ImageIcon)icon).getImage()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * Returns an <code>Icon</code> for use by disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * components that are also selected. This method is used to generate an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * <code>Icon</code> for components that are in both the disabled and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * selected states but do not have a specific <code>Icon</code> for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * state.  For example, if you create a <code>JButton</code> and only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * specify an <code>Icon</code> via <code>setIcon</code> this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * will be called to generate the disabled and selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * <code>Icon</code>. If {@code null} is passed as <code>icon</code> this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * methods returns {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * Some look and feels might not render the disabled and selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * {@code Icon}, in which case they will ignore this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @param component {@code JComponent} that will display the {@code Icon},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *        may be {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @param icon {@code Icon} to generate disabled and selected icon from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @return disabled and selected icon, or {@code null} if a suitable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *         {@code Icon} can not be generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    public Icon getDisabledSelectedIcon(JComponent component, Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        return getDisabledIcon(component, icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * Return a short string that identifies this look and feel, e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * "CDE/Motif".  This string should be appropriate for a menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * Distinct look and feels should have different names, e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * a subclass of MotifLookAndFeel that changes the way a few components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * are rendered should be called "CDE/Motif My Way"; something
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * that would be useful to a user trying to select a L&F from a list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * of names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @return short identifier for the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    public abstract String getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * Return a string that identifies this look and feel.  This string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * will be used by applications/services that want to recognize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * well known look and feel implementations.  Presently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * the well known names are "Motif", "Windows", "Mac", "Metal".  Note
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * that a LookAndFeel derived from a well known superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * that doesn't make any fundamental changes to the look or feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * shouldn't override this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @return identifier for the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    public abstract String getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * Return a one line description of this look and feel implementation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * e.g. "The CDE/Motif Look and Feel".   This string is intended for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * the user, e.g. in the title of a window or in a ToolTip message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * @return short description for the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    public abstract String getDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * Returns {@code true} if the <code>LookAndFeel</code> returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * <code>RootPaneUI</code> instances support providing {@code Window}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * decorations in a <code>JRootPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * The default implementation returns {@code false}, subclasses that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * support {@code Window} decorations should override this and return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @return {@code true} if the {@code RootPaneUI} instances created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *         this look and feel support client side decorations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @see JDialog#setDefaultLookAndFeelDecorated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @see JFrame#setDefaultLookAndFeelDecorated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @see JRootPane#setWindowDecorationStyle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    public boolean getSupportsWindowDecorations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * If the underlying platform has a "native" look and feel, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * this is an implementation of it, return {@code true}.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * example, when the underlying platform is Solaris running CDE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * a CDE/Motif look and feel implementation would return {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @return {@code true} if this look and feel represents the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *         platform look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    public abstract boolean isNativeLookAndFeel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * Return {@code true} if the underlying platform supports and or permits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * this look and feel.  This method returns {@code false} if the look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * and feel depends on special resources or legal agreements that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * aren't defined for the current platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * @return {@code true} if this is a supported look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @see UIManager#setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    public abstract boolean isSupportedLookAndFeel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * Initializes the look and feel. While this method is public,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * it should only be invoked by the {@code UIManager} when a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * look and feel is installed as the current look and feel. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * method is invoked before the {@code UIManager} invokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * {@code getDefaults}. This method is intended to perform any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * initialization for the look and feel. Subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * should do any one-time setup they need here, rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * in a static initializer, because look and feel class objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * may be loaded just to discover that {@code isSupportedLookAndFeel()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * returns {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @see #uninitialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @see UIManager#setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    public void initialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * Uninitializes the look and feel. While this method is public,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * it should only be invoked by the {@code UIManager} when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * the look and feel is uninstalled. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * {@code UIManager.setLookAndFeel} invokes this when the look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * feel is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * Subclasses may choose to free up some resources here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @see #initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * @see UIManager#setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    public void uninitialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * Returns the look and feel defaults. While this method is public,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * it should only be invoked by the {@code UIManager} when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * look and feel is set as the current look and feel and after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * {@code initialize} has been invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @return the look and feel defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @see #initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @see #uninitialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @see UIManager#setLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    public UIDefaults getDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * Returns a string that displays and identifies this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * object's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * @return a String representation of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        return "[" + getDescription() + " - " + getClass().getName() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
}