1. /*
  2. * @(#)DragSourceEvent.java 1.19 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.awt.Point;
  9. import java.util.EventObject;
  10. /**
  11. * This class is the base class for
  12. * <code>DragSourceDragEvent</code> and
  13. * <code>DragSourceDropEvent</code>.
  14. * <p>
  15. * <code>DragSourceEvent</code>s are generated whenever the drag enters, moves
  16. * over, or exits a drop site, when the drop action changes, and when the drag
  17. * ends. The location for the generated <code>DragSourceEvent</code> specifies
  18. * the mouse cursor location in screen coordinates at the moment this event
  19. * occured.
  20. * <p>
  21. * In a multi-screen environment without a virtual device, the cursor location is
  22. * specified in the coordinate system of the <i>initiator</i>
  23. * <code>GraphicsConfiguration</code>. The <i>initiator</i>
  24. * <code>GraphicsConfiguration</code> is the <code>GraphicsConfiguration</code>
  25. * of the <code>Component</code> on which the drag gesture for the current drag
  26. * operation was recognized. If the cursor location is outside the bounds of
  27. * the initiator <code>GraphicsConfiguration</code>, the reported coordinates are
  28. * clipped to fit within the bounds of that <code>GraphicsConfiguration</code>.
  29. * <p>
  30. * In a multi-screen environment with a virtual device, the location is specified
  31. * in the corresponding virtual coordinate system. If the cursor location is
  32. * outside the bounds of the virtual device the reported coordinates are
  33. * clipped to fit within the bounds of the virtual device.
  34. *
  35. * @since 1.2
  36. */
  37. public class DragSourceEvent extends EventObject {
  38. private static final long serialVersionUID = -763287114604032641L;
  39. /**
  40. * The <code>boolean</code> indicating whether the cursor location
  41. * is specified for this event.
  42. *
  43. * @serial
  44. */
  45. private final boolean locationSpecified;
  46. /**
  47. * The horizontal coordinate for the cursor location at the moment this
  48. * event occured if the cursor location is specified for this event;
  49. * otherwise zero.
  50. *
  51. * @serial
  52. */
  53. private final int x;
  54. /**
  55. * The vertical coordinate for the cursor location at the moment this event
  56. * occured if the cursor location is specified for this event;
  57. * otherwise zero.
  58. *
  59. * @serial
  60. */
  61. private final int y;
  62. /**
  63. * Construct a <code>DragSourceEvent</code>
  64. * given a specified <code>DragSourceContext</code>.
  65. * The coordinates for this <code>DragSourceEvent</code>
  66. * are not specified, so <code>getLocation</code> will return
  67. * <code>null</code> for this event.
  68. *
  69. * @param dsc the <code>DragSourceContext</code>
  70. *
  71. * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>.
  72. *
  73. * @see #getLocation
  74. */
  75. public DragSourceEvent(DragSourceContext dsc) {
  76. super(dsc);
  77. locationSpecified = false;
  78. this.x = 0;
  79. this.y = 0;
  80. }
  81. /**
  82. * Construct a <code>DragSourceEvent</code> given a specified
  83. * <code>DragSourceContext</code>, and coordinates of the cursor
  84. * location.
  85. *
  86. * @param dsc the <code>DragSourceContext</code>
  87. * @param x the horizontal coordinate for the cursor location
  88. * @param y the vertical coordinate for the cursor location
  89. *
  90. * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>.
  91. *
  92. * @since 1.4
  93. */
  94. public DragSourceEvent(DragSourceContext dsc, int x, int y) {
  95. super(dsc);
  96. locationSpecified = true;
  97. this.x = x;
  98. this.y = y;
  99. }
  100. /**
  101. * This method returns the <code>DragSourceContext</code> that
  102. * originated the event.
  103. * <P>
  104. * @return the <code>DragSourceContext</code> that originated the event
  105. */
  106. public DragSourceContext getDragSourceContext() {
  107. return (DragSourceContext)getSource();
  108. }
  109. /**
  110. * This method returns a <code>Point</code> indicating the cursor
  111. * location in screen coordinates at the moment this event occured, or
  112. * <code>null</code> if the cursor location is not specified for this
  113. * event.
  114. *
  115. * @return the <code>Point</code> indicating the cursor location
  116. * or <code>null</code> if the cursor location is not specified
  117. * @since 1.4
  118. */
  119. public Point getLocation() {
  120. if (locationSpecified) {
  121. return new Point(x, y);
  122. } else {
  123. return null;
  124. }
  125. }
  126. /**
  127. * This method returns the horizontal coordinate of the cursor location in
  128. * screen coordinates at the moment this event occured, or zero if the
  129. * cursor location is not specified for this event.
  130. *
  131. * @return an integer indicating the horizontal coordinate of the cursor
  132. * location or zero if the cursor location is not specified
  133. * @since 1.4
  134. */
  135. public int getX() {
  136. return x;
  137. }
  138. /**
  139. * This method returns the vertical coordinate of the cursor location in
  140. * screen coordinates at the moment this event occured, or zero if the
  141. * cursor location is not specified for this event.
  142. *
  143. * @return an integer indicating the vertical coordinate of the cursor
  144. * location or zero if the cursor location is not specified
  145. * @since 1.4
  146. */
  147. public int getY() {
  148. return y;
  149. }
  150. }