jdk/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 439 3488710b02f8
child 4371 dc9dcb8b0ae7
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  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
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.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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.awt.ComponentAccessor;
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 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            nc = getNativeContainer(comp);
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) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            ComponentPeer nc_peer = ComponentAccessor.getPeer(nc);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                ((XComponentPeer)nc_peer).pSetCursor(cur);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                // in case of grab we do for Swing we need to update keep cursor updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                // (we don't need this in case of AWT menus).  Window Manager consider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                // the grabber as a current window and use its cursor.  So we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                // change cursor on the grabber too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                updateGrabbedCursor(cur);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Updates cursor on the grabber if it is window peer (i.e. current grab is for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Swing, not for AWT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static void updateGrabbedCursor(Cursor cur) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        XBaseWindow target = XAwtState.getGrabWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (target instanceof XWindowPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            XWindowPeer grabber = (XWindowPeer) target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            grabber.pSetCursor(cur);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    protected void updateCursorOutOfJava() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // in case we have grabbed input for Swing we need to reset cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        // when mouse pointer is out of any java toplevel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        // let's use default cursor for this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        updateGrabbedCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private Component getNativeContainer(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        while (comp != null && ComponentAccessor.getPeer(comp) instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            comp = ComponentAccessor.getParent_NoClientCode(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    protected void getCursorPos(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (!((XToolkit)Toolkit.getDefaultToolkit()).getLastCursorPos(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                long display = XToolkit.getDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                long root_window = XlibWrapper.RootWindow(display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                                          XlibWrapper.DefaultScreen(display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                XlibWrapper.XQueryPointer(display, root_window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                          XlibWrapper.larg1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                          XlibWrapper.larg2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                          XlibWrapper.larg3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                          XlibWrapper.larg4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                          XlibWrapper.larg5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                          XlibWrapper.larg6,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                          XlibWrapper.larg7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                p.x = (int) XlibWrapper.unsafe.getInt(XlibWrapper.larg3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                p.y = (int) XlibWrapper.unsafe.getInt(XlibWrapper.larg4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                XToolkit.awtUnlock();
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
    protected  Component findHeavyweightUnderCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return XAwtState.getComponentMouseEntered();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * two native methods to call corresponding methods in Container and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    protected  Component findComponentAt(Container con, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return con.findComponentAt(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    protected  Point getLocationOnScreen(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return c.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    protected Component findHeavyweightUnderCursor(boolean useCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return findHeavyweightUnderCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    private Cursor getCapableCursor(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        Component c = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        while ((c != null) && !(c instanceof Window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
               && ComponentAccessor.isEnabledImpl(c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
               && ComponentAccessor.getVisible(c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
               && ComponentAccessor.getPeer(c) != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            c = ComponentAccessor.getParent_NoClientCode(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (c instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            return (ComponentAccessor.isEnabledImpl(c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    && ComponentAccessor.getVisible(c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    && (ComponentAccessor.getPeer(c) != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    && ComponentAccessor.isEnabledImpl(comp))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                   ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    ComponentAccessor.getCursor_NoClientCode(comp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                   :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        } else if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return getCapableCursor(ComponentAccessor.getParent_NoClientCode(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /* This methods needs to be called from within XToolkit.awtLock / XToolkit.awtUnlock section. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    static long getCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        long pData = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        int type = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            pData = field_pData.getLong(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            type = field_type.getInt(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        catch (Exception e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (pData != 0) return pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        int cursorType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
          case Cursor.DEFAULT_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   232
              cursorType = XCursorFontConstants.XC_left_ptr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
          case Cursor.CROSSHAIR_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   235
              cursorType = XCursorFontConstants.XC_crosshair;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
          case Cursor.TEXT_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   238
              cursorType = XCursorFontConstants.XC_xterm;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
          case Cursor.WAIT_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   241
              cursorType = XCursorFontConstants.XC_watch;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
          case Cursor.SW_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   244
              cursorType = XCursorFontConstants.XC_bottom_left_corner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
          case Cursor.NW_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   247
              cursorType = XCursorFontConstants.XC_top_left_corner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
          case Cursor.SE_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   250
              cursorType = XCursorFontConstants.XC_bottom_right_corner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
          case Cursor.NE_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   253
              cursorType = XCursorFontConstants.XC_top_right_corner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
          case Cursor.S_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   256
              cursorType = XCursorFontConstants.XC_bottom_side;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
          case Cursor.N_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   259
              cursorType = XCursorFontConstants.XC_top_side;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
          case Cursor.W_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   262
              cursorType = XCursorFontConstants.XC_left_side;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
          case Cursor.E_RESIZE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   265
              cursorType = XCursorFontConstants.XC_right_side;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
          case Cursor.HAND_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   268
              cursorType = XCursorFontConstants.XC_hand2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
          case Cursor.MOVE_CURSOR:
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   271
              cursorType = XCursorFontConstants.XC_fleur;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            pData =(long) XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(), cursorType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        setPData(c,pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    static void setPData(Cursor c, long pData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            method_setPData.invoke(c, pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        catch (Exception e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
}