1. /*
  2. * @(#)DropTargetDragEvent.java 1.16 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.dnd.DropTargetEvent;
  14. import java.util.Arrays;
  15. import java.util.List;
  16. /**
  17. * The <code>DropTargetDragEvent</code> is delivered to a
  18. * <code>DropTargetListener</code> via its
  19. * dragEnter() and dragOver() methods.
  20. *
  21. * @version 1.16, 02/02/00
  22. * @since 1.2
  23. */
  24. public class DropTargetDragEvent extends DropTargetEvent {
  25. /**
  26. * Construct a <code>DropTargetDragEvent</code> given the
  27. * <code>DropTargetContext</code> for this operation,
  28. * the location of the "Drag" <code>Cursor</code>'s hotspot
  29. * in the <code>Component</code>'s coordinates, the
  30. * currently selected user drop action, and current
  31. * set of actions supported by the source.
  32. * <P>
  33. * @param dtc The DropTargetContext for this operation
  34. * @param cursorLocn The location of the "Drag" Cursor's
  35. * hotspot in Component coordinates
  36. * @param dropAction The currently selected user drop action
  37. * @param srcActions The current set of actions supported by the source
  38. * <P>
  39. * @throws NullPointerException if cursorLocn is null
  40. * @throws IllegalArgumentException if the dropAction or
  41. * srcActions are illegal values, or if dtc is null
  42. */
  43. public DropTargetDragEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions) {
  44. super(dtc);
  45. if (cursorLocn == null) throw new NullPointerException("cursorLocn");
  46. if (dropAction != DnDConstants.ACTION_NONE &&
  47. dropAction != DnDConstants.ACTION_COPY &&
  48. dropAction != DnDConstants.ACTION_MOVE &&
  49. dropAction != DnDConstants.ACTION_LINK
  50. ) throw new IllegalArgumentException("dropAction" + dropAction);
  51. if ((srcActions & ~(DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK)) != 0) throw new IllegalArgumentException("srcActions");
  52. location = cursorLocn;
  53. actions = srcActions;
  54. this.dropAction = dropAction;
  55. }
  56. /**
  57. * This method returns a <code>Point</code>
  58. * indicating the <code>Cursor</code>'s current
  59. * location within the <code>Component'</code>s
  60. * coordinates.
  61. * <P>
  62. * @return the current cursor location in
  63. * <code>Component</code>'s coords.
  64. */
  65. public Point getLocation() {
  66. return location;
  67. }
  68. /**
  69. * This method returns the current <code>DataFlavor</code>s from the
  70. * <code>DropTargetContext</code>.
  71. * <P>
  72. * @return current DataFlavors from the DropTargetContext
  73. */
  74. public DataFlavor[] getCurrentDataFlavors() {
  75. return getDropTargetContext().getCurrentDataFlavors();
  76. }
  77. /**
  78. * This method returns the current <code>DataFlavor</code>s
  79. * as a <code>java.util.List</code>
  80. * <P>
  81. * @return a <code>java.util.List</code> of the Current <code>DataFlavor</code>s
  82. */
  83. public List getCurrentDataFlavorsAsList() {
  84. return getDropTargetContext().getCurrentDataFlavorsAsList();
  85. }
  86. /**
  87. * This method returns a <code>boolean</code> indicating
  88. * if the specified <code>DataFlavor</code> is supported.
  89. * <P>
  90. * @param df the <code>DataFlavor</code> to test
  91. * <P>
  92. * @return if a particular DataFlavor is supported
  93. */
  94. public boolean isDataFlavorSupported(DataFlavor df) {
  95. return getDropTargetContext().isDataFlavorSupported(df);
  96. }
  97. /**
  98. * This method returns an <code>int</code> representing
  99. * set of actions supported by the source.
  100. * <P>
  101. * @return source actions
  102. */
  103. public int getSourceActions() { return actions; }
  104. /**
  105. * This method returns an <code>int</code>
  106. * representing the currently selected drop action.
  107. * <P>
  108. * @return currently selected drop action
  109. */
  110. public int getDropAction() { return dropAction; }
  111. /**
  112. * Accept the drag
  113. *
  114. * This method should be called from a DropTargetListeners dragEnter(),
  115. * dragOver() and dragActionChanged() methods if the implementation
  116. * wishes to accept an operation from the srcActions other than the one
  117. * selected by the user as represented by the dropAction.
  118. * <P>
  119. * @param dragOperation the operation accepted by the target
  120. */
  121. public void acceptDrag(int dragOperation) {
  122. getDropTargetContext().acceptDrag(dragOperation);
  123. }
  124. /**
  125. * Reject the drag as a result of examining either the dropAction or
  126. * the available DataFlavor types.
  127. */
  128. public void rejectDrag() {
  129. getDropTargetContext().rejectDrag();
  130. }
  131. /*
  132. * fields
  133. */
  134. private Point location;
  135. private int actions;
  136. private int dropAction;
  137. }