jdk/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 7493 010ad57ed8d1
child 13004 3774b4225633
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7493
diff changeset
     2
 * Copyright (c) 2000, 2010, 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;
5192
506ebd065f86 6887703: Unsigned applet can retrieve the dragged information before drop action occur
denis
parents: 3938
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) {
5192
506ebd065f86 6887703: Unsigned applet can retrieve the dragged information before drop action occur
denis
parents: 3938
diff changeset
   229
                sm.checkSystemClipboardAccess();
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();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        Object ret = getNativeData(format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (ret instanceof byte[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                return DataTransferer.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    translateBytes((byte[])ret, df, format, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                throw new InvalidDnDOperationException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        } else if (ret instanceof InputStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                return DataTransferer.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    translateStream((InputStream)ret, df, format, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                throw new InvalidDnDOperationException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            throw new IOException("no native data was transfered");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    protected abstract Object getNativeData(long format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
      throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @return if the transfer is a local one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public boolean isTransferableJVMLocal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return local != null || getJVMLocalSourceTransferable() != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    private int handleEnterMessage(final Component component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                                   final int x, final int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                   final int dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                                   final int actions, final long[] formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                                   final long nativeCtxt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return postDropTargetEvent(component, x, y, dropAction, actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                   formats, nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                   SunDropTargetEvent.MOUSE_ENTERED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                   SunDropTargetContextPeer.DISPATCH_SYNC);
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
     * actual processing on EventQueue Thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    protected void processEnterMessage(SunDropTargetEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        Component  c    = (Component)event.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        DropTarget dt   = c.getDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        Point      hots = event.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        local = getJVMLocalSourceTransferable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (currentDTC != null) { // some wreckage from last time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            currentDTC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (c.isShowing() && dt != null && dt.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            currentDT  = dt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            currentDTC = currentDT.getDropTargetContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            currentDTC.addNotify(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            currentA   = dt.getDefaultActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                ((DropTargetListener)dt).dragEnter(new DropTargetDragEvent(currentDTC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                                                                           hots,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                                                                           currentDA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                                                                           currentSA));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            currentDT  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            currentDTC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            currentDA   = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            currentSA   = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            currentA   = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
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
     * upcall to handle exit messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    private void handleExitMessage(final Component component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                   final long nativeCtxt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
         * Even though the return value is irrelevant for this event, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
         * dispatched synchronously to fix 4393148 properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        postDropTargetEvent(component, 0, 0, DnDConstants.ACTION_NONE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                            DnDConstants.ACTION_NONE, null, nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                            SunDropTargetEvent.MOUSE_EXITED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                            SunDropTargetContextPeer.DISPATCH_SYNC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
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
    protected void processExitMessage(SunDropTargetEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        Component         c   = (Component)event.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        DropTarget        dt  = c.getDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        DropTargetContext dtc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (dt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            currentDT = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            currentT  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            if (currentDTC != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            currentDTC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (dt != currentDT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            if (currentDTC != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            currentDT  = dt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            currentDTC = dt.getDropTargetContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            currentDTC.addNotify(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        dtc = currentDTC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (dt.isActive()) try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            ((DropTargetListener)dt).dragExit(new DropTargetEvent(dtc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            currentA  = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            currentSA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            currentDT = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            currentT  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            currentDTC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            local = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            dragRejected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    private int handleMotionMessage(final Component component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                                    final int x, final int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                                    final int dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                    final int actions, final long[] formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                    final long nativeCtxt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return postDropTargetEvent(component, x, y, dropAction, actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                   formats, nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                   SunDropTargetEvent.MOUSE_DRAGGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                   SunDropTargetContextPeer.DISPATCH_SYNC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
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
    protected void processMotionMessage(SunDropTargetEvent event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                                      boolean operationChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        Component         c    = (Component)event.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        Point             hots = event.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        int               id   = event.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        DropTarget        dt   = c.getDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        DropTargetContext dtc  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        if (c.isShowing() && (dt != null) && dt.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            if (currentDT != dt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                if (currentDTC != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                currentDT  = dt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                currentDTC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            dtc = currentDT.getDropTargetContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if (dtc != currentDTC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                if (currentDTC != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                currentDTC = dtc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                currentDTC.addNotify(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            currentA = currentDT.getDefaultActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                DropTargetDragEvent dtde = new DropTargetDragEvent(dtc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                                                   hots,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                                                   currentDA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                                                   currentSA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                DropTargetListener dtl = (DropTargetListener)dt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                if (operationChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    dtl.dropActionChanged(dtde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    dtl.dragOver(dtde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                if (dragRejected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
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
     * upcall to handle the Drop message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    private void handleDropMessage(final Component component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                                   final int x, final int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                   final int dropAction, final int actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                   final long[] formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                   final long nativeCtxt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        postDropTargetEvent(component, x, y, dropAction, actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                            formats, nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                            SunDropTargetEvent.MOUSE_DROPPED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                            !SunDropTargetContextPeer.DISPATCH_SYNC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    protected void processDropMessage(SunDropTargetEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        Component  c    = (Component)event.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        Point      hots = event.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        DropTarget dt   = c.getDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        dropStatus   = STATUS_WAIT; // drop pending ACK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        dropComplete = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        if (c.isShowing() && dt != null && dt.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            DropTargetContext dtc = dt.getDropTargetContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            currentDT = dt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            if (currentDTC != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            currentDTC = dtc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            currentDTC.addNotify(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            currentA = dt.getDefaultActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            synchronized(_globalLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                if ((local = getJVMLocalSourceTransferable()) != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                    setCurrentJVMLocalSourceTransferable(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
7493
010ad57ed8d1 6945178: SecurityException upon drag-and-drop
denis
parents: 5506
diff changeset
   534
            dropInProcess = true;
010ad57ed8d1 6945178: SecurityException upon drag-and-drop
denis
parents: 5506
diff changeset
   535
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                ((DropTargetListener)dt).drop(new DropTargetDropEvent(dtc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                                                                      hots,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                                                                      currentDA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                                                                      currentSA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                                                      local != null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                if (dropStatus == STATUS_WAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    rejectDrop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                } else if (dropComplete == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    dropComplete(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                }
7493
010ad57ed8d1 6945178: SecurityException upon drag-and-drop
denis
parents: 5506
diff changeset
   548
                dropInProcess = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            rejectDrop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    protected int postDropTargetEvent(final Component component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                                      final int x, final int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                      final int dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                                      final int actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                                      final long[] formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                                      final long nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                      final int eventID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                                      final boolean dispatchType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        AppContext appContext = SunToolkit.targetToAppContext(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        EventDispatcher dispatcher =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            new EventDispatcher(this, dropAction, actions, formats, nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                dispatchType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        SunDropTargetEvent event =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            new SunDropTargetEvent(component, eventID, x, y, dispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        if (dispatchType == SunDropTargetContextPeer.DISPATCH_SYNC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            DataTransferer.getInstance().getToolkitThreadBlockedHandler().lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        // schedule callback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        SunToolkit.postEvent(appContext, event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        eventPosted(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        if (dispatchType == SunDropTargetContextPeer.DISPATCH_SYNC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            while (!dispatcher.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                DataTransferer.getInstance().getToolkitThreadBlockedHandler().enter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            DataTransferer.getInstance().getToolkitThreadBlockedHandler().unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            // return target's response
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            return dispatcher.getReturnValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
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
     * acceptDrag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    public synchronized void acceptDrag(int dragOperation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        if (currentDT == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            throw new InvalidDnDOperationException("No Drag pending");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        currentDA = mapOperation(dragOperation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        if (currentDA != DnDConstants.ACTION_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            dragRejected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        }
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
     * rejectDrag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    public synchronized void rejectDrag() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        if (currentDT == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            throw new InvalidDnDOperationException("No Drag pending");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        dragRejected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * acceptDrop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    public synchronized void acceptDrop(int dropOperation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        if (dropOperation == DnDConstants.ACTION_NONE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            throw new IllegalArgumentException("invalid acceptDrop() action");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        if (dropStatus != STATUS_WAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            throw new InvalidDnDOperationException("invalid acceptDrop()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        currentDA = currentA = mapOperation(dropOperation & currentSA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        dropStatus   = STATUS_ACCEPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        dropComplete = false;
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
     * reject Drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    public synchronized void rejectDrop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        if (dropStatus != STATUS_WAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            throw new InvalidDnDOperationException("invalid rejectDrop()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        dropStatus = STATUS_REJECT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
         * Fix for 4285634.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
         * The target rejected the drop means that it doesn't perform any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
         * drop action. This change is to make Solaris behavior consistent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
         * with Win32.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        dropComplete(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * mapOperation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    private int mapOperation(int operation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        int[] operations = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                DnDConstants.ACTION_MOVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                DnDConstants.ACTION_COPY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                DnDConstants.ACTION_LINK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        int   ret = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        for (int i = 0; i < operations.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            if ((operation & operations[i]) == operations[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                    ret = operations[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * signal drop complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    public synchronized void dropComplete(boolean success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        if (dropStatus == STATUS_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            throw new InvalidDnDOperationException("No Drop pending");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        if (currentDTC != null) currentDTC.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        currentDT  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        currentDTC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        currentT   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        currentA   = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        synchronized(_globalLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            currentJVMLocalSourceTransferable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        dropStatus   = STATUS_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        dropComplete = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            doDropDone(success, currentDA, local != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            currentDA = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            // The native context is invalid after the drop is done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            // Clear the reference to prohibit access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            nativeDragContext = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    protected abstract void doDropDone(boolean success,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                                       int dropAction, boolean isLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    protected synchronized long getNativeDragContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        return nativeDragContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    protected void eventPosted(SunDropTargetEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    protected void eventProcessed(SunDropTargetEvent e, int returnValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                                  boolean dispatcherDone) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    protected static class EventDispatcher {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        private final SunDropTargetContextPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        // context fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        private final int dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        private final int actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        private final long[] formats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        private long nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        private final boolean dispatchType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        private boolean dispatcherDone = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        // dispatcher state fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        private int returnValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        // set of events to be dispatched by this dispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        private final HashSet eventSet = new HashSet(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        static final ToolkitThreadBlockedHandler handler =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            DataTransferer.getInstance().getToolkitThreadBlockedHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        EventDispatcher(SunDropTargetContextPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                        int dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                        int actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                        long[] formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                        long nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                        boolean dispatchType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            this.peer         = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            this.nativeCtxt   = nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            this.dropAction   = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            this.actions      = actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            this.formats =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                     (null == formats) ? null : Arrays.copyOf(formats, formats.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            this.dispatchType = dispatchType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        void dispatchEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            case SunDropTargetEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                dispatchEnterEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            case SunDropTargetEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                dispatchMotionEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            case SunDropTargetEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                dispatchExitEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            case SunDropTargetEvent.MOUSE_DROPPED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                dispatchDropEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                throw new InvalidDnDOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        private void dispatchEnterEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            synchronized (peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                // store the drop action here to track operation changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                peer.previousDA = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                // setup peer context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                peer.nativeDragContext = nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                peer.currentT          = formats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                peer.currentSA         = actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                peer.currentDA         = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                // To allow data retrieval.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                peer.dropStatus        = STATUS_ACCEPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                peer.dropComplete      = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                    peer.processEnterMessage(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                    peer.dropStatus        = STATUS_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                setReturnValue(peer.currentDA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        private void dispatchMotionEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            synchronized (peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                boolean operationChanged = peer.previousDA != dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                peer.previousDA = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                // setup peer context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                peer.nativeDragContext = nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                peer.currentT          = formats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                peer.currentSA         = actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                peer.currentDA         = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                // To allow data retrieval.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                peer.dropStatus        = STATUS_ACCEPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                peer.dropComplete      = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                    peer.processMotionMessage(e, operationChanged);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                    peer.dropStatus        = STATUS_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                setReturnValue(peer.currentDA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        private void dispatchExitEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            synchronized (peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                // setup peer context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                peer.nativeDragContext = nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                peer.processExitMessage(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        private void dispatchDropEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            synchronized (peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                // setup peer context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                peer.nativeDragContext = nativeCtxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                peer.currentT          = formats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                peer.currentSA         = actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                peer.currentDA         = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                peer.processDropMessage(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        void setReturnValue(int ret) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            returnValue = ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        int getReturnValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            return returnValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        boolean isDone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            return eventSet.isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        void registerEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            handler.lock();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   869
            if (!eventSet.add(e) && dndLog.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   870
                dndLog.fine("Event is already registered: " + e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            handler.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        void unregisterEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            handler.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                if (!eventSet.remove(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                    // This event has already been unregistered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                if (eventSet.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                    if (!dispatcherDone && dispatchType == DISPATCH_SYNC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                        handler.exit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                    dispatcherDone = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                handler.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                peer.eventProcessed(e, returnValue, dispatcherDone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                 * Clear the reference to the native context if all copies of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                 * the original event are processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                if (dispatcherDone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                    nativeCtxt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                    // Fix for 6342381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                    peer.nativeDragContext = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
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
        public void unregisterAllEvents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            Object[] events = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            handler.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                events = eventSet.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                handler.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            if (events != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                for (int i = 0; i < events.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                    unregisterEvent((SunDropTargetEvent)events[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                }
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
}