DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(
dragSourceComponent, supportedActions, new CursorUpdater());
class CursorUpdater implements DragGestureListener, DragSourceListener
{
private Cursor currentAcceptCursor = DragSource.DefaultMoveDrop;
private Cursor currentRejectCursor = DragSource.DefaultMoveNoDrop;
public void dragGestureRecognized(DragGestureEvent e)
{
...
e.startDrag(currentRejectCursor, image, imageOffset, transferable, this);
}
public void dragDropEnd(DragSourceDropEvent e) {}
public void dragEnter(DragSourceDragEvent e) { updateCursor(e); }
public void dragOver(DragSourceDragEvent e) { updateCursor(e); }
public void dropActionChanged(DragSourceDragEvent e) { updateCursor(e); }
public void dragExit(DragSourceEvent e)
{
DragSourceContext ctx = e.getDragSourceContext();
ctx.setCursor(currentRejectCursor);
}
private void updateCursor(DragSourceEvent e)
{
DragSourceContext ctx = e.getDragSourceContext();
int action = ctx.getTrigger().getDragAction();
if ((action & supportedActions) != 0)
{
ctx.setCursor(currentAcceptCursor);
}
else
{
ctx.setCursor(currentRejectCursor);
}
}
}