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