- java.lang.Object
- 
- java.awt.dnd.DropTarget
 
- 
- All Implemented Interfaces:
- DropTargetListener,- Serializable,- EventListener
 
 public class DropTarget extends Object implements DropTargetListener, Serializable TheDropTargetis associated with aComponentwhen thatComponentwishes to accept drops during Drag and Drop operations.Each DropTargetis associated with aFlavorMap. The defaultFlavorMaphereafter designates theFlavorMapreturned bySystemFlavorMap.getDefaultFlavorMap().- Since:
- 1.2
- See Also:
- Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description protected static classDropTarget.DropTargetAutoScrollerthis protected nested class implements autoscrolling
 - 
Constructor SummaryConstructors Constructor Description DropTarget()Creates aDropTarget.DropTarget(Component c, int ops, DropTargetListener dtl)Creates aDropTargetgiven theComponentto associate itself with, anintrepresenting the default acceptable action(s) to support, and aDropTargetListenerto handle event processing.DropTarget(Component c, int ops, DropTargetListener dtl, boolean act)Creates aDropTargetgiven theComponentto associate itself with, anintrepresenting the default acceptable action(s) to support, aDropTargetListenerto handle event processing, and abooleanindicating if theDropTargetis currently accepting drops.DropTarget(Component c, int ops, DropTargetListener dtl, boolean act, FlavorMap fm)Creates a new DropTarget given theComponentto associate itself with, anintrepresenting the default acceptable action(s) to support, aDropTargetListenerto handle event processing, abooleanindicating if theDropTargetis currently accepting drops, and aFlavorMapto use (or null for the defaultFlavorMap).DropTarget(Component c, DropTargetListener dtl)Creates aDropTargetgiven theComponentto associate itself with, and theDropTargetListenerto handle event processing.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDropTargetListener(DropTargetListener dtl)Adds a newDropTargetListener(UNICAST SOURCE).voidaddNotify()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 voidclearAutoscroll()clear autoscrollingprotected DropTarget.DropTargetAutoScrollercreateDropTargetAutoScroller(Component c, Point p)create an embedded autoscrollerprotected DropTargetContextcreateDropTargetContext()Creates the DropTargetContext associated with this DropTarget.voiddragEnter(DropTargetDragEvent dtde)CallsdragEnteron the registeredDropTargetListenerand passes it the specifiedDropTargetDragEvent.voiddragExit(DropTargetEvent dte)CallsdragExiton the registeredDropTargetListenerand passes it the specifiedDropTargetEvent.voiddragOver(DropTargetDragEvent dtde)CallsdragOveron the registeredDropTargetListenerand passes it the specifiedDropTargetDragEvent.voiddrop(DropTargetDropEvent dtde)Callsdropon the registeredDropTargetListenerand passes it the specifiedDropTargetDropEventif thisDropTargetis active.voiddropActionChanged(DropTargetDragEvent dtde)CallsdropActionChangedon the registeredDropTargetListenerand passes it the specifiedDropTargetDragEvent.ComponentgetComponent()Gets theComponentassociated with thisDropTarget.intgetDefaultActions()Gets anintrepresenting the current action(s) supported by thisDropTarget.DropTargetContextgetDropTargetContext()Gets theDropTargetContextassociated with thisDropTarget.FlavorMapgetFlavorMap()Gets theFlavorMapassociated with thisDropTarget.protected voidinitializeAutoscrolling(Point p)initialize autoscrollingbooleanisActive()Reports whether or not thisDropTargetis currently active (ready to accept drops).voidremoveDropTargetListener(DropTargetListener dtl)Removes the currentDropTargetListener(UNICAST SOURCE).voidremoveNotify()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.voidsetActive(boolean isActive)Sets the DropTarget active iftrue, inactive iffalse.voidsetComponent(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);voidsetDefaultActions(int ops)Sets the default acceptable actions for thisDropTargetvoidsetFlavorMap(FlavorMap fm)Sets theFlavorMapassociated with thisDropTarget.protected voidupdateAutoscroll(Point dragCursorLocn)update autoscrolling with current cursor location
 
