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