001 /*
002 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.awt.dnd;
027
028 import java.util.EventListener;
029
030 import java.awt.dnd.DropTargetDragEvent;
031 import java.awt.dnd.DropTargetDropEvent;
032
033 /**
034 * The <code>DropTargetListener</code> interface
035 * is the callback interface used by the
036 * <code>DropTarget</code> class to provide
037 * notification of DnD operations that involve
038 * the subject <code>DropTarget</code>. Methods of
039 * this interface may be implemented to provide
040 * "drag under" visual feedback to the user throughout
041 * the Drag and Drop operation.
042 * <p>
043 * Create a listener object by implementing the interface and then register it
044 * with a <code>DropTarget</code>. When the drag enters, moves over, or exits
045 * the operable part of the drop site for that <code>DropTarget</code>, when
046 * the drop action changes, and when the drop occurs, the relevant method in
047 * the listener object is invoked, and the <code>DropTargetEvent</code> is
048 * passed to it.
049 * <p>
050 * The operable part of the drop site for the <code>DropTarget</code> is
051 * the part of the associated <code>Component</code>'s geometry that is not
052 * obscured by an overlapping top-level window or by another
053 * <code>Component</code> higher in the Z-order that has an associated active
054 * <code>DropTarget</code>.
055 * <p>
056 * During the drag, the data associated with the current drag operation can be
057 * retrieved by calling <code>getTransferable()</code> on
058 * <code>DropTargetDragEvent</code> instances passed to the listener's
059 * methods.
060 * <p>
061 * Note that <code>getTransferable()</code> on the
062 * <code>DropTargetDragEvent</code> instance should only be called within the
063 * respective listener's method and all the necessary data should be retrieved
064 * from the returned <code>Transferable</code> before that method returns.
065 *
066 * @version 1.31, 06/05/07
067 * @since 1.2
068 */
069
070 public interface DropTargetListener extends EventListener {
071
072 /**
073 * Called while a drag operation is ongoing, when the mouse pointer enters
074 * the operable part of the drop site for the <code>DropTarget</code>
075 * registered with this listener.
076 *
077 * @param dtde the <code>DropTargetDragEvent</code>
078 */
079
080 void dragEnter(DropTargetDragEvent dtde);
081
082 /**
083 * Called when a drag operation is ongoing, while the mouse pointer is still
084 * over the operable part of the drop site for the <code>DropTarget</code>
085 * registered with this listener.
086 *
087 * @param dtde the <code>DropTargetDragEvent</code>
088 */
089
090 void dragOver(DropTargetDragEvent dtde);
091
092 /**
093 * Called if the user has modified
094 * the current drop gesture.
095 * <P>
096 * @param dtde the <code>DropTargetDragEvent</code>
097 */
098
099 void dropActionChanged(DropTargetDragEvent dtde);
100
101 /**
102 * Called while a drag operation is ongoing, when the mouse pointer has
103 * exited the operable part of the drop site for the
104 * <code>DropTarget</code> registered with this listener.
105 *
106 * @param dte the <code>DropTargetEvent</code>
107 */
108
109 void dragExit(DropTargetEvent dte);
110
111 /**
112 * Called when the drag operation has terminated with a drop on
113 * the operable part of the drop site for the <code>DropTarget</code>
114 * registered with this listener.
115 * <p>
116 * This method is responsible for undertaking
117 * the transfer of the data associated with the
118 * gesture. The <code>DropTargetDropEvent</code>
119 * provides a means to obtain a <code>Transferable</code>
120 * object that represents the data object(s) to
121 * be transfered.<P>
122 * From this method, the <code>DropTargetListener</code>
123 * shall accept or reject the drop via the
124 * acceptDrop(int dropAction) or rejectDrop() methods of the
125 * <code>DropTargetDropEvent</code> parameter.
126 * <P>
127 * Subsequent to acceptDrop(), but not before,
128 * <code>DropTargetDropEvent</code>'s getTransferable()
129 * method may be invoked, and data transfer may be
130 * performed via the returned <code>Transferable</code>'s
131 * getTransferData() method.
132 * <P>
133 * At the completion of a drop, an implementation
134 * of this method is required to signal the success/failure
135 * of the drop by passing an appropriate
136 * <code>boolean</code> to the <code>DropTargetDropEvent</code>'s
137 * dropComplete(boolean success) method.
138 * <P>
139 * Note: The data transfer should be completed before the call to the
140 * <code>DropTargetDropEvent</code>'s dropComplete(boolean success) method.
141 * After that, a call to the getTransferData() method of the
142 * <code>Transferable</code> returned by
143 * <code>DropTargetDropEvent.getTransferable()</code> is guaranteed to
144 * succeed only if the data transfer is local; that is, only if
145 * <code>DropTargetDropEvent.isLocalTransfer()</code> returns
146 * <code>true</code>. Otherwise, the behavior of the call is
147 * implementation-dependent.
148 * <P>
149 * @param dtde the <code>DropTargetDropEvent</code>
150 */
151
152 void drop(DropTargetDropEvent dtde);
153 }
|