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