📄 dnd入门学习.htm
字号:
alt=推荐此帖 src="DND入门学习.files/emailto.gif" align=absMiddle></A> <A
href="http://www.eclipseworld.org/bbs/post.php?action=quote&fid=91&tid=893&pid=3985&article=3"><IMG
alt=引用回复这个帖子 src="DND入门学习.files/quote.gif" align=absMiddle></A> <A
href="http://www.eclipseworld.org/bbs/post.php?action=modify&fid=91&tid=893&pid=3985&article=3"><IMG
src="DND入门学习.files/edit.gif" align=absMiddle></A> <A
href="http://www.eclipseworld.org/bbs/job.php?action=report&tid=893&pid=3985"
target=_blank><IMG src="DND入门学习.files/report.gif"
align=absMiddle></A> <A title=QQ:9275760
href="http://wpa.qq.com/msgrd?V=1&Uin=9275760&Site=中国Eclipse社区&Menu=yes"
target=_blank><IMG src="DND入门学习.files/qq.gif" align=absMiddle></A>
<BR><BR><SPAN class=tpc_title></SPAN><BR><BR><SPAN
class=tpc_content>其次是DropTarget<BR><BR>// 将dropTable指定为Drop
Target,<BR> DropTarget target=new
DropTarget(dropTable,DND.DROP_MOVE|DND.DROP_COPY|DND.DROP_DEFAULT);<BR>
target.setTransfer(new Transfer[] {textTransfer });<BR>
target.addDropListener(new
MyDropTargetListener());<BR><BR>对于MyDropTargetListener<BR><BR>class
MyDropTargetListener implements DropTargetListener{<BR>
//dragEnter事件在drag and drop动作开始,并且鼠标进入了target
widget的范围内时被调用。<BR> public void
dragEnter(DropTargetEvent event){<BR>
//在dragEnter中应用可以定义default operation.如果一个drop
target在创建的时候被指定为<BR>
//带有DND.DROP_DEFAULT,那么在拖动的过程中如果没有辅助按键被按下,则drop
target就是DND.DROP_DEFAULT的。<BR>
//应用可以通过改变event.detail来指定default
operation。如果应用没有具体指定DND.DROP_DEFAULT的操作,<BR>
//平台会默认将DND.DROP_DEFAULT设置为DND.DROP_MOVE。<BR>
//另外DND.DROP_DEFAULT的值也可以在dragOperationChanged中设置。<BR>
<BR>
if(event.detail==DND.DROP_DEFAULT){<BR>
//给event.detail赋的值必须是event.operations中的一个,event.operations中<BR>
//的操作都是DragSource所支持的. <BR>
if((event.operations&DND.DROP_COPY)!=0){<BR>
event.detail=DND.DROP_COPY;<BR>
}else{<BR>
event.detail=DND.DROP_NONE;<BR>
}<BR> }<BR>
<BR> //drop
target可以选择性的按照传输类型来处理.dragEnter event有两个属性<BR>
//event.currentType 是应用设置的默认类型,以TransferData对象形式表现,<BR>
//event.dataTypes 是drag
source支持的所有类型的列表,以TransferData数组形式表现, <BR>
//我们可以将event.currentType设置成event.dataTypes中的任意一个。<BR>
//这些属性也可以在dragOver,
dragOperationChanged以及dropAccept事件中设置。<BR><BR>
for(int i=0;i<event.dataTypes.length;i++){<BR>
if(textTransfer.isSupportedType(event.dataTypes<I>)){<BR>
event.currentDataType=event.dataTypes<I>;<BR>
//只允许COPY<BR>
if(event.detail!=DND.DROP_COPY){<BR>
event.detail=DND.DROP_NONE;<BR>
}<BR>
break;<BR> }<BR>
}<BR> }<BR><BR> //dragOver
event在光标进入drop target widget时会被重复不停的调用. <BR>
//如果光标是静止的,dragOver event依然会有规则的按一定时间间隔被调用. <BR>
//这个方法一般在drop target是table或tree时用得比较多,可以根据不同的item而改变操作.<BR>
public void dragOver(DropTargetEvent event){<BR>
//event.feedback设置当widget处于光标下时应该给用户一个什么样的feedback.
<BR> //dragOver event.feedback 值描述
<BR> //DND.FEEDBACK_SELECT
使光标下的item被选中,限于table and trees. <BR>
//DND.FEEDBACK_SCROLL 使widget可以滚动以便于用户可以drop在当前看不见的item上,限于table and
trees. <BR> //DND.FEEDBACK_EXPAND
使当前光标下的item展开以便于用户在sub item上drop,限于trees. <BR>
//DND.FEEDBACK_INSERT_BEFORE 在item处于光标下之前显示一个插入标记,限于tables
and trees. <BR>
//DND.FEEDBACK_INSERT_AFTER 在item处于光标下之后显示一个插入标记,限于tables and
trees. <BR> //DND.FEEDBACK_NONE
没有任何效果. <BR>
event.feedback=DND.FEEDBACK_SELECT|DND.FEEDBACK_SCROLL;<BR>
if(textTransfer.isSupportedType(event.currentDataType)){<BR>
String
t=(String)(textTransfer.nativeToJava(event.currentDataType));<BR>
if(t!=null){<BR>
System.out.println(t);<BR>
}<BR> }<BR>
}<BR><BR> //当用户按下或放开辅助按键时,例如Ctrl, Shift, Command,
Option。则dragOperationChanged事件发生。<BR>
//辅助按键可以改变即将进行的操作。例如:<BR> //Ctrl key is down, a copy is
requested,<BR> //Ctrl and Shift keys are both down, a
link is requested<BR> //Shift key is down, a move is
requested<BR> //When no modifier keys are pressed, the
default operation is requested. <BR> public void
dragOperationChanged(DropTargetEvent event){<BR>
if(event.detail==DND.DROP_DEFAULT){<BR>
event.detail=DND.DROP_COPY;<BR>
}else{<BR>
event.detail=DND.DROP_NONE;<BR>
}<BR><BR> // allow text to be moved but
files should only be copied<BR>
if(fileTransfer.isSupportedType(event.currentDataType)){<BR>
if(event.detail!=DND.DROP_COPY){<BR>
event.detail=DND.DROP_NONE;<BR>
}<BR> }<BR>
}<BR><BR> //当光标离开drop target widget时,dragLeave事件发生.
如果你在dragEnter中分配了一些资源,<BR>
//就应该在dragLeave中释放.dragLeave事件在用户通过Escape键取消Drag and
Drop操作时也会发生<BR> //刚好在drop操作被执行之前.<BR>
public void dragLeave(DropTargetEvent event){<BR>
}<BR><BR>
//dropAccept事件为应用提供了最后一次定义数据类型的机会,定义的数据类型将被返回到drop事件. <BR>
//这些是通过向event.currentDataType赋event.dataTypes中的值来实现的.<BR>
public void dropAccept(DropTargetEvent event){<BR>
}<BR><BR>
//如果在之前的事件中得到了有效的操作和currentDataType,那么当用户在drop
target上松开鼠标时,drop事件会发生。<BR>
//event.data属性包含了请求到的数据,event.type包含了Transfer的类型. <BR>
//data是event.currentDataType中定义的类型.<BR> public void
drop(DropTargetEvent event){<BR>
if(textTransfer.isSupportedType(event.currentDataType)){<BR>
String
text=(String)event.data;<BR>
TableItem item=new TableItem(dropTable,SWT.NONE);<BR>
item.setText(text);<BR>
}<BR>
if(fileTransfer.isSupportedType(event.currentDataType)){<BR>
String[]
files=(String[])event.data;<BR>
for(int i=0;i<files.length;i++){<BR>
TableItem item=new
TableItem(dropTable,SWT.NONE);<BR>
item.setText(files<I>);<BR>
}<BR> }<BR> }<BR>
}</SPAN> </I></I></I></TD></TR>
<TR vAlign=bottom bgColor=#ffffff>
<TD colSpan=6><IMG src="DND入门学习.files/sigline.gif" align=absBottom>
<BR>金鳞岂是池中物,一遇风云便化龙<BR></TD></TR>
<TR vAlign=bottom bgColor=#ffffff>
<TD class=smalltxt colSpan=5><FONT color=red>[3 楼]</FONT> |
<B>Posted:</B> 2005年12月02日 19:02</TD>
<TD class=smalltxt align=right><A href="javascript:scroll(0,0)"><IMG
alt=顶端 src="DND入门学习.files/top.gif"></A>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE width="100%" align=center>
<TBODY>
<TR>
<TD height=1></TD></TR></TBODY></TABLE><A name=3986>
<TABLE style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word" cellSpacing=1
cellPadding=0 width="100%" align=center bgColor=#e7e3e7>
<TBODY>
<TR>
<TD
style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px"
vAlign=top width="20%" bgColor=#ffffff height="100%"><FONT face=Gulim
color=#000066><B>金鳞</B></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="98%">
<TBODY>
<TR>
<TD align=middle><IMG src="DND入门学习.files/3462.jpg"
border=0></TD></TR></TBODY></TABLE>状态: <FONT color=red><B>离线</B></FONT>
<BR>级别: <FONT color=#555555><B>CEC版主</B></FONT><BR>精华: <A
href="http://www.eclipseworld.org/bbs/search.php?authorid=3462&digest=1"
target=_blank><FONT color=green><B>2</B></FONT></A> <BR>发帖: <FONT
color=green><B>247</B></FONT><BR>威望: <FONT color=#984b98><B>48
点</B></FONT><BR>财富: <FONT color=#984b98><B>191 元</B></FONT><BR>贡献: <FONT
color=red><B>0 点</B></FONT><BR>注册时间:2005-11-24<BR>最后登录:2006-03-28 </TD>
<TD vAlign=top width="80%" bgColor=#ffffff height="100%">
<TABLE style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word" height="100%"
cellSpacing=0 cellPadding=4 width="99%" align=center>
<TBODY>
<TR>
<TD vAlign=top bgColor=#ffffff colSpan=6><A
href="http://www.eclipseworld.org/bbs/profile.php?action=show&uid=3462"><IMG
alt=查看作者资料 src="DND入门学习.files/profile.gif" align=absMiddle></A> <A
href="http://www.eclipseworld.org/bbs/message.php?action=write&touid=3462"><IMG
alt=发送短消息 src="DND入门学习.files/message.gif" align=absMiddle></A> <A
href="http://www.eclipseworld.org/bbs/sendemail.php?action=tofriend&tid=893"><IMG
alt=推荐此帖 src="DND入门学习.files/emailto.gif" align=absMiddle></A> <A
href="http://www.eclipseworld.org/bbs/post.php?action=quote&fid=91&tid=893&pid=3986&article=4"><IMG
alt=引用回复这个帖子 src="DND入门学习.files/quote.gif" align=absMiddle></A> <A
href="http://www.eclipseworld.org/bbs/post.php?action=modify&fid=91&tid=893&pid=3986&article=4"><IMG
src="DND入门学习.files/edit.gif" align=absMiddle></A> <A
href="http://www.eclipseworld.org/bbs/job.php?action=report&tid=893&pid=3986"
target=_blank><IMG src="DND入门学习.files/report.gif"
align=absMiddle></A> <A title=QQ:9275760
href="http://wpa.qq.com/msgrd?V=1&Uin=9275760&Site=中国Eclipse社区&Menu=yes"
target=_blank><IMG src="DND入门学习.files/qq.gif" align=absMiddle></A>
<BR><BR><SPAN class=tpc_title></SPAN><BR><BR><SPAN
class=tpc_content>代码如下,我把这个功能放在一个视图里了</SPAN> <BR><BR>附件: <IMG
src="DND入门学习.files/zip.gif" align=absBottom> <A
href="http://www.eclipseworld.org/bbs/job.php?action=download&pid=3986&tid=893&aid=456"
target=_blank><FONT color=red>DragAndDrop.java</FONT></A> (11 K)
下载次数:111 </TD></TR>
<TR vAlign=bottom bgColor=#ffffff>
<TD colSpan=6><IMG src="DND入门学习.files/sigline.gif" align=absBottom>
<BR>金鳞岂是池中物,一遇风云便化龙<BR></TD></TR>
<TR vAlign=bottom bgColor=#ffffff>
<TD class=smalltxt colSpan=5><FONT color=red>[4 楼]</FONT> |
<B>Posted:</B> 2005年12月02日 19:04</TD>
<TD class=smalltxt align=right><A href="javascript:scroll(0,0)"><IMG
alt=顶端 src="DND入门学习.files/top.gif"></A>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE width="100%" align=center>
<TBODY>
<TR>
<TD height=1></TD></TR></TBODY></TABLE><A name=5054>
<TABLE style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word" cellSpacing=1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -