jdk/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8133 c7e4a02e928e
child 13604 31089af1a447
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8133
diff changeset
     2
 * Copyright (c) 2003, 2011, 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: 4371
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: 4371
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: 4371
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
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.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.peer.LightweightPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.reflect.Field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.Method;
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
    34
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.awt.GlobalCursorManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public final class XGlobalCursorManager extends GlobalCursorManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static Field  field_pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static Field  field_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static Class  cursorClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static Method method_setPData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        cursorClass = java.awt.Cursor.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        field_pData = SunToolkit.getField(cursorClass, "pData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        field_type  = SunToolkit.getField(cursorClass, "type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        method_setPData = SunToolkit.getMethod(cursorClass, "setPData", new Class[] {long.class});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        if (field_pData == null || field_type == null || method_setPData == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            System.out.println("Unable to initialize XGlobalCursorManager: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            Thread.dumpStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        }
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
    // cached nativeContainer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private WeakReference<Component> nativeContainer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * The XGlobalCursorManager is a singleton.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static XGlobalCursorManager manager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    static GlobalCursorManager getCursorManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        if (manager == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            manager = new XGlobalCursorManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return manager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Should be called in response to a native mouse enter or native mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * button released message. Should not be called during a mouse drag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static void nativeUpdateCursor(Component heavy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        XGlobalCursorManager.getCursorManager().updateCursorLater(heavy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected void setCursor(Component comp, Cursor cursor, boolean useCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (comp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        Cursor cur = useCache ? cursor : getCapableCursor(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        Component nc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (useCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                nc = nativeContainer.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        } else {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
    97
           nc = SunToolkit.getHeavyweightComponent(comp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (nc != null) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   101
            ComponentPeer nc_peer = AWTAccessor.getComponentAccessor().getPeer(nc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            if (nc_peer instanceof XComponentPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    nativeContainer = new WeakReference<Component>(nc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
8133
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   107
                //6431076. A subcomponents (a XTextArea in particular)
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   108
                //may want to override the cursor over some of their parts.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   109
                ((XComponentPeer)nc_peer).pSetCursor(cur, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                // in case of grab we do for Swing we need to update keep cursor updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                // (we don't need this in case of AWT menus).  Window Manager consider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                // the grabber as a current window and use its cursor.  So we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                // change cursor on the grabber too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                updateGrabbedCursor(cur);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Updates cursor on the grabber if it is window peer (i.e. current grab is for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Swing, not for AWT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private static void updateGrabbedCursor(Cursor cur) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        XBaseWindow target = XAwtState.getGrabWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (target instanceof XWindowPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            XWindowPeer grabber = (XWindowPeer) target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            grabber.pSetCursor(cur);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    protected void updateCursorOutOfJava() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        // in case we have grabbed input for Swing we need to reset cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        // when mouse pointer is out of any java toplevel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // let's use default cursor for this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        updateGrabbedCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    protected void getCursorPos(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (!((XToolkit)Toolkit.getDefaultToolkit()).getLastCursorPos(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                long display = XToolkit.getDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                long root_window = XlibWrapper.RootWindow(display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                                          XlibWrapper.DefaultScreen(display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                XlibWrapper.XQueryPointer(display, root_window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                          XlibWrapper.larg1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                          XlibWrapper.larg2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                          XlibWrapper.larg3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                          XlibWrapper.larg4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                          XlibWrapper.larg5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                          XlibWrapper.larg6,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                          XlibWrapper.larg7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                p.x = (int) XlibWrapper.unsafe.getInt(XlibWrapper.larg3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                p.y = (int) XlibWrapper.unsafe.getInt(XlibWrapper.larg4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    protected  Component findHeavyweightUnderCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return XAwtState.getComponentMouseEntered();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * two native methods to call corresponding methods in Container and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    protected  Component findComponentAt(Container con, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return con.findComponentAt(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    protected  Point getLocationOnScreen(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return c.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    protected Component findHeavyweightUnderCursor(boolean useCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return findHeavyweightUnderCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    private Cursor getCapableCursor(Component comp) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   184
        AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   185
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        Component c = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        while ((c != null) && !(c instanceof Window)
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   188
               && compAccessor.isEnabled(c)
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   189
               && compAccessor.isVisible(c)
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   190
               && compAccessor.isDisplayable(c))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   192
            c = compAccessor.getParent(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (c instanceof Window) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   195
            return (compAccessor.isEnabled(c)
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   196
                    && compAccessor.isVisible(c)
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   197
                    && compAccessor.isDisplayable(c)
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   198
                    && compAccessor.isEnabled(comp))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                   ?
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   200
                    compAccessor.getCursor(comp)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                   :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        } else if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 439
diff changeset
   206
        return getCapableCursor(compAccessor.getParent(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /* This methods needs to be called from within XToolkit.awtLock / XToolkit.awtUnlock section. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    static long getCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        long pData = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        int type = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            pData = field_pData.getLong(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            type = field_type.getInt(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        catch (Exception e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (pData != 0) return pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        int cursorType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
          case Cursor.DEFAULT_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   229
              cursorType = XCursorFontConstants.XC_left_ptr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
          case Cursor.CROSSHAIR_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   232
              cursorType = XCursorFontConstants.XC_crosshair;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
          case Cursor.TEXT_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   235
              cursorType = XCursorFontConstants.XC_xterm;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
          case Cursor.WAIT_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   238
              cursorType = XCursorFontConstants.XC_watch;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
          case Cursor.SW_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   241
              cursorType = XCursorFontConstants.XC_bottom_left_corner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
          case Cursor.NW_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   244
              cursorType = XCursorFontConstants.XC_top_left_corner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
          case Cursor.SE_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   247
              cursorType = XCursorFontConstants.XC_bottom_right_corner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
          case Cursor.NE_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   250
              cursorType = XCursorFontConstants.XC_top_right_corner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
          case Cursor.S_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   253
              cursorType = XCursorFontConstants.XC_bottom_side;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
          case Cursor.N_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   256
              cursorType = XCursorFontConstants.XC_top_side;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
          case Cursor.W_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   259
              cursorType = XCursorFontConstants.XC_left_side;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
          case Cursor.E_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   262
              cursorType = XCursorFontConstants.XC_right_side;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
          case Cursor.HAND_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   265
              cursorType = XCursorFontConstants.XC_hand2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
          case Cursor.MOVE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   268
              cursorType = XCursorFontConstants.XC_fleur;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            pData =(long) XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(), cursorType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        setPData(c,pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    static void setPData(Cursor c, long pData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            method_setPData.invoke(c, pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        catch (Exception e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}