1. /*
  2. * @(#)MouseDragGestureRecognizer.java 1.14 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.Component;
  9. import java.awt.event.MouseEvent;
  10. import java.awt.event.MouseListener;
  11. import java.awt.event.MouseMotionListener;
  12. /**
  13. * This abstract subclass of <code>DragGestureRecognizer</code>
  14. * defines a <code>DragGestureRecognizer</code>
  15. * for mouse-based gestures.
  16. *
  17. * Each platform implements its own concrete subclass of this class,
  18. * available via the Toolkit.createDragGestureRecognizer() method,
  19. * to encapsulate
  20. * the recognition of the platform dependent mouse gesture(s) that initiate
  21. * a Drag and Drop operation.
  22. * <p>
  23. * Mouse drag gesture recognizers should honor the
  24. * drag gesture motion threshold, available through
  25. * {@link DragSource#getDragThreshold}.
  26. * A drag gesture should be recognized only when the distance
  27. * in either the horizontal or vertical direction between
  28. * the location of the latest mouse dragged event and the
  29. * location of the corresponding mouse button pressed event
  30. * is greater than the drag gesture motion threshold.
  31. * <p>
  32. * Drag gesture recognizers created with
  33. * {@link DragSource#createDefaultDragGestureRecognizer}
  34. * follow this convention.
  35. *
  36. * @author Laurence P. G. Cable
  37. * @version 1.14
  38. *
  39. * @see java.awt.dnd.DragGestureListener
  40. * @see java.awt.dnd.DragGestureEvent
  41. * @see java.awt.dnd.DragSource
  42. */
  43. public abstract class MouseDragGestureRecognizer extends DragGestureRecognizer implements MouseListener, MouseMotionListener {
  44. private static final long serialVersionUID = 6220099344182281120L;
  45. /**
  46. * Construct a new <code>MouseDragGestureRecognizer</code>
  47. * given the <code>DragSource</code> for the
  48. * <code>Component</code> c, the <code>Component</code>
  49. * to observe, the action(s)
  50. * permitted for this drag operation, and
  51. * the <code>DragGestureListener</code> to
  52. * notify when a drag gesture is detected.
  53. * <P>
  54. * @param ds The DragSource for the Component c
  55. * @param c The Component to observe
  56. * @param act The actions permitted for this Drag
  57. * @param dgl The DragGestureListener to notify when a gesture is detected
  58. *
  59. */
  60. protected MouseDragGestureRecognizer(DragSource ds, Component c, int act, DragGestureListener dgl) {
  61. super(ds, c, act, dgl);
  62. }
  63. /**
  64. * Construct a new <code>MouseDragGestureRecognizer</code>
  65. * given the <code>DragSource</code> for
  66. * the <code>Component</code> c,
  67. * the <code>Component</code> to observe, and the action(s)
  68. * permitted for this drag operation.
  69. * <P>
  70. * @param ds The DragSource for the Component c
  71. * @param c The Component to observe
  72. * @param act The actions permitted for this drag
  73. */
  74. protected MouseDragGestureRecognizer(DragSource ds, Component c, int act) {
  75. this(ds, c, act, null);
  76. }
  77. /**
  78. * Construct a new <code>MouseDragGestureRecognizer</code>
  79. * given the <code>DragSource</code> for the
  80. * <code>Component</code> c, and the
  81. * <code>Component</code> to observe.
  82. * <P>
  83. * @param ds The DragSource for the Component c
  84. * @param c The Component to observe
  85. */
  86. protected MouseDragGestureRecognizer(DragSource ds, Component c) {
  87. this(ds, c, DnDConstants.ACTION_NONE);
  88. }
  89. /**
  90. * Construct a new <code>MouseDragGestureRecognizer</code>
  91. * given the <code>DragSource</code> for the <code>Component</code>.
  92. * <P>
  93. * @param ds The DragSource for the Component
  94. */
  95. protected MouseDragGestureRecognizer(DragSource ds) {
  96. this(ds, null);
  97. }
  98. /**
  99. * register this DragGestureRecognizer's Listeners with the Component
  100. */
  101. protected void registerListeners() {
  102. component.addMouseListener(this);
  103. component.addMouseMotionListener(this);
  104. }
  105. /**
  106. * unregister this DragGestureRecognizer's Listeners with the Component
  107. *
  108. * subclasses must override this method
  109. */
  110. protected void unregisterListeners() {
  111. component.removeMouseListener(this);
  112. component.removeMouseMotionListener(this);
  113. }
  114. /**
  115. * Invoked when the mouse has been clicked on a component.
  116. * <P>
  117. * @param e the <code>MouseEvent</code>
  118. */
  119. public void mouseClicked(MouseEvent e) { }
  120. /**
  121. * Invoked when a mouse button has been
  122. * pressed on a <code>Component</code>.
  123. * <P>
  124. * @param e the <code>MouseEvent</code>
  125. */
  126. public void mousePressed(MouseEvent e) { }
  127. /**
  128. * Invoked when a mouse button has been released on a component.
  129. * <P>
  130. * @param e the <code>MouseEvent</code>
  131. */
  132. public void mouseReleased(MouseEvent e) { }
  133. /**
  134. * Invoked when the mouse enters a component.
  135. * <P>
  136. * @param e the <code>MouseEvent</code>
  137. */
  138. public void mouseEntered(MouseEvent e) { }
  139. /**
  140. * Invoked when the mouse exits a component.
  141. * <P>
  142. * @param e the <code>MouseEvent</code>
  143. */
  144. public void mouseExited(MouseEvent e) { }
  145. /**
  146. * Invoked when a mouse button is pressed on a component.
  147. * <P>
  148. * @param e the <code>MouseEvent</code>
  149. */
  150. public void mouseDragged(MouseEvent e) { }
  151. /**
  152. * Invoked when the mouse button has been moved on a component
  153. * (with no buttons no down).
  154. * <P>
  155. * @param e the <code>MouseEvent</code>
  156. */
  157. public void mouseMoved(MouseEvent e) { }
  158. }