src/java.desktop/share/classes/javax/swing/UIDefaults.java
author psadhukhan
Thu, 11 Oct 2018 14:19:36 +0530
changeset 52254 ac510fd737eb
parent 47216 71c04702a3d5
permissions -rw-r--r--
6828982: UIDefaults.getUI swallows original exception Reviewed-by: kaddepalli, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43308
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
     2
 * Copyright (c) 1997, 2017, 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
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
    33
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
    34
import java.io.InputStream;
52254
ac510fd737eb 6828982: UIDefaults.getUI swallows original exception
psadhukhan
parents: 47216
diff changeset
    35
import java.io.PrintWriter;
ac510fd737eb 6828982: UIDefaults.getUI swallows original exception
psadhukhan
parents: 47216
diff changeset
    36
import java.io.StringWriter;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
    37
import java.io.UncheckedIOException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.security.AccessControlContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.reflect.misc.MethodUtil;
6878
bab0deb709c4 6622002: UIDefault.ProxyLazyValue has unsafe reflection usage
alexp
parents: 5506
diff changeset
    57
import sun.reflect.misc.ReflectUtil;
43308
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
    58
import sun.swing.SwingAccessor;
20800
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16073
diff changeset
    59
import sun.swing.SwingUtilities2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * A table of defaults for Swing components.  Applications can set/get
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * default values via the <code>UIManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * 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
    70
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @see UIManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @author Hans Muller
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 22574
diff changeset
    76
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20854
diff changeset
    78
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
public class UIDefaults extends Hashtable<Object,Object>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
{
28533
aea5ffcd5b2b 7180976: Pending String deadlocks UIDefaults
serb
parents: 28059
diff changeset
    81
    private static final Object PENDING = new Object();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private SwingPropertyChangeSupport changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
    85
    private Vector<String> resourceBundles;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private Locale defaultLocale = Locale.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Maps from a Locale to a cached Map of the ResourceBundle. This is done
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * so as to avoid an exception being thrown when a value is asked for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Access to this should be done while holding a lock on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * UIDefaults, eg synchronized(this).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
    95
    private Map<Locale, Map<String, Object>> resourceCache;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
43308
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
    97
    static {
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
    98
        SwingAccessor.setUIDefaultsAccessor(UIDefaults::addInternalBundle);
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
    99
    }
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   100
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Creates an empty defaults table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public UIDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this(700, .75f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Creates an empty defaults table with the specified initial capacity and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * load factor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param initialCapacity   the initial capacity of the defaults table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param loadFactor        the load factor of the defaults table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @see java.util.Hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public UIDefaults(int initialCapacity, float loadFactor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super(initialCapacity, loadFactor);
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   119
        resourceCache = new HashMap<Locale, Map<String, Object>>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Creates a defaults table initialized with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * key/value pairs.  For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        Object[] uiDefaults = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
             "Font", new Font("Dialog", Font.BOLD, 12),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            "Color", Color.red,
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 36511
diff changeset
   130
             "five", Integer.valueOf(5)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        UIDefaults myDefaults = new UIDefaults(uiDefaults);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param keyValueList  an array of objects containing the key/value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *          pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public UIDefaults(Object[] keyValueList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        super(keyValueList.length / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        for(int i = 0; i < keyValueList.length; i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            super.put(keyValueList[i], keyValueList[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Returns the value for key.  If the value is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * <code>UIDefaults.LazyValue</code> then the real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * value is computed with <code>LazyValue.createValue()</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * the table entry is replaced, and the real value is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * If the value is an <code>UIDefaults.ActiveValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * the table entry is not replaced - the value is computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * with <code>ActiveValue.createValue()</code> for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * <code>get()</code> call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * If the key is not found in the table then it is searched for in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * of resource bundles maintained by this object.  The resource bundles are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * searched most recently added first using the locale returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * <code>getDefaultLocale</code>.  <code>LazyValues</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <code>ActiveValues</code> are not supported in the resource bundles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @return the value for <code>key</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @see LazyValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @see ActiveValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @see java.util.Hashtable#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @see #getDefaultLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @see #addResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public Object get(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        Object value = getFromHashtable( key );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return (value != null) ? value : getFromResourceBundle(key, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   176
     * Looks up the given key in our Hashtable and resolves LazyValues
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * or ActiveValues.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
28533
aea5ffcd5b2b 7180976: Pending String deadlocks UIDefaults
serb
parents: 28059
diff changeset
   179
    private Object getFromHashtable(final Object key) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        /* Quickly handle the common case, without grabbing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         * a lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        Object value = super.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if ((value != PENDING) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            !(value instanceof ActiveValue) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            !(value instanceof LazyValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        /* If the LazyValue for key is being constructed by another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         * thread then wait and then return the new value, otherwise drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         * the lock and construct the ActiveValue or the LazyValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         * We use the special value PENDING to mark LazyValues that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         * are being constructed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            value = super.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            if (value == PENDING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        this.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    value = super.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                while(value == PENDING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            else if (value instanceof LazyValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                super.put(key, PENDING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            else if (!(value instanceof ActiveValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        /* At this point we know that the value of key was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
         * a LazyValue or an ActiveValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (value instanceof LazyValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                /* If an exception is thrown we'll just put the LazyValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                 * back in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                value = ((LazyValue)value).createValue(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                        super.remove(key);
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
                        super.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    this.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            value = ((ActiveValue)value).createValue(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Returns the value for key associated with the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * If the value is a <code>UIDefaults.LazyValue</code> then the real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * value is computed with <code>LazyValue.createValue()</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * the table entry is replaced, and the real value is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * If the value is an <code>UIDefaults.ActiveValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * the table entry is not replaced - the value is computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * with <code>ActiveValue.createValue()</code> for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <code>get()</code> call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * If the key is not found in the table then it is searched for in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * of resource bundles maintained by this object.  The resource bundles are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * searched most recently added first using the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <code>LazyValues</code> and <code>ActiveValues</code> are not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * in the resource bundles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param l the desired <code>locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @return the value for <code>key</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @see LazyValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @see ActiveValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @see java.util.Hashtable#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @see #addResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public Object get(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        Object value = getFromHashtable( key );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return (value != null) ? value : getFromResourceBundle(key, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * Looks up given key in our resource bundles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    private Object getFromResourceBundle(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if( resourceBundles == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            resourceBundles.isEmpty() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            !(key instanceof String) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // A null locale means use the default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if( l == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if( defaultLocale == null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            else
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   294
                l = defaultLocale;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        synchronized(this) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   298
            return getResourceCache(l).get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Returns a Map of the known resources for the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   305
    private Map<String, Object> getResourceCache(Locale l) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   306
        Map<String, Object> values = resourceCache.get(l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (values == null) {
12287
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
   309
            values = new TextAndMnemonicHashMap();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            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
   311
                String bundleName = resourceBundles.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    ResourceBundle b;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   314
                    if (isDesktopResourceBundle(bundleName)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   315
                        // load resource bundle from java.desktop module
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   316
                        b = ResourceBundle.getBundle(bundleName, l, UIDefaults.class.getModule());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    } else {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   318
                        b = ResourceBundle.getBundle(bundleName, l, ClassLoader.getSystemClassLoader());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    }
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   320
                    Enumeration<String> keys = b.getKeys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    while (keys.hasMoreElements()) {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   323
                        String key = keys.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        if (values.get(key) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                            Object value = b.getObject(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                            values.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                } catch( MissingResourceException mre ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    // Keep looking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            resourceCache.put(l, values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   340
    /*
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   341
     * Test if the specified baseName of the ROOT locale is in java.desktop module.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   342
     * JDK always defines the resource bundle of the ROOT locale.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   343
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   344
    private static boolean isDesktopResourceBundle(String baseName) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   345
        Module thisModule = UIDefaults.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   346
        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   347
            @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   348
            public Boolean run() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   349
                Class<?> c = Class.forName(thisModule, baseName);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   350
                if (c != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   351
                    return true;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   352
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   353
                    String resourceName = baseName.replace('.', '/') + ".properties";
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   354
                    try (InputStream in = thisModule.getResourceAsStream(resourceName)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   355
                        return in != null;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   356
                    } catch (IOException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   357
                        throw new UncheckedIOException(e);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   358
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   359
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   360
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   361
        });
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   362
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   363
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Sets the value of <code>key</code> to <code>value</code> for all locales.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * If <code>key</code> is a string and the new value isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * equal to the old one, fire a <code>PropertyChangeEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * If value is <code>null</code>, the key is removed from the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param key    the unique <code>Object</code> who's value will be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *          to retrieve the data value associated with it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @param value  the new <code>Object</code> to store as data under
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *          that key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @return the previous <code>Object</code> value, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @see #putDefaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @see java.util.Hashtable#put
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public Object put(Object key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        Object oldValue = (value == null) ? super.remove(key) : super.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (key instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            firePropertyChange((String)key, oldValue, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        return oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Puts all of the key/value pairs in the database and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * unconditionally generates one <code>PropertyChangeEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * The events oldValue and newValue will be <code>null</code> and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * <code>propertyName</code> will be "UIDefaults".  The key/value pairs are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * added for all locales.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @param keyValueList  an array of key/value pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see #put
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @see java.util.Hashtable#put
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public void putDefaults(Object[] keyValueList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        for(int i = 0, max = keyValueList.length; i < max; i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            Object value = keyValueList[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                super.remove(keyValueList[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                super.put(keyValueList[i], value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        firePropertyChange("UIDefaults", null, 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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * If the value of <code>key</code> is a <code>Font</code> return it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @return if the value for <code>key</code> is a <code>Font</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *          return the <code>Font</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public Font getFont(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        Object value = get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return (value instanceof Font) ? (Font)value : null;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * is a <code>Font</code> return it, otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *          is a <code>Font</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *          return the <code>Font</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public Font getFont(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return (value instanceof Font) ? (Font)value : null;
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 a <code>Color</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 a <code>Color</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *          return the <code>Color</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 Color getColor(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 Color) ? (Color)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 a <code>Color</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 a <code>Color</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *          return the <code>Color</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 Color getColor(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 Color) ? (Color)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 an <code>Icon</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 an <code>Icon</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *          return the <code>Icon</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 Icon getIcon(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 Icon) ? (Icon)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 an <code>Icon</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 an <code>Icon</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *          return the <code>Icon</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 Icon getIcon(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 Icon) ? (Icon)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>Border</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>Border</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *          return the <code>Border</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 Border getBorder(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 Border) ? (Border)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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * is a <code>Border</code> return it, otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *          is a <code>Border</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *          return the <code>Border</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    public Border getBorder(Object key, Locale l)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        return (value instanceof Border) ? (Border)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * If the value of <code>key</code> is a <code>String</code> return it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @return if the value for <code>key</code> is a <code>String</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     *          return the <code>String</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    public String getString(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        Object value = get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        return (value instanceof String) ? (String)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * is a <code>String</code> return it, otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * @param l the desired <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @return if the value for <code>key</code> for the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *          <code>Locale</code> is a <code>String</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *          return the <code>String</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    public String getString(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return (value instanceof String) ? (String)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * If the value of <code>key</code> is an <code>Integer</code> return its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * integer value, otherwise return 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @return if the value for <code>key</code> is an <code>Integer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *          return its value, otherwise return 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    public int getInt(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 Integer) ? ((Integer)value).intValue() : 0;
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 an <code>Integer</code> return its integer value, otherwise return 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *          is an <code>Integer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *          return its value, otherwise return 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    public int getInt(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        return (value instanceof Integer) ? ((Integer)value).intValue() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
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
     * If the value of <code>key</code> is boolean, return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * boolean value, otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @param key an <code>Object</code> specifying the key for the desired boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @return if the value of <code>key</code> is boolean, return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     *         boolean value, otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public boolean getBoolean(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 Boolean) ? ((Boolean)value).booleanValue() : false;
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 boolean, return the boolean value, otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @param key an <code>Object</code> specifying the key for the desired boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     *         is boolean, return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *         boolean value, otherwise return false.
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 boolean getBoolean(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 Boolean) ? ((Boolean)value).booleanValue() : false;
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 an <code>Insets</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 an <code>Insets</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *          return the <code>Insets</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 Insets getInsets(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 Insets) ? (Insets)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 an <code>Insets</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 an <code>Insets</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *          return the <code>Insets</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 Insets getInsets(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 Insets) ? (Insets)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
     * If the value of <code>key</code> is a <code>Dimension</code> return it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @return if the value for <code>key</code> is a <code>Dimension</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *          return the <code>Dimension</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    public Dimension getDimension(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        Object value = get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        return (value instanceof Dimension) ? (Dimension)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * If the value of <code>key</code> for the given <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * is a <code>Dimension</code> return it, otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * @param key the desired key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * @param l the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * @return if the value for <code>key</code> and <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     *          is a <code>Dimension</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     *          return the <code>Dimension</code> object; otherwise return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    public Dimension getDimension(Object key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        Object value = get(key,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        return (value instanceof Dimension) ? (Dimension)value : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * The value of <code>get(uidClassID)</code> must be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * <code>String</code> name of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * class that implements the corresponding <code>ComponentUI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * class.  If the class hasn't been loaded before, this method looks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * up the class with <code>uiClassLoader.loadClass()</code> if a non
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * class loader is provided, <code>classForName()</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * If a mapping for <code>uiClassID</code> exists or if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * class can't be found, return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * This method is used by <code>getUI</code>, it's usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * not necessary to call it directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * @param uiClassID  a string containing the class ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @param uiClassLoader the object which will load the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * @return the value of <code>Class.forName(get(uidClassID))</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @see #getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    public Class<? extends ComponentUI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        getUIClass(String uiClassID, ClassLoader uiClassLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            String className = (String)get(uiClassID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            if (className != null) {
16073
da699ce2f8d2 7186948: Improve Swing data validation
rupashka
parents: 12287
diff changeset
   713
                ReflectUtil.checkPackageAccess(className);
da699ce2f8d2 7186948: Improve Swing data validation
rupashka
parents: 12287
diff changeset
   714
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   715
                Class<?> cls = (Class)get(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                if (cls == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    if (uiClassLoader == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                        cls = SwingUtilities.loadSystemClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                        cls = uiClassLoader.loadClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                    if (cls != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                        // Save lookup for future use, as forName is slow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                        put(className, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                }
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   728
                @SuppressWarnings("unchecked")
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   729
                Class<? extends ComponentUI> tmp = (Class<? extends ComponentUI>)cls;
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   730
                return tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   733
        catch (ClassNotFoundException | ClassCastException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        return null;
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
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 16073
diff changeset
   741
     * Returns the L&amp;F class that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @param uiClassID a string containing the class ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @return the Class object returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     *          <code>getUIClass(uiClassID, null)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    public Class<? extends ComponentUI> getUIClass(String uiClassID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        return getUIClass(uiClassID, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * If <code>getUI()</code> fails for any reason,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * it calls this method before returning <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * Subclasses may choose to do more or less here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * @param msg message string to print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * @see #getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    protected void getUIError(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        try {
47135
9ee067ea1785 6267105: UIDefaults.getUIError dumps error message to System.err and also throws Error.
aghaisas
parents: 43308
diff changeset
   762
            throw new Error(msg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        catch (Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * Creates an <code>ComponentUI</code> implementation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * specified component.  In other words create the look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * and feel specific delegate object for <code>target</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * This is done in two steps:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * <li> Look up the name of the <code>ComponentUI</code> implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * class under the value returned by <code>target.getUIClassID()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * <li> Use the implementation classes static <code>createUI()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * method to construct a look and feel delegate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @param target  the <code>JComponent</code> which needs a UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @return the <code>ComponentUI</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    public ComponentUI getUI(JComponent target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        Object cl = get("ClassLoader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        ClassLoader uiClassLoader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            (cl != null) ? (ClassLoader)cl : target.getClass().getClassLoader();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   788
        Class<? extends ComponentUI> uiClass = getUIClass(target.getUIClassID(), uiClassLoader);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        Object uiObject = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        if (uiClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            getUIError("no ComponentUI class for: " + target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                Method m = (Method)get(uiClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                if (m == null) {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
   798
                    m = uiClass.getMethod("createUI", new Class<?>[]{JComponent.class});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                    put(uiClass, m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   801
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   802
                if (uiClass.getModule() == ComponentUI.class.getModule()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   803
                    // uiClass is a system LAF if it's in java.desktop module
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   804
                    uiObject = m.invoke(null, new Object[]{target});
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   805
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   806
                    uiObject = MethodUtil.invoke(m, null, new Object[]{target});
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30464
diff changeset
   807
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                getUIError("static createUI() method not found in " + uiClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            catch (Exception e) {
52254
ac510fd737eb 6828982: UIDefaults.getUI swallows original exception
psadhukhan
parents: 47216
diff changeset
   813
                StringWriter w = new StringWriter();
ac510fd737eb 6828982: UIDefaults.getUI swallows original exception
psadhukhan
parents: 47216
diff changeset
   814
                PrintWriter pw = new PrintWriter(w);
ac510fd737eb 6828982: UIDefaults.getUI swallows original exception
psadhukhan
parents: 47216
diff changeset
   815
                e.printStackTrace(pw);
ac510fd737eb 6828982: UIDefaults.getUI swallows original exception
psadhukhan
parents: 47216
diff changeset
   816
                pw.flush();
ac510fd737eb 6828982: UIDefaults.getUI swallows original exception
psadhukhan
parents: 47216
diff changeset
   817
                getUIError("createUI() failed for " + target + "\n" + w);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        return (ComponentUI)uiObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * Adds a <code>PropertyChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * A <code>PropertyChangeEvent</code> will get fired whenever a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * @param listener  the <code>PropertyChangeListener</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @see java.beans.PropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        if (changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            changeSupport = new SwingPropertyChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        changeSupport.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * Removes a <code>PropertyChangeListener</code> from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * This removes a <code>PropertyChangeListener</code> that was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @param listener  the <code>PropertyChangeListener</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * @see java.beans.PropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            changeSupport.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * Returns an array of all the <code>PropertyChangeListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * to this UIDefaults with addPropertyChangeListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @return all of the <code>PropertyChangeListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        if (changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            return new PropertyChangeListener[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        return changeSupport.getPropertyChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * Support for reporting bound property changes.  If oldValue and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * newValue are not equal and the <code>PropertyChangeEvent</code>x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * listener list isn't empty, then fire a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * <code>PropertyChange</code> event to each listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * @param propertyName  the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * @param oldValue  the old value of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @param newValue  the new value of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @see java.beans.PropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            changeSupport.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * Adds a resource bundle to the list of resource bundles that are
43308
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   894
     * searched for localized values. Resource bundles are searched in
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   895
     * the reverse order they were added, using the
47155
289b19286b0e 8184244: UIDefaults.addResourceBundle uses system class loader
psadhukhan
parents: 47135
diff changeset
   896
     * {@linkplain ClassLoader#getSystemClassLoader system class loader}.
43308
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   897
     * In other words, the most recently added bundle is searched first.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * @param bundleName  the base name of the resource bundle to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * @see java.util.ResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @see #removeResourceBundle
43308
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   902
     * @see ResourceBundle#getBundle(String, Locale, ClassLoader)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     */
43308
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   905
    public synchronized void addResourceBundle(final String bundleName) {
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   906
        if (bundleName == null) {
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   907
            return;
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   908
        }
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   909
        if (isDesktopResourceBundle(bundleName)) {
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   910
            // Only the java.desktop itself can register resource bundles from
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   911
            // java.desktop module
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        }
43308
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   914
        addInternalBundle(bundleName);
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   915
    }
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   916
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   917
    /**
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   918
     * This methods should be used to register internal resource bundles from
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   919
     * the java.desktop module.
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   920
     *
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   921
     * @param bundleName  the base name of the resource bundle to be added
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   922
     * @since 9
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   923
     */
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   924
    private synchronized void addInternalBundle(final String bundleName) {
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   925
        if (bundleName == null) {
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   926
            return;
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   927
        }
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   928
        if (resourceBundles == null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   929
            resourceBundles = new Vector<String>(5);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        if (!resourceBundles.contains(bundleName)) {
43308
cff6230190e5 8149879: Examine UIDefaults::addResourceBundle(String bundleName) with resource encapsulation
serb
parents: 37714
diff changeset
   932
            resourceBundles.add(bundleName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            resourceCache.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * Removes a resource bundle from the list of resource bundles that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * searched for localized defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * @param bundleName  the base name of the resource bundle to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * @see java.util.ResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * @see #addResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    public synchronized void removeResourceBundle( String bundleName ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        if( resourceBundles != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            resourceBundles.remove( bundleName );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        resourceCache.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * Sets the default locale.  The default locale is used in retrieving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * localized values via <code>get</code> methods that do not take a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * locale argument.  As of release 1.4, Swing UI objects should retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * localized values using the locale of their component rather than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * default locale.  The default locale exists to provide compatibility with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * pre 1.4 behaviour.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @param l the new default locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * @see #getDefaultLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @see #get(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @see #get(Object,Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    public void setDefaultLocale( Locale l ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        defaultLocale = l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * Returns the default locale.  The default locale is used in retrieving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * localized values via <code>get</code> methods that do not take a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * locale argument.  As of release 1.4, Swing UI objects should retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * localized values using the locale of their component rather than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * default locale.  The default locale exists to provide compatibility with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * pre 1.4 behaviour.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * @return the default locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * @see #setDefaultLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * @see #get(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * @see #get(Object,Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    public Locale getDefaultLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        return defaultLocale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * This class enables one to store an entry in the defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * table that isn't constructed until the first time it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * looked up with one of the <code>getXXX(key)</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * Lazy values are useful for defaults that are expensive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * to construct or are seldom retrieved.  The first time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * a <code>LazyValue</code> is retrieved its "real value" is computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * by calling <code>LazyValue.createValue()</code> and the real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * value is used to replace the <code>LazyValue</code> in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * <code>UIDefaults</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * table.  Subsequent lookups for the same key return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * the real value.  Here's an example of a <code>LazyValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * that constructs a <code>Border</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     *  Object borderLazyValue = new UIDefaults.LazyValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     *      public Object createValue(UIDefaults table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     *          return new BorderFactory.createLoweredBevelBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     *  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     *  uiDefaultsTable.put("MyBorder", borderLazyValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * @see UIDefaults#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    public interface LazyValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
         * Creates the actual value retrieved from the <code>UIDefaults</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
         * table. When an object that implements this interface is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
         * retrieved from the table, this method is used to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
         * the real value, which is then stored in the table and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
         * returned to the calling method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
         * @param table  a <code>UIDefaults</code> table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
         * @return the created <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        Object createValue(UIDefaults table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * This class enables one to store an entry in the defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * table that's constructed each time it's looked up with one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * the <code>getXXX(key)</code> methods. Here's an example of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * an <code>ActiveValue</code> that constructs a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * <code>DefaultListCellRenderer</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     *  Object cellRendererActiveValue = new UIDefaults.ActiveValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     *      public Object createValue(UIDefaults table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     *          return new DefaultListCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     *  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     *  uiDefaultsTable.put("MyRenderer", cellRendererActiveValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * @see UIDefaults#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    public interface ActiveValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
         * Creates the value retrieved from the <code>UIDefaults</code> table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
         * The object is created each time it is accessed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
         * @param table  a <code>UIDefaults</code> table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
         * @return the created <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        Object createValue(UIDefaults table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * This class provides an implementation of <code>LazyValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * used to delay loading of the Class for the instance to be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * It also avoids creation of an anonymous inner class for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * <code>LazyValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * subclass.  Both of these improve performance at the time that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * a Look and Feel is loaded, at the cost of a slight performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * reduction the first time <code>createValue</code> is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * (since Reflection APIs are used).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    public static class ProxyLazyValue implements LazyValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        private AccessControlContext acc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        private String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        private String methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        private Object[] args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
         * Creates a <code>LazyValue</code> which will construct an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
         * when asked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
         * @param c    a <code>String</code> specifying the classname
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
         *             of the instance to be created on demand
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        public ProxyLazyValue(String c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            this(c, (String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
         * Creates a <code>LazyValue</code> which will construct an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
         * when asked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
         * @param c    a <code>String</code> specifying the classname of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
         *              the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
         *              containing a static method to be called for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
         *              instance creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
         * @param m    a <code>String</code> specifying the static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
         *              method to be called on class c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        public ProxyLazyValue(String c, String m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            this(c, m, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
         * Creates a <code>LazyValue</code> which will construct an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
         * when asked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
         * @param c    a <code>String</code> specifying the classname
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
         *              of the instance to be created on demand
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
         * @param o    an array of <code>Objects</code> to be passed as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
         *              paramaters to the constructor in class c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        public ProxyLazyValue(String c, Object[] o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            this(c, null, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
         * Creates a <code>LazyValue</code> which will construct an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
         * when asked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
         * @param c    a <code>String</code> specifying the classname
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
         *              of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
         *              containing a static method to be called for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
         *              instance creation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
         * @param m    a <code>String</code> specifying the static method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
         *              to be called on class c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
         * @param o    an array of <code>Objects</code> to be passed as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
         *              paramaters to the static method in class c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        public ProxyLazyValue(String c, String m, Object[] o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            acc = AccessController.getContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            className = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            methodName = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            if (o != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1130
                args = o.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
         * Creates the value retrieved from the <code>UIDefaults</code> table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
         * The object is created each time it is accessed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
         * @param table  a <code>UIDefaults</code> table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
         * @return the created <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        public Object createValue(final UIDefaults table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            // In order to pick up the security policy in effect at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            // time of creation we use a doPrivileged with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            // AccessControlContext that was in place when this was created.
6878
bab0deb709c4 6622002: UIDefault.ProxyLazyValue has unsafe reflection usage
alexp
parents: 5506
diff changeset
  1145
            if (acc == null && System.getSecurityManager() != null) {
bab0deb709c4 6622002: UIDefault.ProxyLazyValue has unsafe reflection usage
alexp
parents: 5506
diff changeset
  1146
                throw new SecurityException("null AccessControlContext");
bab0deb709c4 6622002: UIDefault.ProxyLazyValue has unsafe reflection usage
alexp
parents: 5506
diff changeset
  1147
            }
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1148
            return AccessController.doPrivileged(new PrivilegedAction<Object>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                    try {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1151
                        Class<?> c;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                        Object cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                        // See if we should use a separate ClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                        if (table == null || !((cl = table.get("ClassLoader"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                                               instanceof ClassLoader)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                            cl = Thread.currentThread().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                                        getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                            if (cl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                                // Fallback to the system class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                                cl = ClassLoader.getSystemClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                        }
6878
bab0deb709c4 6622002: UIDefault.ProxyLazyValue has unsafe reflection usage
alexp
parents: 5506
diff changeset
  1163
                        ReflectUtil.checkPackageAccess(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                        c = Class.forName(className, true, (ClassLoader)cl);
20800
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16073
diff changeset
  1165
                        SwingUtilities2.checkAccess(c.getModifiers());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                        if (methodName != null) {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  1167
                            Class<?>[] types = getClassArray(args);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                            Method m = c.getMethod(methodName, types);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                            return MethodUtil.invoke(m, c, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                        } else {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  1171
                            Class<?>[] types = getClassArray(args);
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  1172
                            Constructor<?> constructor = c.getConstructor(types);
20800
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16073
diff changeset
  1173
                            SwingUtilities2.checkAccess(constructor.getModifiers());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                            return constructor.newInstance(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                    } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                        // Ideally we would throw an exception, unfortunately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                        // often times there are errors as an initial look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                        // feel is loaded before one can be switched. Perhaps a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                        // flag should be added for debugging, so that if true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                        // the exception would be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            }, acc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
         * Coerce the array of class types provided into one which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
         * looks the way the Reflection APIs expect.  This is done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
         * by substituting primitive types for their Object counterparts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
         * and superclasses for subclasses used to add the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
         * <code>UIResource</code> tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
         */
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  1195
        private Class<?>[] getClassArray(Object[] args) {
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  1196
            Class<?>[] types = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            if (args!=null) {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  1198
                types = new Class<?>[args.length];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                for (int i = 0; i< args.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                    /* PENDING(ges): At present only the primitive types
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                       used are handled correctly; this should eventually
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                       handle all primitive types */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                    if (args[i] instanceof java.lang.Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                        types[i]=Integer.TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                    } else if (args[i] instanceof java.lang.Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                        types[i]=Boolean.TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                    } else if (args[i] instanceof javax.swing.plaf.ColorUIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                        /* PENDING(ges) Currently the Reflection APIs do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                           search superclasses of parameters supplied for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                           constructor/method lookup.  Since we only have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                           one case where this is needed, we substitute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                           directly instead of adding a massive amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                           of mechanism for this.  Eventually this will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                           probably need to handle the general case as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                           */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                        types[i]=java.awt.Color.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                        types[i]=args[i].getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            return types;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        private String printArgs(Object[] array) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            String s = "{";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            if (array !=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                for (int i = 0 ; i < array.length-1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                    s = s.concat(array[i] + ",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                s = s.concat(array[array.length-1] + "}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                s = s.concat("}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * <code>LazyInputMap</code> will create a <code>InputMap</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * in its <code>createValue</code>
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
  1243
     * method. The bindings are passed in the constructor.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * The bindings are an array with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * the even number entries being string <code>KeyStrokes</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * (eg "alt SPACE") and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     * the odd number entries being the value to use in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     * <code>InputMap</code> (and the key in the <code>ActionMap</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    public static class LazyInputMap implements LazyValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        /** Key bindings are registered under. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        private Object[] bindings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
30464
929bafd0db6f 8075082: Fix missing doclint warnings in the javax.swing package
darcy
parents: 28533
diff changeset
  1255
        /**
929bafd0db6f 8075082: Fix missing doclint warnings in the javax.swing package
darcy
parents: 28533
diff changeset
  1256
         * Constructs a {@code LazyInputMap}.
929bafd0db6f 8075082: Fix missing doclint warnings in the javax.swing package
darcy
parents: 28533
diff changeset
  1257
         * @param bindings the bindings
929bafd0db6f 8075082: Fix missing doclint warnings in the javax.swing package
darcy
parents: 28533
diff changeset
  1258
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        public LazyInputMap(Object[] bindings) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            this.bindings = bindings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
         * Creates an <code>InputMap</code> with the bindings that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
         * passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
         * @param table a <code>UIDefaults</code> table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
         * @return the <code>InputMap</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        public Object createValue(UIDefaults table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            if (bindings != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                InputMap km = LookAndFeel.makeInputMap(bindings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                return km;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    }
12287
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
    /**
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1280
     * <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
  1281
     * 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
  1282
     *   FileChooser.saveButton.textAndMnemonic=&Save
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1283
     * 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
  1284
     * 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
  1285
     *
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1286
     * 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
  1287
     * <code>TextAndMnemonicHashMap</code> class.
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1288
     * 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
  1289
     * (xxxNameText, xxxNameMnemonic)
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1290
     * (xxxNameText, xxxMnemonic)
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1291
     * (xxx.nameText, xxx.mnemonic)
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1292
     * (xxxText, xxxMnemonic)
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
     * 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
  1295
     * (xxxDisplayedMnemonicIndex)
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1296
     *
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1297
     * 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
  1298
     * (xxxTitle, xxxMnemonic)
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1299
     *
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
    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
  1302
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1303
        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
  1304
        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
  1305
        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
  1306
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1307
        @Override
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1308
        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
  1309
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1310
            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
  1311
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1312
            if (value == null) {
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1313
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1314
                boolean checkTitle = false;
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 stringKey = key.toString();
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1317
                String compositeKey = null;
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1318
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1319
                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
  1320
                    return null;
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
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1323
                if (stringKey.endsWith(".mnemonic")) {
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1324
                    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
  1325
                } 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
  1326
                    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
  1327
                } 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
  1328
                    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
  1329
                    checkTitle = true;
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1330
                }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1331
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1332
                if (compositeKey != null) {
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1333
                    value = super.get(compositeKey);
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1334
                    if (value == null && checkTitle) {
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1335
                        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
  1336
                        value = super.get(compositeKey);
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1337
                    }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1338
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1339
                    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
  1340
                }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1341
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1342
                if (stringKey.endsWith("NameText")) {
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1343
                    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
  1344
                } 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
  1345
                    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
  1346
                } 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
  1347
                    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
  1348
                } 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
  1349
                    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
  1350
                }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1351
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1352
                if (compositeKey != null) {
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1353
                    value = super.get(compositeKey);
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1354
                    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
  1355
                }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1356
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1357
                if (stringKey.endsWith("DisplayedMnemonicIndex")) {
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1358
                    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
  1359
                    value = super.get(compositeKey);
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1360
                    if (value == null) {
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1361
                        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
  1362
                        value = super.get(compositeKey);
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1363
                    }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1364
                    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
  1365
                }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1366
            }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1367
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1368
            return value;
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1369
        }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1370
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1371
        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
  1372
            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
  1373
        }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1374
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1375
        String getTextFromProperty(String text) {
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1376
            return text.replace("&", "");
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1377
        }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1378
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1379
        String getMnemonicFromProperty(String text) {
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1380
            int index = text.indexOf('&');
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1381
            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
  1382
                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
  1383
                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
  1384
            }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1385
            return null;
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1386
        }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1387
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1388
        String getIndexFromProperty(String text) {
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1389
            int index = text.indexOf('&');
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1390
            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
  1391
        }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1392
    }
5b5175de639f 7093156: NLS Please change the mnemonic assignment system to avoid translation issue (Swing files)
alexsch
parents: 7668
diff changeset
  1393
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
}