1 19 20 package org.netbeans.core.windows.view.ui.toolbars; 21 22 23 import java.awt.Cursor ; 24 import java.awt.datatransfer.Transferable ; 25 import java.awt.dnd.*; 26 import java.io.IOException ; 27 import java.util.logging.Level ; 28 import java.util.logging.Logger ; 29 import javax.swing.JTree ; 30 import javax.swing.tree.*; 31 import org.openide.explorer.view.*; 32 import org.openide.nodes.Node; 33 34 40 public class ActionsTree extends JTree implements DragGestureListener, DragSourceListener { 41 42 private boolean firstTimeExpand = true; 43 44 private Cursor dragMoveCursor = DragSource.DefaultMoveDrop; 45 private Cursor dragNoDropCursor = DragSource.DefaultMoveNoDrop; 46 47 48 public ActionsTree( Node root ) { 49 super( new NodeTreeModel( root ) ); 50 setRootVisible( false ); 51 getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); 52 setCellRenderer( new NodeRenderer() ); 53 setShowsRootHandles( true ); 54 expandAll(); 55 DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( this, DnDConstants.ACTION_MOVE, this ); 56 } 57 58 private void expandAll() { 59 int i = 0; 60 int j ; 61 62 do { 63 do { 64 j = getRowCount(); 65 expandRow(i); 66 } while (j != getRowCount()); 67 68 i++; 69 } while (i < getRowCount()); 70 } 71 72 public void dragGestureRecognized(DragGestureEvent dge) { 73 TreePath path = getPathForLocation( dge.getDragOrigin().x, dge.getDragOrigin().y ); 74 if( null != path ) { 75 Object obj = path.getLastPathComponent(); 76 if( getModel().isLeaf( obj ) ) { 77 try { 78 Node node = Visualizer.findNode( obj ); 79 Transferable t = node.drag(); 80 dge.getDragSource().addDragSourceListener( this ); 81 dge.startDrag( dragNoDropCursor, t ); 82 } catch( IOException e ) { 83 Logger.getLogger(ActionsTree.class.getName()).log(Level.WARNING, null, e); 84 } 85 } 86 } 87 } 88 89 public void dragExit(java.awt.dnd.DragSourceEvent dse) { 90 dse.getDragSourceContext().setCursor( dragNoDropCursor ); 91 } 92 93 public void dropActionChanged(java.awt.dnd.DragSourceDragEvent dsde) { 94 } 95 96 public void dragOver(java.awt.dnd.DragSourceDragEvent e) { 97 DragSourceContext context = e.getDragSourceContext(); 98 int action = e.getDropAction(); 99 if ((action & DnDConstants.ACTION_MOVE) != 0) { 100 context.setCursor( dragMoveCursor ); 101 } else { 102 context.setCursor( dragNoDropCursor ); 103 } 104 } 105 106 public void dragEnter(java.awt.dnd.DragSourceDragEvent dsde) { 107 dragOver( dsde ); 108 } 109 110 public void dragDropEnd(java.awt.dnd.DragSourceDropEvent dsde) { 111 } 112 } 113 | Popular Tags |