1. /*
  2. * @(#)DropTargetDropEvent.java 1.21 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.awt.dnd;
  11. import java.awt.Point;
  12. import java.awt.datatransfer.DataFlavor;
  13. import java.awt.datatransfer.Transferable;
  14. import java.awt.dnd.DropTargetEvent;
  15. import java.util.Arrays;
  16. import java.util.List;
  17. /**
  18. * The <code>DropTargetDropEvent</code> is delivered
  19. * via the <code>DropTargetListener</code> drop() method.
  20. *
  21. * @version 1.21, 02/02/00
  22. * @since 1.2
  23. */
  24. public class DropTargetDropEvent extends DropTargetEvent {
  25. /**
  26. * Construct a <code>DropTargetDropEvent</code> given
  27. * the <code>DropTargetContext</code> for this operation,
  28. * the location of the drag <code>Cursor</code>'s
  29. * hotspot in the <code>Component</code>'s coordinates,
  30. * the currently
  31. * selected user drop action, and the current set of
  32. * actions supported by the source.
  33. * By default, this constructor
  34. * assumes that the target is not in the same virtual machine as
  35. * the source; that is, {@link #isLocalTransfer()} will
  36. * return <code>false</code>.
  37. * <P>
  38. * @param dtc The <code>DropTargetContext</code> for this operation
  39. * @param cursorLocn The location of the "Drag" Cursor's
  40. * hotspot in <code>Component</code> coordinates
  41. * @param dropAction The currently selected user drop action: COPY, MOVE, or LINK
  42. * constants found in DnDConstants.
  43. * @param srcActions The current set of actions supported by the source: some
  44. * combination of COPY, MOVE, or LINK as exposed by the <code>DragSource</code>.
  45. * <P>
  46. * @throws <code>NullPointerException</code>
  47. * if cursorLocn is <code>null</code>
  48. * @throws <code>IllegalArgumentException</code>
  49. * if the dropAction or srcActions are illegal values,
  50. * or if dtc is <code>null</code>.
  51. */
  52. public DropTargetDropEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions) {
  53. super(dtc);
  54. if (cursorLocn == null) throw new NullPointerException("cursorLocn");
  55. if (dropAction != DnDConstants.ACTION_NONE &&
  56. dropAction != DnDConstants.ACTION_COPY &&
  57. dropAction != DnDConstants.ACTION_MOVE &&
  58. dropAction != DnDConstants.ACTION_LINK
  59. ) throw new IllegalArgumentException("dropAction = " + dropAction);
  60. if ((srcActions & ~(DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK)) != 0) throw new IllegalArgumentException("srcActions");
  61. location = cursorLocn;
  62. actions = srcActions;
  63. this.dropAction = dropAction;
  64. }
  65. /**
  66. * Construct a <code>DropTargetEvent</code> given the
  67. * <code>DropTargetContext</code> for this operation,
  68. * the location of the drag <code>Cursor</code>'s hotspot
  69. * in the <code>Component</code>'s
  70. * coordinates, the currently selected user drop action,
  71. * the current set of actions supported by the source,
  72. * and a <code>boolean</code> indicating if the source is in the same JVM
  73. * as the target.
  74. * <P>
  75. * @param dtc The DropTargetContext for this operation
  76. * @param cursorLocn The location of the "Drag" Cursor's
  77. * hotspot in Component's coordinates
  78. * @param dropAction The currently selected user drop action: COPY, MOVE, or LINK
  79. * constants found in DnDConstants.
  80. * @param srcActions The current set of actions supported by the source: some
  81. * combination of COPY, MOVE, or LINK as exposed by the <code>DragSource</code>.
  82. * @param isLocalTx True if the source is in the same JVM as the target
  83. */
  84. public DropTargetDropEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions, boolean isLocal) {
  85. this(dtc, cursorLocn, dropAction, srcActions);
  86. isLocalTx = isLocal;
  87. }
  88. /**
  89. * This method returns a <code>Point</code>
  90. * indicating the <code>Cursor</code>'s current
  91. * location in the <code>Component</code>'s coordinates.
  92. * <P>
  93. * @return the current <code>Cursor</code> location in Component's coords.
  94. */
  95. public Point getLocation() {
  96. return location;
  97. }
  98. /**
  99. * This method returns the current DataFlavors.
  100. * <P>
  101. * @return current DataFlavors
  102. */
  103. public DataFlavor[] getCurrentDataFlavors() {
  104. return getDropTargetContext().getCurrentDataFlavors();
  105. }
  106. /**
  107. * This method returns the currently available
  108. * <code>DataFlavor</code>s as a <code>java.util.List</code>.
  109. * <P>
  110. * @return the currently available DataFlavors as a java.util.List
  111. */
  112. public List getCurrentDataFlavorsAsList() {
  113. return getDropTargetContext().getCurrentDataFlavorsAsList();
  114. }
  115. /**
  116. * This method returns a <code>boolean</code> indicating if the
  117. * specified <code>DataFlavor</code> is available
  118. * from the source.
  119. * <P>
  120. * @param df the <code>DataFlavor</code> to test
  121. * <P>
  122. * @return if the DataFlavor specified is available from the source
  123. */
  124. public boolean isDataFlavorSupported(DataFlavor df) {
  125. return getDropTargetContext().isDataFlavorSupported(df);
  126. }
  127. /**
  128. * This method returns an <code>int</code> representing the
  129. * action(s) supported by the source.
  130. * <P>
  131. * @return source actions
  132. */
  133. public int getSourceActions() { return actions; }
  134. /**
  135. * This method returns an <code>int</code>
  136. * representing the action(s) supported
  137. * by the source at the time of the drop.
  138. * <P>
  139. * @return source actions
  140. */
  141. public int getDropAction() { return dropAction; }
  142. /**
  143. * This method returns the <code>Transferable</code> object
  144. * associated with the drop.
  145. * <P>
  146. * @return the <code>Transferable</code> associated with the drop
  147. */
  148. public Transferable getTransferable() {
  149. return getDropTargetContext().getTransferable();
  150. }
  151. /**
  152. * accept the drop, using the specified action.
  153. * <P>
  154. * @param dropAction the specified action
  155. */
  156. public void acceptDrop(int dropAction) {
  157. getDropTargetContext().acceptDrop(dropAction);
  158. }
  159. /**
  160. * reject the Drop.
  161. */
  162. public void rejectDrop() {
  163. getDropTargetContext().rejectDrop();
  164. }
  165. /**
  166. * This method notifies the <code>DragSource</code>
  167. * that the drop transfer(s) are completed.
  168. * <P>
  169. * @param success a <code>boolean</code> indicating that the drop transfer(s) are completed.
  170. */
  171. public void dropComplete(boolean success) {
  172. getDropTargetContext().dropComplete(success);
  173. }
  174. /**
  175. * This method returns an <code>int</code> indicating if
  176. * the source is in the same JVM as the target.
  177. * <P>
  178. * @return if the Source is in the same JVM
  179. */
  180. public boolean isLocalTransfer() {
  181. return isLocalTx;
  182. }
  183. /*
  184. * fields
  185. */
  186. static final private Point zero = new Point(0,0);
  187. private Point location = zero;
  188. private int actions = DnDConstants.ACTION_NONE;
  189. private int dropAction = DnDConstants.ACTION_NONE;
  190. private boolean isLocalTx = false;
  191. }