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