KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > view > ExplorerDnDManager


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 JavaDoc;
25 import java.awt.datatransfer.Transferable JavaDoc;
26 import java.awt.dnd.DnDConstants JavaDoc; // TEMP
27

28 import java.util.Iterator JavaDoc;
29
30 import javax.swing.JScrollPane JavaDoc;
31
32
33 /**
34  * Manager for explorer DnD.
35  *
36  *
37  * @author Jiri Rechtacek
38  *
39  * @see TreeViewDragSupport
40  * @see TreeViewDropSupport
41  */

42 final class ExplorerDnDManager {
43     /** Singleton instance of explorer dnd manager. */
44     private static ExplorerDnDManager defaultDnDManager;
45     private Node[] draggedNodes;
46     private Transferable JavaDoc draggedTransForCut;
47     private Transferable JavaDoc draggedTransForCopy;
48     private boolean isDnDActive = false;
49     private int nodeAllowed = 0;
50     private Cursor JavaDoc cursor = null;
51     private boolean maybeExternalDnD = false;
52
53     /** Creates a new instance of <code>WindowsDnDManager</code>. */
54     private ExplorerDnDManager() {
55     }
56
57     /** Gets the singleton instance of this window dnd manager. */
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 JavaDoc trans, boolean isCut) {
75         if (isCut) {
76             draggedTransForCut = trans;
77         } else {
78             draggedTransForCopy = trans;
79         }
80     }
81
82     Transferable JavaDoc getDraggedTransferable(boolean isCut) {
83         if (isCut) {
84             return draggedTransForCut;
85         }
86
87         // only for copy
88
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 JavaDoc c) {
129         this.cursor = c;
130     }
131
132     Cursor JavaDoc getCursor() {
133         return this.cursor;
134     }
135 }
136
Popular Tags