KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > dnd > DropTargetDropEvent


1 /*
2  * @(#)DropTargetDropEvent.java 1.28 04/05/05
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.awt.dnd;
9
10 import java.awt.Point JavaDoc;
11
12 import java.awt.datatransfer.DataFlavor JavaDoc;
13 import java.awt.datatransfer.Transferable JavaDoc;
14
15 import java.util.List JavaDoc;
16
17 /**
18  * The <code>DropTargetDropEvent</code> is delivered
19  * via the <code>DropTargetListener</code> drop() method.
20  * <p>
21  * The <code>DropTargetDropEvent</code> reports the <i>source drop actions</i>
22  * and the <i>user drop action</i> that reflect the current state of the
23  * drag-and-drop operation.
24  * <p>
25  * <i>Source drop actions</i> is a bitwise mask of <code>DnDConstants</code>
26  * that represents the set of drop actions supported by the drag source for
27  * this drag-and-drop operation.
28  * <p>
29  * <i>User drop action</i> depends on the drop actions supported by the drag
30  * source and the drop action selected by the user. The user can select a drop
31  * action by pressing modifier keys during the drag operation:
32  * <pre>
33  * Ctrl + Shift -> ACTION_LINK
34  * Ctrl -> ACTION_COPY
35  * Shift -> ACTION_MOVE
36  * </pre>
37  * If the user selects a drop action, the <i>user drop action</i> is one of
38  * <code>DnDConstants</code> that represents the selected drop action if this
39  * drop action is supported by the drag source or
40  * <code>DnDConstants.ACTION_NONE</code> if this drop action is not supported
41  * by the drag source.
42  * <p>
43  * If the user doesn't select a drop action, the set of
44  * <code>DnDConstants</code> that represents the set of drop actions supported
45  * by the drag source is searched for <code>DnDConstants.ACTION_MOVE</code>,
46  * then for <code>DnDConstants.ACTION_COPY</code>, then for
47  * <code>DnDConstants.ACTION_LINK</code> and the <i>user drop action</i> is the
48  * first constant found. If no constant is found the <i>user drop action</i>
49  * is <code>DnDConstants.ACTION_NONE</code>.
50  *
51  * @version 1.28, 05/05/04
52  * @since 1.2
53  */

