jdk/src/share/classes/java/awt/dnd/DragSourceContext.java
author yan
Tue, 24 Sep 2013 12:25:50 +0400
changeset 20156 e19f062edcfe
parent 5506 202f599c92aa
child 21278 ef8a3a2a72f2
permissions -rw-r--r--
8025114: Eliminate doclint errors in java.awt.dnd package javadoc Reviewed-by: serb, alexsch
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: 3711
diff changeset
     2
 * Copyright (c) 1997, 2008, 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: 3711
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: 3711
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: 3711
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3711
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3711
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 java.awt.dnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.datatransfer.DataFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.datatransfer.Transferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.datatransfer.UnsupportedFlavorException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.dnd.peer.DragSourceContextPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.TooManyListenersException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The <code>DragSourceContext</code> class is responsible for managing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * initiator side of the Drag and Drop protocol. In particular, it is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * for managing drag event notifications to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * {@linkplain DragSourceListener DragSourceListeners}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * and {@linkplain DragSourceMotionListener DragSourceMotionListeners}, and providing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * {@link Transferable} representing the source data for the drag operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Note that the <code>DragSourceContext</code> itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * implements the <code>DragSourceListener</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <code>DragSourceMotionListener</code> interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * This is to allow the platform peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * (the {@link DragSourceContextPeer} instance)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * created by the {@link DragSource} to notify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * the <code>DragSourceContext</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * state changes in the ongoing operation. This allows the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <code>DragSourceContext</code> object to interpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * itself between the platform and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * listeners provided by the initiator of the drag operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <p>
20156
e19f062edcfe 8025114: Eliminate doclint errors in java.awt.dnd package javadoc
yan
parents: 5506
diff changeset
    66
 * <a name="defaultCursor"></a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * By default, {@code DragSourceContext} sets the cursor as appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * for the current state of the drag and drop operation. For example, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * the user has chosen {@linkplain DnDConstants#ACTION_MOVE the move action},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * and the pointer is over a target that accepts
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * the move action, the default move cursor is shown. When
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * the pointer is over an area that does not accept the transfer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * the default "no drop" cursor is shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * This default handling mechanism is disabled when a custom cursor is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * by the {@link #setCursor} method. When the default handling is disabled,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * it becomes the responsibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * of the developer to keep the cursor up to date, by listening
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * to the {@code DragSource} events and calling the {@code setCursor()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * Alternatively, you can provide custom cursor behavior by providing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * custom implementations of the {@code DragSource}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * and the {@code DragSourceContext} classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @see DragSourceListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @see DragSourceMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @see DnDConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
public class DragSourceContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    implements DragSourceListener, DragSourceMotionListener, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static final long serialVersionUID = -115407898692194719L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // used by updateCurrentCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * An <code>int</code> used by updateCurrentCursor()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * indicating that the <code>Cursor</code> should change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * to the default (no drop) <code>Cursor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    protected static final int DEFAULT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * An <code>int</code> used by updateCurrentCursor()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * indicating that the <code>Cursor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * has entered a <code>DropTarget</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    protected static final int ENTER   = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * An <code>int</code> used by updateCurrentCursor()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * indicating that the <code>Cursor</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * over a <code>DropTarget</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    protected static final int OVER    = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * An <code>int</code> used by updateCurrentCursor()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * indicating that the user operation has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    protected static final int CHANGED = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Called from <code>DragSource</code>, this constructor creates a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * <code>DragSourceContext</code> given the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * <code>DragSourceContextPeer</code> for this Drag, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <code>DragGestureEvent</code> that triggered the Drag, the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <code>Cursor</code> to use for the Drag, an (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <code>Image</code> to display while the Drag is taking place, the offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * of the <code>Image</code> origin from the hotspot at the instant of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * triggering event, the <code>Transferable</code> subject data, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * <code>DragSourceListener</code> to use during the Drag and Drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * If <code>DragSourceContextPeer</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <code>NullPointerException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * If <code>DragGestureEvent</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * <code>NullPointerException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * If <code>Cursor</code> is <code>null</code> no exception is thrown and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * the default drag cursor behavior is activated for this drag operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * If <code>Image</code> is <code>null</code> no exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * If <code>Image</code> is not <code>null</code> and the offset is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * <code>null</code> <code>NullPointerException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * If <code>Transferable</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * <code>NullPointerException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * If <code>DragSourceListener</code> is <code>null</code> no exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param dscp       the <code>DragSourceContextPeer</code> for this drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param trigger    the triggering event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param dragCursor     the initial {@code Cursor} for this drag operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *                       or {@code null} for the default cursor handling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *                       see <a href="DragSourceContext.html#defaultCursor">class level documentation</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *                       for more details on the cursor handling mechanism during drag and drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param dragImage  the <code>Image</code> to drag (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @param offset     the offset of the image origin from the hotspot at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *                   instant of the triggering event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @param t          the <code>Transferable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @param dsl        the <code>DragSourceListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @throws IllegalArgumentException if the <code>Component</code> associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *         with the trigger event is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @throws IllegalArgumentException if the <code>DragSource</code> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *         trigger event is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @throws IllegalArgumentException if the drag action for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *         trigger event is <code>DnDConstants.ACTION_NONE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @throws IllegalArgumentException if the source actions for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *         <code>DragGestureRecognizer</code> associated with the trigger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *         event are equal to <code>DnDConstants.ACTION_NONE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @throws NullPointerException if dscp, trigger, or t are null, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *         if dragImage is non-null and offset is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public DragSourceContext(DragSourceContextPeer dscp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                             DragGestureEvent trigger, Cursor dragCursor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                             Image dragImage, Point offset, Transferable t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                             DragSourceListener dsl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (dscp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            throw new NullPointerException("DragSourceContextPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (trigger == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw new NullPointerException("Trigger");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (trigger.getDragSource() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new IllegalArgumentException("DragSource");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (trigger.getComponent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            throw new IllegalArgumentException("Component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (trigger.getSourceAsDragGestureRecognizer().getSourceActions() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                 DnDConstants.ACTION_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            throw new IllegalArgumentException("source actions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (trigger.getDragAction() == DnDConstants.ACTION_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            throw new IllegalArgumentException("no drag action");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (t == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            throw new NullPointerException("Transferable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (dragImage != null && offset == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            throw new NullPointerException("offset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        peer         = dscp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        this.trigger = trigger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        cursor       = dragCursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        transferable = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        listener     = dsl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        sourceActions =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            trigger.getSourceAsDragGestureRecognizer().getSourceActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        useCustomCursor = (dragCursor != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        updateCurrentCursor(trigger.getDragAction(), getSourceActions(), DEFAULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Returns the <code>DragSource</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * that instantiated this <code>DragSourceContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @return the <code>DragSource</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *   instantiated this <code>DragSourceContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public DragSource   getDragSource() { return trigger.getDragSource(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Returns the <code>Component</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <code>DragSourceContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @return the <code>Component</code> that started 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 Component    getComponent() { return trigger.getComponent(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Returns the <code>DragGestureEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * that initially triggered the drag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return the Event that triggered the drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public DragGestureEvent getTrigger() { return trigger; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Returns a bitwise mask of <code>DnDConstants</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * represent the set of drop actions supported by the drag source for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * drag operation associated with this <code>DragSourceContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @return the drop actions supported by the drag source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public int  getSourceActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return sourceActions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Sets the cursor for this drag operation to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <code>Cursor</code>.  If the specified <code>Cursor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * is <code>null</code>, the default drag cursor behavior is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * activated for this drag operation, otherwise it is deactivated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @param c     the initial {@code Cursor} for this drag operation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *                       or {@code null} for the default cursor handling;
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 1173
diff changeset
   278
     *                       see {@linkplain Cursor class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *                       level documentation} for more details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *                       on the cursor handling during drag and drop
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
    public synchronized void setCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        useCustomCursor = (c != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        setCursorImpl(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Returns the current drag <code>Cursor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @return the current drag <code>Cursor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public Cursor getCursor() { return cursor; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Add a <code>DragSourceListener</code> to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * <code>DragSourceContext</code> if one has not already been added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * If a <code>DragSourceListener</code> already exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * this method throws a <code>TooManyListenersException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param dsl the <code>DragSourceListener</code> to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Note that while <code>null</code> is not prohibited,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * it is not acceptable as a parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @throws TooManyListenersException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * a <code>DragSourceListener</code> has already been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public synchronized void addDragSourceListener(DragSourceListener dsl) throws TooManyListenersException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (dsl == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (equals(dsl)) throw new IllegalArgumentException("DragSourceContext may not be its own listener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (listener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            throw new TooManyListenersException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            listener = dsl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Removes the specified <code>DragSourceListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * from  this <code>DragSourceContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @param dsl the <code>DragSourceListener</code> to remove;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *     note that while <code>null</code> is not prohibited,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *     it is not acceptable as a parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public synchronized void removeDragSourceListener(DragSourceListener dsl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (listener != null && listener.equals(dsl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            listener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Notifies the peer that the <code>Transferable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * <code>DataFlavor</code>s have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public void transferablesFlavorsChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (peer != null) peer.transferablesFlavorsChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Calls <code>dragEnter</code> on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * <code>DragSourceListener</code>s registered with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * <code>DragSourceContext</code> and with the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * <code>DragSource</code>, and passes them the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <code>DragSourceDragEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @param dsde the <code>DragSourceDragEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public void dragEnter(DragSourceDragEvent dsde) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        DragSourceListener dsl = listener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (dsl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            dsl.dragEnter(dsde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        getDragSource().processDragEnter(dsde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), ENTER);
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
     * Calls <code>dragOver</code> on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * <code>DragSourceListener</code>s registered with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * <code>DragSourceContext</code> and with the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * <code>DragSource</code>, and passes them the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * <code>DragSourceDragEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @param dsde the <code>DragSourceDragEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public void dragOver(DragSourceDragEvent dsde) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        DragSourceListener dsl = listener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (dsl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            dsl.dragOver(dsde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        getDragSource().processDragOver(dsde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), OVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Calls <code>dragExit</code> on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * <code>DragSourceListener</code>s registered with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * <code>DragSourceContext</code> and with the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * <code>DragSource</code>, and passes them the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * <code>DragSourceEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @param dse the <code>DragSourceEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    public void dragExit(DragSourceEvent dse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        DragSourceListener dsl = listener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (dsl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            dsl.dragExit(dse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        getDragSource().processDragExit(dse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        updateCurrentCursor(DnDConstants.ACTION_NONE, DnDConstants.ACTION_NONE, DEFAULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Calls <code>dropActionChanged</code> on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * <code>DragSourceListener</code>s registered with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * <code>DragSourceContext</code> and with the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * <code>DragSource</code>, and passes them the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * <code>DragSourceDragEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @param dsde the <code>DragSourceDragEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void dropActionChanged(DragSourceDragEvent dsde) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        DragSourceListener dsl = listener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (dsl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            dsl.dropActionChanged(dsde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        getDragSource().processDropActionChanged(dsde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), CHANGED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * Calls <code>dragDropEnd</code> on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * <code>DragSourceListener</code>s registered with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * <code>DragSourceContext</code> and with the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * <code>DragSource</code>, and passes them the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * <code>DragSourceDropEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @param dsde the <code>DragSourceDropEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public void dragDropEnd(DragSourceDropEvent dsde) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        DragSourceListener dsl = listener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (dsl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            dsl.dragDropEnd(dsde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        getDragSource().processDragDropEnd(dsde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Calls <code>dragMouseMoved</code> on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * <code>DragSourceMotionListener</code>s registered with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * <code>DragSource</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * <code>DragSourceContext</code>, and them passes the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * <code>DragSourceDragEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param dsde the <code>DragSourceDragEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public void dragMouseMoved(DragSourceDragEvent dsde) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        getDragSource().processDragMouseMoved(dsde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Returns the <code>Transferable</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * this <code>DragSourceContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @return the <code>Transferable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public Transferable getTransferable() { return transferable; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * If the default drag cursor behavior is active, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * sets the default drag cursor for the specified actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * supported by the drag source, the drop target action,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * and status, otherwise this method does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @param sourceAct the actions supported by the drag source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @param targetAct the drop target action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @param status one of the fields <code>DEFAULT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *               <code>ENTER</code>, <code>OVER</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *               <code>CHANGED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    protected synchronized void updateCurrentCursor(int sourceAct, int targetAct, int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        // if the cursor has been previously set then dont do any defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        // processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (useCustomCursor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        // do defaults processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        Cursor c = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        switch (status) {
1173
96c2af2cb574 6716137: Fix 6691328 is broken
dav
parents: 638
diff changeset
   489
            default:
96c2af2cb574 6716137: Fix 6691328 is broken
dav
parents: 638
diff changeset
   490
                targetAct = DnDConstants.ACTION_NONE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            case ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            case OVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            case CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                int    ra = sourceAct & targetAct;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                if (ra == DnDConstants.ACTION_NONE) { // no drop possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                    if ((sourceAct & DnDConstants.ACTION_LINK) == DnDConstants.ACTION_LINK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                        c = DragSource.DefaultLinkNoDrop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    else if ((sourceAct & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                        c = DragSource.DefaultMoveNoDrop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                        c = DragSource.DefaultCopyNoDrop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                } else { // drop possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                    if ((ra & DnDConstants.ACTION_LINK) == DnDConstants.ACTION_LINK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                        c = DragSource.DefaultLinkDrop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                    else if ((ra & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                        c = DragSource.DefaultMoveDrop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                        c = DragSource.DefaultCopyDrop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        setCursorImpl(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    private void setCursorImpl(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (cursor == null || !cursor.equals(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            cursor = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            if (peer != null) peer.setCursor(cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Serializes this <code>DragSourceContext</code>. This method first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * performs default serialization. Next, this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * <code>Transferable</code> is written out if and only if it can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * serialized. If not, <code>null</code> is written instead. In this case,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * a <code>DragSourceContext</code> created from the resulting deserialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * stream will contain a dummy <code>Transferable</code> which supports no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * <code>DataFlavor</code>s. Finally, this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * <code>DragSourceListener</code> is written out if and only if it can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * serialized. If not, <code>null</code> is written instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @serialData The default serializable fields, in alphabetical order,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *             followed by either a <code>Transferable</code> instance, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     *             <code>null</code>, followed by either a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *             <code>DragSourceListener</code> instance, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        s.writeObject(SerializationTester.test(transferable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                      ? transferable : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        s.writeObject(SerializationTester.test(listener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                      ? listener : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * Deserializes this <code>DragSourceContext</code>. This method first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * performs default deserialization for all non-<code>transient</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * fields. This object's <code>Transferable</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * <code>DragSourceListener</code> are then deserialized as well by using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * the next two objects in the stream. If the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * <code>Transferable</code> is <code>null</code>, this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * <code>Transferable</code> is set to a dummy <code>Transferable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * which supports no <code>DataFlavor</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        throws ClassNotFoundException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        transferable = (Transferable)s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        listener = (DragSourceListener)s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        // Implementation assumes 'transferable' is never null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        if (transferable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            if (emptyTransferable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                emptyTransferable = new Transferable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                        public DataFlavor[] getTransferDataFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                            return new DataFlavor[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                        public boolean isDataFlavorSupported(DataFlavor flavor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                        public Object getTransferData(DataFlavor flavor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                            throws UnsupportedFlavorException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                            throw new UnsupportedFlavorException(flavor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            transferable = emptyTransferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    private static Transferable emptyTransferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    private transient DragSourceContextPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * The event which triggered the start of the drag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    private DragGestureEvent    trigger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * The current drag cursor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    private Cursor              cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    private transient Transferable      transferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    private transient DragSourceListener    listener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * <code>true</code> if the custom drag cursor is used instead of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * default one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    private boolean useCustomCursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * A bitwise mask of <code>DnDConstants</code> that represents the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * drop actions supported by the drag source for the drag operation associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * with this <code>DragSourceContext.</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    private final int sourceActions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
}