public class DragSource extends Object implements Serializable
DragSource负责拖放操作开始的实体,可以用在一些场景:
Component实例或应用程序特定的对象与界面中的Component实例关联。[实现依赖]DragSource,一
DragGestureRecognizer也应该获得联想
DragSource与特定的
Component。
对用户的手势的初步解释,并随后开始拖动操作的实施Component责任,这通常是由一个DragGestureRecognizer实施。
当拖动手势时,该DragSource的startdrag()方法应调用,以引起用户的导航手势和交货的拖放协议通知的处理。一个DragSource只允许一个单一的拖放操作是目前在任何一个时间,并应拒绝任何进一步的startdrag()请求通过抛出IllegalDnDOperationException直到现存操作完成。
的startdrag()方法调用createdragsourcecontext()方法实例化一个合适的DragSourceContext将DragSourceContextPeer与。
如果拖放系统无法为某些原因启动拖动操作,该startdrag()方法抛出一个java.awt.dnd.InvalidDnDOperationException信号这种情况。通常此异常被抛出时,底层平台系统不是在一个状态来启动一个拖动,或指定的参数是无效的。
请注意,在拖动过程中,在拖动操作开始时由源程序所暴露的操作集可能不会更改,直到操作完成。运行(S)是相对于DragSource操作的持续时间常数。
| Modifier and Type | Field and Description |
|---|---|
static Cursor |
DefaultCopyDrop
默认
Cursor使用复制操作表明下降是目前允许的。
|
static Cursor |
DefaultCopyNoDrop
默认
Cursor使用复制操作说明下降目前不允许。
|
static Cursor |
DefaultLinkDrop
默认
Cursor使用链接操作表明下降是目前允许的。
|
static Cursor |
DefaultLinkNoDrop
默认
Cursor使用链接操作说明下降目前不允许。
|
static Cursor |
DefaultMoveDrop
默认
Cursor使用移动操作,表明下降是目前允许的。
|
static Cursor |
DefaultMoveNoDrop
默认
Cursor使用移动操作说明下降目前不允许。
|
| Constructor and Description |
|---|
DragSource()
创建一个新的
DragSource。
|
| Modifier and Type | Method and Description |
|---|---|
void |
addDragSourceListener(DragSourceListener dsl)
增加了
DragSource指定
DragSourceListener接收拖放源事件在拖动操作启动这个
DragSource。
|
void |
addDragSourceMotionListener(DragSourceMotionListener dsml)
增加了
DragSource指定
DragSourceMotionListener收到阻力运动事件在拖动操作,这
DragSource。
|
DragGestureRecognizer |
createDefaultDragGestureRecognizer(Component c, int actions, DragGestureListener dgl)
创建一个新的
DragGestureRecognizer实现这
DragSource
DragGestureRecognizer默认的抽象类,并将新创建的对象指定的
Component和
DragGestureListener。
|
<T extends DragGestureRecognizer> |
createDragGestureRecognizer(类<T> recognizerAbstractClass, Component c, int actions, DragGestureListener dgl)
创建一个新的
DragGestureRecognizer实现指定的抽象类
DragGestureRecognizer,并将新创建的对象指定的
Component和
DragGestureListener。
|
protected DragSourceContext |
createDragSourceContext(java.awt.dnd.peer.DragSourceContextPeer dscp, DragGestureEvent dgl, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable t, DragSourceListener dsl)
创建
DragSourceContext处理当前的拖动操作。
|
static DragSource |
getDefaultDragSource()
获取与底层平台相关的
DragSource对象。
|
DragSourceListener[] |
getDragSourceListeners()
得到所有的
DragSourceListeners注册这个
DragSource。
|
DragSourceMotionListener[] |
getDragSourceMotionListeners()
得到所有的
DragSourceMotionListeners注册这个
DragSource。
|
static int |
getDragThreshold()
返回拖动手势运动阈值。
|
FlavorMap |
getFlavorMap()
此方法返回此
DragSource的
FlavorMap。
|
<T extends EventListener> |
getListeners(类<T> listenerType)
得到所有的对象目前注册为
FooListeners在这
DragSource。
|
static boolean |
isDragImageSupported()
报告是否拖
Image支持可在底层平台。
|
void |
removeDragSourceListener(DragSourceListener dsl)
从这个
DragSource移除指定的
DragSourceListener。
|
void |
removeDragSourceMotionListener(DragSourceMotionListener dsml)
从这个
DragSource移除指定的
DragSourceMotionListener。
|
void |
startDrag(DragGestureEvent trigger, Cursor dragCursor, Image dragImage, Point dragOffset, Transferable transferable, DragSourceListener dsl)
开始拖动,鉴于启动拖动
DragGestureEvent,初始
Cursor使用的
Image阻,偏移的
Image起源的
Cursor热点在触发的瞬间,拖动的对象数据,并
DragSourceListener。
|
void |
startDrag(DragGestureEvent trigger, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable transferable, DragSourceListener dsl, FlavorMap flavorMap)
开始拖动,鉴于启动拖动
DragGestureEvent,初始
Cursor使用的
Image阻,偏移的
Image起源的
Cursor热点在触发瞬间的
Transferable主题数据的拖累,该
DragSourceListener,和
FlavorMap。
|
void |
startDrag(DragGestureEvent trigger, Cursor dragCursor, Transferable transferable, DragSourceListener dsl)
开始拖动,鉴于启动拖动
DragGestureEvent,初始
Cursor使用,拖动的
Transferable主题数据,和
DragSourceListener。
|
void |
startDrag(DragGestureEvent trigger, Cursor dragCursor, Transferable transferable, DragSourceListener dsl, FlavorMap flavorMap)
开始拖动,鉴于启动拖动
DragGestureEvent,初始
Cursor使用的
Transferable主题数据的拖累,该
DragSourceListener,和
FlavorMap。
|
public static final Cursor DefaultCopyDrop
Cursor使用复制操作表明下降是目前允许的。
null如果
GraphicsEnvironment.isHeadless()返回
true。
public static final Cursor DefaultMoveDrop
Cursor使用移动操作,表明下降是目前允许的。
null如果
GraphicsEnvironment.isHeadless()返回
true。
public static final Cursor DefaultLinkDrop
Cursor使用链接操作表明下降是目前允许的。
null如果
GraphicsEnvironment.isHeadless()返回
true。
public static final Cursor DefaultCopyNoDrop
Cursor使用复制操作说明下降目前不允许。
null如果
GraphicsEnvironment.isHeadless()返回
true。
public static final Cursor DefaultMoveNoDrop
Cursor使用移动操作说明下降目前不允许。
null如果
GraphicsEnvironment.isHeadless()返回
true。
public static final Cursor DefaultLinkNoDrop
Cursor使用链接操作说明下降目前不允许。
null如果
GraphicsEnvironment.isHeadless()返回
true。
public DragSource()
throws HeadlessException
DragSource。
HeadlessException -如果graphicsenvironment isheadless()返回true。
GraphicsEnvironment.isHeadless()
public static DragSource getDefaultDragSource()
DragSource对象。
HeadlessException -如果graphicsenvironment isheadless()返回true。
GraphicsEnvironment.isHeadless()
public static boolean isDragImageSupported()
Image支持可在底层平台。
public void startDrag(DragGestureEvent trigger, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable transferable, DragSourceListener dsl, FlavorMap flavorMap) throws InvalidDnDOperationException
DragGestureEvent,初始
Cursor使用的
Image阻,偏移的
Image起源的
Cursor热点在触发瞬间的
Transferable主题数据的拖累,该
DragSourceListener,和
FlavorMap。
trigger -启动拖动
DragGestureEvent
dragCursor为默认光标处理这个拖动操作或
null初始
Cursor;见的鼠标拖放在处理机制的更多细节
DragSourceContext
dragImage -图像拖动或
null
imageOffset -偏移的
Image起源的
Cursor热点在扳机的瞬间
transferable -拖动对象数据
dsl -
DragSourceListener
flavorMap -
FlavorMap使用,或
null
InvalidDnDOperationException如果拖放系统无法启动拖动操作,或者如果用户试图在现有的拖动操作仍执行开始拖动
public void startDrag(DragGestureEvent trigger, Cursor dragCursor, Transferable transferable, DragSourceListener dsl, FlavorMap flavorMap) throws InvalidDnDOperationException
DragGestureEvent,初始
Cursor使用的
Transferable主题数据的拖累,该
DragSourceListener,和
FlavorMap。
trigger -启动拖动
DragGestureEvent
dragCursor为默认光标处理这个拖动操作或
null初始
Cursor;见的鼠标拖放在处理机制的更多细节
DragSourceContext
transferable -拖动对象数据
dsl -
DragSourceListener
flavorMap -
FlavorMap使用或
null
InvalidDnDOperationException如果拖放系统无法启动拖动操作,或者如果用户试图在现有的拖动操作仍执行开始拖动
public void startDrag(DragGestureEvent trigger, Cursor dragCursor, Image dragImage, Point dragOffset, Transferable transferable, DragSourceListener dsl) throws InvalidDnDOperationException
DragGestureEvent,初始
Cursor使用的
Image阻,偏移的
Image起源的
Cursor热点在触发的瞬间,拖动的对象数据,并
DragSourceListener。
trigger -启动拖动
DragGestureEvent
dragCursor为默认光标处理这个拖动操作或
null初始
Cursor;见的鼠标拖放在处理机制的更多细节
DragSourceContext
dragImage -
Image拖或
null
dragOffset -偏移的
Image起源的
Cursor热点在扳机的瞬间
transferable -拖动对象数据
dsl -
DragSourceListener
InvalidDnDOperationException如果拖放系统无法启动拖动操作,或者如果用户试图在现有的拖动操作仍执行开始拖动
public void startDrag(DragGestureEvent trigger, Cursor dragCursor, Transferable transferable, DragSourceListener dsl) throws InvalidDnDOperationException
DragGestureEvent,初始
Cursor使用,拖动的
Transferable主题数据,和
DragSourceListener。
trigger -启动拖动
DragGestureEvent
dragCursor为默认光标处理这个拖动操作或
null初始
Cursor;见的鼠标拖放在处理机制的更多细节
DragSourceContext类
transferable -拖动对象数据
dsl -
DragSourceListener
InvalidDnDOperationException如果拖放系统无法启动拖动操作,或者如果用户试图在现有的拖动操作仍执行开始拖动
protected DragSourceContext createDragSourceContext(java.awt.dnd.peer.DragSourceContextPeer dscp, DragGestureEvent dgl, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable t, DragSourceListener dsl)
DragSourceContext处理当前的拖动操作。
将一个新的DragSourceContext子类,子类并重写此方法DragSource。
如果dragImage是null,没有图像是用来代表这个拖动操作反馈的阻力,但NullPointerException不扔。
如果dsl是null拖动源,没有听众与创建的DragSourceContext注册,但NullPointerException不扔。
dscp -这将
DragSourceContextPeer
dgl -触发拖动
DragGestureEvent
dragCursor为默认光标处理这个拖动操作或
null初始
Cursor;见的鼠标拖放在处理机制的更多细节
DragSourceContext类
dragImage -
Image拖或
null
imageOffset -偏移的
Image起源从光标热点在扳机的瞬间
t -拖动对象数据
dsl -
DragSourceListener
DragSourceContext
null
dscp
NullPointerException
null
dgl
NullPointerException
NullPointerException -如果
dragImage不
null和
imageOffset是
null
null
t
NullPointerException
IllegalArgumentException如果与触发事件相关的
Component是
null。
IllegalArgumentException如果触发事件的
DragSource是
null。
IllegalArgumentException如果触发事件的阻力作用是
DnDConstants.ACTION_NONE。
IllegalArgumentException如果与触发事件相关的
DragGestureRecognizer源行动等于
DnDConstants.ACTION_NONE。
public FlavorMap getFlavorMap()
DragSource的
FlavorMap。
DragSource的
FlavorMap
public <T extends DragGestureRecognizer> T createDragGestureRecognizer(类<T> recognizerAbstractClass, Component c, int actions, DragGestureListener dgl)
DragGestureRecognizer实现指定的抽象类
DragGestureRecognizer,并将新创建的对象指定的
Component和
DragGestureListener。
recognizerAbstractClass -要求的抽象类型
actions -允许源拖动操作
c -
Component目标
dgl -
DragGestureListener通知
DragGestureRecognizer或
null如果
Toolkit.createDragGestureRecognizer方法没有实现可用于请求的
DragGestureRecognizer类并返回
null
public DragGestureRecognizer createDefaultDragGestureRecognizer(Component c, int actions, DragGestureListener dgl)
DragGestureRecognizer实现这
DragSource
DragGestureRecognizer默认的抽象类,并将新创建的对象指定的
Component和
DragGestureListener。这
DragSource默认是
MouseDragGestureRecognizer。
c -
Component目标识别器
actions -允许源作用
dgl -
DragGestureListener通知
DragGestureRecognizer或
null如果
Toolkit.createDragGestureRecognizer方法没有实现可用于请求的
DragGestureRecognizer类并返回
null
public void addDragSourceListener(DragSourceListener dsl)
DragSource指定
DragSourceListener接收拖放源事件在拖动操作启动这个
DragSource。如果一个
null听众是指定的,没有采取任何行动,不引发异常。
dsl -
DragSourceListener添加
removeDragSourceListener(java.awt.dnd.DragSourceListener),
getDragSourceListeners()
public void removeDragSourceListener(DragSourceListener dsl)
DragSource移除指定的
DragSourceListener。如果一个
null听众是指定的,没有采取任何行动,不引发异常。如果该参数指定侦听器是以前没有加入这个
DragSource,不采取行动而不引发异常。
dsl -
DragSourceListener删除
addDragSourceListener(java.awt.dnd.DragSourceListener),
getDragSourceListeners()
public DragSourceListener[] getDragSourceListeners()
DragSourceListeners注册这个
DragSource。
DragSource的
DragSourceListeners或空数组,如果没有这样的听众正在注册
addDragSourceListener(java.awt.dnd.DragSourceListener),
removeDragSourceListener(java.awt.dnd.DragSourceListener)
public void addDragSourceMotionListener(DragSourceMotionListener dsml)
DragSource指定
DragSourceMotionListener收到阻力运动事件在拖动操作,这
DragSource。如果一个
null听众是指定的,没有采取任何行动,不引发异常。
dsml -
DragSourceMotionListener添加
removeDragSourceMotionListener(java.awt.dnd.DragSourceMotionListener),
getDragSourceMotionListeners()
public void removeDragSourceMotionListener(DragSourceMotionListener dsml)
DragSource移除指定的
DragSourceMotionListener。如果一个
null听众是指定的,没有采取任何行动,不引发异常。如果该参数指定侦听器是以前没有加入这个
DragSource,不采取行动而不引发异常。
dsml -
DragSourceMotionListener删除
addDragSourceMotionListener(java.awt.dnd.DragSourceMotionListener),
getDragSourceMotionListeners()
public DragSourceMotionListener[] getDragSourceMotionListeners()
DragSourceMotionListeners注册这个
DragSource。
DragSource的
DragSourceMotionListeners或如果没有这样的听众,目前注册一个空数组
addDragSourceMotionListener(java.awt.dnd.DragSourceMotionListener),
removeDragSourceMotionListener(java.awt.dnd.DragSourceMotionListener)
public <T extends EventListener> T[] getListeners(类<T> listenerType)
FooListeners在这
DragSource。
FooListeners使用
addFooListener方法注册。
listenerType -听众的类型要求;这个参数应该指定一个接口,从
java.util.EventListener
DragSource
FooListeners数组,或一个空数组如果没有这样的听众已添加
ClassCastException -如果
listenerType不指定一个类或接口实现
java.util.EventListener
getDragSourceListeners(),
getDragSourceMotionListeners()
public static int getDragThreshold()
MouseDragGestureRecognizers推荐的行为。
如果系统性能awt.dnd.drag.threshold设置为一个正整数,该方法返回系统属性的值;否则,如果相关的桌面属性可通过java平台实现支持,此方法返回该属性的值;否则,该方法返回的默认值。有关桌面属性可以查询使用java.awt.Toolkit.getDesktopProperty("DnD.gestureMotionThreshold")。
MouseDragGestureRecognizer
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.