- 
- 
- 
Constructor Detail- 
DropTargetpublic DropTarget(Component c, int ops, DropTargetListener dtl, boolean act, FlavorMap fm) throws HeadlessException Creates a new DropTarget given theComponentto associate itself with, anintrepresenting the default acceptable action(s) to support, aDropTargetListenerto handle event processing, abooleanindicating if theDropTargetis currently accepting drops, and aFlavorMapto use (or null for the defaultFlavorMap).The Component will receive drops only if it is enabled. - Parameters:
- c- The- Componentwith which this- DropTargetis associated
- ops- The default acceptable actions for this- DropTarget
- dtl- The- DropTargetListenerfor this- DropTarget
- act- Is the- DropTargetaccepting drops.
- fm- The- FlavorMapto use, or null for the default- FlavorMap
- Throws:
- HeadlessException- if GraphicsEnvironment.isHeadless() returns true
- See Also:
- GraphicsEnvironment.isHeadless()
 
 - 
DropTargetpublic DropTarget(Component c, int ops, DropTargetListener dtl, boolean act) throws HeadlessException Creates aDropTargetgiven theComponentto associate itself with, anintrepresenting the default acceptable action(s) to support, aDropTargetListenerto handle event processing, and abooleanindicating if theDropTargetis currently accepting drops.The Component will receive drops only if it is enabled. - Parameters:
- c- The- Componentwith which this- DropTargetis associated
- ops- The default acceptable actions for this- DropTarget
- dtl- The- DropTargetListenerfor this- DropTarget
- act- Is the- DropTargetaccepting drops.
- Throws:
- HeadlessException- if GraphicsEnvironment.isHeadless() returns true
- See Also:
- GraphicsEnvironment.isHeadless()
 
 - 
DropTargetpublic DropTarget() throws HeadlessExceptionCreates aDropTarget.- Throws:
- HeadlessException- if GraphicsEnvironment.isHeadless() returns true
- See Also:
- GraphicsEnvironment.isHeadless()
 
 - 
DropTargetpublic DropTarget(Component c, DropTargetListener dtl) throws HeadlessException Creates aDropTargetgiven theComponentto associate itself with, and theDropTargetListenerto handle event processing.The Component will receive drops only if it is enabled. - Parameters:
- c- The- Componentwith which this- DropTargetis associated
- dtl- The- DropTargetListenerfor this- DropTarget
- Throws:
- HeadlessException- if GraphicsEnvironment.isHeadless() returns true
- See Also:
- GraphicsEnvironment.isHeadless()
 
 - 
DropTargetpublic DropTarget(Component c, int ops, DropTargetListener dtl) throws HeadlessException Creates aDropTargetgiven theComponentto associate itself with, anintrepresenting the default acceptable action(s) to support, and aDropTargetListenerto handle event processing.The Component will receive drops only if it is enabled. - Parameters:
- c- The- Componentwith which this- DropTargetis associated
- ops- The default acceptable actions for this- DropTarget
- dtl- The- DropTargetListenerfor this- DropTarget
- Throws:
- HeadlessException- if GraphicsEnvironment.isHeadless() returns true
- See Also:
- GraphicsEnvironment.isHeadless()
 
 
- 
 - 
Method Detail- 
setComponentpublic 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 new- Componentthis- DropTargetis to be associated with.
 
 - 
getComponentpublic Component getComponent() Gets theComponentassociated with thisDropTarget.- Returns:
- the current Component
 
 - 
setDefaultActionspublic void setDefaultActions(int ops) Sets the default acceptable actions for thisDropTarget- Parameters:
- ops- the default actions
- See Also:
- DnDConstants
 
 - 
getDefaultActionspublic int getDefaultActions() Gets anintrepresenting the current action(s) supported by thisDropTarget.- Returns:
- the current default actions
 
 - 
setActivepublic void setActive(boolean isActive) Sets the DropTarget active iftrue, inactive iffalse.- Parameters:
- isActive- sets the- DropTarget(in)active.
 
 - 
isActivepublic boolean isActive() Reports whether or not thisDropTargetis currently active (ready to accept drops).- Returns:
- trueif active,- falseif not
 
 - 
addDropTargetListenerpublic void addDropTargetListener(DropTargetListener dtl) throws TooManyListenersException Adds a newDropTargetListener(UNICAST SOURCE).- Parameters:
- dtl- The new- DropTargetListener
- Throws:
- TooManyListenersException- if a- DropTargetListeneris already added to this- DropTarget.
 
 - 
