FileDocCategorySizeDatePackage
DragGestureEvent.javaAPI DocJava SE 5 API11116Fri Aug 26 14:56:48 BST 2005java.awt.dnd

DragGestureEvent

public class DragGestureEvent extends EventObject
A DragGestureEvent is passed to DragGestureListener's dragGestureRecognized() method when a particular DragGestureRecognizer detects that a platform dependent drag initiating gesture has occurred on the Component that it is tracking.
version
1.23
see
java.awt.dnd.DragGestureRecognizer
see
java.awt.dnd.DragGestureListener
see
java.awt.dnd.DragSource

Fields Summary
private static final long
serialVersionUID
private transient List
events
private DragSource
dragSource
The DragSource associated with this DragGestureEvent.
private Component
component
The Component associated with this DragGestureEvent.
private Point
origin
The origin of the drag.
private int
action
The user's preferred action.
Constructors Summary
public DragGestureEvent(DragGestureRecognizer dgr, int act, Point ori, List evs)
Construct a DragGestureEvent given the DragGestureRecognizer firing this event, an int representing the user's preferred action, a Point indicating the origin of the drag, and a List of events that comprise the gesture.

param
dgr The DragGestureRecognizer firing this event
param
act The the user's preferred action
param
ori The origin of the drag
param
evs The List of events that comprise the gesture

throws
IllegalArgumentException if input parameters are null


                                                                                      

          
			       
    
	super(dgr);

	if ((component = dgr.getComponent()) == null)
	    throw new IllegalArgumentException("null component");
	if ((dragSource = dgr.getDragSource()) == null)
	    throw new IllegalArgumentException("null DragSource");

	if (evs == null || evs.isEmpty())
	    throw new IllegalArgumentException("null or empty list of events");

	if (act != DnDConstants.ACTION_COPY &&
	    act != DnDConstants.ACTION_MOVE &&
	    act != DnDConstants.ACTION_LINK)
	    throw new IllegalArgumentException("bad action");

	if (ori == null) throw new IllegalArgumentException("null origin");

	events     = evs;
	action     = act;
	origin     = ori;
    
Methods Summary
public java.awt.ComponentgetComponent()
Returns the Component associated with this DragGestureEvent.

return
the Component

 return component; 
public intgetDragAction()
Returns an int representing the action selected by the user.

return
the action selected by the user

 return action; 
public java.awt.PointgetDragOrigin()
Returns a Point in the coordinates of the Component over which the drag originated.

return
the Point where the drag originated in Component coords.

	return origin;
    
public java.awt.dnd.DragSourcegetDragSource()
Returns the DragSource.

return
the DragSource

 return dragSource; 
public java.awt.dnd.DragGestureRecognizergetSourceAsDragGestureRecognizer()
Returns the source as a DragGestureRecognizer.

return
the source as a DragGestureRecognizer

	return (DragGestureRecognizer)getSource();
    
public java.awt.event.InputEventgetTriggerEvent()
Returns the initial event that triggered the gesture.

return
the first "triggering" event in the sequence of the gesture

	return getSourceAsDragGestureRecognizer().getTriggerEvent();
    
public java.util.Iteratoriterator()
Returns an Iterator for the events comprising the gesture.

return
an Iterator for the events comprising the gesture

 return events.iterator(); 
private voidreadObject(java.io.ObjectInputStream s)
Deserializes this DragGestureEvent. This method first performs default deserialization for all non-transient fields. An attempt is then made to deserialize this object's List of gesture events as well. This is first attempted by deserializing the field events, because, in releases prior to 1.4, a non-transient field of this name stored the List of gesture events. If this fails, the next object in the stream is used instead. If the resulting List is null, this object's List of gesture events is set to an empty List.

since
1.4

        ObjectInputStream.GetField f = s.readFields();

        dragSource = (DragSource)f.get("dragSource", null);
        component = (Component)f.get("component", null);
        origin = (Point)f.get("origin", null);
        action = f.get("action", 0);

        // Pre-1.4 support. 'events' was previously non-transient
        try {
            events = (List)f.get("events", null);
        } catch (IllegalArgumentException e) {
            // 1.4-compatible byte stream. 'events' was written explicitly
            events = (List)s.readObject();
        }

        // Implementation assumes 'events' is never null.
        if (events == null) {
            events = Collections.EMPTY_LIST;
        }
    
public voidstartDrag(java.awt.Cursor dragCursor, java.awt.datatransfer.Transferable transferable)
Starts the drag operation given the Cursor for this drag operation and the Transferable representing the source data for this drag operation.
If a null Cursor is specified no exception will be thrown and default drag cursors will be used instead.
If a null Transferable is specified NullPointerException will be thrown.

param
dragCursor The Cursor for this drag operation
param
transferable The Transferable representing the source data for this drag operation.
throws
InvalidDnDOperationException if the Drag and Drop system is unable to initiate a drag operation, or if the user attempts to start a drag while an existing drag operation is still executing.
throws
NullPointerException if the Transferable is null.
since
1.4

        dragSource.startDrag(this, dragCursor, transferable, null);
    
public voidstartDrag(java.awt.Cursor dragCursor, java.awt.datatransfer.Transferable transferable, java.awt.dnd.DragSourceListener dsl)
Starts the drag given the initial Cursor to display, the Transferable object, and the DragSourceListener to use.

param
dragCursor The initial drag Cursor
param
transferable The source's Transferable
param
dsl The source's DragSourceListener

throws
InvalidDnDOperationException if the Drag and Drop system is unable to initiate a drag operation, or if the user attempts to start a drag while an existing drag operation is still executing.

	dragSource.startDrag(this, dragCursor, transferable, dsl);
    
public voidstartDrag(java.awt.Cursor dragCursor, java.awt.Image dragImage, java.awt.Point imageOffset, java.awt.datatransfer.Transferable transferable, java.awt.dnd.DragSourceListener dsl)
Start the drag given the initial Cursor to display, a drag Image, the offset of the Image, the Transferable object, and the DragSourceListener to use.

param
dragCursor The initial drag Cursor
param
dragImage The source's dragImage
param
imageOffset The dragImage's offset
param
transferable The source's Transferable
param
dsl The source's DragSourceListener

throws
InvalidDnDOperationException if the Drag and Drop system is unable to initiate a drag operation, or if the user attempts to start a drag while an existing drag operation is still executing.

	dragSource.startDrag(this,  dragCursor, dragImage, imageOffset, transferable, dsl);
    
public java.lang.Object[]toArray()
Returns an Object array of the events comprising the drag gesture.

return
an array of the events comprising the gesture

 return events.toArray(); 
public java.lang.Object[]toArray(java.lang.Object[] array)
Returns an array of the events comprising the drag gesture.

param
array the array of EventObject sub(types)

return
an array of the events comprising the gesture

 return events.toArray(array); 
private voidwriteObject(java.io.ObjectOutputStream s)
Serializes this DragGestureEvent. Performs default serialization and then writes out this object's List of gesture events if and only if the List can be serialized. If not, null is written instead. In this case, a DragGestureEvent created from the resulting deserialized stream will contain an empty List of gesture events.

serialData
The default serializable fields, in alphabetical order, followed by either a List instance, or null.
since
1.4

        s.defaultWriteObject();

        s.writeObject(SerializationTester.test(events) ? events : null);