⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dnd入门学习.htm

📁 DND入门学习
💻 HTM
📖 第 1 页 / 共 5 页
字号:
            alt=推荐此帖 src="DND入门学习.files/emailto.gif" align=absMiddle></A> <A 
            href="http://www.eclipseworld.org/bbs/post.php?action=quote&amp;fid=91&amp;tid=893&amp;pid=3985&amp;article=3"><IMG 
            alt=引用回复这个帖子 src="DND入门学习.files/quote.gif" align=absMiddle></A> <A 
            href="http://www.eclipseworld.org/bbs/post.php?action=modify&amp;fid=91&amp;tid=893&amp;pid=3985&amp;article=3"><IMG 
            src="DND入门学习.files/edit.gif" align=absMiddle></A> <A 
            href="http://www.eclipseworld.org/bbs/job.php?action=report&amp;tid=893&amp;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&amp;Uin=9275760&amp;Site=中国Eclipse社区&amp;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>&nbsp; &nbsp; DropTarget target=new 
            DropTarget(dropTable,DND.DROP_MOVE|DND.DROP_COPY|DND.DROP_DEFAULT);<BR>&nbsp; 
            &nbsp; target.setTransfer(new Transfer[] {textTransfer });<BR>&nbsp; 
            &nbsp; target.addDropListener(new 
            MyDropTargetListener());<BR><BR>对于MyDropTargetListener<BR><BR>class 
            MyDropTargetListener implements DropTargetListener{<BR>&nbsp; &nbsp; 
            //dragEnter事件在drag and drop动作开始,并且鼠标进入了target 
            widget的范围内时被调用。<BR>&nbsp; &nbsp; public void 
            dragEnter(DropTargetEvent event){<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            //在dragEnter中应用可以定义default operation.如果一个drop 
            target在创建的时候被指定为<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            //带有DND.DROP_DEFAULT,那么在拖动的过程中如果没有辅助按键被按下,则drop 
            target就是DND.DROP_DEFAULT的。<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            //应用可以通过改变event.detail来指定default 
            operation。如果应用没有具体指定DND.DROP_DEFAULT的操作,<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; //平台会默认将DND.DROP_DEFAULT设置为DND.DROP_MOVE。<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; 
            //另外DND.DROP_DEFAULT的值也可以在dragOperationChanged中设置。<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            if(event.detail==DND.DROP_DEFAULT){<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; 
            //给event.detail赋的值必须是event.operations中的一个,event.operations中<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; //的操作都是DragSource所支持的. <BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; 
            if((event.operations&amp;DND.DROP_COPY)!=0){<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; event.detail=DND.DROP_COPY;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; }else{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; event.detail=DND.DROP_NONE;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; }<BR>&nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; //drop 
            target可以选择性的按照传输类型来处理.dragEnter event有两个属性<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; //event.currentType 是应用设置的默认类型,以TransferData对象形式表现,<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; //event.dataTypes 是drag 
            source支持的所有类型的列表,以TransferData数组形式表现, <BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; //我们可以将event.currentType设置成event.dataTypes中的任意一个。<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; //这些属性也可以在dragOver, 
            dragOperationChanged以及dropAccept事件中设置。<BR><BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; for(int i=0;i&lt;event.dataTypes.length;i++){<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; 
            if(textTransfer.isSupportedType(event.dataTypes<I>)){<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            event.currentDataType=event.dataTypes<I>;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; //只允许COPY<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; if(event.detail!=DND.DROP_COPY){<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            event.detail=DND.DROP_NONE;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; }<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            break;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; }<BR>&nbsp; &nbsp; }<BR><BR>&nbsp; &nbsp; //dragOver 
            event在光标进入drop target widget时会被重复不停的调用. <BR>&nbsp; &nbsp; 
            //如果光标是静止的,dragOver event依然会有规则的按一定时间间隔被调用. <BR>&nbsp; &nbsp; 
            //这个方法一般在drop target是table或tree时用得比较多,可以根据不同的item而改变操作.<BR>&nbsp; 
            &nbsp; public void dragOver(DropTargetEvent event){<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; //event.feedback设置当widget处于光标下时应该给用户一个什么样的feedback. 
            <BR>&nbsp; &nbsp; &nbsp; &nbsp; //dragOver event.feedback 值描述 
            <BR>&nbsp; &nbsp; &nbsp; &nbsp; //DND.FEEDBACK_SELECT 
            使光标下的item被选中,限于table and trees. <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            //DND.FEEDBACK_SCROLL 使widget可以滚动以便于用户可以drop在当前看不见的item上,限于table and 
            trees. <BR>&nbsp; &nbsp; &nbsp; &nbsp; //DND.FEEDBACK_EXPAND 
            使当前光标下的item展开以便于用户在sub item上drop,限于trees. <BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; //DND.FEEDBACK_INSERT_BEFORE 在item处于光标下之前显示一个插入标记,限于tables 
            and trees. <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            //DND.FEEDBACK_INSERT_AFTER &nbsp; 在item处于光标下之后显示一个插入标记,限于tables and 
            trees. <BR>&nbsp; &nbsp; &nbsp; &nbsp; //DND.FEEDBACK_NONE &nbsp; 
            没有任何效果. <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            event.feedback=DND.FEEDBACK_SELECT|DND.FEEDBACK_SCROLL;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; 
            if(textTransfer.isSupportedType(event.currentDataType)){<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; String 
            t=(String)(textTransfer.nativeToJava(event.currentDataType));<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; if(t!=null){<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; System.out.println(t);<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; }<BR>&nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; 
            }<BR><BR>&nbsp; &nbsp; //当用户按下或放开辅助按键时,例如Ctrl, Shift, Command, 
            Option。则dragOperationChanged事件发生。<BR>&nbsp; &nbsp; 
            //辅助按键可以改变即将进行的操作。例如:<BR>&nbsp; &nbsp; //Ctrl key is down, a copy is 
            requested,<BR>&nbsp; &nbsp; //Ctrl and Shift keys are both down, a 
            link is requested<BR>&nbsp; &nbsp; //Shift key is down, a move is 
            requested<BR>&nbsp; &nbsp; //When no modifier keys are pressed, the 
            default operation is requested. <BR>&nbsp; &nbsp; public void 
            dragOperationChanged(DropTargetEvent event){<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; if(event.detail==DND.DROP_DEFAULT){<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; event.detail=DND.DROP_COPY;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; }else{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            event.detail=DND.DROP_NONE;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            }<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; // allow text to be moved but 
            files should only be copied<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            if(fileTransfer.isSupportedType(event.currentDataType)){<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; 
            if(event.detail!=DND.DROP_COPY){<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; event.detail=DND.DROP_NONE;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; }<BR>&nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; 
            }<BR><BR>&nbsp; &nbsp; //当光标离开drop target widget时,dragLeave事件发生. 
            如果你在dragEnter中分配了一些资源,<BR>&nbsp; &nbsp; 
            //就应该在dragLeave中释放.dragLeave事件在用户通过Escape键取消Drag and 
            Drop操作时也会发生<BR>&nbsp; &nbsp; //刚好在drop操作被执行之前.<BR>&nbsp; &nbsp; 
            public void dragLeave(DropTargetEvent event){<BR>&nbsp; &nbsp; 
            }<BR><BR>&nbsp; &nbsp; 
            //dropAccept事件为应用提供了最后一次定义数据类型的机会,定义的数据类型将被返回到drop事件. <BR>&nbsp; 
            &nbsp; 
            //这些是通过向event.currentDataType赋event.dataTypes中的值来实现的.<BR>&nbsp; 
            &nbsp; public void dropAccept(DropTargetEvent event){<BR>&nbsp; 
            &nbsp; }<BR><BR>&nbsp; &nbsp; 
            //如果在之前的事件中得到了有效的操作和currentDataType,那么当用户在drop 
            target上松开鼠标时,drop事件会发生。<BR>&nbsp; &nbsp; 
            //event.data属性包含了请求到的数据,event.type包含了Transfer的类型. <BR>&nbsp; &nbsp; 
            //data是event.currentDataType中定义的类型.<BR>&nbsp; &nbsp; public void 
            drop(DropTargetEvent event){<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            if(textTransfer.isSupportedType(event.currentDataType)){<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; String 
            text=(String)event.data;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            TableItem item=new TableItem(dropTable,SWT.NONE);<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; item.setText(text);<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; }<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            if(fileTransfer.isSupportedType(event.currentDataType)){<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; String[] 
            files=(String[])event.data;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            for(int i=0;i&lt;files.length;i++){<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; TableItem item=new 
            TableItem(dropTable,SWT.NONE);<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; item.setText(files<I>);<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            }<BR>&nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; }<BR>&nbsp; 
            }</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&amp;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&amp;uid=3462"><IMG 
            alt=查看作者资料 src="DND入门学习.files/profile.gif" align=absMiddle></A> <A 
            href="http://www.eclipseworld.org/bbs/message.php?action=write&amp;touid=3462"><IMG 
            alt=发送短消息 src="DND入门学习.files/message.gif" align=absMiddle></A> <A 
            href="http://www.eclipseworld.org/bbs/sendemail.php?action=tofriend&amp;tid=893"><IMG 
            alt=推荐此帖 src="DND入门学习.files/emailto.gif" align=absMiddle></A> <A 
            href="http://www.eclipseworld.org/bbs/post.php?action=quote&amp;fid=91&amp;tid=893&amp;pid=3986&amp;article=4"><IMG 
            alt=引用回复这个帖子 src="DND入门学习.files/quote.gif" align=absMiddle></A> <A 
            href="http://www.eclipseworld.org/bbs/post.php?action=modify&amp;fid=91&amp;tid=893&amp;pid=3986&amp;article=4"><IMG 
            src="DND入门学习.files/edit.gif" align=absMiddle></A> <A 
            href="http://www.eclipseworld.org/bbs/job.php?action=report&amp;tid=893&amp;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&amp;Uin=9275760&amp;Site=中国Eclipse社区&amp;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&amp;pid=3986&amp;tid=893&amp;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 + -