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

public Class DropTarget

extends Object
implements DropTargetListener, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.awt.dnd.DropTargetListener, java.util.EventListener
Known Direct Subclasses
javax.swing.TransferHandler.SwingDropTarget, sun.awt.X11.XEmbedCanvasPeer.XEmbedDropTarget
Imports
java.awt.Component, .Dimension, .GraphicsEnvironment, .HeadlessException, .Insets, .Point, .Rectangle, .Toolkit, java.awt.datatransfer.FlavorMap, .SystemFlavorMap, java.awt.dnd.peer.DropTargetPeer, java.awt.event.ActionEvent, .ActionListener, java.awt.peer.ComponentPeer, .LightweightPeer, java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serial, .Serializable, java.util.TooManyListenersException, javax.swing.Timer, sun.awt.AWTAccessor, .AWTAccessor.ComponentAccessor

The DropTarget is associated with a Component when that Component wishes to accept drops during Drag and Drop operations.

Each DropTarget is associated with a FlavorMap. The default FlavorMap hereafter designates the FlavorMap returned by SystemFlavorMap.getDefaultFlavorMap().

Since
1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
DropTarget.DropTargetAutoScroller

this protected nested class implements autoscrolling

Field Summary

Modifier and TypeField and Description
pack-priv int
actions

Default permissible actions supported by this DropTarget.

pack-priv boolean
active

true if the DropTarget is accepting Drag & Drop operations.

private transient DropTarget.DropTargetAutoScroller
private Component
component

The Component associated with this DropTarget.

private transient ComponentPeer
private DropTargetContext
dropTargetContext

The DropTargetContext associated with this DropTarget.

private transient DropTargetListener
private transient FlavorMap
private transient boolean
private transient DropTargetPeer
private static final long
serialVersionUID

Use serialVersionUID from JDK 1.4 for interoperability.

Constructor Summary

AccessConstructor and Description
public
DropTarget(Component
The Component with which this DropTarget is associated
c
,
int
The default acceptable actions for this DropTarget
ops
,
DropTargetListener
The DropTargetListener for this DropTarget
dtl
,
boolean
Is the DropTarget accepting drops.
act
,
FlavorMap
The FlavorMap to use, or null for the default FlavorMap
fm
)

Creates a new DropTarget given the Component to associate itself with, an int representing the default acceptable action(s) to support, a DropTargetListener to handle event processing, a boolean indicating if the DropTarget is currently accepting drops, and a FlavorMap to use (or null for the default FlavorMap).

public
DropTarget(Component
The Component with which this DropTarget is associated
c
,
int
The default acceptable actions for this DropTarget
ops
,
DropTargetListener
The DropTargetListener for this DropTarget
dtl
,
boolean
Is the DropTarget accepting drops.
act
)

Creates a DropTarget given the Component to associate itself with, an int representing the default acceptable action(s) to support, a DropTargetListener to handle event processing, and a boolean indicating if the DropTarget is currently accepting drops.

public
DropTarget()

Creates a DropTarget.

public
DropTarget(Component
The Component with which this DropTarget is associated
c
,
DropTargetListener
The DropTargetListener for this DropTarget
dtl
)

Creates a DropTarget given the Component to associate itself with, and the DropTargetListener to handle event processing.

public
DropTarget(Component
The Component with which this DropTarget is associated
c
,
int
The default acceptable actions for this DropTarget
ops
,
DropTargetListener
The DropTargetListener for this DropTarget
dtl
)

Creates a DropTarget given the Component to associate itself with, an int representing the default acceptable action(s) to support, and a DropTargetListener to handle event processing.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addDropTargetListener(DropTargetListener
The new DropTargetListener
dtl
)

Adds a new DropTargetListener (UNICAST SOURCE).

public void
addNotify()

Notify the DropTarget that it has been associated with a Component This method is usually called from java.awt.Component.addNotify() of the Component associated with this DropTarget to notify the DropTarget that a ComponentPeer has been associated with that Component.

protected void
clearAutoscroll()

clear autoscrolling

protected DropTarget.DropTargetAutoScroller

Returns:

an embedded autoscroller
createDropTargetAutoScroller
(Component
the Component
c
,
Point
the Point
p
)

create an embedded autoscroller

