TestD&DTree_e.rar

  • PUDN用户
    了解作者
  • JavaScript
    开发工具
  • 39KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 5
    下载次数
  • 2005-07-25 08:02
    上传日期
本程序是在JBuild 9.0中开发的,主程序是 DiskManager.java。实现一个树形控件,可以添加和删除节点。
TestD&DTree_e.rar
  • TestD&DTree_e
  • AbstractTreeTransferHandler.class
    7.6KB
  • RAID.PNG
    2.5KB
  • ADD_SMALL.GIF
    77B
  • MyDiskInfoTree.class
    1.3KB
  • TransferableNode.class
    1.5KB
  • DiskManager.java
    6.4KB
  • .project
    513B
  • DefaultTreeTransferHandler.class
    2.1KB
  • .classpath
    226B
  • LevelChangeDlg$1.class
    725B
  • TransferableNode.java
    2.3KB
  • Volume.PNG
    2.7KB
  • Thumbs.db
    7.5KB
  • AbstractTreeTransferHandler.java
    7.4KB
  • MyDiskInfoTree.java
    1.6KB
  • LevelChangeDlg$2.class
    1.4KB
  • MyRenderer.java
    2.3KB
  • DNDTree.class
    3.1KB
  • MyRenderer.class
    1.6KB
  • DefaultTreeTransferHandler.java
    2.5KB
  • LevelChangeDlg.java
    3.6KB
  • DiskManager.class
    6.3KB
  • HD.PNG
    1.8KB
  • DNDTree.java
    3.2KB
  • DiskManager$1.class
    870B
  • I.png
    148B
  • ADD_SMALL.png
    965B
  • LevelChangeDlg.class
    2.9KB
  • www.pudn.com.txt
    218B
内容介绍
/* * Created on 2005-4-14 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author fangkun * Third class : AbstractTreeTransferHandler * This class is the most important. It manages all the DnD behavior. * It is abstract because it contains two abstract methods : * public abstract boolean canPerformAction(DNDTree target, MyDiskInfoTree draggedNode, int action, Point location); * and : * public abstract boolean executeDrop(DNDTree tree, MyDiskInfoTree draggedNode, MyDiskInfoTree newParentNode, int action); * * we have to override to give the required behavior of DnD in your tree. * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ import java.awt.*; import javax.swing.*; import javax.swing.tree.*; import java.awt.dnd.*; import java.awt.datatransfer.*; import java.awt.image.*; public abstract class AbstractTreeTransferHandler implements DragGestureListener, DragSourceListener, DropTargetListener { private DNDTree tree; private DragSource dragSource; // dragsource private DropTarget dropTarget; //droptarget private static MyDiskInfoTree draggedNode; private MyDiskInfoTree draggedNodeParent; private static BufferedImage image = null; //buff image private Rectangle rect2D = new Rectangle(); private boolean drawImage; protected AbstractTreeTransferHandler(DNDTree tree, int action, boolean drawIcon) { this.tree = tree; drawImage = drawIcon; dragSource = new DragSource(); dragSource.createDefaultDragGestureRecognizer(tree, action, this); dropTarget = new DropTarget(tree, action, this); } /* Methods for DragSourceListener */ public void dragDropEnd(DragSourceDropEvent dsde) { if (dsde.getDropSuccess() && dsde.getDropAction()==DnDConstants.ACTION_MOVE && draggedNodeParent != null) { ((DefaultTreeModel)tree.getModel()).nodeStructureChanged(draggedNodeParent); } } public final void dragEnter(DragSourceDragEvent dsde) { int action = dsde.getDropAction(); if (action == DnDConstants.ACTION_COPY) { dsde.getDragSourceContext().setCursor(DragSource.DefaultCopyDrop); } else { if (action == DnDConstants.ACTION_MOVE) { dsde.getDragSourceContext().setCursor(DragSource.DefaultMoveDrop); } else { dsde.getDragSourceContext().setCursor(DragSource.DefaultMoveNoDrop); } } } public final void dragOver(DragSourceDragEvent dsde) { int action = dsde.getDropAction(); if (action == DnDConstants.ACTION_COPY) { dsde.getDragSourceContext().setCursor(DragSource.DefaultCopyDrop); } else { if (action == DnDConstants.ACTION_MOVE) { dsde.getDragSourceContext().setCursor(DragSource.DefaultMoveDrop); } else { dsde.getDragSourceContext().setCursor(DragSource.DefaultMoveNoDrop); } } } public final void dropActionChanged(DragSourceDragEvent dsde) { int action = dsde.getDropAction(); if (action == DnDConstants.ACTION_COPY) { dsde.getDragSourceContext().setCursor(DragSource.DefaultCopyDrop); } else { if (action == DnDConstants.ACTION_MOVE) { dsde.getDragSourceContext().setCursor(DragSource.DefaultMoveDrop); } else { dsde.getDragSourceContext().setCursor(DragSource.DefaultMoveNoDrop); } } } public final void dragExit(DragSourceEvent dse) { dse.getDragSourceContext().setCursor(DragSource.DefaultMoveNoDrop); } /* Methods for DragGestureListener */ public final void dragGestureRecognized(DragGestureEvent dge) { TreePath path = tree.getSelectionPath(); if (path != null) { draggedNode = (MyDiskInfoTree)path.getLastPathComponent(); draggedNodeParent = (MyDiskInfoTree)draggedNode.getParent(); if (drawImage) { Rectangle pathBounds = tree.getPathBounds(path); //getpathbounds of selectionpath JComponent lbl = (JComponent)tree.getCellRenderer().getTreeCellRendererComponent(tree, draggedNode, false , tree.isExpanded(path),((DefaultTreeModel)tree.getModel()).isLeaf(path.getLastPathComponent()), 0,false);//returning the label lbl.setBounds(pathBounds);//setting bounds to lbl image = new BufferedImage(lbl.getWidth(), lbl.getHeight(), java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE);//buffered image reference passing the label's ht and width Graphics2D graphics = image.createGraphics();//creating the graphics for buffered image graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); //Sets the Composite for the Graphics2D context lbl.setOpaque(false); lbl.paint(graphics); //painting the graphics to label graphics.dispose(); } dragSource.startDrag(dge, DragSource.DefaultMoveNoDrop , image, new Point(0,0), new TransferableNode(draggedNode), this); } } /* Methods for DropTargetListener */ public final void dragEnter(DropTargetDragEvent dtde) { Point pt = dtde.getLocation(); int action = dtde.getDropAction(); if (drawImage) { paintImage(pt); } if (canPerformAction(tree, draggedNode, action, pt)) { dtde.acceptDrag(action); } else { dtde.rejectDrag(); } } public final void dragExit(DropTargetEvent dte) { if (drawImage) { clearImage(); } } public final void dragOver(DropTargetDragEvent dtde) { Point pt = dtde.getLocation(); int action = dtde.getDropAction(); tree.autoscroll(pt); if (drawImage) { paintImage(pt); } if (canPerformAction(tree, draggedNode, action, pt)) { dtde.acceptDrag(action); } else { dtde.rejectDrag(); } } public final void dropActionChanged(DropTargetDragEvent dtde) { Point pt = dtde.getLocation(); int action = dtde.getDropAction(); if (drawImage) { paintImage(pt); } if (canPerformAction(tree, draggedNode, action, pt)) { dtde.acceptDrag(action); } else { dtde.rejectDrag(); } } public final void drop(DropTargetDropEvent dtde) { try { if (drawImage) { clearImage(); } int action = dtde.getDropAction(); Transferable transferable = dtde.getTransferable(); Point pt = dtde.getLocation(); if (transferable.isDataFlavorSupported(TransferableNode.NODE_FLAVOR) && canPerformAction(tree, draggedNode, action, pt)) { TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y); MyDiskInfoTree node = (MyDiskInfoTree) transferable.getTransferData(TransferableNode.NODE_FLAVOR); MyDiskInfoTree newParentNode =(MyDiskInfoTree)pathTarget.getLastPathComponent(); if (executeDrop(tree, node, newParentNode, action)) { dtde.acceptDrop(action); dtde.dropComplete(true); return; } } dtde.rejectDrop(); dtde.dropComplete(false); } catch (Exception e) { System.out.println(e); dtde.rejectDrop(); dtde.dropComplete(false); } } private final void paintImage(Point pt) { tree.paintImmediately(rect2D.getBounds()); rect2D.setRect((int) pt.getX(),(int) pt.getY(),image.getWidth(),image.getHeight()); tree.getGraphics().drawImage(image,(int) pt.getX(),(int) pt.getY(),tree); } private final void clearImage() { tree.paintImmediately(rect2D.getBounds()); } public abstract boolean canPerformAction(DNDTree target, MyDiskInfoTree draggedNode, int action, Point location); public abstract boolean executeDrop(DNDTree tree, MyDiskInfoTree draggedNode, MyDiskInfoTree newParentNode, int action); }
评论
    相关推荐
    • javascript树
      javascript树
    • javascript树
      javascript树结构设计 网页中树形菜单的设计
    • javascript
      免费的javascript树,简单实用,内有说明文档
    • JavaScript
      很好用的一棵,我再项目中经常用它。 PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv L0VOIj4NCjxIVE1MPjxIRUFEPjxUSVRMRT7Dt7uo0anW0M7EzfggLSBXRUKx4LPMzsTVwjwvVElU
    • Javascript树
      JAVASCRIPT写的一个,带ICO显示!
    • JAVASCRIPT树
      JAVASCRIPT导航 你可以修改添加 部门 子部门 子部门 这样的效果,里面有几个比较流行经典的
    • javascript树
      集合了几个经典的javascript实现,内容明了易懂,是初学入门的好选择!
    • javascript
      JavaScript写的以及相关的Demo
    • javascript
      javascript写的形结构用javascript写的形结构用javascript写的形结构用javascript写的形结构用javascript写的形结构用javascript写的形结构
    • javascript树
      javascript树javascript树javascript树javascript树javascript树javascript树javascript树javascript树javascript树javascript树javascript树javascript树javascript树javascript树javascript树