FileDocCategorySizeDatePackage
DragSourceDragEvent.javaAPI DocJava SE 6 API11351Tue Jun 10 00:25:20 BST 2008java.awt.dnd

DragSourceDragEvent

public class DragSourceDragEvent extends DragSourceEvent
The DragSourceDragEvent is delivered from the DragSourceContextPeer, via the DragSourceContext, to the DragSourceListener registered with that DragSourceContext and with its associated DragSource.

The DragSourceDragEvent reports the target drop action and the user drop action that reflect the current state of the drag operation.

Target drop action is one of DnDConstants that represents the drop action selected by the current drop target if this drop action is supported by the drag source or DnDConstants.ACTION_NONE if this drop action is not supported by the drag source.

User drop action depends on the drop actions supported by the drag source and the drop action selected by the user. The user can select a drop action by pressing modifier keys during the drag operation:

Ctrl + Shift -> ACTION_LINK
Ctrl -> ACTION_COPY
Shift -> ACTION_MOVE
If the user selects a drop action, the user drop action is one of DnDConstants that represents the selected drop action if this drop action is supported by the drag source or DnDConstants.ACTION_NONE if this drop action is not supported by the drag source.

If the user doesn't select a drop action, the set of DnDConstants that represents the set of drop actions supported by the drag source is searched for DnDConstants.ACTION_MOVE, then for DnDConstants.ACTION_COPY, then for DnDConstants.ACTION_LINK and the user drop action is the first constant found. If no constant is found the user drop action is DnDConstants.ACTION_NONE.

version
1.31, 04/04/06
since
1.2

Fields Summary
private static final long
serialVersionUID
private static final int
JDK_1_3_MODIFIERS
private static final int
JDK_1_4_MODIFIERS
private int
targetActions
The target drop action.
private int
dropAction
The user drop action.
private int
gestureModifiers
The state of the input device modifiers associated with the user gesture.
private boolean
invalidModifiers
Indicates whether the gestureModifiers are invalid.
Constructors Summary
public DragSourceDragEvent(DragSourceContext dsc, int dropAction, int action, int modifiers)
Constructs a DragSourceDragEvent. This class is typically instantiated by the DragSourceContextPeer rather than directly by client code. The coordinates for this DragSourceDragEvent are not specified, so getLocation will return null for this event.

The arguments dropAction and action should be one of DnDConstants that represents a single action. The argument modifiers should be either a bitwise mask of old java.awt.event.InputEvent.*_MASK constants or a bitwise mask of extended java.awt.event.InputEvent.*_DOWN_MASK constants. This constructor does not throw any exception for invalid dropAction, action and modifiers.

param
dsc the DragSourceContext that is to manage notifications for this event.
param
dropAction the user drop action.
param
action the target drop action.
param
modifiers the modifier keys down during event (shift, ctrl, alt, meta) Either extended _DOWN_MASK or old _MASK modifiers should be used, but both models should not be mixed in one event. Use of the extended modifiers is preferred.
throws
IllegalArgumentException if dsc is null.
see
java.awt.event.InputEvent
see
DragSourceEvent#getLocation


                                                                                                                                                                                                                           

         
                                    
	super(dsc);
	
	targetActions    = action;
	gestureModifiers = modifiers;
	this.dropAction  = dropAction;
        if ((modifiers & ~(JDK_1_3_MODIFIERS | JDK_1_4_MODIFIERS)) != 0) {
            invalidModifiers = true;
        } else if ((getGestureModifiers() != 0) && (getGestureModifiersEx() == 0)) {
	    setNewModifiers();
	} else if ((getGestureModifiers() == 0) && (getGestureModifiersEx() != 0)) {
	    setOldModifiers();
	} else {
            invalidModifiers = true;
        }
    
public DragSourceDragEvent(DragSourceContext dsc, int dropAction, int action, int modifiers, int x, int y)
Constructs a DragSourceDragEvent given the specified DragSourceContext, user drop action, target drop action, modifiers and coordinates.

The arguments dropAction and action should be one of DnDConstants that represents a single action. The argument modifiers should be either a bitwise mask of old java.awt.event.InputEvent.*_MASK constants or a bitwise mask of extended java.awt.event.InputEvent.*_DOWN_MASK constants. This constructor does not throw any exception for invalid dropAction, action and modifiers.

