edu.northwestern.at.utils.swing
Class XDragSource

java.lang.Object
  extended by edu.northwestern.at.utils.swing.XDragSource
All Implemented Interfaces:
java.awt.dnd.DragGestureListener, java.awt.dnd.DragSourceListener, java.util.EventListener
Direct Known Subclasses:
ListDragSource, TreeDragSource

public abstract class XDragSource
extends java.lang.Object
implements java.awt.dnd.DragGestureListener, java.awt.dnd.DragSourceListener

An abstract base class for drag sources.

This class implements both drag gesture and drag source listeners for any AWT component and handles the details of the source side of drag and drop operations.

Concrete subclasses must implement the dragGestureRecognized method. This method should compute both the drag image and the drag data, then call the startDrag method in this class to start the drag. The startDrag method computes the proper offset for the drag image and tells the drag gesture event to start the drag using the image and data supplied by the subclass.

Empty implementations are provided for the required drag enter, drag over, drag exit, and drop action changed event handlers. Subclasses may override these handlers if they wish.

This class has an incestuous relationship with its partner XDropTarget class and its subclasses:


Constructor Summary
XDragSource(java.awt.Component component)
          Constructs a new drag source object.
 
Method Summary
 void dragDropEnd(java.awt.dnd.DragSourceDropEvent dsde)
          Handles a drag drop end event.
 void dragEnter(java.awt.dnd.DragSourceDragEvent dsde)
          Handles a drag enter event.
 void dragExit(java.awt.dnd.DragSourceEvent dse)
          Handles a drag exit event.
abstract  void dragGestureRecognized(java.awt.dnd.DragGestureEvent dge)
          Handles a drag gesture recognized event.
 void dragOver(java.awt.dnd.DragSourceDragEvent dsde)
          Handles a drag over event.
 void dropActionChanged(java.awt.dnd.DragSourceDragEvent dsde)
          Handles a drop action changed event.
static java.awt.datatransfer.Transferable getCurrentDragData()
          Gets the current drag data.
static java.awt.Component getCurrentDragSource()
          Gets the current drag source component.
static java.awt.event.InputEvent getTriggerEvent()
          Gets the trigger event for the most recent drag.
 void startDrag(java.awt.dnd.DragGestureEvent dge, java.awt.Rectangle bounds, java.awt.image.BufferedImage image, java.awt.datatransfer.Transferable transferable)
          Starts a drag.
 void startDrag(java.awt.dnd.DragGestureEvent dge, java.awt.Rectangle bounds, java.awt.image.BufferedImage image, java.awt.datatransfer.Transferable transferable, java.awt.Cursor cursor)
          Starts a drag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XDragSource

public XDragSource(java.awt.Component component)
Constructs a new drag source object.

A new default drag gesture recognizer is created for the component.

Parameters:
component - The drag source component.
Method Detail

getCurrentDragSource

public static java.awt.Component getCurrentDragSource()
Gets the current drag source component.

Returns:
The current drag source component if a drag is in progress, else null.

getCurrentDragData

public static java.awt.datatransfer.Transferable getCurrentDragData()
Gets the current drag data.

Returns:
The current drag data if a drag is in progress, else null.

getTriggerEvent

public static java.awt.event.InputEvent getTriggerEvent()
Gets the trigger event for the most recent drag.

Returns:
The trigger event.

startDrag

public void startDrag(java.awt.dnd.DragGestureEvent dge,
                      java.awt.Rectangle bounds,
                      java.awt.image.BufferedImage image,
                      java.awt.datatransfer.Transferable transferable,
                      java.awt.Cursor cursor)
Starts a drag.

Parameters:
dge - The drag gesture event.
bounds - The bounds of the drag image.
image - The drag image.
transferable - The drag data.
cursor - The drag cursor.

startDrag

public void startDrag(java.awt.dnd.DragGestureEvent dge,
                      java.awt.Rectangle bounds,
                      java.awt.image.BufferedImage image,
                      java.awt.datatransfer.Transferable transferable)
Starts a drag.

Parameters:
dge - The drag gesture event.
bounds - The bounds of the drag image.
image - The drag image.
transferable - The drag data.

dragDropEnd

public void dragDropEnd(java.awt.dnd.DragSourceDropEvent dsde)
Handles a drag drop end event.

Subclasses may override this method, but must remember to invoke super.dragDropEnd.

Specified by:
dragDropEnd in interface java.awt.dnd.DragSourceListener
Parameters:
dsde - The event.

dragEnter

public void dragEnter(java.awt.dnd.DragSourceDragEvent dsde)
Handles a drag enter event.

Specified by:
dragEnter in interface java.awt.dnd.DragSourceListener
Parameters:
dsde - The event.

dragExit

public void dragExit(java.awt.dnd.DragSourceEvent dse)
Handles a drag exit event.

Specified by:
dragExit in interface java.awt.dnd.DragSourceListener
Parameters:
dse - The event.

dragOver

public void dragOver(java.awt.dnd.DragSourceDragEvent dsde)
Handles a drag over event.

Specified by:
dragOver in interface java.awt.dnd.DragSourceListener
Parameters:
dsde - The event.

dropActionChanged

public void dropActionChanged(java.awt.dnd.DragSourceDragEvent dsde)
Handles a drop action changed event.

Specified by:
dropActionChanged in interface java.awt.dnd.DragSourceListener
Parameters:
dsde - The event.

dragGestureRecognized

public abstract void dragGestureRecognized(java.awt.dnd.DragGestureEvent dge)
Handles a drag gesture recognized event.

Specified by:
dragGestureRecognized in interface java.awt.dnd.DragGestureListener
Parameters:
dge - The event.