Class DropTarget
- All Implemented Interfaces:
-
DropTargetListener
,Serializable
,EventListener
public class DropTarget extends Object implements DropTargetListener, Serializable
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
- See Also:
Nested Class Summary
Modifier and Type | Class | Description |
---|---|---|
protected static class |
DropTarget.DropTargetAutoScroller |
this protected nested class implements autoscrolling |
Constructor Summary
Constructor | Description |
---|---|
DropTarget() |
Creates a DropTarget . |
DropTarget |
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. |
DropTarget |
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. |
DropTarget |
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 ). |
DropTarget |
Creates a DropTarget given the Component to associate itself with, and the DropTargetListener to handle event processing. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
void |
addDropTargetListener |
Adds a new DropTargetListener (UNICAST SOURCE). |
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 |
createDropTargetAutoScroller |
create an embedded autoscroller |
protected DropTargetContext |
createDropTargetContext() |
Creates the DropTargetContext associated with this DropTarget. |
void |
dragEnter |
Calls dragEnter on the registered DropTargetListener and passes it the specified DropTargetDragEvent . |
void |
dragExit |
Calls dragExit on the registered DropTargetListener and passes it the specified DropTargetEvent . |
void |
dragOver |
Calls dragOver on the registered DropTargetListener and passes it the specified DropTargetDragEvent . |
void |
drop |
Calls drop on the registered DropTargetListener and passes it the specified DropTargetDropEvent if this DropTarget is active. |
void |
dropActionChanged |
Calls dropActionChanged on the registered DropTargetListener and passes it the specified DropTargetDragEvent . |
Component |
getComponent() |
Gets the Component associated with this DropTarget . |
int |
getDefaultActions() |
Gets an int representing the current action(s) supported by this DropTarget . |
DropTargetContext |
getDropTargetContext() |
Gets the DropTargetContext associated with this DropTarget . |
FlavorMap |
getFlavorMap() |
Gets the FlavorMap associated with this DropTarget . |
protected void |
initializeAutoscrolling |
initialize autoscrolling |
boolean |
isActive() |
Reports whether or not this DropTarget is currently active (ready to accept drops). |
void |
removeDropTargetListener |
Removes the current DropTargetListener (UNICAST SOURCE). |
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. |
void |
setActive |
Sets the DropTarget active if true , inactive if false . |
void |
setComponent |
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);
|
void |
setDefaultActions |
Sets the default acceptable actions for this DropTarget
|
void |
setFlavorMap |
Sets the FlavorMap associated with this DropTarget . |
protected void |
updateAutoscroll |
update autoscrolling with current cursor location |
Constructor Details
DropTarget
public DropTarget(Component c, int ops, DropTargetListener dtl, boolean act, FlavorMap fm) throws HeadlessException
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
- TheComponent
with which thisDropTarget
is associated -
ops
- The default acceptable actions for thisDropTarget
-
dtl
- TheDropTargetListener
for thisDropTarget
-
act
- Is theDropTarget
accepting drops. -
fm
- TheFlavorMap
to use, or null for the defaultFlavorMap
- Throws:
-
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true - See Also:
DropTarget
public DropTarget(Component c, int ops, DropTargetListener dtl, boolean act) throws HeadlessException
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
- TheComponent
with which thisDropTarget
is associated -
ops
- The default acceptable actions for thisDropTarget
-
dtl
- TheDropTargetListener
for thisDropTarget
-
act
- Is theDropTarget
accepting drops. - Throws:
-
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true - See Also:
DropTarget
public DropTarget() throws HeadlessException
DropTarget
.- Throws:
-
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true - See Also:
DropTarget
public DropTarget(Component c, DropTargetListener dtl) throws HeadlessException
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
- TheComponent
with which thisDropTarget
is associated -
dtl
- TheDropTargetListener
for thisDropTarget
- Throws:
-
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true - See Also:
DropTarget
public DropTarget(Component c, int ops, DropTargetListener dtl) throws HeadlessException
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
- TheComponent
with which thisDropTarget
is associated -
ops
- The default acceptable actions for thisDropTarget
-
dtl
- TheDropTargetListener
for thisDropTarget
- Throws:
-
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true - See Also:
Method Details
setComponent
public void setComponent(Component c)
component.setDropTarget(droptarget);
or droptarget.setComponent(component);
The Component will receive drops only if it is enabled.
- Parameters:
-
c
- The newComponent
thisDropTarget
is to be associated with.
getComponent
public Component getComponent()
Component
associated with this DropTarget
.- Returns:
- the current
Component
setDefaultActions
public void setDefaultActions(int ops)
DropTarget
- Parameters:
-
ops
- the default actions - See Also:
getDefaultActions
public int getDefaultActions()
int
representing the current action(s) supported by this DropTarget
.- Returns:
- the current default actions
setActive
public void setActive(boolean isActive)
true
, inactive if false
.- Parameters:
-
isActive
- sets theDropTarget
(in)active.
isActive
public boolean isActive()
DropTarget
is currently active (ready to accept drops).- Returns:
-
true
if active,false
if not
addDropTargetListener
public void addDropTargetListener(DropTargetListener dtl) throws TooManyListenersException
DropTargetListener
(UNICAST SOURCE).- Parameters:
-
dtl
- The newDropTargetListener
- Throws:
-
TooManyListenersException
- if aDropTargetListener
is already added to thisDropTarget
.
removeDropTargetListener
public void removeDropTargetListener(DropTargetListener dtl)
DropTargetListener
(UNICAST SOURCE).- Parameters:
-
dtl
- the DropTargetListener to deregister.
dragEnter
public void dragEnter(DropTargetDragEvent dtde)
dragEnter
on the registered DropTargetListener
and passes it the specified DropTargetDragEvent
. Has no effect if this DropTarget
is not active.- Specified by:
-
dragEnter
in interfaceDropTargetListener
- Parameters:
-
dtde
- theDropTargetDragEvent
- Throws:
-
NullPointerException
- if thisDropTarget
is active anddtde
isnull
- See Also:
dragOver
public void dragOver(DropTargetDragEvent dtde)
dragOver
on the registered DropTargetListener
and passes it the specified DropTargetDragEvent
. Has no effect if this DropTarget
is not active.- Specified by:
-
dragOver
in interfaceDropTargetListener
- Parameters:
-
dtde
- theDropTargetDragEvent
- Throws:
-
NullPointerException
- if thisDropTarget
is active anddtde
isnull
- See Also:
dropActionChanged
public void dropActionChanged(DropTargetDragEvent dtde)
dropActionChanged
on the registered DropTargetListener
and passes it the specified DropTargetDragEvent
. Has no effect if this DropTarget
is not active.- Specified by:
-
dropActionChanged
in interfaceDropTargetListener
- Parameters:
-
dtde
- theDropTargetDragEvent
- Throws:
-
NullPointerException
- if thisDropTarget
is active anddtde
isnull
- See Also:
dragExit
public void dragExit(DropTargetEvent dte)
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.
- Specified by:
-
dragExit
in interfaceDropTargetListener
- Parameters:
-
dte
- theDropTargetEvent
- See Also:
drop
public void drop(DropTargetDropEvent dtde)
drop
on the registered DropTargetListener
and passes it the specified DropTargetDropEvent
if this DropTarget
is active.- Specified by:
-
drop
in interfaceDropTargetListener
- Parameters:
-
dtde
- theDropTargetDropEvent
- Throws:
-
NullPointerException
- ifdtde
is null and at least one of the following is true: thisDropTarget
is not active, or there is no aDropTargetListener
registered. - See Also:
getFlavorMap
public FlavorMap getFlavorMap()
FlavorMap
associated with this DropTarget
. If no FlavorMap
has been set for this DropTarget
, it is associated with the default FlavorMap
.- Returns:
- the FlavorMap for this DropTarget
setFlavorMap
public void setFlavorMap(FlavorMap fm)
FlavorMap
associated with this DropTarget
.- Parameters:
-
fm
- the newFlavorMap
, or null to associate the default FlavorMap with this DropTarget.
addNotify
public void addNotify()
removeNotify
public void removeNotify()
getDropTargetContext
public DropTargetContext getDropTargetContext()
DropTargetContext
associated with this DropTarget
.- Returns:
- the
DropTargetContext
associated with thisDropTarget
.
createDropTargetContext
protected DropTargetContext createDropTargetContext()
- Returns:
- the DropTargetContext associated with this DropTarget
createDropTargetAutoScroller
protected DropTarget.DropTargetAutoScroller createDropTargetAutoScroller(Component c, Point p)
- Parameters:
-
c
- theComponent
-
p
- thePoint
- Returns:
- an embedded autoscroller
initializeAutoscrolling
protected void initializeAutoscrolling(Point p)
- Parameters:
-
p
- thePoint
updateAutoscroll
protected void updateAutoscroll(Point dragCursorLocn)
- Parameters:
-
dragCursorLocn
- thePoint
clearAutoscroll
protected void clearAutoscroll()
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/dnd/DropTarget.html