APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.dnd

public abstract Class DragGestureRecognizer

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
java.awt.dnd.MouseDragGestureRecognizer, javax.swing.TransferHandler.SwingDragGestureRecognizer
Imports
java.awt.Component, .Point, java.awt.event.InputEvent, java.io.IOException, .InvalidObjectException, .ObjectInputStream, .ObjectOutputStream, .Serial, .Serializable, java.util.ArrayList, .TooManyListenersException

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 instance is obtained from the DragSource associated 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 fires 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
See Also
java.awt.dnd.DragGestureListener, java.awt.dnd.DragGestureEvent, java.awt.dnd.DragSource

Field Summary

Modifier and TypeField and Description
protected Component
component

The Component associated with this DragGestureRecognizer.

protected transient DragGestureListener
dragGestureListener

The DragGestureListener associated with this DragGestureRecognizer.

protected DragSource
dragSource

The DragSource associated with this DragGestureRecognizer.

protected ArrayList<InputEvent>
events

The list of events (in order) that the DragGestureRecognizer "recognized" as a "gesture" that triggers a drag.

private static final long
serialVersionUID

Use serialVersionUID from JDK 1.4 for interoperability.

protected int
sourceActions

An int representing the type(s) of action(s) used in this Drag and Drop operation.

Constructor Summary

