- java.lang.Object
-
- java.awt.dnd.DropTarget
-
- All Implemented Interfaces:
- DropTargetListener, Serializable, EventListener
public class DropTarget extends Object implements DropTargetListener, Serializable
TheDropTarget
is associated with aComponent
when thatComponent
wishes to accept drops during Drag and Drop operations.Each
DropTarget
is associated with aFlavorMap
. The defaultFlavorMap
hereafter designates theFlavorMap
returned bySystemFlavorMap.getDefaultFlavorMap()
.- Since:
- 1.2
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description protected static class
DropTarget.DropTargetAutoScroller
this protected nested class implements autoscrolling
-
Constructor Summary
Constructors Constructor and Description DropTarget()
Creates aDropTarget
.DropTarget(Component c, DropTargetListener dtl)
Creates aDropTarget
given theComponent
to associate itself with, and theDropTargetListener
to handle event processing.DropTarget(Component c, int ops, DropTargetListener dtl)
Creates aDropTarget
given theComponent
to associate itself with, anint
representing the default acceptable action(s) to support, and aDropTargetListener
to handle event processing.DropTarget(Component c, int ops, DropTargetListener dtl, boolean act)
Creates aDropTarget
given theComponent
to associate itself with, anint
representing the default acceptable action(s) to support, aDropTargetListener
to handle event processing, and aboolean
indicating if theDropTarget
is currently accepting drops.DropTarget(Component c, int ops, DropTargetListener dtl, boolean act, FlavorMap fm)
Creates a new DropTarget given theComponent
to associate itself with, anint
representing the default acceptable action(s) to support, aDropTargetListener
to handle event processing, aboolean
indicating if theDropTarget
is currently accepting drops, and aFlavorMap
to use (or null for the defaultFlavorMap
).
-
Method Summary
Methods Modifier and Type Method and Description void
addDropTargetListener(DropTargetListener dtl)
Adds a newDropTargetListener
(UNICAST SOURCE).void
addNotify(java.awt.peer.ComponentPeer peer)
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 autoscrollingprotected DropTarget.DropTargetAutoScroller
createDropTargetAutoScroller(Component c, Point p)
create an embedded autoscrollerprotected DropTargetContext
createDropTargetContext()
Creates the DropTargetContext associated with this DropTarget.void
dragEnter(DropTargetDragEvent dtde)
CallsdragEnter
on the registeredDropTargetListener
and passes it the specifiedDropTargetDragEvent
.void
dragExit(DropTargetEvent dte)
CallsdragExit
on the registeredDropTargetListener
and passes it the specifiedDropTargetEvent
.void
dragOver(DropTargetDragEvent dtde)
CallsdragOver
on the registeredDropTargetListener
and passes it the specifiedDropTargetDragEvent
.void
drop(DropTargetDropEvent dtde)
Callsdrop
on the registeredDropTargetListener
and passes it the specifiedDropTargetDropEvent
if thisDropTarget
is active.void
dropActionChanged(DropTargetDragEvent dtde)
CallsdropActionChanged
on the registeredDropTargetListener
and passes it the specifiedDropTargetDragEvent
.Component
getComponent()
Gets theComponent
associated with thisDropTarget
.int
getDefaultActions()
Gets anint
representing the current action(s) supported by thisDropTarget
.DropTargetContext
getDropTargetContext()
Gets theDropTargetContext
associated with thisDropTarget
.FlavorMap
getFlavorMap()
Gets theFlavorMap
associated with thisDropTarget
.protected void
initializeAutoscrolling(Point p)
initialize autoscrollingboolean
isActive()
Reports whether or not thisDropTarget
is currently active (ready to accept drops).void
removeDropTargetListener(DropTargetListener dtl)
Removes the currentDropTargetListener
(UNICAST SOURCE).void
removeNotify(java.awt.peer.ComponentPeer peer)
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(boolean isActive)
Sets the DropTarget active iftrue
, inactive iffalse
.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);
ordroptarget.setComponent(component);
void
setDefaultActions(int ops)
Sets the default acceptable actions for thisDropTarget
void
setFlavorMap(FlavorMap fm)
Sets theFlavorMap
associated with thisDropTarget
.protected void
updateAutoscroll(Point dragCursorLocn)
update autoscrolling with current cursor locn
-
-
-
Constructor Detail
-
DropTarget
public DropTarget(Component c, int ops, DropTargetListener dtl, boolean act, FlavorMap fm) throws HeadlessException
Creates a new DropTarget given theComponent
to associate itself with, anint
representing the default acceptable action(s) to support, aDropTargetListener
to handle event processing, aboolean
indicating if theDropTarget
is currently accepting drops, and aFlavorMap
to use (or null for the defaultFlavorMap
).The Component will receive drops only if it is enabled.
- Parameters:
c
- TheComponent
with which thisDropTarget
is associatedops
- 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:
GraphicsEnvironment.isHeadless()
-
DropTarget
public DropTarget(Component c, int ops, DropTargetListener dtl, boolean act) throws HeadlessException
Creates aDropTarget
given theComponent
to associate itself with, anint
representing the default acceptable action(s) to support, aDropTargetListener
to handle event processing, and aboolean
indicating if theDropTarget
is currently accepting drops.The Component will receive drops only if it is enabled.
- Parameters:
c
- TheComponent
with which thisDropTarget
is associatedops
- The default acceptable actions for thisDropTarget
dtl
- TheDropTargetListener
for thisDropTarget
act
- Is theDropTarget
accepting drops.- Throws:
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true- See Also:
GraphicsEnvironment.isHeadless()
-
DropTarget
public DropTarget() throws HeadlessException
Creates aDropTarget
.- Throws:
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true- See Also:
GraphicsEnvironment.isHeadless()
-
DropTarget
public DropTarget(Component c, DropTargetListener dtl) throws HeadlessException
Creates aDropTarget
given theComponent
to associate itself with, and theDropTargetListener
to handle event processing.The Component will receive drops only if it is enabled.
- Parameters:
c
- TheComponent
with which thisDropTarget
is associateddtl
- TheDropTargetListener
for thisDropTarget
- Throws:
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true- See Also:
GraphicsEnvironment.isHeadless()
-
DropTarget
public DropTarget(Component c, int ops, DropTargetListener dtl) throws HeadlessException
Creates aDropTarget
given theComponent
to associate itself with, anint
representing the default acceptable action(s) to support, and aDropTargetListener
to handle event processing.The Component will receive drops only if it is enabled.
- Parameters:
c
- TheComponent
with which thisDropTarget
is associatedops
- The default acceptable actions for thisDropTarget
dtl
- TheDropTargetListener
for thisDropTarget
- Throws:
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true- See Also:
GraphicsEnvironment.isHeadless()
-
-
Method Detail
-
setComponent
public 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);
ordroptarget.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()
Gets theComponent
associated with thisDropTarget
.- Returns:
- the current
Component
-
setDefaultActions
public void setDefaultActions(int ops)
Sets the default acceptable actions for thisDropTarget
- Parameters:
ops
- the default actions- See Also:
DnDConstants
-
getDefaultActions
public int getDefaultActions()
Gets anint
representing the current action(s) supported by thisDropTarget
.- Returns:
- the current default actions
-
setActive
public void setActive(boolean isActive)
Sets the DropTarget active iftrue
, inactive iffalse
.- Parameters:
isActive
- sets theDropTarget
(in)active.
-
isActive
public boolean isActive()
Reports whether or not thisDropTarget
is currently active (ready to accept drops).- Returns:
true
if active,false
if not
-
addDropTargetListener
public void addDropTargetListener(DropTargetListener dtl) throws TooManyListenersException
Adds a newDropTargetListener
(UNICAST SOURCE).- Parameters:
dtl
- The newDropTargetListener
- Throws:
- if aTooManyListenersException
DropTargetListener
is already added to thisDropTarget
.TooManyListenersException
-
removeDropTargetListener
public void removeDropTargetListener(DropTargetListener dtl)
Removes the currentDropTargetListener
(UNICAST SOURCE).- Parameters:
dtl
- the DropTargetListener to deregister.
-
dragEnter
public void dragEnter(DropTargetDragEvent dtde)
CallsdragEnter
on the registeredDropTargetListener
and passes it the specifiedDropTargetDragEvent
. Has no effect if thisDropTarget
is not active.- Specified by:
dragEnter
in interfaceDropTargetListener
- Parameters:
dtde
- theDropTargetDragEvent
- Throws:
NullPointerException
- if thisDropTarget
is active anddtde
isnull
- See Also:
isActive()
-
dragOver
public void dragOver(DropTargetDragEvent dtde)
CallsdragOver
on the registeredDropTargetListener
and passes it the specifiedDropTargetDragEvent
. Has no effect if thisDropTarget
is not active.- Specified by:
dragOver
in interfaceDropTargetListener
- Parameters:
dtde
- theDropTargetDragEvent
- Throws:
NullPointerException
- if thisDropTarget
is active anddtde
isnull
- See Also:
isActive()
-
dropActionChanged
public void dropActionChanged(DropTargetDragEvent dtde)
CallsdropActionChanged
on the registeredDropTargetListener
and passes it the specifiedDropTargetDragEvent
. Has no effect if thisDropTarget
is not active.- Specified by:
dropActionChanged
in interfaceDropTargetListener
- Parameters:
dtde
- theDropTargetDragEvent
- Throws:
NullPointerException
- if thisDropTarget
is active anddtde
isnull
- See Also:
isActive()
-
dragExit
public void dragExit(DropTargetEvent dte)
CallsdragExit
on the registeredDropTargetListener
and passes it the specifiedDropTargetEvent
. Has no effect if thisDropTarget
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:
isActive()
-
drop
public void drop(DropTargetDropEvent dtde)
Callsdrop
on the registeredDropTargetListener
and passes it the specifiedDropTargetDropEvent
if thisDropTarget
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:
isActive()
-
getFlavorMap
public FlavorMap getFlavorMap()
Gets theFlavorMap
associated with thisDropTarget
. If noFlavorMap
has been set for thisDropTarget
, it is associated with the defaultFlavorMap
.- Returns:
- the FlavorMap for this DropTarget
-
setFlavorMap
public void setFlavorMap(FlavorMap fm)
Sets theFlavorMap
associated with thisDropTarget
.- Parameters:
fm
- the newFlavorMap
, or null to associate the default FlavorMap with this DropTarget.
-
addNotify
public void addNotify(java.awt.peer.ComponentPeer peer)
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.- Parameters:
peer
- The Peer of the Component we are associated with!
-
removeNotify
public void removeNotify(java.awt.peer.ComponentPeer peer)
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.- Parameters:
peer
- The Peer of the Component we are being disassociated from!
-
getDropTargetContext
public DropTargetContext getDropTargetContext()
Gets theDropTargetContext
associated with thisDropTarget
.- Returns:
- the
DropTargetContext
associated with thisDropTarget
.
-
createDropTargetContext
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.
-
createDropTargetAutoScroller
protected DropTarget.DropTargetAutoScroller createDropTargetAutoScroller(Component c, Point p)
create an embedded autoscroller- Parameters:
c
- theComponent
p
- thePoint
-
initializeAutoscrolling
protected void initializeAutoscrolling(Point p)
initialize autoscrolling- Parameters:
p
- thePoint
-
updateAutoscroll
protected void updateAutoscroll(Point dragCursorLocn)
update autoscrolling with current cursor locn- Parameters:
dragCursorLocn
- thePoint
-
clearAutoscroll
protected void clearAutoscroll()
clear autoscrolling
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-java/awt/dnd/DropTarget.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.