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

DragGestureRecognizer

public abstract class DragGestureRecognizer extends Object implements Serializable
The DragGestureRecognizer is an abstract base class for the specification of a platform-dependent listener that can be associated with a particular Component in order to identify platform-dependent drag initiating gestures.

The appropriate DragGestureRecognizer subclass is obtained from the DragSource asssociated with a particular Component, or from the Toolkit object via its createDragGestureRecognizer() method.

Once the DragGestureRecognizer is associated with a particular Component it will register the appropriate listener interfaces on that Component in order to track the input events delivered to the Component.

Once the DragGestureRecognizer identifies a sequence of events on the Component as a drag initiating gesture, it will notify its unicast DragGestureListener by invoking its gestureRecognized() method.

When a concrete DragGestureRecognizer instance detects a drag initiating gesture on the Component it is associated with, it will fire a DragGestureEvent to the DragGestureListener registered on its unicast event source for DragGestureListener events. This DragGestureListener is responsible for causing the associated DragSource to start the Drag and Drop operation (if appropriate).

author
Laurence P. G. Cable
version
1.20
see
java.awt.dnd.DragGestureListener
see
java.awt.dnd.DragGestureEvent
see
java.awt.dnd.DragSource

Fields Summary
private static final long
serialVersionUID
protected DragSource
dragSource
The DragSource associated with this DragGestureRecognizer.
protected Component
component
The Component associated with this DragGestureRecognizer.
protected transient DragGestureListener
dragGestureListener
The DragGestureListener associated with this DragGestureRecognizer.
protected int
sourceActions
An int representing the type(s) of action(s) used in this Drag and Drop operation.
protected ArrayList
events
The list of events (in order) that the DragGestureRecognizer "recognized" as a "gesture" that triggers a drag.
Constructors Summary
protected DragGestureRecognizer(DragSource ds, Component c, int sa, DragGestureListener dgl)
Construct a new DragGestureRecognizer given the DragSource to be used in this Drag and Drop operation, the Component this DragGestureRecognizer should "observe" for drag initiating gestures, the action(s) supported for this Drag and Drop operation, and the DragGestureListener to notify once a drag initiating gesture has been detected.

param
ds the DragSource this DragGestureRecognizer will use to process the Drag and Drop operation
param
c the Component this DragGestureRecognizer should "observe" the event stream to, in order to detect a drag initiating gesture. If this value is null, the DragGestureRecognizer is not associated with any Component.
param
sa the set (logical OR) of the DnDConstants that this Drag and Drop operation will support
param
dgl the DragGestureRecognizer to notify when a drag gesture is detected

throws
IllegalArgumentException if ds is null.


                                                                                                                                                                

             
	super();

	if (ds == null) throw new IllegalArgumentException("null DragSource");

	dragSource    = ds;
	component     = c;
	sourceActions = sa & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);

	try {
	    if (dgl != null) addDragGestureListener(dgl);
	} catch (TooManyListenersException tmle) {
	    // cant happen ...
	}
    
protected DragGestureRecognizer(DragSource ds, Component c, int sa)
Construct a new DragGestureRecognizer given the DragSource to be used in this Drag and Drop operation, the Component this DragGestureRecognizer should "observe" for drag initiating gestures, and the action(s) supported for this Drag and Drop operation.

param
ds the DragSource this DragGestureRecognizer will use to process the Drag and Drop operation
param
c the Component this DragGestureRecognizer should "observe" the event stream to, in order to detect a drag initiating gesture. If this value is null, the DragGestureRecognizer is not associated with any Component.
param
sa the set (logical OR) of the DnDConstants that this Drag and Drop operation will support

throws
IllegalArgumentException if ds is null.

	this(ds, c, sa, null);
    
protected DragGestureRecognizer(DragSource ds, Component c)
Construct a new DragGestureRecognizer given the DragSource to be used in this Drag and Drop operation, and the Component this DragGestureRecognizer should "observe" for drag initiating gestures.

param
ds the DragSource this DragGestureRecognizer will use to process the Drag and Drop operation
param
c the Component this DragGestureRecognizer should "observe" the event stream to, in order to detect a drag initiating gesture. If this value is null, the DragGestureRecognizer is not associated with any Component.

throws
IllegalArgumentException if ds is null.

	this(ds, c, DnDConstants.ACTION_NONE);
    
protected DragGestureRecognizer(DragSource ds)
Construct a new DragGestureRecognizer given the DragSource to be used in this Drag and Drop operation.

param
ds the DragSource this DragGestureRecognizer will use to process the Drag and Drop operation

