jdk/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java
author anthony
Tue, 17 Dec 2013 18:41:58 +0400
changeset 23241 e59e85da457f
parent 21280 68b145d54e2a
child 23276 add6f5c93bc6
permissions -rw-r--r--
8029979: Allow multiple calls to DropTargetDropEvent.acceptDrop() Reviewed-by: pchelko, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
21280
68b145d54e2a 8027151: AWT_DnD/Basic_DnD/Automated/DnDMerlinQL/MultipleJVM failing on windows machine
bagiras
parents: 19807
diff changeset
     2
 * Copyright (c) 2000, 2013, 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: 5192
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: 5192
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: 5192
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5192
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5192
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.dnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.datatransfer.DataFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.datatransfer.Transferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.datatransfer.UnsupportedFlavorException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.dnd.DnDConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.dnd.DropTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.dnd.DropTargetContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.dnd.DropTargetListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.dnd.DropTargetEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.dnd.DropTargetDragEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.dnd.DropTargetDropEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.dnd.InvalidDnDOperationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.dnd.peer.DropTargetContextPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    51
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.awt.datatransfer.DataTransferer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 18178
diff changeset
    60
import sun.security.util.SecurityConstants;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * The SunDropTargetContextPeer class is the generic class responsible for handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * the interaction between a windowing systems DnD system and Java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @since JDK1.3.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
public abstract class SunDropTargetContextPeer implements DropTargetContextPeer, Transferable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * A boolean constant that requires the peer to wait until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * SunDropTargetEvent is processed and return the status back
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * to the native code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static final boolean DISPATCH_SYNC = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private   DropTarget              currentDT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private   DropTargetContext       currentDTC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private   long[]                  currentT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private   int                     currentA;   // target actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private   int                     currentSA;  // source actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private   int                     currentDA;  // current drop action
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private   int                     previousDA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private   long                    nativeDragContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private   Transferable            local;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private boolean                   dragRejected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected int                     dropStatus   = STATUS_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    protected boolean                 dropComplete = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
7493
010ad57ed8d1 6945178: SecurityException upon drag-and-drop
denis
parents: 5506
diff changeset
    97
    // The flag is used to monitor whether the drop action is
010ad57ed8d1 6945178: SecurityException upon drag-and-drop
denis
parents: 5506
diff changeset
    98
    // handled by a user. That allows to distinct during
010ad57ed8d1 6945178: SecurityException upon drag-and-drop
denis
parents: 5506
diff changeset
    99
    // which operation getTransferData() method is invoked.
010ad57ed8d1 6945178: SecurityException upon drag-and-drop
denis
parents: 5506
diff changeset
   100
    boolean                           dropInProcess = false;
