jdk/src/share/classes/javax/swing/UIDefaults.java
author malenkov
Wed, 07 May 2008 23:20:32 +0400
changeset 466 6acd5ec503a8
parent 2 90ce3da70b43
child 1301 15e81207e1f2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.plaf.ComponentUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.event.SwingPropertyChangeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.ResourceBundle.Control;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.security.AccessControlContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.reflect.misc.MethodUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.util.CoreResourceBundleControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * A table of defaults for Swing components.  Applications can set/get
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * default values via the <code>UIManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @see UIManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
public class UIDefaults extends Hashtable<Object,Object>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static final Object PENDING = new String("Pending");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private SwingPropertyChangeSupport changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private Vector resourceBundles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private Locale defaultLocale = Locale.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Maps from a Locale to a cached Map of the ResourceBundle. This is done
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * so as to avoid an exception being thrown when a value is asked for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Access to this should be done while holding a lock on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * UIDefaults, eg synchronized(this).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private Map resourceCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Creates an empty defaults table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public UIDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        this(700, .75f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Creates an empty defaults table with the specified initial capacity and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * load factor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param initialCapacity   the initial capacity of the defaults table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param loadFactor        the load factor of the defaults table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @see java.util.Hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public UIDefaults(int initialCapacity, float loadFactor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        super(initialCapacity, loadFactor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        resourceCache = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Creates a defaults table initialized with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * key/value pairs.  For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        Object[] uiDefaults = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
             "Font", new Font("Dialog", Font.BOLD, 12),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            "Color", Color.red,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
             "five", new Integer(5)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        UIDefaults myDefaults = new UIDefaults(uiDefaults);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param keyValueList  an array of objects containing the key/value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *          pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public UIDefaults(Object[] keyValueList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        super(keyValueList.length / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        for(int i = 0; i < keyValueList.length; i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            super.put(keyValueList[i], keyValueList[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns the value for key.  If the value is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <code>UIDefaults.LazyValue</code> then the real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * value is computed with <code>LazyValue.createValue()</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * the table entry is replaced, and the real value is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * If the value is an <code>UIDefaults.ActiveValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * the table entry is not replaced - the value is computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * with <code>ActiveValue.createValue()</code> for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <code>get()</code> call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * If the key is not found in the table then it is searched for in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * of resource bundles maintained by this object.  The resource bundles are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * searched most recently added first using the locale returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <code>getDefaultLocale</code>.  <code>LazyValues</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * <code>ActiveValues</code> are not supported in the resource bundles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return the value for <code>key</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @see LazyValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @see ActiveValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @see java.util.Hashtable#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @see #getDefaultLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @see #addResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public Object get(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        Object value = getFromHashtable( key );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return (value != null) ? value : getFromResourceBundle(key, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Looks up up the given key in our Hashtable and resolves LazyValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * or ActiveValues.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    private Object getFromHashtable(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        /* Quickly handle the common case, without grabbing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
         * a lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        Object value = super.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if ((value != PENDING) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            !(value instanceof ActiveValue) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            !(value instanceof LazyValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        /* If the LazyValue for key is being constructed by another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         * thread then wait and then return the new value, otherwise drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         * the lock and construct the ActiveValue or the LazyValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * We use the special value PENDING to mark LazyValues that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         * are being constructed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            value = super.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            if (value == PENDING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                        this.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    value = super.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                while(value == PENDING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            else if (value instanceof LazyValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                super.put(key, PENDING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            else if (!(value instanceof ActiveValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        /* At this point we know that the value of key was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
         * a LazyValue or an ActiveValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (value instanceof LazyValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                /* If an exception is thrown we'll just put the LazyValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                 * back in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                value = ((LazyValue)value).createValue(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                        super.remove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        super.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    this.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            value = ((ActiveValue)value).createValue(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Returns the value for key associated with the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * If the value is a <code>UIDefaults.LazyValue</code> then the real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * value is computed with <code>LazyValue.createValue()</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * the table entry is replaced, and the real value is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * If the value is an <code>UIDefaults.ActiveValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * the table entry is not replaced - the value is computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * with <code>ActiveValue.createValue()</code> for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <code>get()</code> call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * If the key is not found in the table then it is searched for in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * of resource bundles maintained by this object.  The resource bundles are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * searched most recently added first using the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <code>LazyValues</code> and <code>ActiveValues</code> are not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * in the resource bundles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param l the desired <code>locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return the value for <code>key</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @see LazyValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see ActiveValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @see java.util.Hashtable#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @see #addResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public Object get(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        Object value = getFromHashtable( key );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return (value != null) ? value : getFromResourceBundle(key, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Looks up given key in our resource bundles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private Object getFromResourceBundle(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if( resourceBundles == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            resourceBundles.isEmpty() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            !(key instanceof String) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        // A null locale means use the default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if( l == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            if( defaultLocale == null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                l = (Locale)defaultLocale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            return getResourceCache(l).get((String)key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Returns a Map of the known resources for the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    private Map getResourceCache(Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        Map values = (Map)resourceCache.get(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (values == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            values = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            for (int i=resourceBundles.size()-1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                String bundleName = (String)resourceBundles.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    ResourceBundle b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        b = ResourceBundle.getBundle(bundleName, l, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                        b = ResourceBundle.getBundle(bundleName, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    Enumeration keys = b.getKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    while (keys.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                        String key = (String)keys.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        if (values.get(key) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                            Object value = b.getObject(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                            values.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                } catch( MissingResourceException mre ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    // Keep looking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            resourceCache.put(l, values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Sets the value of <code>key</code> to <code>value</code> for all locales.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * If <code>key</code> is a string and the new value isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * equal to the old one, fire a <code>PropertyChangeEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * If value is <code>null</code>, the key is removed from the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @param key    the unique <code>Object</code> who's value will be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *          to retrieve the data value associated with it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @param value  the new <code>Object</code> to store as data under
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *          that key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @return the previous <code>Object</code> value, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @see #putDefaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see java.util.Hashtable#put
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public Object put(Object key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        Object oldValue = (value == null) ? super.remove(key) : super.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (key instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            firePropertyChange((String)key, oldValue, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Puts all of the key/value pairs in the database and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * unconditionally generates one <code>PropertyChangeEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * The events oldValue and newValue will be <code>null</code> and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * <code>propertyName</code> will be "UIDefaults".  The key/value pairs are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * added for all locales.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @param keyValueList  an array of key/value pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @see #put
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @see java.util.Hashtable#put
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public void putDefaults(Object[] keyValueList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        for(int i = 0, max = keyValueList.length; i < max; i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            Object value = keyValueList[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                super.remove(keyValueList[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                super.put(keyValueList[i], value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        firePropertyChange("UIDefaults", null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * If the value of <code>key</code> is a <code>Font</code> return it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @return if the value for <code>key</code> is a <code>Font</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *          return the <code>Font</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public Font getFont(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        Object value = get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return (value instanceof Font) ? (Font)value : null;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * is a <code>Font</code> return it, otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *          is a <code>Font</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *          return the <code>Font</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public Font getFont(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return (value instanceof Font) ? (Font)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * If the value of <code>key</code> is a <code>Color</code> return it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @return if the value for <code>key</code> is a <code>Color</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *          return the <code>Color</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public Color getColor(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        Object value = get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return (value instanceof Color) ? (Color)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * is a <code>Color</code> return it, otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *          is a <code>Color</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *          return the <code>Color</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    public Color getColor(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        return (value instanceof Color) ? (Color)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * If the value of <code>key</code> is an <code>Icon</code> return it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @return if the value for <code>key</code> is an <code>Icon</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *          return the <code>Icon</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    public Icon getIcon(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        Object value = get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return (value instanceof Icon) ? (Icon)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * is an <code>Icon</code> return it, otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *          is an <code>Icon</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *          return the <code>Icon</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public Icon getIcon(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return (value instanceof Icon) ? (Icon)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
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
     * If the value of <code>key</code> is a <code>Border</code> return it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @return if the value for <code>key</code> is a <code>Border</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *          return the <code>Border</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    public Border getBorder(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        Object value = get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        return (value instanceof Border) ? (Border)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
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
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * is a <code>Border</code> return it, otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *          is a <code>Border</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *          return the <code>Border</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    public Border getBorder(Object key, Locale l)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return (value instanceof Border) ? (Border)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * If the value of <code>key</code> is a <code>String</code> return it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @return if the value for <code>key</code> is a <code>String</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *          return the <code>String</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public String getString(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        Object value = get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        return (value instanceof String) ? (String)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * is a <code>String</code> return it, otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * @param l the desired <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @return if the value for <code>key</code> for the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *          <code>Locale</code> is a <code>String</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *          return the <code>String</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    public String getString(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        return (value instanceof String) ? (String)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * If the value of <code>key</code> is an <code>Integer</code> return its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * integer value, otherwise return 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @return if the value for <code>key</code> is an <code>Integer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *          return its value, otherwise return 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public int getInt(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        Object value = get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        return (value instanceof Integer) ? ((Integer)value).intValue() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * is an <code>Integer</code> return its integer value, otherwise return 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     *          is an <code>Integer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *          return its value, otherwise return 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    public int getInt(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        return (value instanceof Integer) ? ((Integer)value).intValue() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * If the value of <code>key</code> is boolean, return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * boolean value, otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @param key an <code>Object</code> specifying the key for the desired boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @return if the value of <code>key</code> is boolean, return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *         boolean value, otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public boolean getBoolean(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        Object value = get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        return (value instanceof Boolean) ? ((Boolean)value).booleanValue() : false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * is boolean, return the boolean value, otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @param key an <code>Object</code> specifying the key for the desired boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *         is boolean, return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *         boolean value, otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    public boolean getBoolean(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        return (value instanceof Boolean) ? ((Boolean)value).booleanValue() : false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * If the value of <code>key</code> is an <code>Insets</code> return it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * @return if the value for <code>key</code> is an <code>Insets</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *          return the <code>Insets</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    public Insets getInsets(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        Object value = get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        return (value instanceof Insets) ? (Insets)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * is an <code>Insets</code> return it, otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *          is an <code>Insets</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     *          return the <code>Insets</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    public Insets getInsets(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        return (value instanceof Insets) ? (Insets)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * If the value of <code>key</code> is a <code>Dimension</code> return it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @return if the value for <code>key</code> is a <code>Dimension</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *          return the <code>Dimension</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public Dimension getDimension(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        Object value = get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        return (value instanceof Dimension) ? (Dimension)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * is a <code>Dimension</code> return it, otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *          is a <code>Dimension</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     *          return the <code>Dimension</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    public Dimension getDimension(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        return (value instanceof Dimension) ? (Dimension)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * The value of <code>get(uidClassID)</code> must be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * <code>String</code> name of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * class that implements the corresponding <code>ComponentUI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * class.  If the class hasn't been loaded before, this method looks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * up the class with <code>uiClassLoader.loadClass()</code> if a non
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * class loader is provided, <code>classForName()</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * If a mapping for <code>uiClassID</code> exists or if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * class can't be found, return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * This method is used by <code>getUI</code>, it's usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * not necessary to call it directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @param uiClassID  a string containing the class ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * @param uiClassLoader the object which will load the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @return the value of <code>Class.forName(get(uidClassID))</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @see #getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    public Class<? extends ComponentUI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        getUIClass(String uiClassID, ClassLoader uiClassLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            String className = (String)get(uiClassID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            if (className != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                Class cls = (Class)get(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                if (cls == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                    if (uiClassLoader == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                        cls = SwingUtilities.loadSystemClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                        cls = uiClassLoader.loadClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    if (cls != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                        // Save lookup for future use, as forName is slow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                        put(className, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                return cls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    }
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 L&F class that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * @param uiClassID a string containing the class ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * @return the Class object returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     *          <code>getUIClass(uiClassID, null)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    public Class<? extends ComponentUI> getUIClass(String uiClassID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        return getUIClass(uiClassID, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * If <code>getUI()</code> fails for any reason,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * it calls this method before returning <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * Subclasses may choose to do more or less here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * @param msg message string to print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * @see #getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    protected void getUIError(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        System.err.println("UIDefaults.getUI() failed: " + msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            throw new Error();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        catch (Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * Creates an <code>ComponentUI</code> implementation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * specified component.  In other words create the look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * and feel specific delegate object for <code>target</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * This is done in two steps:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * <li> Look up the name of the <code>ComponentUI</code> implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * class under the value returned by <code>target.getUIClassID()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * <li> Use the implementation classes static <code>createUI()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * method to construct a look and feel delegate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @param target  the <code>JComponent</code> which needs a UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @return the <code>ComponentUI</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public ComponentUI getUI(JComponent target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        Object cl = get("ClassLoader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        ClassLoader uiClassLoader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            (cl != null) ? (ClassLoader)cl : target.getClass().getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        Class uiClass = getUIClass(target.getUIClassID(), uiClassLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        Object uiObject = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        if (uiClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            getUIError("no ComponentUI class for: " + target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                Method m = (Method)get(uiClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                if (m == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                    Class acClass = javax.swing.JComponent.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                    m = uiClass.getMethod("createUI", new Class[]{acClass});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                    put(uiClass, m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                uiObject = MethodUtil.invoke(m, null, new Object[]{target});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                getUIError("static createUI() method not found in " + uiClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                getUIError("createUI() failed for " + target + " " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        return (ComponentUI)uiObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * Adds a <code>PropertyChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * A <code>PropertyChangeEvent</code> will get fired whenever a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * @param listener  the <code>PropertyChangeListener</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * @see java.beans.PropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        if (changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            changeSupport = new SwingPropertyChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        changeSupport.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * Removes a <code>PropertyChangeListener</code> from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * This removes a <code>PropertyChangeListener</code> that was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * @param listener  the <code>PropertyChangeListener</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * @see java.beans.PropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            changeSupport.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * Returns an array of all the <code>PropertyChangeListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * to this UIDefaults with addPropertyChangeListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * @return all of the <code>PropertyChangeListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        if (changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            return new PropertyChangeListener[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        return changeSupport.getPropertyChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * Support for reporting bound property changes.  If oldValue and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * newValue are not equal and the <code>PropertyChangeEvent</code>x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * listener list isn't empty, then fire a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * <code>PropertyChange</code> event to each listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * @param propertyName  the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * @param oldValue  the old value of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * @param newValue  the new value of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * @see java.beans.PropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            changeSupport.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * Adds a resource bundle to the list of resource bundles that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * searched for localized values.  Resource bundles are searched in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * reverse order they were added.  In other words, the most recently added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * bundle is searched first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @param bundleName  the base name of the resource bundle to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * @see java.util.ResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @see #removeResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    public synchronized void addResourceBundle( String bundleName ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        if( bundleName == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        if( resourceBundles == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            resourceBundles = new Vector(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if (!resourceBundles.contains(bundleName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            resourceBundles.add( bundleName );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            resourceCache.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * Removes a resource bundle from the list of resource bundles that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * searched for localized defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * @param bundleName  the base name of the resource bundle to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * @see java.util.ResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @see #addResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    public synchronized void removeResourceBundle( String bundleName ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        if( resourceBundles != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            resourceBundles.remove( bundleName );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        resourceCache.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * Sets the default locale.  The default locale is used in retrieving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * localized values via <code>get</code> methods that do not take a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * locale argument.  As of release 1.4, Swing UI objects should retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * localized values using the locale of their component rather than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * default locale.  The default locale exists to provide compatibility with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * pre 1.4 behaviour.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @param l the new default locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * @see #getDefaultLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * @see #get(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @see #get(Object,Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    public void setDefaultLocale( Locale l ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        defaultLocale = l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * Returns the default locale.  The default locale is used in retrieving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * localized values via <code>get</code> methods that do not take a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * locale argument.  As of release 1.4, Swing UI objects should retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * localized values using the locale of their component rather than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * default locale.  The default locale exists to provide compatibility with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * pre 1.4 behaviour.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * @return the default locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * @see #setDefaultLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @see #get(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @see #get(Object,Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    public Locale getDefaultLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        return defaultLocale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * This class enables one to store an entry in the defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * table that isn't constructed until the first time it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * looked up with one of the <code>getXXX(key)</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * Lazy values are useful for defaults that are expensive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * to construct or are seldom retrieved.  The first time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * a <code>LazyValue</code> is retrieved its "real value" is computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * by calling <code>LazyValue.createValue()</code> and the real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * value is used to replace the <code>LazyValue</code> in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * <code>UIDefaults</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * table.  Subsequent lookups for the same key return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * the real value.  Here's an example of a <code>LazyValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * that constructs a <code>Border</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     *  Object borderLazyValue = new UIDefaults.LazyValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     *      public Object createValue(UIDefaults table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     *          return new BorderFactory.createLoweredBevelBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     *  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     *  uiDefaultsTable.put("MyBorder", borderLazyValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * @see UIDefaults#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    public interface LazyValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
         * Creates the actual value retrieved from the <code>UIDefaults</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
         * table. When an object that implements this interface is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
         * retrieved from the table, this method is used to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
         * the real value, which is then stored in the table and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
         * returned to the calling method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
         * @param table  a <code>UIDefaults</code> table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
         * @return the created <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        Object createValue(UIDefaults table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * This class enables one to store an entry in the defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * table that's constructed each time it's looked up with one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * the <code>getXXX(key)</code> methods. Here's an example of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * an <code>ActiveValue</code> that constructs a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * <code>DefaultListCellRenderer</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     *  Object cellRendererActiveValue = new UIDefaults.ActiveValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     *      public Object createValue(UIDefaults table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     *          return new DefaultListCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     *  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     *  uiDefaultsTable.put("MyRenderer", cellRendererActiveValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * @see UIDefaults#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    public interface ActiveValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
         * Creates the value retrieved from the <code>UIDefaults</code> table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
         * The object is created each time it is accessed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
         * @param table  a <code>UIDefaults</code> table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
         * @return the created <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        Object createValue(UIDefaults table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * This class provides an implementation of <code>LazyValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * used to delay loading of the Class for the instance to be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * It also avoids creation of an anonymous inner class for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * <code>LazyValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * subclass.  Both of these improve performance at the time that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * a Look and Feel is loaded, at the cost of a slight performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * reduction the first time <code>createValue</code> is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * (since Reflection APIs are used).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    public static class ProxyLazyValue implements LazyValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        private AccessControlContext acc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        private String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        private String methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        private Object[] args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
         * Creates a <code>LazyValue</code> which will construct an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
         * when asked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
         * @param c    a <code>String</code> specifying the classname
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
         *             of the instance to be created on demand
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        public ProxyLazyValue(String c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            this(c, (String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
         * Creates a <code>LazyValue</code> which will construct an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
         * when asked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
         * @param c    a <code>String</code> specifying the classname of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
         *              the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
         *              containing a static method to be called for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
         *              instance creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
         * @param m    a <code>String</code> specifying the static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
         *              method to be called on class c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        public ProxyLazyValue(String c, String m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            this(c, m, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
         * Creates a <code>LazyValue</code> which will construct an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
         * when asked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
         * @param c    a <code>String</code> specifying the classname
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
         *              of the instance to be created on demand
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
         * @param o    an array of <code>Objects</code> to be passed as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
         *              paramaters to the constructor in class c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        public ProxyLazyValue(String c, Object[] o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            this(c, null, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
         * Creates a <code>LazyValue</code> which will construct an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
         * when asked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
         * @param c    a <code>String</code> specifying the classname
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
         *              of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
         *              containing a static method to be called for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
         *              instance creation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
         * @param m    a <code>String</code> specifying the static method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
         *              to be called on class c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
         * @param o    an array of <code>Objects</code> to be passed as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
         *              paramaters to the static method in class c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        public ProxyLazyValue(String c, String m, Object[] o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            acc = AccessController.getContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            className = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            methodName = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            if (o != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                args = (Object[])o.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
         * Creates the value retrieved from the <code>UIDefaults</code> table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
         * The object is created each time it is accessed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
         * @param table  a <code>UIDefaults</code> table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
         * @return the created <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        public Object createValue(final UIDefaults table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            // In order to pick up the security policy in effect at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            // time of creation we use a doPrivileged with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            // AccessControlContext that was in place when this was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            return AccessController.doPrivileged(new PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                        Class c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                        Object cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                        // See if we should use a separate ClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                        if (table == null || !((cl = table.get("ClassLoader"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                                               instanceof ClassLoader)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                            cl = Thread.currentThread().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                                        getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                            if (cl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                                // Fallback to the system class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                                cl = ClassLoader.getSystemClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                        c = Class.forName(className, true, (ClassLoader)cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                        if (methodName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                            Class[] types = getClassArray(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                            Method m = c.getMethod(methodName, types);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                            return MethodUtil.invoke(m, c, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                            Class[] types = getClassArray(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                            Constructor constructor = c.getConstructor(types);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                            return constructor.newInstance(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                    } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                        // Ideally we would throw an exception, unfortunately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                        // often times there are errors as an initial look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                        // feel is loaded before one can be switched. Perhaps a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                        // flag should be added for debugging, so that if true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                        // the exception would be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            }, acc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
         * Coerce the array of class types provided into one which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
         * looks the way the Reflection APIs expect.  This is done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
         * by substituting primitive types for their Object counterparts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
         * and superclasses for subclasses used to add the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
         * <code>UIResource</code> tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        private Class[] getClassArray(Object[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            Class[] types = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            if (args!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                types = new Class[args.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                for (int i = 0; i< args.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                    /* PENDING(ges): At present only the primitive types
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                       used are handled correctly; this should eventually
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                       handle all primitive types */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                    if (args[i] instanceof java.lang.Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                        types[i]=Integer.TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                    } else if (args[i] instanceof java.lang.Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                        types[i]=Boolean.TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                    } else if (args[i] instanceof javax.swing.plaf.ColorUIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                        /* PENDING(ges) Currently the Reflection APIs do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                           search superclasses of parameters supplied for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                           constructor/method lookup.  Since we only have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                           one case where this is needed, we substitute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                           directly instead of adding a massive amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                           of mechanism for this.  Eventually this will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                           probably need to handle the general case as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                           */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                        types[i]=java.awt.Color.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                        types[i]=args[i].getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            return types;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        private String printArgs(Object[] array) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            String s = "{";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            if (array !=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                for (int i = 0 ; i < array.length-1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                    s = s.concat(array[i] + ",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                s = s.concat(array[array.length-1] + "}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                s = s.concat("}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * <code>LazyInputMap</code> will create a <code>InputMap</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * in its <code>createValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * method. The bindings are passed in in the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * The bindings are an array with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * the even number entries being string <code>KeyStrokes</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * (eg "alt SPACE") and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * the odd number entries being the value to use in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * <code>InputMap</code> (and the key in the <code>ActionMap</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    public static class LazyInputMap implements LazyValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        /** Key bindings are registered under. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        private Object[] bindings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        public LazyInputMap(Object[] bindings) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            this.bindings = bindings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
         * Creates an <code>InputMap</code> with the bindings that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
         * passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
         * @param table a <code>UIDefaults</code> table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
         * @return the <code>InputMap</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        public Object createValue(UIDefaults table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            if (bindings != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                InputMap km = LookAndFeel.makeInputMap(bindings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                return km;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
}