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