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