010ad57ed8d1 6945178: SecurityException upon drag-and-drop
denis
parents: 5506
diff changeset
   101
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * global lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    protected static final Object _globalLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   108
    private static final PlatformLogger dndLog = PlatformLogger.getLogger("sun.awt.dnd.SunDropTargetContextPeer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * a primitive mechanism for advertising intra-JVM Transferables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    protected static Transferable         currentJVMLocalSourceTransferable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static void setCurrentJVMLocalSourceTransferable(Transferable t) throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        synchronized(_globalLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            if (t != null && currentJVMLocalSourceTransferable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    throw new InvalidDnDOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                currentJVMLocalSourceTransferable = t;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * obtain the transferable iff the operation is in the same VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private static Transferable getJVMLocalSourceTransferable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return currentJVMLocalSourceTransferable;
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
     * constants used by dropAccept() or dropReject()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    protected final static int STATUS_NONE   =  0; // none pending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    protected final static int STATUS_WAIT   =  1; // drop pending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    protected final static int STATUS_ACCEPT =  2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    protected final static int STATUS_REJECT = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * create the peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public SunDropTargetContextPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return the DropTarget associated with this peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public DropTarget getDropTarget() { return currentDT; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param actions set the current actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public synchronized void setTargetActions(int actions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        currentA = actions &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @return the current target actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public int getTargetActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return currentA;
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
     * get the Transferable associated with the drop
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 Transferable getTransferable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @return current DataFlavors available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public DataFlavor[] getTransferDataFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        final Transferable    localTransferable = local;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (localTransferable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return localTransferable.getTransferDataFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return DataTransferer.getInstance().getFlavorsForFormatsAsArray
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                (currentT, DataTransferer.adaptFlavorMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    (currentDT.getFlavorMap()));
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
     * @return if the flavor is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public boolean isDataFlavorSupported(DataFlavor df) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        Transferable localTransferable = local;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (localTransferable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return localTransferable.isDataFlavorSupported(df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return DataTransferer.getInstance().getFlavorsForFormats
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                (currentT, DataTransferer.adaptFlavorMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    (currentDT.getFlavorMap())).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                containsKey(df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @return the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public Object getTransferData(DataFlavor df)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
      throws UnsupportedFlavorException, IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        InvalidDnDOperationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    {
5192
506ebd065f86 6887703: Unsigned applet can retrieve the dragged information before drop action occur
denis
parents: 3938
diff changeset
   225
506ebd065f86 6887703: Unsigned applet can retrieve the dragged information before drop action occur
denis
parents: 3938
diff changeset
   226
        SecurityManager sm = System.getSecurityManager();
506ebd065f86 6887703: Unsigned applet can retrieve the dragged information before drop action occur
denis
parents: 3938
diff changeset
   227
        try {
7493
010ad57ed8d1 6945178: SecurityException upon drag-and-drop
denis
parents: 5506
diff changeset
   228
            if (!dropInProcess && sm != null) {
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 18178
diff changeset
   229
                sm.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
5192
506ebd065f86 6887703: Unsigned applet can retrieve the dragged information before drop action occur
denis
parents: 3938
diff changeset
   230
            }
506ebd065f86 6887703: Unsigned applet can retrieve the dragged information before drop action occur
denis
parents: 3938
diff changeset
   231
        } catch (Exception e) {
506ebd065f86 6887703: Unsigned applet can retrieve the dragged information before drop action occur
denis
parents: 3938
diff changeset
   232
            Thread currentThread = Thread.currentThread();
506ebd065f86 6887703: Unsigned applet can retrieve the dragged information before drop action occur
denis
parents: 3938
diff changeset
   233
            currentThread.getUncaughtExceptionHandler().uncaughtException(currentThread, e);
506ebd065f86 6887703: Unsigned applet can retrieve the dragged information before drop action occur
denis
parents: 3938
diff changeset
   234
            return null;
506ebd065f86 6887703: Unsigned applet can retrieve the dragged information before drop action occur
denis
parents: 3938
diff changeset
   235
        }
506ebd065f86 6887703: Unsigned applet can retrieve the dragged information before drop action occur
denis
parents: 3938
diff changeset
   236
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        Long lFormat = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        Transferable localTransferable = local;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (localTransferable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return localTransferable.getTransferData(df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (dropStatus != STATUS_ACCEPT || dropComplete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            throw new InvalidDnDOperationException("No drop current");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        Map flavorMap = DataTransferer.getInstance().getFlavorsForFormats
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            (currentT, DataTransferer.adaptFlavorMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                (currentDT.getFlavorMap()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        lFormat = (Long)flavorMap.get(df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (lFormat == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            throw new UnsupportedFlavorException(df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (df.isRepresentationClassRemote() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            currentDA != DnDConstants.ACTION_LINK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            throw new InvalidDnDOperationException("only ACTION_LINK is permissable for transfer of java.rmi.Remote objects");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        final long format = lFormat.longValue();
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15987
diff changeset
   263
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        Object ret = getNativeData(format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (ret instanceof byte[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                return DataTransferer.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    translateBytes((byte[])ret, df, format, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                throw new InvalidDnDOperationException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        } else if (ret instanceof InputStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                return DataTransferer.getInstance().
21280
68b145d54e2a 8027151: AWT_DnD/Basic_DnD/Automated/DnDMerlinQL/MultipleJVM failing on windows machine
bagiras
parents: 19807
diff changeset
   276
                    translateStream((InputStream)ret, df, format, this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                throw new InvalidDnDOperationException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            throw new IOException("no native data was transfered");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    protected abstract Object getNativeData(long format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @return if the transfer is a local one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public boolean isTransferableJVMLocal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return local != null || getJVMLocalSourceTransferable() != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    private int handleEnterMessage(final Component component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                   final int x, final int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                                   final int dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                                   final int actions, final long[] formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                   final long nativeCtxt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return postDropTargetEvent(component, x, y, dropAction, actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                   formats, nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                   SunDropTargetEvent.MOUSE_ENTERED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                   SunDropTargetContextPeer.DISPATCH_SYNC);
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
     * actual processing on EventQueue Thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    protected void processEnterMessage(SunDropTargetEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        Component  c    = (Component)event.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        DropTarget dt   = c.getDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        Point      hots = event.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        local = getJVMLocalSourceTransferable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (currentDTC != null) { // some wreckage from last time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            currentDTC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (c.isShowing() && dt != null && dt.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            currentDT  = dt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            currentDTC = currentDT.getDropTargetContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            currentDTC.addNotify(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            currentA   = dt.getDefaultActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                ((DropTargetListener)dt).dragEnter(new DropTargetDragEvent(currentDTC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                                                                           hots,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                                                                           currentDA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                                                                           currentSA));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            currentDT  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            currentDTC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            currentDA   = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            currentSA   = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            currentA   = DnDConstants.ACTION_NONE;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * upcall to handle exit messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    private void handleExitMessage(final Component component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                   final long nativeCtxt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
         * Even though the return value is irrelevant for this event, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
         * dispatched synchronously to fix 4393148 properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        postDropTargetEvent(component, 0, 0, DnDConstants.ACTION_NONE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                            DnDConstants.ACTION_NONE, null, nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                            SunDropTargetEvent.MOUSE_EXITED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                            SunDropTargetContextPeer.DISPATCH_SYNC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    protected void processExitMessage(SunDropTargetEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        Component         c   = (Component)event.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        DropTarget        dt  = c.getDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        DropTargetContext dtc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (dt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            currentDT = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            currentT  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            if (currentDTC != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            currentDTC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (dt != currentDT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            if (currentDTC != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            currentDT  = dt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            currentDTC = dt.getDropTargetContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            currentDTC.addNotify(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        dtc = currentDTC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (dt.isActive()) try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            ((DropTargetListener)dt).dragExit(new DropTargetEvent(dtc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            currentA  = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            currentSA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            currentDT = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            currentT  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            currentDTC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            local = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            dragRejected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    private int handleMotionMessage(final Component component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                                    final int x, final int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                    final int dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                    final int actions, final long[] formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                    final long nativeCtxt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return postDropTargetEvent(component, x, y, dropAction, actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                   formats, nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                   SunDropTargetEvent.MOUSE_DRAGGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                   SunDropTargetContextPeer.DISPATCH_SYNC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    protected void processMotionMessage(SunDropTargetEvent event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                      boolean operationChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        Component         c    = (Component)event.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        Point             hots = event.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        int               id   = event.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        DropTarget        dt   = c.getDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        DropTargetContext dtc  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        if (c.isShowing() && (dt != null) && dt.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            if (currentDT != dt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                if (currentDTC != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                currentDT  = dt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                currentDTC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            dtc = currentDT.getDropTargetContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            if (dtc != currentDTC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                if (currentDTC != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                currentDTC = dtc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                currentDTC.addNotify(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            currentA = currentDT.getDefaultActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                DropTargetDragEvent dtde = new DropTargetDragEvent(dtc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                                                   hots,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                                                   currentDA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                                                                   currentSA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                DropTargetListener dtl = (DropTargetListener)dt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                if (operationChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    dtl.dropActionChanged(dtde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    dtl.dragOver(dtde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                if (dragRejected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * upcall to handle the Drop message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    private void handleDropMessage(final Component component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                   final int x, final int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                   final int dropAction, final int actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                   final long[] formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                                   final long nativeCtxt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        postDropTargetEvent(component, x, y, dropAction, actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                            formats, nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                            SunDropTargetEvent.MOUSE_DROPPED,
15987
1cd2a92ba636 8009158: Incomplete fix for 7178079
denis
parents: 13004
diff changeset
   502
                            !SunDropTargetContextPeer.DISPATCH_SYNC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    protected void processDropMessage(SunDropTargetEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        Component  c    = (Component)event.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        Point      hots = event.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        DropTarget dt   = c.getDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        dropStatus   = STATUS_WAIT; // drop pending ACK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        dropComplete = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (c.isShowing() && dt != null && dt.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            DropTargetContext dtc = dt.getDropTargetContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            currentDT = dt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            if (currentDTC != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            currentDTC = dtc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            currentDTC.addNotify(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            currentA = dt.getDefaultActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            synchronized(_globalLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                if ((local = getJVMLocalSourceTransferable()) != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    setCurrentJVMLocalSourceTransferable(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
7493
010ad57ed8d1 6945178: SecurityException upon drag-and-drop
denis
parents: 5506
diff changeset
   535
            dropInProcess = true;
010ad57ed8d1 6945178: SecurityException upon drag-and-drop
denis
parents: 5506
diff changeset
   536
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                ((DropTargetListener)dt).drop(new DropTargetDropEvent(dtc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                                                                      hots,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                                                                      currentDA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                                                      currentSA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                                                                      local != null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                if (dropStatus == STATUS_WAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    rejectDrop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                } else if (dropComplete == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    dropComplete(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                }
7493
010ad57ed8d1 6945178: SecurityException upon drag-and-drop
denis
parents: 5506
diff changeset
   549
                dropInProcess = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            rejectDrop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    protected int postDropTargetEvent(final Component component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                      final int x, final int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                                      final int dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                                      final int actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                                      final long[] formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                      final long nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                                      final int eventID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                                      final boolean dispatchType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        AppContext appContext = SunToolkit.targetToAppContext(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        EventDispatcher dispatcher =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            new EventDispatcher(this, dropAction, actions, formats, nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                dispatchType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        SunDropTargetEvent event =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            new SunDropTargetEvent(component, eventID, x, y, dispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (dispatchType == SunDropTargetContextPeer.DISPATCH_SYNC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            DataTransferer.getInstance().getToolkitThreadBlockedHandler().lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        // schedule callback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        SunToolkit.postEvent(appContext, event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        eventPosted(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        if (dispatchType == SunDropTargetContextPeer.DISPATCH_SYNC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            while (!dispatcher.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                DataTransferer.getInstance().getToolkitThreadBlockedHandler().enter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            DataTransferer.getInstance().getToolkitThreadBlockedHandler().unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            // return target's response
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            return dispatcher.getReturnValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * acceptDrag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    public synchronized void acceptDrag(int dragOperation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if (currentDT == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            throw new InvalidDnDOperationException("No Drag pending");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        currentDA = mapOperation(dragOperation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        if (currentDA != DnDConstants.ACTION_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            dragRejected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * rejectDrag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    public synchronized void rejectDrag() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        if (currentDT == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            throw new InvalidDnDOperationException("No Drag pending");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        dragRejected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * acceptDrop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    public synchronized void acceptDrop(int dropOperation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        if (dropOperation == DnDConstants.ACTION_NONE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            throw new IllegalArgumentException("invalid acceptDrop() action");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
23241
e59e85da457f 8029979: Allow multiple calls to DropTargetDropEvent.acceptDrop()
anthony
parents: 21280
diff changeset
   630
        if (dropStatus == STATUS_WAIT || dropStatus == STATUS_ACCEPT) {
e59e85da457f 8029979: Allow multiple calls to DropTargetDropEvent.acceptDrop()
anthony
parents: 21280
diff changeset
   631
            currentDA = currentA = mapOperation(dropOperation & currentSA);
e59e85da457f 8029979: Allow multiple calls to DropTargetDropEvent.acceptDrop()
anthony
parents: 21280
diff changeset
   632
e59e85da457f 8029979: Allow multiple calls to DropTargetDropEvent.acceptDrop()
anthony
parents: 21280
diff changeset
   633
            dropStatus   = STATUS_ACCEPT;
e59e85da457f 8029979: Allow multiple calls to DropTargetDropEvent.acceptDrop()
anthony
parents: 21280
diff changeset
   634
            dropComplete = false;
e59e85da457f 8029979: Allow multiple calls to DropTargetDropEvent.acceptDrop()
anthony
parents: 21280
diff changeset
   635
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            throw new InvalidDnDOperationException("invalid acceptDrop()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * reject Drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    public synchronized void rejectDrop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        if (dropStatus != STATUS_WAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            throw new InvalidDnDOperationException("invalid rejectDrop()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        dropStatus = STATUS_REJECT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
         * Fix for 4285634.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
         * The target rejected the drop means that it doesn't perform any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
         * drop action. This change is to make Solaris behavior consistent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
         * with Win32.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        dropComplete(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * mapOperation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    private int mapOperation(int operation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        int[] operations = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                DnDConstants.ACTION_MOVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                DnDConstants.ACTION_COPY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                DnDConstants.ACTION_LINK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        int   ret = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        for (int i = 0; i < operations.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            if ((operation & operations[i]) == operations[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    ret = operations[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * signal drop complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    public synchronized void dropComplete(boolean success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        if (dropStatus == STATUS_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            throw new InvalidDnDOperationException("No Drop pending");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        if (currentDTC != null) currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        currentDT  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        currentDTC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        currentT   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        currentA   = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        synchronized(_globalLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            currentJVMLocalSourceTransferable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        dropStatus   = STATUS_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        dropComplete = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            doDropDone(success, currentDA, local != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            // The native context is invalid after the drop is done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            // Clear the reference to prohibit access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            nativeDragContext = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    protected abstract void doDropDone(boolean success,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                                       int dropAction, boolean isLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    protected synchronized long getNativeDragContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        return nativeDragContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    protected void eventPosted(SunDropTargetEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    protected void eventProcessed(SunDropTargetEvent e, int returnValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                                  boolean dispatcherDone) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    protected static class EventDispatcher {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        private final SunDropTargetContextPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        // context fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        private final int dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        private final int actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        private final long[] formats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        private long nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        private final boolean dispatchType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        private boolean dispatcherDone = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        // dispatcher state fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        private int returnValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        // set of events to be dispatched by this dispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        private final HashSet eventSet = new HashSet(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        static final ToolkitThreadBlockedHandler handler =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            DataTransferer.getInstance().getToolkitThreadBlockedHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        EventDispatcher(SunDropTargetContextPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                        int dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                        int actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                        long[] formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                        long nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                        boolean dispatchType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            this.peer         = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            this.nativeCtxt   = nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            this.dropAction   = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            this.actions      = actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            this.formats =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                     (null == formats) ? null : Arrays.copyOf(formats, formats.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            this.dispatchType = dispatchType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        void dispatchEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            case SunDropTargetEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                dispatchEnterEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            case SunDropTargetEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                dispatchMotionEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            case SunDropTargetEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                dispatchExitEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            case SunDropTargetEvent.MOUSE_DROPPED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                dispatchDropEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                throw new InvalidDnDOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        private void dispatchEnterEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            synchronized (peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                // store the drop action here to track operation changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                peer.previousDA = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                // setup peer context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                peer.nativeDragContext = nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                peer.currentT          = formats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                peer.currentSA         = actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                peer.currentDA         = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                // To allow data retrieval.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                peer.dropStatus        = STATUS_ACCEPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                peer.dropComplete      = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                    peer.processEnterMessage(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                    peer.dropStatus        = STATUS_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                setReturnValue(peer.currentDA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        private void dispatchMotionEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            synchronized (peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                boolean operationChanged = peer.previousDA != dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                peer.previousDA = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                // setup peer context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                peer.nativeDragContext = nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                peer.currentT          = formats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                peer.currentSA         = actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                peer.currentDA         = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                // To allow data retrieval.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                peer.dropStatus        = STATUS_ACCEPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                peer.dropComplete      = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                    peer.processMotionMessage(e, operationChanged);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                    peer.dropStatus        = STATUS_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                setReturnValue(peer.currentDA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        private void dispatchExitEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            synchronized (peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                // setup peer context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                peer.nativeDragContext = nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                peer.processExitMessage(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        private void dispatchDropEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            synchronized (peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                // setup peer context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                peer.nativeDragContext = nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                peer.currentT          = formats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                peer.currentSA         = actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                peer.currentDA         = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                peer.processDropMessage(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        void setReturnValue(int ret) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            returnValue = ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        int getReturnValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            return returnValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        boolean isDone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            return eventSet.isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        void registerEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            handler.lock();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16705
diff changeset
   870
            if (!eventSet.add(e) && dndLog.isLoggable(PlatformLogger.Level.FINE)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   871
                dndLog.fine("Event is already registered: " + e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            handler.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        void unregisterEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            handler.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                if (!eventSet.remove(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                    // This event has already been unregistered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                if (eventSet.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                    if (!dispatcherDone && dispatchType == DISPATCH_SYNC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                        handler.exit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                    dispatcherDone = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                handler.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                peer.eventProcessed(e, returnValue, dispatcherDone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                 * Clear the reference to the native context if all copies of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                 * the original event are processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                if (dispatcherDone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                    nativeCtxt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                    // Fix for 6342381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                    peer.nativeDragContext = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        public void unregisterAllEvents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            Object[] events = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            handler.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                events = eventSet.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                handler.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            if (events != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                for (int i = 0; i < events.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                    unregisterEvent((SunDropTargetEvent)events[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
}