1. /*
  2. * @(#)DropTargetListener.java 1.22 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt.dnd;
  8. import java.util.EventListener;
  9. import java.awt.dnd.DropTargetContext;
  10. import java.awt.dnd.DropTargetDragEvent;
  11. import java.awt.dnd.DropTargetDropEvent;
  12. /**
  13. * The <code>DropTargetListener</code> interface
  14. * is the callback interface used by the
  15. * <code>DropTarget</code> class to provide
  16. * notification of DnD operations that involve
  17. * the subject <code>DropTarget</code>. Methods of
  18. * this interface may be implemented to provide
  19. * "drag under" visual feedback to the user throughout
  20. * the Drag and Drop operation.
  21. * <p>
  22. * Create a listener object by implementing the interface and then register it
  23. * with a <code>DropTarget</code>. When the drag enters, moves over, or exits
  24. * the operable part of the drop site for that <code>DropTarget</code>, when
  25. * the drop action changes, and when the drop occurs, the relevant method in
  26. * the listener object is invoked, and the <code>DropTargetEvent</code> is
  27. * passed to it.
  28. * <p>
  29. * The operable part of the drop site for the <code>DropTarget</code> is
  30. * the part of the associated <code>Component</code>'s geometry that is not
  31. * obscured by an overlapping top-level window or by another
  32. * <code>Component</code> higher in the Z-order that has an associated active
  33. * <code>DropTarget</code>.
  34. * <p>
  35. * During the drag, the data associated with the current drag operation can be
  36. * retrieved by calling <code>getTransferable()</code> on
  37. * <code>DropTargetDragEvent</code> instances passed to the listener's
  38. * methods.
  39. * <p>
  40. * Note that <code>getTransferable()</code> on the
  41. * <code>DropTargetDragEvent</code> instance should only be called within the
  42. * respective listener's method and all the necessary data should be retrieved
  43. * from the returned <code>Transferable</code> before that method returns.
  44. *
  45. * @version 1.22, 12/19/03
  46. * @since 1.2
  47. */
  48. public interface DropTargetListener extends EventListener {
  49. /**
  50. * Called while a drag operation is ongoing, when the mouse pointer enters
  51. * the operable part of the drop site for the <code>DropTarget</code>
  52. * registered with this listener.
  53. *
  54. * @param dtde the <code>DropTargetDragEvent</code>
  55. */
  56. void dragEnter(DropTargetDragEvent dtde);
  57. /**
  58. * Called when a drag operation is ongoing, while the mouse pointer is still
  59. * over the operable part of the drop site for the <code>DropTarget</code>
  60. * registered with this listener.
  61. *
  62. * @param dtde the <code>DropTargetDragEvent</code>
  63. */
  64. void dragOver(DropTargetDragEvent dtde);
  65. /**
  66. * Called if the user has modified
  67. * the current drop gesture.
  68. * <P>
  69. * @param dtde the <code>DropTargetDragEvent</code>
  70. */
  71. void dropActionChanged(DropTargetDragEvent dtde);
  72. /**
  73. * Called while a drag operation is ongoing, when the mouse pointer has
  74. * exited the operable part of the drop site for the
  75. * <code>DropTarget</code> registered with this listener.
  76. *
  77. * @param dte the <code>DropTargetEvent</code>
  78. */
  79. void dragExit(DropTargetEvent dte);
  80. /**
  81. * Called when the drag operation has terminated with a drop on
  82. * the operable part of the drop site for the <code>DropTarget</code>
  83. * registered with this listener.
  84. * <p>
  85. * This method is responsible for undertaking
  86. * the transfer of the data associated with the
  87. * gesture. The <code>DropTargetDropEvent</code>
  88. * provides a means to obtain a <code>Transferable</code>
  89. * object that represents the data object(s) to
  90. * be transfered.<P>
  91. * From this method, the <code>DropTargetListener</code>
  92. * shall accept or reject the drop via the
  93. * acceptDrop(int dropAction) or rejectDrop() methods of the
  94. * <code>DropTargetDropEvent</code> parameter.
  95. * <P>
  96. * Subsequent to acceptDrop(), but not before,
  97. * <code>DropTargetDropEvent</code>'s getTransferable()
  98. * method may be invoked, and data transfer may be
  99. * performed via the returned <code>Transferable</code>'s
  100. * getTransferData() method.
  101. * <P>
  102. * At the completion of a drop, an implementation
  103. * of this method is required to signal the success/failure
  104. * of the drop by passing an appropriate
  105. * <code>boolean</code> to the <code>DropTargetDropEvent</code>'s
  106. * dropComplete(boolean success) method.
  107. * <P>
  108. * Note: The data transfer should be completed before the call to the
  109. * <code>DropTargetDropEvent</code>'s dropComplete(boolean success) method.
  110. * After that, a call to the getTransferData() method of the
  111. * <code>Transferable</code> returned by
  112. * <code>DropTargetDropEvent.getTransferable()</code> is guaranteed to
  113. * succeed only if the data transfer is local; that is, only if
  114. * <code>DropTargetDropEvent.isLocalTransfer()</code> returns
  115. * <code>true</code>. Otherwise, the behavior of the call is
  116. * implementation-dependent.
  117. * <P>
  118. * @param dtde the <code>DropTargetDropEvent</code>
  119. */
  120. void drop(DropTargetDropEvent dtde);
  121. }