protected DropTargetContext

Returns:

the DropTargetContext associated with this DropTarget
createDropTargetContext
()

Creates the DropTargetContext associated with this DropTarget.

pack-priv void
public synchronized void
dragEnter(DropTargetDragEvent
the DropTargetDragEvent
dtde
)

Implements java.awt.dnd.DropTargetListener.dragEnter.

Calls dragEnter on the registered DropTargetListener and passes it the specified DropTargetDragEvent.

public synchronized void
dragExit(DropTargetEvent
the DropTargetEvent
dte
)

Implements java.awt.dnd.DropTargetListener.dragExit.

Calls dragExit on the registered DropTargetListener and passes it the specified DropTargetEvent.

public synchronized void
dragOver(DropTargetDragEvent
the DropTargetDragEvent
dtde
)

Implements java.awt.dnd.DropTargetListener.dragOver.

Calls dragOver on the registered DropTargetListener and passes it the specified DropTargetDragEvent.

public synchronized void
drop(DropTargetDropEvent
the DropTargetDropEvent
dtde
)

Implements java.awt.dnd.DropTargetListener.drop.

Calls drop on the registered DropTargetListener and passes it the specified DropTargetDropEvent if this DropTarget is active.

public synchronized void
dropActionChanged(DropTargetDragEvent
the DropTargetDragEvent
dtde
)

Implements java.awt.dnd.DropTargetListener.dropActionChanged.

Calls dropActionChanged on the registered DropTargetListener and passes it the specified DropTargetDragEvent.

public synchronized Component

Returns:

the current Component
getComponent
()

Gets the Component associated with this DropTarget.

public int

Returns:

the current default actions
getDefaultActions
()

Gets an int representing the current action(s) supported by this DropTarget.

public DropTargetContext

Returns:

the DropTargetContext associated with this DropTarget.
getDropTargetContext
()

Gets the DropTargetContext associated with this DropTarget.

public FlavorMap

Returns:

the FlavorMap for this DropTarget
getFlavorMap
()

Gets the FlavorMap associated with this DropTarget.

protected void
initializeAutoscrolling(Point
the Point
p
)

initialize autoscrolling

public boolean

Returns:

true if active, false if not
isActive
()

Reports whether or not this DropTarget is currently active (ready to accept drops).

private void
readObject(ObjectInputStream
the ObjectInputStream to read
s
)

Deserializes this DropTarget.

public synchronized void
removeDropTargetListener(DropTargetListener
the DropTargetListener to deregister.
dtl
)

Removes the current DropTargetListener (UNICAST SOURCE).

public void
removeNotify()

Notify the DropTarget that it has been disassociated from a Component This method is usually called from java.awt.Component.removeNotify() of the Component associated with this DropTarget to notify the DropTarget that a ComponentPeer has been disassociated with that Component.

public synchronized void
setActive(boolean
sets the DropTarget (in)active.
isActive
)

Sets the DropTarget active if true, inactive if false.

public synchronized void
setComponent(Component
The new Component this DropTarget is to be associated with.
c
)

The Component will receive drops only if it is enabled.

public void
setDefaultActions(int
the default actions
ops
)

Sets the default acceptable actions for this DropTarget

public void
setFlavorMap(FlavorMap
the new FlavorMap, or null to associate the default FlavorMap with this DropTarget.
fm
)

Sets the FlavorMap associated with this DropTarget.

protected void
updateAutoscroll(Point
the Point
dragCursorLocn
)

update autoscrolling with current cursor location

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to write
s
)

Serializes this DropTarget.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actionsback to summary
pack-priv int actions

Default permissible actions supported by this DropTarget.

See Also
setDefaultActions, getDefaultActions
activeback to summary
pack-priv boolean active

true if the DropTarget is accepting Drag & Drop operations.

autoScrollerback to summary
private transient DropTarget.DropTargetAutoScroller autoScroller
componentback to summary
private Component component

The Component associated with this DropTarget.

componentPeerback to summary
private transient ComponentPeer componentPeer
dropTargetContextback to summary
private DropTargetContext dropTargetContext

The DropTargetContext associated with this DropTarget.

