src/jdk.jconsole/share/classes/sun/tools/jconsole/inspector/Utils.java
author vlivanov
Thu, 18 Jan 2018 02:25:18 +0300
changeset 48596 860326263d1f
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194963: SystemDictionary::link_method_handle_constant() can't link MethodHandle.invoke()/invokeExact() Reviewed-by: kvn, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 18137
diff changeset
     2
 * Copyright (c) 2004, 2013, 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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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 sun.tools.jconsole.inspector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.math.BigDecimal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.math.BigInteger;
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    32
import java.util.*;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    33
import java.util.concurrent.ExecutionException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.management.openmbean.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class Utils {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private Utils() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static Set<Integer> tableNavigationKeys =
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    44
            new HashSet<Integer>(Arrays.asList(new Integer[]{
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        KeyEvent.VK_TAB, KeyEvent.VK_ENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        KeyEvent.VK_HOME, KeyEvent.VK_END,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        KeyEvent.VK_UP, KeyEvent.VK_DOWN,
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    49
        KeyEvent.VK_PAGE_UP, KeyEvent.VK_PAGE_DOWN
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    50
    }));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final Set<Class<?>> primitiveWrappers =
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    52
            new HashSet<Class<?>>(Arrays.asList(new Class<?>[]{
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        Byte.class, Short.class, Integer.class, Long.class,
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    54
        Float.class, Double.class, Character.class, Boolean.class
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    55
    }));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final Set<Class<?>> primitives = new HashSet<Class<?>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static final Map<String, Class<?>> primitiveMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            new HashMap<String, Class<?>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final Map<String, Class<?>> primitiveToWrapper =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            new HashMap<String, Class<?>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static final Set<String> editableTypes = new HashSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final Set<Class<?>> extraEditableClasses =
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    63
            new HashSet<Class<?>>(Arrays.asList(new Class<?>[]{
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        BigDecimal.class, BigInteger.class, Number.class,
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    65
        String.class, ObjectName.class
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    66
    }));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static final Set<String> numericalTypes = new HashSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static final Set<String> extraNumericalTypes =
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    69
            new HashSet<String>(Arrays.asList(new String[]{
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        BigDecimal.class.getName(), BigInteger.class.getName(),
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    71
        Number.class.getName()
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    72
    }));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static final Set<String> booleanTypes =
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    74
            new HashSet<String>(Arrays.asList(new String[]{
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    75
        Boolean.TYPE.getName(), Boolean.class.getName()
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    76
    }));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        // compute primitives/primitiveMap/primitiveToWrapper
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        for (Class<?> c : primitiveWrappers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                Field f = c.getField("TYPE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                Class<?> p = (Class<?>) f.get(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                primitives.add(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                primitiveMap.put(p.getName(), p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                primitiveToWrapper.put(p.getName(), c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                throw new AssertionError(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        // compute editableTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        for (Class<?> c : primitives) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            editableTypes.add(c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        for (Class<?> c : primitiveWrappers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            editableTypes.add(c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        for (Class<?> c : extraEditableClasses) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            editableTypes.add(c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // compute numericalTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        for (Class<?> c : primitives) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            String name = c.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            if (!name.equals(Boolean.TYPE.getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                numericalTypes.add(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        for (Class<?> c : primitiveWrappers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            String name = c.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            if (!name.equals(Boolean.class.getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                numericalTypes.add(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * This method returns the class matching the name className.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * It's used to cater for the primitive types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public static Class<?> getClass(String className)
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   121
            throws ClassNotFoundException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        Class<?> c;
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   123
        if ((c = primitiveMap.get(className)) != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            return c;
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   125
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return Class.forName(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Check if the given collection is a uniform collection of the given type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public static boolean isUniformCollection(Collection<?> c, Class<?> e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            throw new IllegalArgumentException("Null reference type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            throw new IllegalArgumentException("Null collection");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (c.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        for (Object o : c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (o == null || !e.isAssignableFrom(o.getClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Check if the given element denotes a supported array-friendly data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * structure, i.e. a data structure jconsole can render as an array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public static boolean canBeRenderedAsArray(Object elem) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   155
        if (isSupportedArray(elem)) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   156
            return true;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   157
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (elem instanceof Collection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            Collection<?> c = (Collection<?>) elem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            if (c.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                // Empty collections of any Java type are not handled as arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                // - Collections of CompositeData/TabularData are not handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                //   as arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                // - Collections of other Java types are handled as arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                return !isUniformCollection(c, CompositeData.class) &&
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   170
                        !isUniformCollection(c, TabularData.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (elem instanceof Map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            return !(elem instanceof TabularData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Check if the given element is an array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Multidimensional arrays are not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Non-empty 1-dimensional arrays of CompositeData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * and TabularData are not handled as arrays but as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * tabular data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public static boolean isSupportedArray(Object elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (elem == null || !elem.getClass().isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        Class<?> ct = elem.getClass().getComponentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (ct.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (Array.getLength(elem) > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                (CompositeData.class.isAssignableFrom(ct) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                TabularData.class.isAssignableFrom(ct))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * This method provides a readable classname if it's an array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * i.e. either the classname of the component type for arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * of java reference types or the name of the primitive type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * for arrays of java primitive types. Otherwise, it returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public static String getArrayClassName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        String className = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (name.startsWith("[")) {
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 23010
diff changeset
   213
            int index = name.lastIndexOf('[');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            className = name.substring(index, name.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            if (className.startsWith("[L")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                className = className.substring(2, className.length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    Class<?> c = Class.forName(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    className = c.getComponentType().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    // Should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                            "Bad class name " + name, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * This methods provides a readable classname. If the supplied name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * parameter denotes an array this method returns either the classname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * of the component type for arrays of java reference types or the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * of the primitive type for arrays of java primitive types followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * n-times "[]" where 'n' denotes the arity of the array. Otherwise, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * the supplied name doesn't denote an array it returns the same classname.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public static String getReadableClassName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        String className = getArrayClassName(name);
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   241
        if (className == null) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   242
            return name;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   243
        }
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 23010
diff changeset
   244
        int index = name.lastIndexOf('[');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        StringBuilder brackets = new StringBuilder(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        for (int i = 0; i <= index; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            brackets.append("[]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return brackets.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * This method tells whether the type is editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * (means can be created with a String or not)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public static boolean isEditableType(String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return editableTypes.contains(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * This method inserts a default value for the standard java types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * else it inserts the text name of the expected class type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * It acts to give a clue as to the input type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public static String getDefaultValue(String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (numericalTypes.contains(type) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                extraNumericalTypes.contains(type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return "0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (booleanTypes.contains(type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            return "true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        type = getReadableClassName(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        int i = type.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            return type.substring(i + 1, type.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Try to create a Java object using a one-string-param constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public static Object newStringConstructor(String type, String param)
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   286
            throws Exception {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   287
        Constructor<?> c = Utils.getClass(type).getConstructor(String.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            return c.newInstance(param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        } catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            Throwable t = e.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (t instanceof Exception) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                throw (Exception) t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Try to convert a string value into a numerical value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    private static Number createNumberFromStringValue(String value)
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   304
            throws NumberFormatException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        final String suffix = value.substring(value.length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if ("L".equalsIgnoreCase(suffix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            return Long.valueOf(value.substring(0, value.length() - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if ("F".equalsIgnoreCase(suffix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            return Float.valueOf(value.substring(0, value.length() - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if ("D".equalsIgnoreCase(suffix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            return Double.valueOf(value.substring(0, value.length() - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            return Integer.valueOf(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        } catch (NumberFormatException e) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   318
        // OK: Ignore exception...
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            return Long.valueOf(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        } catch (NumberFormatException e1) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   323
        // OK: Ignore exception...
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            return Double.valueOf(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        } catch (NumberFormatException e2) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   328
        // OK: Ignore exception...
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        throw new NumberFormatException("Cannot convert string value '" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                value + "' into a numerical value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * This method attempts to create an object of the given "type"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * using the "value" parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * e.g. calling createObjectFromString("java.lang.Integer", "10")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * will return an Integer object initialized to 10.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public static Object createObjectFromString(String type, String value)
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   341
            throws Exception {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        Object result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if (primitiveToWrapper.containsKey(type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            if (type.equals(Character.TYPE.getName())) {
25187
08aff438def8 8048874: Replace uses of 'new Byte', 'new Short' and 'new Character' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   345
                result = value.charAt(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                result = newStringConstructor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                        ((Class<?>) primitiveToWrapper.get(type)).getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                        value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        } else if (type.equals(Character.class.getName())) {
25187
08aff438def8 8048874: Replace uses of 'new Byte', 'new Short' and 'new Character' with appropriate alternative across core classes
prappo
parents: 24685
diff changeset
   352
            result = value.charAt(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        } else if (Number.class.isAssignableFrom(Utils.getClass(type))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            result = createNumberFromStringValue(value);
18137
264000e285e9 8015470: Remove redundant calls of toString() on String objects
dholmes
parents: 14342
diff changeset
   355
        } else if (value == null || value.equals("null")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            // hack for null value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            // try to create a Java object using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            // the one-string-param constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            result = newStringConstructor(type, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * This method is responsible for converting the inputs given by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * into a useful object array for passing into a parameter array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public static Object[] getParameters(XTextField[] inputs, String[] params)
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   371
            throws Exception {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        Object result[] = new Object[inputs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        Object userInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        for (int i = 0; i < inputs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            userInput = inputs[i].getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            // if it's already a complex object, use the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            // else try to instantiate with string constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            if (userInput instanceof XObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                result[i] = ((XObject) userInput).getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                result[i] = createObjectFromString(params[i].toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                        (String) userInput);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * If the exception is wrapped, unwrap it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public static Throwable getActualException(Throwable e) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   392
        if (e instanceof ExecutionException) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   393
            e = e.getCause();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   394
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (e instanceof MBeanException ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                e instanceof RuntimeMBeanException ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                e instanceof RuntimeOperationsException ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                e instanceof ReflectionException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            Throwable t = e.getCause();
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   400
            if (t != null) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   401
                return t;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   402
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    @SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public static class ReadOnlyTableCellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            extends DefaultCellEditor {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   410
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        public ReadOnlyTableCellEditor(JTextField tf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            super(tf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            tf.addFocusListener(new Utils.EditFocusAdapter(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            tf.addKeyListener(new Utils.CopyKeyAdapter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    public static class EditFocusAdapter extends FocusAdapter {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   419
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        private CellEditor editor;
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   421
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        public EditFocusAdapter(CellEditor editor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            this.editor = editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   425
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   426
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            editor.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   430
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public static class CopyKeyAdapter extends KeyAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        private static final String defaultEditorKitCopyActionName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                DefaultEditorKit.copyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        private static final String transferHandlerCopyActionName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                (String) TransferHandler.getCopyAction().getValue(Action.NAME);
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   437
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        public void keyPressed(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            // Accept "copy" key strokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            KeyStroke ks = KeyStroke.getKeyStroke(
43722
25ba19c20260 8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents: 25859
diff changeset
   441
                    e.getKeyCode(), e.getModifiersEx());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            JComponent comp = (JComponent) e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            for (int i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                InputMap im = comp.getInputMap(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                Object key = im.get(ks);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                if (defaultEditorKitCopyActionName.equals(key) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                        transferHandlerCopyActionName.equals(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            // Accept JTable navigation key strokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            if (!tableNavigationKeys.contains(e.getKeyCode())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   456
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   457
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        public void keyTyped(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
}