1 19 package org.openide.explorer.view; 20 21 import org.openide.explorer.ExplorerManager; 22 import org.openide.nodes.Node; 23 24 import java.awt.Component ; 25 import java.awt.dnd.*; 26 27 import javax.swing.JTree ; 28 import javax.swing.SwingUtilities ; 29 import javax.swing.tree.*; 30 31 32 36 final class TreeViewDragSupport extends ExplorerDragSupport { 37 40 41 protected TreeView view; 42 43 44 private JTree tree; 45 46 47 48 51 52 public TreeViewDragSupport(TreeView view, JTree tree) { 53 this.view = view; 54 this.comp = tree; 55 this.tree = tree; 56 } 57 58 public int getAllowedDragActions() { 59 return view.getAllowedDragActions(); 60 } 61 62 int getAllowedDropActions() { 63 return view.getAllowedDropActions(); 64 } 65 66 public void dragGestureRecognized(DragGestureEvent dge) { 67 super.dragGestureRecognized(dge); 68 69 if (exDnD.isDnDActive()) { 71 TreeCellEditor tce = ((JTree ) tree).getCellEditor(); 72 73 if (tce instanceof TreeViewCellEditor) { 74 ((TreeViewCellEditor) tce).setDnDActive(true); 75 } 76 } 77 } 78 79 public void dragDropEnd(DragSourceDropEvent dsde) { 80 Node[] dropedNodes = exDnD.getDraggedNodes(); 82 super.dragDropEnd(dsde); 83 84 if (DropGlassPane.isOriginalPaneStored()) { 86 DropGlassPane.putBackOriginal(); 88 89 exDnD.setDnDActive(false); 91 } 92 93 try { 95 if (dropedNodes != null) { 96 ExplorerManager.Provider panel = (ExplorerManager.Provider) SwingUtilities.getAncestorOfClass( 97 ExplorerManager.Provider.class, view 98 ); 99 100 if (panel != null) { 101 panel.getExplorerManager().setSelectedNodes(dropedNodes); 102 } 103 } 104 } catch (Exception e) { 105 } 107 108 TreeCellEditor tce = tree.getCellEditor(); 111 112 if (tce instanceof TreeViewCellEditor) { 113 ((TreeViewCellEditor) tce).setDnDActive(false); 114 } 115 } 116 117 123 Node[] obtainNodes(DragGestureEvent dge) { 124 TreePath[] tps = tree.getSelectionPaths(); 125 126 if (tps == null) { 127 return null; 128 } 129 130 Node[] result = new Node[tps.length]; 131 132 int cnt = 0; 133 134 for (int i = 0; i < tps.length; i++) { 135 if (tree.getPathBounds(tps[i]).contains(dge.getDragOrigin())) { 136 cnt++; 137 } 138 139 result[i] = DragDropUtilities.secureFindNode(tps[i].getLastPathComponent()); 140 } 141 142 return (cnt == 0) ? null : result; 146 } 147 } 148 149 | Popular Tags |