Microsoft SDK for Java

DragHelper Class

The DragHelper Class of the com.ms.object.dragdrop package provides a default implementation for a dragdrop protocol involving a set of objects that the system does not support. For instance, if you are designing a tree control that is not composed of system components, you could use this class (along with the DragProxy class) to help implement the enter, continue, leave, and drop behaviors over the subelements in your tree.

public abstract class DragHelper implements DragHandler
{
  // Methods
  public void dragEnter(DragSession session);
  public void dragLeave();
  public int dragOver(DragSession session, int x, int y);
  public void drop(DragSession session, int x, int y);
  protected abstract Object findDragObject(DragSession session, int
        x, int y);
  protected abstract DragHandler getDragHandler(
        DragSession session, Object object);
  protected void trackDragStatus(DragSession session,
        Object object, int effect);
}

Typically, you would extend the DragHelper class, providing hit-testing code to implement the findDragObject and getDragHandler methods.

When a drag method is called on a class that extends DragHelper, the drag method calls the findDragObject method to hit-test the coordinates in the drag method. The derived class returns an Object that represents the hit result.

If the Object has changed since the last hit-test, the drag helper then calls the getDragHandler method to obtain a DragHandler for the new hit Object. In addition, the derived class can override the trackDragStatus method to implement highlighting or some other form of feedback.

© 1999 Microsoft Corporation. All rights reserved. Terms of use.