removeDropTargetListenerpublic void removeDropTargetListener(DropTargetListener dtl) Removes the currentDropTargetListener(UNICAST SOURCE).- Parameters:
- dtl- the DropTargetListener to deregister.
 
 - 
dragEnterpublic void dragEnter(DropTargetDragEvent dtde) CallsdragEnteron the registeredDropTargetListenerand passes it the specifiedDropTargetDragEvent. Has no effect if thisDropTargetis not active.- Specified by:
- dragEnterin interface- DropTargetListener
- Parameters:
- dtde- the- DropTargetDragEvent
- Throws:
- NullPointerException- if this- DropTargetis active and- dtdeis- null
- See Also:
- isActive()
 
 - 
dragOverpublic void dragOver(DropTargetDragEvent dtde) CallsdragOveron the registeredDropTargetListenerand passes it the specifiedDropTargetDragEvent. Has no effect if thisDropTargetis not active.- Specified by:
- dragOverin interface- DropTargetListener
- Parameters:
- dtde- the- DropTargetDragEvent
- Throws:
- NullPointerException- if this- DropTargetis active and- dtdeis- null
- See Also:
- isActive()
 
 - 
dropActionChangedpublic void dropActionChanged(DropTargetDragEvent dtde) CallsdropActionChangedon the registeredDropTargetListenerand passes it the specifiedDropTargetDragEvent. Has no effect if thisDropTargetis not active.- Specified by:
- dropActionChangedin interface- DropTargetListener
- Parameters:
- dtde- the- DropTargetDragEvent
- Throws:
- NullPointerException- if this- DropTargetis active and- dtdeis- null
- See Also:
- isActive()
 
 - 
dragExitpublic void dragExit(DropTargetEvent dte) CallsdragExiton the registeredDropTargetListenerand passes it the specifiedDropTargetEvent. Has no effect if thisDropTargetis 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:
- dragExitin interface- DropTargetListener
- Parameters:
- dte- the- DropTargetEvent
- See Also:
- isActive()
 
 - 
droppublic void drop(DropTargetDropEvent dtde) Callsdropon the registeredDropTargetListenerand passes it the specifiedDropTargetDropEventif thisDropTargetis active.- Specified by:
- dropin interface- DropTargetListener
- Parameters:
- dtde- the- DropTargetDropEvent
- Throws:
- NullPointerException- if- dtdeis null and at least one of the following is true: this- DropTargetis not active, or there is no a- DropTargetListenerregistered.
- See Also:
- isActive()
 
 - 
getFlavorMappublic FlavorMap getFlavorMap() Gets theFlavorMapassociated with thisDropTarget. If noFlavorMaphas been set for thisDropTarget, it is associated with the defaultFlavorMap.- Returns:
- the FlavorMap for this DropTarget
 
 - 
setFlavorMappublic void setFlavorMap(FlavorMap fm) Sets theFlavorMapassociated with thisDropTarget.- Parameters:
- fm- the new- FlavorMap, or null to associate the default FlavorMap with this DropTarget.
 
 - 
addNotifypublic 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.
 - 
removeNotifypublic 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.
 - 
getDropTargetContextpublic DropTargetContext getDropTargetContext() Gets theDropTargetContextassociated with thisDropTarget.- Returns:
- the DropTargetContextassociated with thisDropTarget.
 
 - 
createDropTargetContextprotected 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:
- the DropTargetContext associated with this DropTarget
 
 - 
createDropTargetAutoScrollerprotected DropTarget.DropTargetAutoScroller createDropTargetAutoScroller(Component c, Point p) create an embedded autoscroller- Parameters:
- c- the- Component
- p- the- Point
- Returns:
- an embedded autoscroller
 
 - 
initializeAutoscrollingprotected void initializeAutoscrolling(Point p) initialize autoscrolling- Parameters:
- p- the- Point
 
 - 
updateAutoscrollprotected void updateAutoscroll(Point dragCursorLocn) update autoscrolling with current cursor location- Parameters:
- dragCursorLocn- the- Point
 
 - 
clearAutoscrollprotected void clearAutoscroll() clear autoscrolling
 
- 
 
-