dtListenerback to summary
private transient DropTargetListener dtListener
flavorMapback to summary
private transient FlavorMap flavorMap
isDraggingInsideback to summary
private transient boolean isDraggingInside
nativePeerback to summary
private transient DropTargetPeer nativePeer
serialVersionUIDback to summary
private static final long serialVersionUID

Use serialVersionUID from JDK 1.4 for interoperability.

Annotations
@Serial

Constructor Detail

DropTargetback to summary
public DropTarget(Component c, int ops, DropTargetListener dtl, boolean act, FlavorMap fm) throws HeadlessException

Creates a new DropTarget given the Component to associate itself with, an int representing the default acceptable action(s) to support, a DropTargetListener to handle event processing, a boolean indicating if the DropTarget is currently accepting drops, and a FlavorMap to use (or null for the default FlavorMap).

The Component will receive drops only if it is enabled.

Parameters
c:Component

The Component with which this DropTarget is associated

ops:int

The default acceptable actions for this DropTarget

dtl:DropTargetListener

The DropTargetListener for this DropTarget

act:boolean

Is the DropTarget accepting drops.

fm:FlavorMap

The FlavorMap to use, or null for the default FlavorMap

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless() returns true
See Also
java.awt.GraphicsEnvironment#isHeadless
DropTargetback to summary
public DropTarget(Component c, int ops, DropTargetListener dtl, boolean act) throws HeadlessException

Creates a DropTarget given the Component to associate itself with, an int representing the default acceptable action(s) to support, a DropTargetListener to handle event processing, and a boolean indicating if the DropTarget is currently accepting drops.

The Component will receive drops only if it is enabled.

Parameters
c:Component

The Component with which this DropTarget is associated

ops:int

The default acceptable actions for this DropTarget

dtl:DropTargetListener

The DropTargetListener for this DropTarget

act:boolean

Is the DropTarget accepting drops.

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless() returns true
See Also
java.awt.GraphicsEnvironment#isHeadless
DropTargetback to summary
public DropTarget() throws HeadlessException

Creates a DropTarget.

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless() returns true
See Also
java.awt.GraphicsEnvironment#isHeadless
DropTargetback to summary
public DropTarget(Component c, DropTargetListener dtl) throws HeadlessException

Creates a DropTarget given the Component to associate itself with, and the DropTargetListener to handle event processing.

The Component will receive drops only if it is enabled.

Parameters
c:Component

The Component with which this DropTarget is associated

dtl:DropTargetListener

The DropTargetListener for this DropTarget

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless() returns true
See Also
java.awt.GraphicsEnvironment#isHeadless
DropTargetback to summary
public DropTarget(Component c, int ops, DropTargetListener dtl) throws HeadlessException

Creates a DropTarget given the Component to associate itself with, an int representing the default acceptable action(s) to support, and a DropTargetListener to handle event processing.

The Component will receive drops only if it is enabled.

Parameters
c:Component

The Component with which this DropTarget is associated

ops:int

The default acceptable actions for this DropTarget

dtl:DropTargetListener

The DropTargetListener for this DropTarget

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless() returns true
See Also
java.awt.GraphicsEnvironment#isHeadless

Method Detail

addDropTargetListenerback to summary
public synchronized void addDropTargetListener(DropTargetListener dtl) throws TooManyListenersException

Adds a new DropTargetListener (UNICAST SOURCE).

Parameters
dtl:DropTargetListener

The new DropTargetListener

Exceptions
TooManyListenersException:
if a DropTargetListener is already added to this DropTarget.
addNotifyback to summary
public void addNotify()

Notify the DropTarget that it has been associated with a Component This method is usually called from java.awt.Component.addNotify() of the Component associated with this DropTarget to notify the DropTarget that a ComponentPeer has been associated with that Component. Calling this method, other than to notify this DropTarget of the association of the ComponentPeer with the Component may result in a malfunction of the DnD system.

clearAutoscrollback to summary
protected void clearAutoscroll()

clear autoscrolling

createDropTargetAutoScrollerback to summary
protected DropTarget.DropTargetAutoScroller createDropTargetAutoScroller(Component c, Point p)

create an embedded autoscroller

Parameters
c:Component

the Component

p:Point

the Point

Returns:DropTarget.DropTargetAutoScroller

an embedded autoscroller

createDropTargetContextback to summary
protected DropTargetContext createDropTargetContext()