AccessConstructor and Description
protected
DragGestureRecognizer(DragSource
the DragSource this DragGestureRecognizer will use to process the Drag and Drop operation
ds
,
Component
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.
c
,
int
the set (logical OR) of the DnDConstants that this Drag and Drop operation will support
sa
,
DragGestureListener
the DragGestureRecognizer to notify when a drag gesture is detected
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.

protected
DragGestureRecognizer(DragSource
the DragSource this DragGestureRecognizer will use to process the Drag and Drop operation
ds
,
Component
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.
c
,
int
the set (logical OR) of the DnDConstants that this Drag and Drop operation will support
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.

protected
DragGestureRecognizer(DragSource
the DragSource this DragGestureRecognizer will use to process the Drag and Drop operation
ds
,
Component
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.
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.

protected
DragGestureRecognizer(DragSource
the DragSource this DragGestureRecognizer will use to process the Drag and Drop operation
ds
)

Construct a new DragGestureRecognizer given the DragSource to be used in this Drag and Drop operation.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addDragGestureListener(DragGestureListener
the DragGestureListener to register with this DragGestureRecognizer.
dgl
)

Register a new DragGestureListener.

protected synchronized void
appendEvent(InputEvent
the InputEvent to add to this DragGestureRecognizer's internal array of events. Note that null is not a valid value, and will be ignored.
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.

protected synchronized void
fireDragGestureRecognized(int
The action initially selected by the users gesture
dragAction
,
Point
The point (in Component coords) where the gesture originated
p
)

Notify the DragGestureListener that a Drag and Drop initiating gesture has occurred.

public synchronized Component

Returns:

The Component this DragGestureRecognizer is associated with
getComponent
()

This method returns the Component that is to be "observed" by the DragGestureRecognizer for drag initiating gestures.

public DragSource

Returns:

the DragSource
getDragSource
()

This method returns the DragSource this DragGestureRecognizer will use in order to process the Drag and Drop operation.

public synchronized int

Returns:

the currently permitted source action(s)
getSourceActions
()

This method returns an int representing the type of action(s) this Drag and Drop operation will support.

public InputEvent

Returns:

the initial event that triggered the drag gesture
getTriggerEvent
()

This method returns the first event in the series of events that initiated the Drag and Drop operation.

private void
readObject(ObjectInputStream
the ObjectInputStream to read
s
)

Deserializes this DragGestureRecognizer.

protected abstract void
registerListeners()

register this DragGestureRecognizer's Listeners with the Component subclasses must override this method

public synchronized void
removeDragGestureListener(DragGestureListener
the DragGestureListener to unregister from this DragGestureRecognizer
dgl
)

unregister the current DragGestureListener

public void
resetRecognizer()

Reset the Recognizer, if its currently recognizing a gesture, ignore it.

public synchronized void
setComponent(Component
The Component or null
c
)

set the Component that the DragGestureRecognizer is associated with registerListeners() and unregisterListeners() are called as a side effect as appropriate.

public synchronized void
setSourceActions(int
the permitted source drag action(s)
actions
)

This method sets the permitted source drag action(s) for this Drag and Drop operation.

protected abstract void
unregisterListeners()

unregister this DragGestureRecognizer's Listeners with the Component subclasses must override this method

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to write
s
)

Serializes this DragGestureRecognizer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

componentback to summary
protected Component component

The Component associated with this DragGestureRecognizer.

dragGestureListenerback to summary
protected transient DragGestureListener dragGestureListener

The DragGestureListener associated with this DragGestureRecognizer.

dragSourceback to summary
protected DragSource dragSource

The DragSource associated with this DragGestureRecognizer.

eventsback to summary
protected ArrayList<InputEvent> events

The list of events (in order) that the DragGestureRecognizer "recognized" as a "gesture" that triggers a drag.

serialVersionUIDback to summary
private static final long serialVersionUID

Use serialVersionUID from JDK 1.4 for interoperability.

Annotations
@Serial
sourceActionsback to summary
protected int sourceActions

An int representing the type(s) of action(s) used in this Drag and Drop operation.

Constructor Detail

DragGestureRecognizerback to 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.

Parameters
ds:DragSource

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

c:Component

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.

sa:int

the set (logical OR) of the DnDConstants that this Drag and Drop operation will support

dgl:DragGestureListener

the DragGestureRecognizer to notify when a drag gesture is detected

Exceptions
IllegalArgumentException:
if ds is null.
DragGestureRecognizerback to summary
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.

Parameters
ds:DragSource

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

c:Component

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.

sa:int

the set (logical OR) of the DnDConstants that this Drag and Drop operation will support

Exceptions
IllegalArgumentException:
if ds is null.
DragGestureRecognizerback to summary
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.

Parameters
ds:DragSource

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

c:Component

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.

Exceptions
IllegalArgumentException:
if ds is null.
DragGestureRecognizerback to summary
protected DragGestureRecognizer(DragSource ds)

Construct a new DragGestureRecognizer given the DragSource to be used in this Drag and Drop operation.

Parameters
ds:DragSource

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

Exceptions
IllegalArgumentException:
if ds is null.

Method Detail

addDragGestureListenerback to summary
public synchronized void addDragGestureListener(DragGestureListener dgl) throws TooManyListenersException

Register a new DragGestureListener.

Parameters
dgl:DragGestureListener

the DragGestureListener to register with this DragGestureRecognizer.

Exceptions
TooManyListenersException:
if a DragGestureListener has already been added.
appendEventback to summary
protected synchronized void appendEvent(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.

Parameters
awtie:InputEvent

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

fireDragGestureRecognizedback to summary
protected synchronized void fireDragGestureRecognized(int dragAction, Point p)

Notify the DragGestureListener that a Drag and Drop initiating gesture has occurred. Then reset the state of the Recognizer.

Parameters
dragAction:int

The action initially selected by the users gesture

p:Point

The point (in Component coords) where the gesture originated

getComponentback to summary
public synchronized Component getComponent()

This method returns the Component that is to be "observed" by the DragGestureRecognizer for drag initiating gestures.

Returns:Component

The Component this DragGestureRecognizer is associated with

getDragSourceback to summary
public DragSource getDragSource()

This method returns the DragSource this DragGestureRecognizer will use in order to process the Drag and Drop operation.

Returns:DragSource

the DragSource

getSourceActionsback to summary
public synchronized int getSourceActions()

This method returns an int representing the type of action(s) this Drag and Drop operation will support.

Returns:int

the currently permitted source action(s)

getTriggerEventback to summary
public InputEvent getTriggerEvent()

This method returns the first event in the series of events that initiated the Drag and Drop operation.

Returns:InputEvent

the initial event that triggered the drag gesture

readObjectback to summary
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException

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.

Parameters
s:ObjectInputStream

the ObjectInputStream to read

Annotations
@Serial
@SuppressWarnings:unchecked
Exceptions
ClassNotFoundException:
if the class of a serialized object could not be found
IOException:
if an I/O error occurs
Since
1.4
registerListenersback to summary
protected abstract void registerListeners()

register this DragGestureRecognizer's Listeners with the Component subclasses must override this method

removeDragGestureListenerback to summary
public synchronized void removeDragGestureListener(DragGestureListener dgl)

unregister the current DragGestureListener

Parameters
dgl:DragGestureListener

the DragGestureListener to unregister from this DragGestureRecognizer

Exceptions
IllegalArgumentException:
if dgl is not (equal to) the currently registered DragGestureListener.
resetRecognizerback to summary
public void resetRecognizer()

Reset the Recognizer, if its currently recognizing a gesture, ignore it.

setComponentback to summary
public synchronized void setComponent(Component c)

set the Component that the DragGestureRecognizer is associated with registerListeners() and unregisterListeners() are called as a side effect as appropriate.

Parameters
c:Component

The Component or null

setSourceActionsback to summary
public synchronized void setSourceActions(int actions)

This method sets the permitted source drag action(s) for this Drag and Drop operation.

Parameters
actions:int

the permitted source drag action(s)

unregisterListenersback to summary
protected abstract void unregisterListeners()

unregister this DragGestureRecognizer's Listeners with the Component subclasses must override this method

writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

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.

Parameters
s:ObjectOutputStream

the ObjectOutputStream to write

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
Since
1.4
Serial data
The default serializable fields, in alphabetical order, followed by either a DragGestureListener, or null.