1. /*
  2. * @(#)DragSourceEvent.java 1.17 03/01/23
  3. *
  4. * Copyright 2003 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. * @see #getLocation
  71. */
  72. public DragSourceEvent(DragSourceContext dsc) {
  73. super(dsc);
  74. locationSpecified = false;
  75. this.x = 0;
  76. this.y = 0;
  77. }
  78. /**
  79. * Construct a <code>DragSourceEvent</code> given a specified
  80. * <code>DragSourceContext</code>, and coordinates of the cursor
  81. * location.
  82. *
  83. * @param dsc the <code>DragSourceContext</code>
  84. * @param x the horizontal coordinate for the cursor location
  85. * @param y the vertical coordinate for the cursor location
  86. * @since 1.4
  87. */
  88. public DragSourceEvent(DragSourceContext dsc, int x, int y) {
  89. super(dsc);
  90. locationSpecified = true;
  91. this.x = x;
  92. this.y = y;
  93. }
  94. /**
  95. * This method returns the <code>DragSourceContext</code> that
  96. * originated the event.
  97. * <P>
  98. * @return the <code>DragSourceContext</code> that originated the event
  99. */
  100. public DragSourceContext getDragSourceContext() {
  101. return (DragSourceContext)getSource();
  102. }
  103. /**
  104. * This method returns a <code>Point</code> indicating the cursor
  105. * location in screen coordinates at the moment this event occured, or
  106. * <code>null</code> if the cursor location is not specified for this
  107. * event.
  108. *
  109. * @return the <code>Point</code> indicating the cursor location
  110. * or <code>null</code> if the cursor location is not specified
  111. * @since 1.4
  112. */
  113. public Point getLocation() {
  114. if (locationSpecified) {
  115. return new Point(x, y);
  116. } else {
  117. return null;
  118. }
  119. }
  120. /**
  121. * This method returns the horizontal coordinate of the cursor location in
  122. * screen coordinates at the moment this event occured, or zero if the
  123. * cursor location is not specified for this event.
  124. *
  125. * @return an integer indicating the horizontal coordinate of the cursor
  126. * location or zero if the cursor location is not specified
  127. * @since 1.4
  128. */
  129. public int getX() {
  130. return x;
  131. }
  132. /**
  133. * This method returns the vertical coordinate of the cursor location in
  134. * screen coordinates at the moment this event occured, or zero if the
  135. * cursor location is not specified for this event.
  136. *
  137. * @return an integer indicating the vertical coordinate of the cursor
  138. * location or zero if the cursor location is not specified
  139. * @since 1.4
  140. */
  141. public int getY() {
  142. return y;
  143. }
  144. }