- listen for mouseExited during a drag and clear the target
- broke enter/exit/released into their own methods - don't assume components don't have their own custom cursors, restore their old cursors when we're done with them. git-svn-id: https://samskivert.googlecode.com/svn/trunk@816 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: DnDManager.java,v 1.1 2002/08/20 02:49:19 ray Exp $
|
// $Id: DnDManager.java,v 1.2 2002/08/20 21:05:10 ray Exp $
|
||||||
|
|
||||||
package com.samskivert.swing.dnd;
|
package com.samskivert.swing.dnd;
|
||||||
|
|
||||||
@@ -124,38 +124,73 @@ public class DnDManager
|
|||||||
|
|
||||||
// and start out with the no-drop cursor
|
// and start out with the no-drop cursor
|
||||||
_lastComp = _sourceComp;
|
_lastComp = _sourceComp;
|
||||||
|
_oldCursor = _lastComp.getCursor();
|
||||||
_lastComp.setCursor(_cursors[1]);
|
_lastComp.setCursor(_cursors[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface AWTEventListener
|
// documentation inherited from interface AWTEventListener
|
||||||
public void eventDispatched (AWTEvent event)
|
public void eventDispatched (AWTEvent event)
|
||||||
{
|
{
|
||||||
int id = event.getID();
|
switch (event.getID()) {
|
||||||
if (id == MouseEvent.MOUSE_ENTERED) {
|
case MouseEvent.MOUSE_ENTERED:
|
||||||
Component oldcomp = _lastComp;
|
mouseEntered((MouseEvent) event);
|
||||||
_lastComp = ((MouseEvent) event).getComponent();
|
break;
|
||||||
_lastTarget = findAppropriateTarget(_lastComp);
|
|
||||||
_lastComp.setCursor(_cursors[(_lastTarget == null) ? 1 : 0]);
|
|
||||||
if (_lastComp != oldcomp) {
|
|
||||||
oldcomp.setCursor(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (id == MouseEvent.MOUSE_RELEASED) {
|
case MouseEvent.MOUSE_EXITED:
|
||||||
// since the release comes with a component of the source,
|
mouseExited((MouseEvent) event);
|
||||||
// we use the last enter...
|
break;
|
||||||
if (_lastTarget != null) {
|
|
||||||
_lastTarget.dropCompleted(_data[0]);
|
|
||||||
_source.dragCompleted(_lastTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_lastComp != null) {
|
case MouseEvent.MOUSE_RELEASED:
|
||||||
_lastComp.setCursor(null);
|
mouseReleased((MouseEvent) event);
|
||||||
}
|
break;
|
||||||
Toolkit.getDefaultToolkit().removeAWTEventListener(this);
|
|
||||||
reset();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the mouse entering a new component.
|
||||||
|
*/
|
||||||
|
protected void mouseEntered (MouseEvent event)
|
||||||
|
{
|
||||||
|
Component oldcomp = _lastComp;
|
||||||
|
_lastComp = ((MouseEvent) event).getComponent();
|
||||||
|
_lastTarget = findAppropriateTarget(_lastComp);
|
||||||
|
if (_lastComp != oldcomp) {
|
||||||
|
oldcomp.setCursor(_oldCursor);
|
||||||
|
_oldCursor = _lastComp.getCursor();
|
||||||
|
}
|
||||||
|
_lastComp.setCursor(_cursors[(_lastTarget == null) ? 1 : 0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the mouse leaving a component.
|
||||||
|
*/
|
||||||
|
protected void mouseExited (MouseEvent event)
|
||||||
|
{
|
||||||
|
_lastTarget = null;
|
||||||
|
if (_lastComp != null) {
|
||||||
|
_lastComp.setCursor(_oldCursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the mouse button being released.
|
||||||
|
*/
|
||||||
|
protected void mouseReleased (MouseEvent event)
|
||||||
|
{
|
||||||
|
// since the release comes with a component of the source,
|
||||||
|
// we use the last enter...
|
||||||
|
if (_lastTarget != null) {
|
||||||
|
_lastTarget.dropCompleted(_data[0]);
|
||||||
|
_source.dragCompleted(_lastTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_lastComp != null) {
|
||||||
|
_lastComp.setCursor(_oldCursor);
|
||||||
|
}
|
||||||
|
Toolkit.getDefaultToolkit().removeAWTEventListener(this);
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the lowest accepting parental target to this component.
|
* Find the lowest accepting parental target to this component.
|
||||||
*/
|
*/
|
||||||
@@ -218,6 +253,9 @@ public class DnDManager
|
|||||||
/** The last target, or null if no last target. */
|
/** The last target, or null if no last target. */
|
||||||
protected DropTarget _lastTarget;
|
protected DropTarget _lastTarget;
|
||||||
|
|
||||||
|
/** The cursor that used to be set for _lastComp. */
|
||||||
|
protected Cursor _oldCursor;
|
||||||
|
|
||||||
/** The accept/reject cursors. */
|
/** The accept/reject cursors. */
|
||||||
protected Cursor[] _cursors = new Cursor[2];
|
protected Cursor[] _cursors = new Cursor[2];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user