jdk/src/share/classes/java/awt/dnd/DragGestureEvent.java
author flar
Fri, 29 Apr 2011 10:58:33 -0700
changeset 9465 d336b679b605
parent 5506 202f599c92aa
child 15994 5c8a3d840366
permissions -rw-r--r--
6522514: Extending Arc2D.Double and serializing the object causes InvalidClassException Reviewed-by: prr
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: 440
diff changeset
     2
 * Copyright (c) 1998, 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: 440
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: 440
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: 440
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 440
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 440
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package java.awt.dnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
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
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.event.InputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.datatransfer.Transferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.EventObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * A <code>DragGestureEvent</code> is passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * to <code>DragGestureListener</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * dragGestureRecognized() method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * when a particular <code>DragGestureRecognizer</code> detects that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * platform dependent drag initiating gesture has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * on the <code>Component</code> that it is tracking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    58
 * The {@code action} field of any {@code DragGestureEvent} instance should take one of the following
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    59
 * values:
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    60
 * <ul>
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    61
 * <li> {@code DnDConstants.ACTION_COPY}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    62
 * <li> {@code DnDConstants.ACTION_MOVE}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    63
 * <li> {@code DnDConstants.ACTION_LINK}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    64
 * </ul>
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    65
 * Assigning the value different from listed above will cause an unspecified behavior.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    66
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @see java.awt.dnd.DragGestureRecognizer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @see java.awt.dnd.DragGestureListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @see java.awt.dnd.DragSource
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    70
 * @see java.awt.dnd.DnDConstants
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
public class DragGestureEvent extends EventObject {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static final long serialVersionUID = 9080172649166731306L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    78
     * Constructs a <code>DragGestureEvent</code> object given by the
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    79
     * <code>DragGestureRecognizer</code> instance firing this event,
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    80
     * an {@code act} parameter representing
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    81
     * the user's preferred action, an {@code ori} parameter
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    82
     * indicating the origin of the drag, and a {@code List} of
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    83
     * events that comprise the gesture({@code evs} parameter).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param dgr The <code>DragGestureRecognizer</code> firing this event
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    86
     * @param act The user's preferred action.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    87
     *            For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    88
     *            the class description for {@link DragGestureEvent}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param ori The origin of the drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param evs The <code>List</code> of events that comprise the gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * <P>
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    92
     * @throws IllegalArgumentException if any parameter equals {@code null}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    93
     * @throws IllegalArgumentException if the act parameter does not comply with
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    94
     *                                  the values given in the class
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    95
     *                                  description for {@link DragGestureEvent}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    96
     * @see java.awt.dnd.DnDConstants
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public DragGestureEvent(DragGestureRecognizer dgr, int act, Point ori,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                            List<? extends InputEvent> evs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        super(dgr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if ((component = dgr.getComponent()) == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            throw new IllegalArgumentException("null component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if ((dragSource = dgr.getDragSource()) == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            throw new IllegalArgumentException("null DragSource");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (evs == null || evs.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            throw new IllegalArgumentException("null or empty list of events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (act != DnDConstants.ACTION_COPY &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            act != DnDConstants.ACTION_MOVE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            act != DnDConstants.ACTION_LINK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            throw new IllegalArgumentException("bad action");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (ori == null) throw new IllegalArgumentException("null origin");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        events     = evs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        action     = act;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        origin     = ori;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Returns the source as a <code>DragGestureRecognizer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @return the source as a <code>DragGestureRecognizer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public DragGestureRecognizer getSourceAsDragGestureRecognizer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return (DragGestureRecognizer)getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns the <code>Component</code> associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * with this <code>DragGestureEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @return the Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public Component getComponent() { return component; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Returns the <code>DragSource</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @return the <code>DragSource</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public DragSource getDragSource() { return dragSource; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Returns a <code>Point</code> in the coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * of the <code>Component</code> over which the drag originated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @return the Point where the drag originated in Component coords.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public Point getDragOrigin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Returns an <code>Iterator</code> for the events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * comprising the gesture.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @return an Iterator for the events comprising the gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public Iterator<InputEvent> iterator() { return events.iterator(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Returns an <code>Object</code> array of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * events comprising the drag gesture.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @return an array of the events comprising the gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public Object[] toArray() { return events.toArray(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Returns an array of the events comprising the drag gesture.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param array the array of <code>EventObject</code> sub(types)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @return an array of the events comprising the gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public Object[] toArray(Object[] array) { return events.toArray(array); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Returns an <code>int</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * action selected by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @return the action selected by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public int getDragAction() { return action; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Returns the initial event that triggered the gesture.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @return the first "triggering" event in the sequence of the gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public InputEvent getTriggerEvent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return getSourceAsDragGestureRecognizer().getTriggerEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Starts the drag operation given the <code>Cursor</code> for this drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * operation and the <code>Transferable</code> representing the source data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * for this drag operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * If a <code>null</code> <code>Cursor</code> is specified no exception will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * be thrown and default drag cursors will be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * If a <code>null</code> <code>Transferable</code> is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <code>NullPointerException</code> will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param dragCursor     The initial {@code Cursor} for this drag operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *                       or {@code null} for the default cursor handling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *                       see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *                       <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *                       for more details on the cursor handling mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *                       during drag and drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param transferable The <code>Transferable</code> representing the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *                     data for this drag operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @throws InvalidDnDOperationException if the Drag and Drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *         system is unable to initiate a drag operation, or if the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *         attempts to start a drag while an existing drag operation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *         still executing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @throws NullPointerException if the {@code Transferable} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public void startDrag(Cursor dragCursor, Transferable transferable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
      throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        dragSource.startDrag(this, dragCursor, transferable, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Starts the drag given the initial <code>Cursor</code> to display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * the <code>Transferable</code> object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * and the <code>DragSourceListener</code> to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param dragCursor     The initial {@code Cursor} for this drag operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *                       or {@code null} for the default cursor handling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *                       see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *                       <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *                       for more details on the cursor handling mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *                       during drag and drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param transferable The source's Transferable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @param dsl          The source's DragSourceListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @throws InvalidDnDOperationException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * the Drag and Drop system is unable to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * initiate a drag operation, or if the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * attempts to start a drag while an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * drag operation is still executing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public void startDrag(Cursor dragCursor, Transferable transferable, DragSourceListener dsl) throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        dragSource.startDrag(this, dragCursor, transferable, dsl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Start the drag given the initial <code>Cursor</code> to display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * a drag <code>Image</code>, the offset of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * the <code>Image</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * the <code>Transferable</code> object, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * the <code>DragSourceListener</code> to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @param dragCursor     The initial {@code Cursor} for this drag operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *                       or {@code null} for the default cursor handling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *                       see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *                       <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *                       for more details on the cursor handling mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *                       during drag and drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param dragImage    The source's dragImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param imageOffset  The dragImage's offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param transferable The source's Transferable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @param dsl          The source's DragSourceListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @throws InvalidDnDOperationException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * the Drag and Drop system is unable to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * initiate a drag operation, or if the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * attempts to start a drag while an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * drag operation is still executing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public void startDrag(Cursor dragCursor, Image dragImage, Point imageOffset, Transferable transferable, DragSourceListener dsl) throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        dragSource.startDrag(this,  dragCursor, dragImage, imageOffset, transferable, dsl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Serializes this <code>DragGestureEvent</code>. Performs default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * serialization and then writes out this object's <code>List</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * gesture events if and only if the <code>List</code> can be serialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * If not, <code>null</code> is written instead. In this case, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * <code>DragGestureEvent</code> created from the resulting deserialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * stream will contain an empty <code>List</code> of gesture events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @serialData The default serializable fields, in alphabetical order,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *             followed by either a <code>List</code> instance, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        s.writeObject(SerializationTester.test(events) ? events : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Deserializes this <code>DragGestureEvent</code>. This method first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * performs default deserialization for all non-<code>transient</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * fields. An attempt is then made to deserialize this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * <code>List</code> of gesture events as well. This is first attempted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * by deserializing the field <code>events</code>, because, in releases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * prior to 1.4, a non-<code>transient</code> field of this name stored the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <code>List</code> of gesture events. If this fails, the next object in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * the stream is used instead. If the resulting <code>List</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * <code>null</code>, this object's <code>List</code> of gesture events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * is set to an empty <code>List</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        throws ClassNotFoundException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        ObjectInputStream.GetField f = s.readFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        dragSource = (DragSource)f.get("dragSource", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        component = (Component)f.get("component", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        origin = (Point)f.get("origin", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        action = f.get("action", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        // Pre-1.4 support. 'events' was previously non-transient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            events = (List)f.get("events", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            // 1.4-compatible byte stream. 'events' was written explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            events = (List)s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        // Implementation assumes 'events' is never null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (events == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            events = Collections.EMPTY_LIST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    private transient List events;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * The DragSource associated with this DragGestureEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    private DragSource dragSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * The Component associated with this DragGestureEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    private Component  component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * The origin of the drag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    private Point      origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * The user's preferred action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    private int        action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
}