jdk/src/share/classes/sun/awt/dnd/SunDragSourceContextPeer.java
author lana
Tue, 09 Apr 2013 15:14:31 -0700
changeset 16746 24848973edc4
parent 16710 f041f82cdeac
parent 16734 da1901d79073
child 22567 5816a47fa4dd
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
     2
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
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: 4831
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: 4831
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
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.dnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.AWTEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.EventQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.datatransfer.Transferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.dnd.DnDConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.dnd.DragSourceContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.dnd.DragSourceEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.dnd.DragSourceDropEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.dnd.DragSourceDragEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.dnd.DragGestureEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.dnd.InvalidDnDOperationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.dnd.peer.DragSourceContextPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.event.InputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.event.MouseEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.SortedMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.awt.datatransfer.DataTransferer;
11271
f10f98b24801 7117011: Reduce number of warnings in sun/awt/windows and sun/awt/datatransfer
denis
parents: 5506
diff changeset
    55
import java.awt.datatransfer.DataFlavor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 11271
diff changeset
    57
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * TBC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @since JDK1.3.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
public abstract class SunDragSourceContextPeer implements DragSourceContextPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private DragGestureEvent  trigger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private Component         component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private Cursor            cursor;
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
    71
    private Image             dragImage;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
    72
    private Point             dragImageOffset;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private long              nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private DragSourceContext dragSourceContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private int               sourceActions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static boolean    dragDropInProgress = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static boolean    discardingMouseEvents = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * dispatch constants
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 final static int DISPATCH_ENTER   = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected final static int DISPATCH_MOTION  = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected final static int DISPATCH_CHANGED = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected final static int DISPATCH_EXIT    = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    protected final static int DISPATCH_FINISH  = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected final static int DISPATCH_MOUSE_MOVED  = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * construct a new SunDragSourceContextPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public SunDragSourceContextPeer(DragGestureEvent dge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        trigger = dge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (trigger != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            component = trigger.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            component = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Synchro messages in AWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public void startSecondaryEventLoop(){}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public void quitSecondaryEventLoop(){}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * initiate a DnD operation ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public void startDrag(DragSourceContext dsc, Cursor c, Image di, Point p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        /* Fix for 4354044: don't initiate a drag if event sequence provided by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         * DragGestureRecognizer is empty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (getTrigger().getTriggerEvent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new InvalidDnDOperationException("DragGestureEvent has a null trigger");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        dragSourceContext = dsc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        cursor            = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        sourceActions     = getDragSourceContext().getSourceActions();
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   126
        dragImage         = di;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   127
        dragImageOffset   = p;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Transferable transferable  = getDragSourceContext().getTransferable();
11271
f10f98b24801 7117011: Reduce number of warnings in sun/awt/windows and sun/awt/datatransfer
denis
parents: 5506
diff changeset
   130
        SortedMap<Long,DataFlavor> formatMap = DataTransferer.getInstance().
f10f98b24801 7117011: Reduce number of warnings in sun/awt/windows and sun/awt/datatransfer
denis
parents: 5506
diff changeset
   131
            getFormatsForTransferable(transferable, DataTransferer.adaptFlavorMap
f10f98b24801 7117011: Reduce number of warnings in sun/awt/windows and sun/awt/datatransfer
denis
parents: 5506
diff changeset
   132
                (getTrigger().getDragSource().getFlavorMap()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        long[] formats = DataTransferer.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            keysToLongArray(formatMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        startDrag(transferable, formats, formatMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
         * Fix for 4613903.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
         * Filter out all mouse events that are currently on the event queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        discardingMouseEvents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        EventQueue.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    discardingMouseEvents = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    protected abstract void startDrag(Transferable trans,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                      long[] formats, Map formatMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * set cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public void setCursor(Cursor c) throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            if (cursor == null || !cursor.equals(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                cursor = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                // NOTE: native context can be null at this point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                // setNativeCursor() should handle it properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                setNativeCursor(getNativeContext(), c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                c != null ? c.getType() : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            }
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * return cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   177
     * Returns the drag image. If there is no image to drag,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   178
     * the returned value is {@code null}
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   179
     *
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   180
     * @return the reference to the drag image
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   181
     */
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   182
    public Image getDragImage() {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   183
        return dragImage;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   184
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   185
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   186
    /**
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   187
     * Returns an anchor offset for the image to drag.
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   188
     *
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   189
     * @return a {@code Point} object that corresponds
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   190
     * to coordinates of an anchor offset of the image
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   191
     * relative to the upper left corner of the image.
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   192
     * The point {@code (0,0)} returns by default.
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   193
     */
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   194
    public Point getDragImageOffset() {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   195
        if (dragImageOffset == null) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   196
            return new Point(0,0);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   197
        }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   198
        return new Point(dragImageOffset);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   199
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   200
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   201
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * downcall into native code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    protected abstract void setNativeCursor(long nativeCtxt, Cursor c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                                            int cType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    protected synchronized void setTrigger(DragGestureEvent dge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        trigger = dge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (trigger != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            component = trigger.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            component = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    protected DragGestureEvent getTrigger() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return trigger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    protected Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    protected synchronized void setNativeContext(long ctxt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        nativeCtxt = ctxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    protected synchronized long getNativeContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    protected DragSourceContext getDragSourceContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return dragSourceContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Notify the peer that the transferables' DataFlavors have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * No longer useful as the transferables are determined at the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * of the drag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public void transferablesFlavorsChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    protected final void postDragSourceDragEvent(final int targetAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                                 final int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                                 final int x, final int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                                 final int dispatchType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        final int dropAction =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            SunDragSourceContextPeer.convertModifiersToDropAction(modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                                                  sourceActions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        DragSourceDragEvent event =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            new DragSourceDragEvent(getDragSourceContext(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                                    dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                    targetAction & sourceActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                    modifiers, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        EventDispatcher dispatcher = new EventDispatcher(dispatchType, event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        SunToolkit.invokeLaterOnAppContext(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            SunToolkit.targetToAppContext(getComponent()), dispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        startSecondaryEventLoop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * upcall from native code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
16710
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 12813
diff changeset
   278
    protected void dragEnter(final int targetActions,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                           final int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                           final int x, final int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        postDragSourceDragEvent(targetActions, modifiers, x, y, DISPATCH_ENTER);
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
     * upcall from native code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private void dragMotion(final int targetActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                            final int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                            final int x, final int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        postDragSourceDragEvent(targetActions, modifiers, x, y, DISPATCH_MOTION);
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
     * upcall from native code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    private void operationChanged(final int targetActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                  final int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                  final int x, final int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        postDragSourceDragEvent(targetActions, modifiers, x, y, DISPATCH_CHANGED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * upcall from native code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    protected final void dragExit(final int x, final int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        DragSourceEvent event =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            new DragSourceEvent(getDragSourceContext(), x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        EventDispatcher dispatcher =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            new EventDispatcher(DISPATCH_EXIT, event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        SunToolkit.invokeLaterOnAppContext(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            SunToolkit.targetToAppContext(getComponent()), dispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        startSecondaryEventLoop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * upcall from native code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    private void dragMouseMoved(final int targetActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                final int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                final int x, final int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        postDragSourceDragEvent(targetActions, modifiers, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                DISPATCH_MOUSE_MOVED);
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
     * upcall from native code via implemented class (do)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    protected final void dragDropFinished(final boolean success,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                                          final int operations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                          final int x, final int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        DragSourceEvent event =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            new DragSourceDropEvent(getDragSourceContext(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                                    operations & sourceActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                    success, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        EventDispatcher dispatcher =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            new EventDispatcher(DISPATCH_FINISH, event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        SunToolkit.invokeLaterOnAppContext(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            SunToolkit.targetToAppContext(getComponent()), dispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        startSecondaryEventLoop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        setNativeContext(0);
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   350
        dragImage = null;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 2
diff changeset
   351
        dragImageOffset = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public static void setDragDropInProgress(boolean b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
      throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        synchronized (SunDragSourceContextPeer.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (dragDropInProgress == b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                throw new InvalidDnDOperationException(getExceptionMessage(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            dragDropInProgress = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Filters out all mouse events that were on the java event queue when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * startDrag was called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public static boolean checkEvent(AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (discardingMouseEvents && event instanceof MouseEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            MouseEvent mouseEvent = (MouseEvent)event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            if (!(mouseEvent instanceof SunDropTargetEvent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public static void checkDragDropInProgress()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
      throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (dragDropInProgress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            throw new InvalidDnDOperationException(getExceptionMessage(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    private static String getExceptionMessage(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        return b ? "Drag and drop in progress" : "No drag in progress";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public static int convertModifiersToDropAction(final int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                                   final int supportedActions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        int dropAction = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
         * Fix for 4285634.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
         * Calculate the drop action to match Motif DnD behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
         * If the user selects an operation (by pressing a modifier key),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
         * return the selected operation or ACTION_NONE if the selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
         * operation is not supported by the drag source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
         * If the user doesn't select an operation search the set of operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         * supported by the drag source for ACTION_MOVE, then for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
         * ACTION_COPY, then for ACTION_LINK and return the first operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
         * found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        switch (modifiers & (InputEvent.SHIFT_DOWN_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                             InputEvent.CTRL_DOWN_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        case InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            dropAction = DnDConstants.ACTION_LINK; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        case InputEvent.CTRL_DOWN_MASK:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            dropAction = DnDConstants.ACTION_COPY; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        case InputEvent.SHIFT_DOWN_MASK:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            dropAction = DnDConstants.ACTION_MOVE; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            if ((supportedActions & DnDConstants.ACTION_MOVE) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                dropAction = DnDConstants.ACTION_MOVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            } else if ((supportedActions & DnDConstants.ACTION_COPY) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                dropAction = DnDConstants.ACTION_COPY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            } else if ((supportedActions & DnDConstants.ACTION_LINK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                dropAction = DnDConstants.ACTION_LINK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return dropAction & supportedActions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    private void cleanup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        trigger = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        component = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        cursor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        dragSourceContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        SunDragSourceContextPeer.setDragDropInProgress(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    private class EventDispatcher implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        private final int dispatchType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        private final DragSourceEvent event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        EventDispatcher(int dispatchType, DragSourceEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            switch (dispatchType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            case DISPATCH_ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            case DISPATCH_MOTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            case DISPATCH_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            case DISPATCH_MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                if (!(event instanceof DragSourceDragEvent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    throw new IllegalArgumentException("Event: " + event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            case DISPATCH_EXIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            case DISPATCH_FINISH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                if (!(event instanceof DragSourceDropEvent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    throw new IllegalArgumentException("Event: " + event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                throw new IllegalArgumentException("Dispatch type: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                                   dispatchType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            this.dispatchType  = dispatchType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            this.event         = event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            DragSourceContext dragSourceContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                SunDragSourceContextPeer.this.getDragSourceContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                switch (dispatchType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                case DISPATCH_ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    dragSourceContext.dragEnter((DragSourceDragEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                case DISPATCH_MOTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    dragSourceContext.dragOver((DragSourceDragEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                case DISPATCH_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    dragSourceContext.dropActionChanged((DragSourceDragEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                case DISPATCH_EXIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    dragSourceContext.dragExit(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                case DISPATCH_MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    dragSourceContext.dragMouseMoved((DragSourceDragEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                case DISPATCH_FINISH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                        dragSourceContext.dragDropEnd((DragSourceDropEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                        SunDragSourceContextPeer.this.cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                    throw new IllegalStateException("Dispatch type: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                                    dispatchType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                 SunDragSourceContextPeer.this.quitSecondaryEventLoop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
}