Creates the DropTargetContext associated with this DropTarget. Subclasses may override this method to instantiate their own DropTargetContext subclass. This call is typically *only* called by the platform's DropTargetContextPeer as a drag operation encounters this DropTarget. Accessing the Context while no Drag is current has undefined results.

Returns:DropTargetContext

the DropTargetContext associated with this DropTarget

doSetDefaultActionsback to summary
pack-priv void doSetDefaultActions(int ops)
dragEnterback to summary
public synchronized void dragEnter(DropTargetDragEvent dtde)

Implements java.awt.dnd.DropTargetListener.dragEnter.

Calls dragEnter on the registered DropTargetListener and passes it the specified DropTargetDragEvent. Has no effect if this DropTarget is not active.

Parameters
dtde:DropTargetDragEvent

the DropTargetDragEvent

Exceptions
NullPointerException:
if this DropTarget is active and dtde is null
See Also
isActive
dragExitback to summary
public synchronized void dragExit(DropTargetEvent dte)

Implements java.awt.dnd.DropTargetListener.dragExit.

Calls dragExit on the registered DropTargetListener and passes it the specified DropTargetEvent. Has no effect if this DropTarget is not active.

This method itself does not throw any exception for null parameter but for exceptions thrown by the respective method of the listener.

Parameters
dte:DropTargetEvent

the DropTargetEvent

See Also
isActive
dragOverback to summary
public synchronized void dragOver(DropTargetDragEvent dtde)

Implements java.awt.dnd.DropTargetListener.dragOver.

Calls dragOver on the registered DropTargetListener and passes it the specified DropTargetDragEvent. Has no effect if this DropTarget is not active.

Parameters
dtde:DropTargetDragEvent

the DropTargetDragEvent

Exceptions
NullPointerException:
if this DropTarget is active and dtde is null
See Also
isActive
dropback to summary
public synchronized void drop(DropTargetDropEvent dtde)

Implements java.awt.dnd.DropTargetListener.drop.

Calls drop on the registered DropTargetListener and passes it the specified DropTargetDropEvent if this DropTarget is active.

Parameters
dtde:DropTargetDropEvent

the DropTargetDropEvent

Exceptions
NullPointerException:
if dtde is null and at least one of the following is true: this DropTarget is not active, or there is no a DropTargetListener registered.
See Also
isActive
dropActionChangedback to summary
public synchronized void dropActionChanged(DropTargetDragEvent dtde)

Implements java.awt.dnd.DropTargetListener.dropActionChanged.

Calls dropActionChanged on the registered DropTargetListener and passes it the specified DropTargetDragEvent. Has no effect if this DropTarget is not active.

Parameters
dtde:DropTargetDragEvent

the DropTargetDragEvent

Exceptions
NullPointerException:
if this DropTarget is active and dtde is null
See Also
isActive
getComponentback to summary
public synchronized Component getComponent()

Gets the Component associated with this DropTarget.

Returns:Component

the current Component

getDefaultActionsback to summary
public int getDefaultActions()

Gets an int representing the current action(s) supported by this DropTarget.

Returns:int

the current default actions

getDropTargetContextback to summary
public DropTargetContext getDropTargetContext()

Gets the DropTargetContext associated with this DropTarget.

Returns:DropTargetContext

the DropTargetContext associated with this DropTarget.

getFlavorMapback to summary
public FlavorMap getFlavorMap()

Gets the FlavorMap associated with this DropTarget. If no FlavorMap has been set for this DropTarget, it is associated with the default FlavorMap.

Returns:FlavorMap

the FlavorMap for this DropTarget

initializeAutoscrollingback to summary
protected void initializeAutoscrolling(Point p)

initialize autoscrolling

Parameters
p:Point

the Point

isActiveback to summary
public boolean isActive()

Reports whether or not this DropTarget is currently active (ready to accept drops).

Returns:boolean

true if active, false if not

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

Deserializes this DropTarget. This method first performs default deserialization for all non-transient fields. An attempt is then made to deserialize this object's DropTargetListener as well. This is first attempted by deserializing the field dtListener, because, in releases prior to 1.4, a non-transient field of this name stored the DropTargetListener. If this fails, the next object in the stream is used instead.

