jdk/src/share/classes/java/awt/dnd/DropTargetContext.java
author yan
Fri, 28 Mar 2014 14:33:53 +0400
changeset 23588 b0269b21e313
parent 5506 202f599c92aa
permissions -rw-r--r--
8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event Reviewed-by: pchelko, serb Contributed-by: Alexander Stepanov <alexander.v.stepanov@oracle.com>
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: 2
diff changeset
     2
 * Copyright (c) 1997, 2004, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.datatransfer.DataFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.datatransfer.Transferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.datatransfer.UnsupportedFlavorException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.dnd.peer.DropTargetContextPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * A <code>DropTargetContext</code> is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * whenever the logical cursor associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * with a Drag and Drop operation coincides with the visible geometry of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * a <code>Component</code> associated with a <code>DropTarget</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * The <code>DropTargetContext</code> provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * the mechanism for a potential receiver
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * of a drop operation to both provide the end user with the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * drag under feedback, but also to effect the subsequent data transfer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * if appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public class DropTargetContext implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final long serialVersionUID = -634158968993743371L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Construct a <code>DropTargetContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * given a specified <code>DropTarget</code>.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
    64
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @param dt the DropTarget to associate with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    DropTargetContext(DropTarget dt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        dropTarget = dt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * This method returns the <code>DropTarget</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <code>DropTargetContext</code>.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
    77
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @return the <code>DropTarget</code> associated with this <code>DropTargetContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public DropTarget getDropTarget() { return dropTarget; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * This method returns the <code>Component</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * this <code>DropTargetContext</code>.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
    86
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @return the Component associated with this Context
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 Component getComponent() { return dropTarget.getComponent(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Called when associated with the <code>DropTargetContextPeer</code>.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
    94
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param dtcp the <code>DropTargetContextPeer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public void addNotify(DropTargetContextPeer dtcp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        dropTargetContextPeer = dtcp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Called when disassociated with the <code>DropTargetContextPeer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        dropTargetContextPeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        transferable          = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * This method sets the current actions acceptable to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * this <code>DropTarget</code>.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   114
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @param actions an <code>int</code> representing the supported action(s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    protected void setTargetActions(int actions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        DropTargetContextPeer peer = getDropTargetContextPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            synchronized (peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                peer.setTargetActions(actions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                getDropTarget().doSetDefaultActions(actions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            getDropTarget().doSetDefaultActions(actions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * This method returns an <code>int</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * current actions this <code>DropTarget</code> will accept.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   133
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @return the current actions acceptable to this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    protected int getTargetActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        DropTargetContextPeer peer = getDropTargetContextPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return ((peer != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                        ? peer.getTargetActions()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                        : dropTarget.getDefaultActions()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * This method signals that the drop is completed and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * if it was successful or not.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   148
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param success true for success, false if not
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   150
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @throws InvalidDnDOperationException if a drop is not outstanding/extant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public void dropComplete(boolean success) throws InvalidDnDOperationException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        DropTargetContextPeer peer = getDropTargetContextPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            peer.dropComplete(success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * accept the Drag.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   163
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @param dragOperation the supported action(s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    protected void acceptDrag(int dragOperation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        DropTargetContextPeer peer = getDropTargetContextPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            peer.acceptDrag(dragOperation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * reject the Drag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    protected void rejectDrag() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        DropTargetContextPeer peer = getDropTargetContextPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            peer.rejectDrag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * called to signal that the drop is acceptable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * using the specified operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * must be called during DropTargetListener.drop method invocation.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   189
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param dropOperation the supported action(s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    protected void acceptDrop(int dropOperation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        DropTargetContextPeer peer = getDropTargetContextPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            peer.acceptDrop(dropOperation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * called to signal that the drop is unacceptable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * must be called during DropTargetListener.drop method invocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    protected void rejectDrop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        DropTargetContextPeer peer = getDropTargetContextPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            peer.rejectDrop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * get the available DataFlavors of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * <code>Transferable</code> operand of this operation.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   215
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @return a <code>DataFlavor[]</code> containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * supported <code>DataFlavor</code>s of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <code>Transferable</code> operand.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    protected DataFlavor[] getCurrentDataFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        DropTargetContextPeer peer = getDropTargetContextPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return peer != null ? peer.getTransferDataFlavors() : new DataFlavor[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * This method returns a the currently available DataFlavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * of the <code>Transferable</code> operand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * as a <code>java.util.List</code>.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   230
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @return the currently available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * DataFlavors as a <code>java.util.List</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    protected List<DataFlavor> getCurrentDataFlavorsAsList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return Arrays.asList(getCurrentDataFlavors());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * This method returns a <code>boolean</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * indicating if the given <code>DataFlavor</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * supported by this <code>DropTargetContext</code>.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   243
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @param df the <code>DataFlavor</code>
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   245
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @return if the <code>DataFlavor</code> specified is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    protected boolean isDataFlavorSupported(DataFlavor df) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return getCurrentDataFlavorsAsList().contains(df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * get the Transferable (proxy) operand of this operation
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   255
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @throws InvalidDnDOperationException if a drag is not outstanding/extant
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   257
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return the <code>Transferable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    protected Transferable getTransferable() throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        DropTargetContextPeer peer = getDropTargetContextPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            throw new InvalidDnDOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (transferable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                Transferable t = peer.getTransferable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                boolean isLocal = peer.isTransferableJVMLocal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    if (transferable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                        transferable = createTransferableProxy(t, isLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            return transferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Get the <code>DropTargetContextPeer</code>
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   282
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @return the platform peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    DropTargetContextPeer getDropTargetContextPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return dropTargetContextPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Creates a TransferableProxy to proxy for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Transferable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @param t the <tt>Transferable</tt> to be proxied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @param local <tt>true</tt> if <tt>t</tt> represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *        the result of a local drag-n-drop operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @return the new <tt>TransferableProxy</tt> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    protected Transferable createTransferableProxy(Transferable t, boolean local) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return new TransferableProxy(t, local);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
/****************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <code>TransferableProxy</code> is a helper inner class that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * <code>Transferable</code> interface and serves as a proxy for another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * <code>Transferable</code> object which represents data transfer for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * a particular drag-n-drop operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * The proxy forwards all requests to the encapsulated transferable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * and automatically performs additional conversion on the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * returned by the encapsulated transferable in case of local transfer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    protected class TransferableProxy implements Transferable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
         * Constructs a <code>TransferableProxy</code> given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
         * a specified <code>Transferable</code> object representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
         * data transfer for a particular drag-n-drop operation and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
         * a <code>boolean</code> which indicates whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
         * drag-n-drop operation is local (within the same JVM).
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   325
         *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
         * @param t the <code>Transferable</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         * @param local <code>true</code>, if <code>t</code> represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
         *        the result of local drag-n-drop operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        TransferableProxy(Transferable t, boolean local) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            proxy = new sun.awt.datatransfer.TransferableProxy(t, local);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            transferable = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            isLocal      = local;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
         * Returns an array of DataFlavor objects indicating the flavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         * the data can be provided in by the encapsulated transferable.
23588
b0269b21e313 8038242: Tidy warnings cleanup for java.awt.datatransfer, java.awt.dnd, java.awt.event
yan
parents: 5506
diff changeset
   339
         *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
         * @return an array of data flavors in which the data can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         *         provided by the encapsulated transferable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        public DataFlavor[] getTransferDataFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            return proxy.getTransferDataFlavors();
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
         * Returns whether or not the specified data flavor is supported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         * the encapsulated transferable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         * @param flavor the requested flavor for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
         * @return <code>true</code> if the data flavor is supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
         *         <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        public boolean isDataFlavorSupported(DataFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            return proxy.isDataFlavorSupported(flavor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
         * Returns an object which represents the data provided by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
         * the encapsulated transferable for the requested data flavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
         * In case of local transfer a serialized copy of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
         * returned by the encapsulated transferable is provided when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
         * the data is requested in application/x-java-serialized-object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         * data flavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         * @param df the requested flavor for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         * @throws IOException if the data is no longer available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         *              in the requested flavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
         * @throws UnsupportedFlavorException if the requested data flavor is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
         *              not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        public Object getTransferData(DataFlavor df)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            throws UnsupportedFlavorException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            return proxy.getTransferData(df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
         * fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        // We don't need to worry about client code changing the values of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        // these variables. Since TransferableProxy is a protected class, only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        // subclasses of DropTargetContext can access it. And DropTargetContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        // cannot be subclassed by client code because it does not have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        // public constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
         * The encapsulated <code>Transferable</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        protected Transferable  transferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
         * A <code>boolean</code> indicating if the encapsulated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
         * <code>Transferable</code> object represents the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
         * of local drag-n-drop operation (within the same JVM).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        protected boolean       isLocal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        private sun.awt.datatransfer.TransferableProxy proxy;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * The DropTarget associated with this DropTargetContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    private DropTarget dropTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    private transient DropTargetContextPeer dropTargetContextPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    private transient Transferable transferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
}