FileDocCategorySizeDatePackage
BasicDragGestureRecognizer.javaAPI DocJava SE 5 API3742Fri Aug 26 14:58:04 BST 2005javax.swing.plaf.basic

BasicDragGestureRecognizer

public class BasicDragGestureRecognizer extends Object implements MouseListener, MouseMotionListener
Default drag gesture recognition for drag operations performed by classses that have a dragEnabled property. The gesture for a drag in this package is a mouse press over a selection followed by some movement by enough pixels to keep it from being treated as a click.
author
Timothy Prinzing
version
1.7 12/19/03

Fields Summary
private MouseEvent
dndArmedEvent
Constructors Summary
Methods Summary
protected javax.swing.JComponentgetComponent(java.awt.event.MouseEvent e)

	Object src = e.getSource();
	if (src instanceof JComponent) {
	    JComponent c = (JComponent) src;
	    return c;
	}
	return null;
    
private static intgetMotionThreshold()

    
        
        return DragSource.getDragThreshold();
    
private javax.swing.TransferHandlergetTransferHandler(java.awt.event.MouseEvent e)

        JComponent c = getComponent(e);
        return c == null ? null : c.getTransferHandler();
    
protected booleanisDragPossible(java.awt.event.MouseEvent e)
Determines if the following are true:
  • the press event is located over a selection
  • the dragEnabled property is true
  • A TranferHandler is installed

This is implemented to check for a TransferHandler. Subclasses should perform the remaining conditions.

        JComponent c = getComponent(e);
        return (c == null) ? true : (c.getTransferHandler() != null);
    
protected intmapDragOperationFromModifiers(java.awt.event.MouseEvent e)

        int mods = e.getModifiersEx();
        
        if ((mods & InputEvent.BUTTON1_DOWN_MASK) != InputEvent.BUTTON1_DOWN_MASK) {
            return TransferHandler.NONE;
        }

        JComponent c = getComponent(e);
        TransferHandler th = c.getTransferHandler();
        return SunDragSourceContextPeer.convertModifiersToDropAction(mods, th.getSourceActions(c)); 
    
public voidmouseClicked(java.awt.event.MouseEvent e)

    
public voidmouseDragged(java.awt.event.MouseEvent e)

	if (dndArmedEvent != null) {
            e.consume();
            
            int action = mapDragOperationFromModifiers(e);
            
            if (action == TransferHandler.NONE) {
                return;
            }
            
	    int dx = Math.abs(e.getX() - dndArmedEvent.getX());
	    int dy = Math.abs(e.getY() - dndArmedEvent.getY());
            if ((dx > getMotionThreshold()) || (dy > getMotionThreshold())) {
		// start transfer... shouldn't be a click at this point
                JComponent c = getComponent(e);
		TransferHandler th = c.getTransferHandler();
		th.exportAsDrag(c, dndArmedEvent, action);
		dndArmedEvent = null;
	    }
	}
    
public voidmouseEntered(java.awt.event.MouseEvent e)

        //dndArmedEvent = null;
    
public voidmouseExited(java.awt.event.MouseEvent e)

        //if (dndArmedEvent != null && mapDragOperationFromModifiers(e) == TransferHandler.NONE) {
        //    dndArmedEvent = null;
        //}
    
public voidmouseMoved(java.awt.event.MouseEvent e)

    
public voidmousePressed(java.awt.event.MouseEvent e)

        dndArmedEvent = null;

	if (isDragPossible(e) && mapDragOperationFromModifiers(e) != TransferHandler.NONE) {
            dndArmedEvent = e;
	    e.consume();
	}
    
public voidmouseReleased(java.awt.event.MouseEvent e)

        dndArmedEvent = null;