jdk/src/share/classes/java/awt/dnd/DropTarget.java
author dav
Thu, 29 May 2008 13:48:51 +0400
changeset 638 69a80895db21
parent 109 ddfda358e547
child 5506 202f599c92aa
permissions -rw-r--r--
6691328: DragSourceContext returns unexpected cursor Summary: make the code to be executed if other options don't suit Reviewed-by: dcherepanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  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
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 java.awt.dnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.TooManyListenersException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.HeadlessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.event.ActionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.datatransfer.FlavorMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.datatransfer.SystemFlavorMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.swing.Timer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.peer.LightweightPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.dnd.peer.DropTargetPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * The <code>DropTarget</code> is associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * with a <code>Component</code> when that <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * wishes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * to accept drops during Drag and Drop operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *  Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <code>DropTarget</code> is associated with a <code>FlavorMap</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * The default <code>FlavorMap</code> hereafter designates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <code>FlavorMap</code> returned by <code>SystemFlavorMap.getDefaultFlavorMap()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
public class DropTarget implements DropTargetListener, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final long serialVersionUID = -6283860791671019047L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Creates a new DropTarget given the <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * to associate itself with, an <code>int</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * the default acceptable action(s) to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * support, a <code>DropTargetListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * to handle event processing, a <code>boolean</code> indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * if the <code>DropTarget</code> is currently accepting drops, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * The Component will receive drops only if it is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param ops       The default acceptable actions for this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param act       Is the <code>DropTarget</code> accepting drops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *            returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public DropTarget(Component c, int ops, DropTargetListener dtl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                      boolean act, FlavorMap fm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        throws HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        component = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        setDefaultActions(ops);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (dtl != null) try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            addDropTargetListener(dtl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        } catch (TooManyListenersException tmle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            // do nothing!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            c.setDropTarget(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            setActive(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   113
        if (fm != null) {
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   114
            flavorMap = fm;
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   115
        } else {
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   116
            flavorMap = SystemFlavorMap.getDefaultFlavorMap();
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   117
        }
2
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
     * Creates a <code>DropTarget</code> given the <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * to associate itself with, an <code>int</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * the default acceptable action(s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * to support, a <code>DropTargetListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * to handle event processing, and a <code>boolean</code> indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * if the <code>DropTarget</code> is currently accepting drops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * The Component will receive drops only if it is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param ops       The default acceptable actions for this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param act       Is the <code>DropTarget</code> accepting drops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *            returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public DropTarget(Component c, int ops, DropTargetListener dtl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                      boolean act)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        throws HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        this(c, ops, dtl, act, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Creates a <code>DropTarget</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *            returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public DropTarget() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this(null, DnDConstants.ACTION_COPY_OR_MOVE, null, true, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Creates a <code>DropTarget</code> given the <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * to associate itself with, and the <code>DropTargetListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * to handle event processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * The Component will receive drops only if it is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *            returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public DropTarget(Component c, DropTargetListener dtl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        throws HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        this(c, DnDConstants.ACTION_COPY_OR_MOVE, dtl, true, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Creates a <code>DropTarget</code> given the <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * to associate itself with, an <code>int</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * the default acceptable action(s) to support, and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * <code>DropTargetListener</code> to handle event processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * The Component will receive drops only if it is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param ops       The default acceptable actions for this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *            returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public DropTarget(Component c, int ops, DropTargetListener dtl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        throws HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        this(c, ops, dtl, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Note: this interface is required to permit the safe association
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * of a DropTarget with a Component in one of two ways, either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <code> component.setDropTarget(droptarget); </code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * or <code> droptarget.setComponent(component); </code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * The Component will receive drops only if it is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param c The new <code>Component</code> this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * is to be associated with.<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public synchronized void setComponent(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (component == c || component != null && component.equals(c))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        Component     old;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        ComponentPeer oldPeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if ((old = component) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            clearAutoscroll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            component = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            if (componentPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                oldPeer = componentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                removeNotify(componentPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            old.setDropTarget(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if ((component = c) != null) try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            c.setDropTarget(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        } catch (Exception e) { // undo the change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                old.setDropTarget(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                addNotify(oldPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Gets the <code>Component</code> associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * with this <code>DropTarget</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @return the current <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public synchronized Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Sets the default acceptable actions for this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param ops the default actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @see java.awt.dnd.DnDConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public void setDefaultActions(int ops) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        getDropTargetContext().setTargetActions(ops & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Called by DropTargetContext.setTargetActions()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * with appropriate synchronization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    void doSetDefaultActions(int ops) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        actions = ops;
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
     * Gets an <code>int</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * current action(s) supported by this <code>DropTarget</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @return the current default actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public int getDefaultActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Sets the DropTarget active if <code>true</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * inactive if <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param isActive sets the <code>DropTarget</code> (in)active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public synchronized void setActive(boolean isActive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (isActive != active) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            active = isActive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (!active) clearAutoscroll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Reports whether or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * is currently active (ready to accept drops).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @return <CODE>true</CODE> if active, <CODE>false</CODE> if not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    public boolean isActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return active;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Adds a new <code>DropTargetListener</code> (UNICAST SOURCE).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @param dtl The new <code>DropTargetListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @throws <code>TooManyListenersException</code> if a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * <code>DropTargetListener</code> is already added to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * <code>DropTarget</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public synchronized void addDropTargetListener(DropTargetListener dtl) throws TooManyListenersException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (dtl == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (equals(dtl)) throw new IllegalArgumentException("DropTarget may not be its own Listener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if (dtListener == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            dtListener = dtl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            throw new TooManyListenersException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * Removes the current <code>DropTargetListener</code> (UNICAST SOURCE).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @param dtl the DropTargetListener to deregister.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public synchronized void removeDropTargetListener(DropTargetListener dtl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (dtl != null && dtListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            if(dtListener.equals(dtl))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                dtListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                throw new IllegalArgumentException("listener mismatch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Calls <code>dragEnter</code> on the registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * <code>DropTargetListener</code> and passes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * the specified <code>DropTargetDragEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Has no effect if this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * is not active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @param dtde the <code>DropTargetDragEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @throws NullPointerException if this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *         is active and <code>dtde</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @see #isActive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public synchronized void dragEnter(DropTargetDragEvent dtde) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if (!active) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        if (dtListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            dtListener.dragEnter(dtde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            dtde.getDropTargetContext().setTargetActions(DnDConstants.ACTION_NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        initializeAutoscrolling(dtde.getLocation());
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
     * Calls <code>dragOver</code> on the registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * <code>DropTargetListener</code> and passes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * the specified <code>DropTargetDragEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * Has no effect if this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * is not active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @param dtde the <code>DropTargetDragEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @throws NullPointerException if this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *         is active and <code>dtde</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @see #isActive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public synchronized void dragOver(DropTargetDragEvent dtde) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (!active) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (dtListener != null && active) dtListener.dragOver(dtde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        updateAutoscroll(dtde.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * Calls <code>dropActionChanged</code> on the registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * <code>DropTargetListener</code> and passes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * the specified <code>DropTargetDragEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Has no effect if this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * is not active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @param dtde the <code>DropTargetDragEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @throws NullPointerException if this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *         is active and <code>dtde</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @see #isActive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public synchronized void dropActionChanged(DropTargetDragEvent dtde) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (!active) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (dtListener != null) dtListener.dropActionChanged(dtde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        updateAutoscroll(dtde.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Calls <code>dragExit</code> on the registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * <code>DropTargetListener</code> and passes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * the specified <code>DropTargetEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * Has no effect if this <code>DropTarget</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * is not active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * This method itself does not throw any exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * for null parameter but for exceptions thrown by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * the respective method of the listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @param dte the <code>DropTargetEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @see #isActive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public synchronized void dragExit(DropTargetEvent dte) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (!active) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (dtListener != null && active) dtListener.dragExit(dte);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        clearAutoscroll();
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
     * Calls <code>drop</code> on the registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * <code>DropTargetListener</code> and passes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * the specified <code>DropTargetDropEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * if this <code>DropTarget</code> is active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @param dtde the <code>DropTargetDropEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @throws NullPointerException if <code>dtde</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *         and at least one of the following is true: this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *         <code>DropTarget</code> is not active, or there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *         no a <code>DropTargetListener</code> registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @see #isActive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    public synchronized void drop(DropTargetDropEvent dtde) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        clearAutoscroll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if (dtListener != null && active)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            dtListener.drop(dtde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        else { // we should'nt get here ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            dtde.rejectDrop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Gets the <code>FlavorMap</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * associated with this <code>DropTarget</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * If no <code>FlavorMap</code> has been set for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * <code>DropTarget</code>, it is associated with the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * <code>FlavorMap</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @return the FlavorMap for this DropTarget
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public FlavorMap getFlavorMap() { return flavorMap; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * Sets the <code>FlavorMap</code> associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * with this <code>DropTarget</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @param fm the new <code>FlavorMap</code>, or null to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * associate the default FlavorMap with this DropTarget.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public void setFlavorMap(FlavorMap fm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        flavorMap = fm == null ? SystemFlavorMap.getDefaultFlavorMap() : fm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Notify the DropTarget that it has been associated with a Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     **********************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * This method is usually called from java.awt.Component.addNotify() of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * the Component associated with this DropTarget to notify the DropTarget
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * that a ComponentPeer has been associated with that Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * Calling this method, other than to notify this DropTarget of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * association of the ComponentPeer with the Component may result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * a malfunction of the DnD system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     **********************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @param peer The Peer of the Component we are associated with!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    public void addNotify(ComponentPeer peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        if (peer == componentPeer) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        componentPeer = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        for (Component c = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
             c != null && peer instanceof LightweightPeer; c = c.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            peer = c.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        if (peer instanceof DropTargetPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            nativePeer = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            ((DropTargetPeer)peer).addDropTarget(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            nativePeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * Notify the DropTarget that it has been disassociated from a Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     **********************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * This method is usually called from java.awt.Component.removeNotify() of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * the Component associated with this DropTarget to notify the DropTarget
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * that a ComponentPeer has been disassociated with that Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * Calling this method, other than to notify this DropTarget of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * disassociation of the ComponentPeer from the Component may result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * a malfunction of the DnD system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     **********************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @param peer The Peer of the Component we are being disassociated from!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public void removeNotify(ComponentPeer peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        if (nativePeer != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            ((DropTargetPeer)nativePeer).removeDropTarget(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        componentPeer = nativePeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * Gets the <code>DropTargetContext</code> associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * with this <code>DropTarget</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @return the <code>DropTargetContext</code> associated with this <code>DropTarget</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public DropTargetContext getDropTargetContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        return dropTargetContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * Creates the DropTargetContext associated with this DropTarget.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * Subclasses may override this method to instantiate their own
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * DropTargetContext subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * This call is typically *only* called by the platform's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * DropTargetContextPeer as a drag operation encounters this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * DropTarget. Accessing the Context while no Drag is current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * has undefined results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    protected DropTargetContext createDropTargetContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return new DropTargetContext(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * Serializes this <code>DropTarget</code>. Performs default serialization,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * and then writes out this object's <code>DropTargetListener</code> if and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * only if it can be serialized. If not, <code>null</code> is written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @serialData The default serializable fields, in alphabetical order,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *             followed by either a <code>DropTargetListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *             instance, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        s.writeObject(SerializationTester.test(dtListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                      ? dtListener : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * Deserializes this <code>DropTarget</code>. This method first performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * default deserialization for all non-<code>transient</code> fields. An
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * attempt is then made to deserialize this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * <code>DropTargetListener</code> as well. This is first attempted by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * deserializing the field <code>dtListener</code>, because, in releases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * prior to 1.4, a non-<code>transient</code> field of this name stored the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * <code>DropTargetListener</code>. If this fails, the next object in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * stream is used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        throws ClassNotFoundException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        ObjectInputStream.GetField f = s.readFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            dropTargetContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                (DropTargetContext)f.get("dropTargetContext", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            // Pre-1.4 support. 'dropTargetContext' was previoulsy transient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        if (dropTargetContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            dropTargetContext = createDropTargetContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        component = (Component)f.get("component", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        actions = f.get("actions", DnDConstants.ACTION_COPY_OR_MOVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        active = f.get("active", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        // Pre-1.4 support. 'dtListener' was previously non-transient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            dtListener = (DropTargetListener)f.get("dtListener", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            // 1.4-compatible byte stream. 'dtListener' was written explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            dtListener = (DropTargetListener)s.readObject();
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
    /*********************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * this protected nested class implements autoscrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    protected static class DropTargetAutoScroller implements ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
         * construct a DropTargetAutoScroller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
         * @param c the <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
         * @param p the <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        protected DropTargetAutoScroller(Component c, Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            component  = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            autoScroll = (Autoscroll)component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            Toolkit t  = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            Integer    initial  = Integer.valueOf(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            Integer    interval = Integer.valueOf(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                initial = (Integer)t.getDesktopProperty("DnD.Autoscroll.initialDelay");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                interval = (Integer)t.getDesktopProperty("DnD.Autoscroll.interval");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            timer  = new Timer(interval.intValue(), this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            timer.setCoalesce(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            timer.setInitialDelay(initial.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            locn = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            prev = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                hysteresis = ((Integer)t.getDesktopProperty("DnD.Autoscroll.cursorHysteresis")).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            timer.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
         * update the geometry of the autoscroll region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        private void updateRegion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
           Insets    i    = autoScroll.getAutoscrollInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
           Dimension size = component.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
           if (size.width != outer.width || size.height != outer.height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                outer.reshape(0, 0, size.width, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
           if (inner.x != i.left || inner.y != i.top)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                inner.setLocation(i.left, i.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
           int newWidth  = size.width -  (i.left + i.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
           int newHeight = size.height - (i.top  + i.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
           if (newWidth != inner.width || newHeight != inner.height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                inner.setSize(newWidth, newHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
         * cause autoscroll to occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
         * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
         * @param newLocn the <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        protected synchronized void updateLocation(Point newLocn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            prev = locn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            locn = newLocn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            if (Math.abs(locn.x - prev.x) > hysteresis ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                Math.abs(locn.y - prev.y) > hysteresis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                if (timer.isRunning()) timer.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                if (!timer.isRunning()) timer.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
         * cause autoscrolling to stop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        protected void stop() { timer.stop(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
         * cause autoscroll to occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
         * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
         * @param e the <code>ActionEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        public synchronized void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            updateRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            if (outer.contains(locn) && !inner.contains(locn))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                autoScroll.autoscroll(locn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
         * fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        private Component  component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        private Autoscroll autoScroll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        private Timer      timer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        private Point      locn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        private Point      prev;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        private Rectangle  outer = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        private Rectangle  inner = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        private int        hysteresis = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    /*********************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * create an embedded autoscroller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * @param c the <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @param p the <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    protected DropTargetAutoScroller createDropTargetAutoScroller(Component c, Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        return new DropTargetAutoScroller(c, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * initialize autoscrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * @param p the <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    protected void initializeAutoscrolling(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        if (component == null || !(component instanceof Autoscroll)) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        autoScroller = createDropTargetAutoScroller(component, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * update autoscrolling with current cursor locn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * @param dragCursorLocn the <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    protected void updateAutoscroll(Point dragCursorLocn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        if (autoScroller != null) autoScroller.updateLocation(dragCursorLocn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * clear autoscrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    protected void clearAutoscroll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        if (autoScroller != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            autoScroller.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            autoScroller = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * The DropTargetContext associated with this DropTarget.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    private DropTargetContext dropTargetContext = createDropTargetContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * The Component associated with this DropTarget.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    private Component component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * That Component's  Peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    private transient ComponentPeer componentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * That Component's "native" Peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    private transient ComponentPeer nativePeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * Default permissible actions supported by this DropTarget.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * @see #setDefaultActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * @see #getDefaultActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    int     actions = DnDConstants.ACTION_COPY_OR_MOVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * <code>true</code> if the DropTarget is accepting Drag & Drop operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    boolean active = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * the auto scrolling object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    private transient DropTargetAutoScroller autoScroller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * The delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    private transient DropTargetListener dtListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * The FlavorMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   857
    private transient FlavorMap flavorMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
}