Parameters
s:ObjectInputStream

the ObjectInputStream to read

Annotations
@Serial
Exceptions
ClassNotFoundException:
if the class of a serialized object could not be found
IOException:
if an I/O error occurs
Since
1.4
removeDropTargetListenerback to summary
public synchronized void removeDropTargetListener(DropTargetListener dtl)

Removes the current DropTargetListener (UNICAST SOURCE).

Parameters
dtl:DropTargetListener

the DropTargetListener to deregister.

removeNotifyback to summary
public void removeNotify()

Notify the DropTarget that it has been disassociated from a Component This method is usually called from java.awt.Component.removeNotify() of the Component associated with this DropTarget to notify the DropTarget that a ComponentPeer has been disassociated with that Component. Calling this method, other than to notify this DropTarget of the disassociation of the ComponentPeer from the Component may result in a malfunction of the DnD system.

setActiveback to summary
public synchronized void setActive(boolean isActive)

Sets the DropTarget active if true, inactive if false.

Parameters
isActive:boolean

sets the DropTarget (in)active.

setComponentback to summary
public synchronized void setComponent(Component c)

Note

this interface is required to permit the safe association of a DropTarget with a Component in one of two ways, either: component.setDropTarget(droptarget); or droptarget.setComponent(component);

The Component will receive drops only if it is enabled.

Parameters
c:Component

The new Component this DropTarget is to be associated with.

setDefaultActionsback to summary
public void setDefaultActions(int ops)

Sets the default acceptable actions for this DropTarget

Parameters
ops:int

the default actions

See Also
java.awt.dnd.DnDConstants
setFlavorMapback to summary
public void setFlavorMap(FlavorMap fm)

Sets the FlavorMap associated with this DropTarget.

Parameters
fm:FlavorMap

the new FlavorMap, or null to associate the default FlavorMap with this DropTarget.

updateAutoscrollback to summary
protected void updateAutoscroll(Point dragCursorLocn)

update autoscrolling with current cursor location

Parameters
dragCursorLocn:Point

the Point

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

Serializes this DropTarget. Performs default serialization, and then writes out this object's DropTargetListener 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 DropTargetListener instance, or null.
java.awt.dnd back to summary

protected Class DropTarget.DropTargetAutoScroller

extends Object
implements ActionListener
Class Inheritance
All Implemented Interfaces
java.awt.event.ActionListener, java.util.EventListener

this protected nested class implements autoscrolling

Field Summary

Modifier and TypeField and Description
private Autoscroll
private Component
private int
private Rectangle
private Point
private Rectangle
private Point
private Timer

Constructor Summary

AccessConstructor and Description
protected
DropTargetAutoScroller(Component
the Component
c
,
Point
the Point
p
)

construct a DropTargetAutoScroller

Method Summary

Modifier and TypeMethod and Description
public synchronized void
actionPerformed(ActionEvent
the ActionEvent
e
)

Implements java.awt.event.ActionListener.actionPerformed.

cause autoscroll to occur

protected void
stop()

cause autoscrolling to stop

protected synchronized void
updateLocation(Point
the Point
newLocn
)

cause autoscroll to occur

private void
updateRegion()

update the geometry of the autoscroll region

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autoScrollback to summary
private Autoscroll autoScroll
componentback to summary
private Component component
hysteresisback to summary
private int hysteresis
innerback to summary
private Rectangle inner
locnback to summary
private Point locn
outerback to summary
private Rectangle outer
prevback to summary
private Point prev
timerback to summary
private Timer timer

Constructor Detail

DropTargetAutoScrollerback to summary
protected DropTargetAutoScroller(Component c, Point p)

construct a DropTargetAutoScroller

Parameters
c:Component

the Component

p:Point

the Point

Method Detail

actionPerformedback to summary
public synchronized void actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

cause autoscroll to occur

Parameters
e:ActionEvent

the ActionEvent

stopback to summary
protected void stop()

cause autoscrolling to stop

updateLocationback to summary
protected synchronized void updateLocation(Point newLocn)

cause autoscroll to occur

Parameters
newLocn:Point

the Point

updateRegionback to summary
private void updateRegion()

update the geometry of the autoscroll region

Annotations
@SuppressWarnings:deprecation