54
55 public class DropTargetDropEvent extends DropTargetEvent JavaDoc {
56
57     private static final long serialVersionUID = -1721911170440459322L;
58
59     /**
60      * Construct a <code>DropTargetDropEvent</code> given
61      * the <code>DropTargetContext</code> for this operation,
62      * the location of the drag <code>Cursor</code>'s
63      * hotspot in the <code>Component</code>'s coordinates,
64      * the currently
65      * selected user drop action, and the current set of
66      * actions supported by the source.
67      * By default, this constructor
68      * assumes that the target is not in the same virtual machine as
69      * the source; that is, {@link #isLocalTransfer()} will
70      * return <code>false</code>.
71      * <P>
72      * @param dtc The <code>DropTargetContext</code> for this operation
73      * @param cursorLocn The location of the "Drag" Cursor's
74      * hotspot in <code>Component</code> coordinates
75      * @param dropAction the user drop action.
76      * @param srcActions the source drop actions.
77      *
78      * @throws <code>NullPointerException</code>
79      * if cursorLocn is <code>null</code>
80      * @throws <code>IllegalArgumentException</code> if dropAction is not one of
81      * <code>DnDConstants</code>.
82      * @throws <code>IllegalArgumentException</code> if srcActions is not
83      * a bitwise mask of <code>DnDConstants</code>.
84      * @throws <code>IllegalArgumentException</code> if dtc is <code>null</code>.
85      */

86
87     public DropTargetDropEvent(DropTargetContext JavaDoc dtc, Point JavaDoc cursorLocn, int dropAction, int srcActions) {
88     super(dtc);
89
90     if (cursorLocn == null) throw new NullPointerException JavaDoc("cursorLocn");
91
92     if (dropAction != DnDConstants.ACTION_NONE &&
93         dropAction != DnDConstants.ACTION_COPY &&
94         dropAction != DnDConstants.ACTION_MOVE &&
95         dropAction != DnDConstants.ACTION_LINK
96     ) throw new IllegalArgumentException JavaDoc("dropAction = " + dropAction);
97
98     if ((srcActions & ~(DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK)) != 0) throw new IllegalArgumentException JavaDoc("srcActions");
99
100     location = cursorLocn;
101     actions = srcActions;
102     this.dropAction = dropAction;
103     }
104
105     /**
106      * Construct a <code>DropTargetEvent</code> given the
107      * <code>DropTargetContext</code> for this operation,
108      * the location of the drag <code>Cursor</code>'s hotspot
109      * in the <code>Component</code>'s
110      * coordinates, the currently selected user drop action,
111      * the current set of actions supported by the source,
112      * and a <code>boolean</code> indicating if the source is in the same JVM
113      * as the target.
114      * <P>
115      * @param dtc The DropTargetContext for this operation
116      * @param cursorLocn The location of the "Drag" Cursor's
117      * hotspot in Component's coordinates
118      * @param dropAction the user drop action.
119      * @param srcActions the source drop actions.
120      * @param isLocal True if the source is in the same JVM as the target
121      *
122      * @throws <code>NullPointerException</code> if cursorLocn is
123      * <code>null</code>
124      * @throws <code>IllegalArgumentException</code> if dropAction is not one of
125      * <code>DnDConstants</code>.
126      * @throws <code>IllegalArgumentException</code> if srcActions is not
127      * a bitwise mask of <code>DnDConstants</code>.
128      * @throws <code>IllegalArgumentException</code> if dtc is <code>null</code>.
129      */

130
131     public DropTargetDropEvent(DropTargetContext JavaDoc dtc, Point JavaDoc cursorLocn, int dropAction, int srcActions, boolean isLocal) {
132     this(dtc, cursorLocn, dropAction, srcActions);
133
134     isLocalTx = isLocal;
135     }
136
137     /**
138      * This method returns a <code>Point</code>
139      * indicating the <code>Cursor</code>'s current
140      * location in the <code>Component</code>'s coordinates.
141      * <P>
142      * @return the current <code>Cursor</code> location in Component's coords.
143      */

144
145     public Point JavaDoc getLocation() {
146     return location;
147     }
148
149
150     /**
151      * This method returns the current DataFlavors.
152      * <P>
153      * @return current DataFlavors
154      */

155
156     public DataFlavor JavaDoc[] getCurrentDataFlavors() {
157     return getDropTargetContext().getCurrentDataFlavors();
158     }
159
160     /**
161      * This method returns the currently available
162      * <code>DataFlavor</code>s as a <code>java.util.List</code>.
163      * <P>
164      * @return the currently available DataFlavors as a java.util.List
165      */

166
167     public List JavaDoc<DataFlavor JavaDoc> getCurrentDataFlavorsAsList() {
168     return getDropTargetContext().getCurrentDataFlavorsAsList();
169     }
170
171     /**
172      * This method returns a <code>boolean</code> indicating if the
173      * specified <code>DataFlavor</code> is available
174      * from the source.
175      * <P>
176      * @param df the <code>DataFlavor</code> to test
177      * <P>
178      * @return if the DataFlavor specified is available from the source
179      */

180
181     public boolean isDataFlavorSupported(DataFlavor JavaDoc df) {
182     return getDropTargetContext().isDataFlavorSupported(df);
183     }
184
185     /**
186      * This method returns the source drop actions.
187      *
188      * @return the source drop actions.
189      */

190     public int getSourceActions() { return actions; }
191
192     /**
193      * This method returns the user drop action.
194      *
195      * @return the user drop actions.
196      */

197     public int getDropAction() { return dropAction; }
198
199     /**
200      * This method returns the <code>Transferable</code> object
201      * associated with the drop.
202      * <P>
203      * @return the <code>Transferable</code> associated with the drop
204      */

205
206     public Transferable JavaDoc getTransferable() {
207     return getDropTargetContext().getTransferable();
208     }
209
210     /**
211      * accept the drop, using the specified action.
212      * <P>
213      * @param dropAction the specified action
214      */

215
216     public void acceptDrop(int dropAction) {
217     getDropTargetContext().acceptDrop(dropAction);
218     }
219
220     /**
221      * reject the Drop.
222      */

223
224     public void rejectDrop() {
225     getDropTargetContext().rejectDrop();
226     }
227
228     /**
229      * This method notifies the <code>DragSource</code>
230      * that the drop transfer(s) are completed.
231      * <P>
232      * @param success a <code>boolean</code> indicating that the drop transfer(s) are completed.
233      */

234
235     public void dropComplete(boolean success) {
236     getDropTargetContext().dropComplete(success);
237     }
238     
239     /**
240      * This method returns an <code>int</code> indicating if
241      * the source is in the same JVM as the target.
242      * <P>
243      * @return if the Source is in the same JVM
244      */

245
246     public boolean isLocalTransfer() {
247     return isLocalTx;
248     }
249
250     /*
251      * fields
252      */

253
254     static final private Point JavaDoc zero = new Point JavaDoc(0,0);
255
256     /**
257      * The location of the drag cursor's hotspot in Component coordinates.
258      *
259      * @serial
260      */

261     private Point JavaDoc location = zero;
262
263     /**
264      * The source drop actions.
265      *
266      * @serial
267      */

268     private int actions = DnDConstants.ACTION_NONE;
269
270     /**
271      * The user drop action.
272      *
273      * @serial
274      */

275     private int dropAction = DnDConstants.ACTION_NONE;
276
277     /**
278      * <code>true</code> if the source is in the same JVM as the target.
279      *
280      * @serial
281      */

282     private boolean isLocalTx = false;
283 }
284
Popular Tags