throws
IllegalArgumentException if ds is null.

	this(ds, null);
    
Methods Summary
public synchronized voidaddDragGestureListener(java.awt.dnd.DragGestureListener dgl)
Register a new DragGestureListener.

param
dgl the DragGestureListener to register with this DragGestureRecognizer.

throws
java.util.TooManyListenersException if a DragGestureListener has already been added.

	if (dragGestureListener != null)
	    throw new TooManyListenersException();
	else {
	    dragGestureListener = dgl;

	    if (component != null) registerListeners();
	}
    
protected synchronized voidappendEvent(java.awt.event.InputEvent awtie)
Listeners registered on the Component by this Recognizer shall record all Events that are recognized as part of the series of Events that go to comprise a Drag and Drop initiating gesture via this API.

This method is used by a DragGestureRecognizer implementation to add an InputEvent subclass (that it believes is one in a series of events that comprise a Drag and Drop operation) to the array of events that this DragGestureRecognizer maintains internally.

param
awtie the InputEvent to add to this DragGestureRecognizer's internal array of events. Note that null is not a valid value, and will be ignored.

	events.add(awtie);
    
protected synchronized voidfireDragGestureRecognized(int dragAction, java.awt.Point p)
Notify the DragGestureListener that a Drag and Drop initiating gesture has occurred. Then reset the state of the Recognizer.

param
dragAction The action initially selected by the users gesture
param
p The point (in Component coords) where the gesture originated

        try {
            if (dragGestureListener != null) {
                dragGestureListener.dragGestureRecognized(new DragGestureEvent(this, dragAction, p, events));
            }
        } finally {
            events.clear();
        }
    
public synchronized java.awt.ComponentgetComponent()
This method returns the Component that is to be "observed" by the DragGestureRecognizer for drag initiating gestures.

return
The Component this DragGestureRecognizer is associated with

 return component; 
public java.awt.dnd.DragSourcegetDragSource()
This method returns the DragSource this DragGestureRecognizer will use in order to process the Drag and Drop operation.

return
the DragSource

 return dragSource; 
public synchronized intgetSourceActions()
This method returns an int representing the type of action(s) this Drag and Drop operation will support.

return
the currently permitted source action(s)

 return sourceActions; 
public java.awt.event.InputEventgetTriggerEvent()
This method returns the first event in the series of events that initiated the Drag and Drop operation.

return
the initial event that triggered the drag gesture

 return events.isEmpty() ? null : (InputEvent)events.get(0); 
private voidreadObject(java.io.ObjectInputStream s)
Deserializes this DragGestureRecognizer. This method first performs default deserialization for all non-transient fields. This object's DragGestureListener is then deserialized as well by using the next object in the stream.

since
1.4

        s.defaultReadObject();

        dragGestureListener = (DragGestureListener)s.readObject();
    
protected abstract voidregisterListeners()
register this DragGestureRecognizer's Listeners with the Component subclasses must override this method

public synchronized voidremoveDragGestureListener(java.awt.dnd.DragGestureListener dgl)
unregister the current DragGestureListener

param
dgl the DragGestureListener to unregister from this DragGestureRecognizer

throws
IllegalArgumentException if dgl is not (equal to) the currently registered DragGestureListener.

	if (dragGestureListener == null || !dragGestureListener.equals(dgl))
	    throw new IllegalArgumentException();
	else {
	    dragGestureListener = null;

	    if (component != null) unregisterListeners();
	}
    
public voidresetRecognizer()
Reset the Recognizer, if its currently recognizing a gesture, ignore it.

 events.clear(); 
public synchronized voidsetComponent(java.awt.Component c)
set the Component that the DragGestureRecognizer is associated with registerListeners() and unregisterListeners() are called as a side effect as appropriate.

param
c The Component or null

	if (component != null && dragGestureListener != null)
	    unregisterListeners();

	component = c;

	if (component != null && dragGestureListener != null)
	    registerListeners();
    
public synchronized voidsetSourceActions(int actions)
This method sets the permitted source drag action(s) for this Drag and Drop operation.

param
actions the permitted source drag action(s)

	sourceActions = actions & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
    
protected abstract voidunregisterListeners()
unregister this DragGestureRecognizer's Listeners with the Component subclasses must override this method

private voidwriteObject(java.io.ObjectOutputStream s)
Serializes this DragGestureRecognizer. This method first performs default serialization. Then, this object's DragGestureListener is written out if and only if it can be serialized. If not, null is written instead.

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

        s.defaultWriteObject();

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