jdk/src/share/classes/sun/awt/ComponentAccessor.java
author anthony
Fri, 20 Feb 2009 17:34:16 +0300
changeset 2459 08f3416ff334
parent 2 90ce3da70b43
child 3938 ef327bd847c0
permissions -rw-r--r--
6804747: Ensure consistent graphicsConfig member across components hierarchy Reviewed-by: art, dcherepanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.AWTEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.reflect.Field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.logging.Logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * A collection of methods for modifying package private fields in AWT components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * This class is meant to be used by Peer code only. Previously peer code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * got around this problem by modifying fields from native code. However
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * as we move away from native code to Pure-java peers we need this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @author Bino George
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class ComponentAccessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static Class componentClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static Field fieldX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static Field fieldY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static Field fieldWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static Field fieldHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static Method methodGetParentNoClientCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static Method methodGetFontNoClientCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static Method methodProcessEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static Method methodEnableEvents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static Field fieldParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static Field fieldBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static Field fieldForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static Field fieldFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static Field fieldPacked;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static Field fieldIgnoreRepaint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static Field fieldPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static Field fieldVisible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static Method methodIsEnabledImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static Method methodGetCursorNoClientCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static Method methodLocationNoClientCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final Logger log = Logger.getLogger("sun.awt.ComponentAccessor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private ComponentAccessor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        AccessController.doPrivileged( new PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                        componentClass = Class.forName("java.awt.Component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                        fieldX  = componentClass.getDeclaredField("x");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                        fieldX.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                        fieldY  = componentClass.getDeclaredField("y");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                        fieldY.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                        fieldWidth  = componentClass.getDeclaredField("width");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                        fieldWidth.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                        fieldHeight  = componentClass.getDeclaredField("height");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                        fieldHeight.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                        fieldForeground  = componentClass.getDeclaredField("foreground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                        fieldForeground.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                        fieldBackground  = componentClass.getDeclaredField("background");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                        fieldBackground.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                        fieldFont = componentClass.getDeclaredField("font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                        fieldFont.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                        methodGetParentNoClientCode = componentClass.getDeclaredMethod("getParent_NoClientCode", (Class[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                        methodGetParentNoClientCode.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                        methodGetFontNoClientCode = componentClass.getDeclaredMethod("getFont_NoClientCode", (Class[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                        methodGetFontNoClientCode.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                        Class[] argTypes = { AWTEvent.class };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                        methodProcessEvent = componentClass.getDeclaredMethod("processEvent",argTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                        methodProcessEvent.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                        Class[] argTypesForMethodEnableEvents = { Long.TYPE };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                        methodEnableEvents = componentClass.getDeclaredMethod("enableEvents",argTypesForMethodEnableEvents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                        methodEnableEvents.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                        fieldParent  = componentClass.getDeclaredField("parent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                        fieldParent.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                        fieldPacked = componentClass.getDeclaredField("isPacked");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        fieldPacked.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                        fieldIgnoreRepaint = componentClass.getDeclaredField("ignoreRepaint");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                        fieldIgnoreRepaint.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                        fieldPeer = componentClass.getDeclaredField("peer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                        fieldPeer.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                        fieldVisible = componentClass.getDeclaredField("visible");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                        fieldVisible.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        methodIsEnabledImpl = componentClass.getDeclaredMethod("isEnabledImpl", (Class[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                        methodIsEnabledImpl.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                        methodGetCursorNoClientCode = componentClass.getDeclaredMethod("getCursor_NoClientCode", (Class[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                        methodGetCursorNoClientCode.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                        methodLocationNoClientCode = componentClass.getDeclaredMethod("location_NoClientCode", (Class[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                        methodLocationNoClientCode.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    catch (NoSuchFieldException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                        log.log(Level.FINE, "Unable to initialize ComponentAccessor", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                        log.log(Level.FINE, "Unable to initialize ComponentAccessor", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                        log.log(Level.FINE, "Unable to initialize ComponentAccessor", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    // to please javac
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public static void setX(Component c, int x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            fieldX.setInt(c,x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static void setY(Component c, int y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            fieldY.setInt(c,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public static void setWidth(Component c, int width)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            fieldWidth.setInt(c,width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public static void setHeight(Component c, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            fieldHeight.setInt(c,height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public static void setBounds(Component c, int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            fieldX.setInt(c,x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            fieldY.setInt(c,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            fieldWidth.setInt(c,width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            fieldHeight.setInt(c,height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public static int getX(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            return fieldX.getInt(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public static int getY(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            return fieldY.getInt(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public static int getWidth(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            return fieldWidth.getInt(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public static int getHeight(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return fieldHeight.getInt(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public static boolean getIsPacked(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            return fieldPacked.getBoolean(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public static Container getParent_NoClientCode(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        Container parent=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            parent = (Container) methodGetParentNoClientCode.invoke(c, (Object[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            log.log(Level.FINE, "Unable to invoke on the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public static Font getFont_NoClientCode(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        Font font=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            font = (Font) methodGetFontNoClientCode.invoke(c, (Object[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            log.log(Level.FINE, "Unable to invoke on the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public static void processEvent(Component c, AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        Font font=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            Object[] args = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            args[0] = event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            methodProcessEvent.invoke(c,args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            log.log(Level.FINE, "Unable to invoke on the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public static void enableEvents(Component c, long event_mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            Object[] args = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            args[0] = Long.valueOf(event_mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            methodEnableEvents.invoke(c,args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            log.log(Level.FINE, "Unable to invoke on the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public static void setParent(Component c, Container parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            fieldParent.set(c,parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public static Color getForeground(Component c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        Color color = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            color = (Color) fieldForeground.get(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public static Color getBackground(Component c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        Color color = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            color = (Color) fieldBackground.get(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        return color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    public static void setBackground(Component c, Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            fieldBackground.set(c, color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public static Font getFont(Component c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        Font f = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            f = (Font) fieldFont.get(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public static ComponentPeer getPeer(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        ComponentPeer peer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            peer = (ComponentPeer)fieldPeer.get(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public static void setPeer(Component c, ComponentPeer peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            fieldPeer.set(c, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        } catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            log.log(Level.FINE, "Unable to access the Component object", e);
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
    public static boolean getIgnoreRepaint(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return fieldIgnoreRepaint.getBoolean(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public static boolean getVisible(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            return fieldVisible.getBoolean(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    public static boolean isEnabledImpl(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        boolean enabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            enabled = (Boolean) methodIsEnabledImpl.invoke(c, (Object[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            log.log(Level.FINE, "Unable to invoke on the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public static Cursor getCursor_NoClientCode(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        Cursor cursor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            cursor = (Cursor) methodGetCursorNoClientCode.invoke(c, (Object[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            log.log(Level.FINE, "Unable to invoke on the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public static Point getLocation_NoClientCode(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        Point loc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            loc = (Point) methodLocationNoClientCode.invoke(c, (Object[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        catch (IllegalAccessException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            log.log(Level.FINE, "Unable to access the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            log.log(Level.FINE, "Unable to invoke on the Component object", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        return loc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
}