param
dsc the DragSourceContext associated with this event.
param
dropAction the user drop action.
param
action the target drop action.
param
modifiers the modifier keys down during event (shift, ctrl, alt, meta) Either extended _DOWN_MASK or old _MASK modifiers should be used, but both models should not be mixed in one event. Use of the extended modifiers is preferred.
param
x the horizontal coordinate for the cursor location
param
y the vertical coordinate for the cursor location
throws
IllegalArgumentException if dsc is null.
see
java.awt.event.InputEvent
since
1.4

        super(dsc, x, y);

        targetActions    = action;
        gestureModifiers = modifiers;
        this.dropAction  = dropAction;
        if ((modifiers & ~(JDK_1_3_MODIFIERS | JDK_1_4_MODIFIERS)) != 0) {
            invalidModifiers = true;
        } else if ((getGestureModifiers() != 0) && (getGestureModifiersEx() == 0)) {
	    setNewModifiers();    
	} else if ((getGestureModifiers() == 0) && (getGestureModifiersEx() != 0)) {
	    setOldModifiers();
	} else {
            invalidModifiers = true;
        }
    
Methods Summary
public intgetDropAction()
This method returns the logical intersection of the target drop action and the set of drop actions supported by the drag source.

return
the logical intersection of the target drop action and the set of drop actions supported by the drag source.

	return targetActions & getDragSourceContext().getSourceActions();
    
public intgetGestureModifiers()
This method returns an int representing the current state of the input device modifiers associated with the user's gesture. Typically these would be mouse buttons or keyboard modifiers.

If the modifiers passed to the constructor are invalid, this method returns them unchanged.

return
the current state of the input device modifiers


                                                             

       
	return invalidModifiers ? gestureModifiers : gestureModifiers & JDK_1_3_MODIFIERS;
    
public intgetGestureModifiersEx()
This method returns an int representing the current state of the input device extended modifiers associated with the user's gesture. See {@link InputEvent#getModifiersEx}

If the modifiers passed to the constructor are invalid, this method returns them unchanged.

return
the current state of the input device extended modifiers
since
1.4

	return invalidModifiers ? gestureModifiers : gestureModifiers & JDK_1_4_MODIFIERS;
    
public intgetTargetActions()
This method returns the target drop action.

return
the target drop action.

	return targetActions;
    
public intgetUserAction()
This method returns the user drop action.

return
the user drop action.

 return dropAction; 
private voidsetNewModifiers()
Sets new modifiers by the old ones. The mouse modifiers have higher priority than overlaying key modifiers.


                            
       
    	if ((gestureModifiers & InputEvent.BUTTON1_MASK) != 0) {
	    gestureModifiers |= InputEvent.BUTTON1_DOWN_MASK;
	}
	if ((gestureModifiers & InputEvent.BUTTON2_MASK) != 0) {
	    gestureModifiers |= InputEvent.BUTTON2_DOWN_MASK;
	}
	if ((gestureModifiers & InputEvent.BUTTON3_MASK) != 0) {
	    gestureModifiers |= InputEvent.BUTTON3_DOWN_MASK;
	}	
	if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) {
	    gestureModifiers |= InputEvent.SHIFT_DOWN_MASK;
	}
	if ((gestureModifiers & InputEvent.CTRL_MASK) != 0) {
	    gestureModifiers |= InputEvent.CTRL_DOWN_MASK;
	}
	if ((gestureModifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
	    gestureModifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
	}
    
private voidsetOldModifiers()
Sets old modifiers by the new ones.

	if ((gestureModifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
	    gestureModifiers |= InputEvent.BUTTON1_MASK;
        }
        if ((gestureModifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
            gestureModifiers |= InputEvent.BUTTON2_MASK;
        }
	if ((gestureModifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
	    gestureModifiers |= InputEvent.BUTTON3_MASK;
        }
	if ((gestureModifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
	    gestureModifiers |= InputEvent.SHIFT_MASK;
	}
	if ((gestureModifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
	    gestureModifiers |= InputEvent.CTRL_MASK;
	}
	if ((gestureModifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
	    gestureModifiers |= InputEvent.ALT_GRAPH_MASK;
	}