1 19 package org.openide.explorer.view; 20 21 import org.openide.nodes.Node; 22 import org.openide.util.WeakSet; 23 24 import java.awt.Cursor ; 25 import java.awt.datatransfer.Transferable ; 26 import java.awt.dnd.DnDConstants ; 28 import java.util.Iterator ; 29 30 import javax.swing.JScrollPane ; 31 32 33 42 final class ExplorerDnDManager { 43 44 private static ExplorerDnDManager defaultDnDManager; 45 private Node[] draggedNodes; 46 private Transferable draggedTransForCut; 47 private Transferable draggedTransForCopy; 48 private boolean isDnDActive = false; 49 private int nodeAllowed = 0; 50 private Cursor cursor = null; 51 private boolean maybeExternalDnD = false; 52 53 54 private ExplorerDnDManager() { 55 } 56 57 58 static synchronized ExplorerDnDManager getDefault() { 59 if (defaultDnDManager == null) { 60 defaultDnDManager = new ExplorerDnDManager(); 61 } 62 63 return defaultDnDManager; 64 } 65 66 void setDraggedNodes(Node[] n) { 67 draggedNodes = n; 68 } 69 70 Node[] getDraggedNodes() { 71 return draggedNodes; 72 } 73 74 void setDraggedTransferable(Transferable trans, boolean isCut) { 75 if (isCut) { 76 draggedTransForCut = trans; 77 } else { 78 draggedTransForCopy = trans; 79 } 80 } 81 82 Transferable getDraggedTransferable(boolean isCut) { 83 if (isCut) { 84 return draggedTransForCut; 85 } 86 87 return draggedTransForCopy; 89 } 90 91 void setNodeAllowedActions(int actions) { 92 nodeAllowed = actions; 93 } 94 95 final int getNodeAllowedActions() { 96 if( !isDnDActive && maybeExternalDnD ) 97 return DnDConstants.ACTION_COPY; 98 99 return nodeAllowed; 100 } 101 102 void setDnDActive(boolean state) { 103 isDnDActive = state; 104 } 105 106 boolean isDnDActive() { 107 return isDnDActive || maybeExternalDnD; 108 } 109 110 int getAdjustedDropAction(int action, int allowed) { 111 int possibleAction = action; 112 113 if ((possibleAction & allowed) == 0) { 114 possibleAction = allowed; 115 } 116 117 if ((possibleAction & getNodeAllowedActions()) == 0) { 118 possibleAction = getNodeAllowedActions(); 119 } 120 121 return possibleAction; 122 } 123 124 void setMaybeExternalDragAndDrop( boolean maybeExternalDnD ) { 125 this.maybeExternalDnD = maybeExternalDnD; 126 } 127 128 void prepareCursor(Cursor c) { 129 this.cursor = c; 130 } 131 132 Cursor getCursor() { 133 return this.cursor; 134 } 135 } 136 | Popular Tags |