001 /*
002 * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.awt.dnd;
027
028 import java.awt.Point;
029
030 import java.awt.datatransfer.DataFlavor;
031 import java.awt.datatransfer.Transferable;
032
033 import java.util.List;
034
035 /**
036 * The <code>DropTargetDropEvent</code> is delivered
037 * via the <code>DropTargetListener</code> drop() method.
038 * <p>
039 * The <code>DropTargetDropEvent</code> reports the <i>source drop actions</i>
040 * and the <i>user drop action</i> that reflect the current state of the
041 * drag-and-drop operation.
042 * <p>
043 * <i>Source drop actions</i> is a bitwise mask of <code>DnDConstants</code>
044 * that represents the set of drop actions supported by the drag source for
045 * this drag-and-drop operation.
046 * <p>
047 * <i>User drop action</i> depends on the drop actions supported by the drag
048 * source and the drop action selected by the user. The user can select a drop
049 * action by pressing modifier keys during the drag operation:
050 * <pre>
051 * Ctrl + Shift -> ACTION_LINK
052 * Ctrl -> ACTION_COPY
053 * Shift -> ACTION_MOVE
054 * </pre>
055 * If the user selects a drop action, the <i>user drop action</i> is one of
056 * <code>DnDConstants</code> that represents the selected drop action if this
057 * drop action is supported by the drag source or
058 * <code>DnDConstants.ACTION_NONE</code> if this drop action is not supported
059 * by the drag source.
060 * <p>
061 * If the user doesn't select a drop action, the set of
062 * <code>DnDConstants</code> that represents the set of drop actions supported
063 * by the drag source is searched for <code>DnDConstants.ACTION_MOVE</code>,
064 * then for <code>DnDConstants.ACTION_COPY</code>, then for
065 * <code>DnDConstants.ACTION_LINK</code> and the <i>user drop action</i> is the
066 * first constant found. If no constant is found the <i>user drop action</i>
067 * is <code>DnDConstants.ACTION_NONE</code>.
068 *
069 * @version 1.35, 05/05/07
070 * @since 1.2
071 */
072
073 public class DropTargetDropEvent extends DropTargetEvent {
074
075 private static final long serialVersionUID = -1721911170440459322L;
076
077 /**
078 * Construct a <code>DropTargetDropEvent</code> given
079 * the <code>DropTargetContext</code> for this operation,
080 * the location of the drag <code>Cursor</code>'s
081 * hotspot in the <code>Component</code>'s coordinates,
082 * the currently
083 * selected user drop action, and the current set of
084 * actions supported by the source.
085 * By default, this constructor
086 * assumes that the target is not in the same virtual machine as
087 * the source; that is, {@link #isLocalTransfer()} will
088 * return <code>false</code>.
089 * <P>
090 * @param dtc The <code>DropTargetContext</code> for this operation
091 * @param cursorLocn The location of the "Drag" Cursor's
092 * hotspot in <code>Component</code> coordinates
093 * @param dropAction the user drop action.
094 * @param srcActions the source drop actions.
095 *
096 * @throws <code>NullPointerException</code>
097 * if cursorLocn is <code>null</code>
098 * @throws <code>IllegalArgumentException</code> if dropAction is not one of
099 * <code>DnDConstants</code>.
100 * @throws <code>IllegalArgumentException</code> if srcActions is not
101 * a bitwise mask of <code>DnDConstants</code>.
102 * @throws <code>IllegalArgumentException</code> if dtc is <code>null</code>.
103 */
104
105 public DropTargetDropEvent(DropTargetContext dtc, Point cursorLocn,
106 int dropAction, int srcActions) {
107 super (dtc);
108
109 if (cursorLocn == null)
110 throw new NullPointerException("cursorLocn");
111
112 if (dropAction != DnDConstants.ACTION_NONE
113 && dropAction != DnDConstants.ACTION_COPY
114 && dropAction != DnDConstants.ACTION_MOVE
115 && dropAction != DnDConstants.ACTION_LINK)
116 throw new IllegalArgumentException("dropAction = "
117 + dropAction);
118
119 if ((srcActions & ~(DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK)) != 0)
120 throw new IllegalArgumentException("srcActions");
121
122 location = cursorLocn;
123 actions = srcActions;
124 this .dropAction = dropAction;
125 }
126
127 /**
128 * Construct a <code>DropTargetEvent</code> given the
129 * <code>DropTargetContext</code> for this operation,
130 * the location of the drag <code>Cursor</code>'s hotspot
131 * in the <code>Component</code>'s
132 * coordinates, the currently selected user drop action,
133 * the current set of actions supported by the source,
134 * and a <code>boolean</code> indicating if the source is in the same JVM
135 * as the target.
136 * <P>
137 * @param dtc The DropTargetContext for this operation
138 * @param cursorLocn The location of the "Drag" Cursor's
139 * hotspot in Component's coordinates
140 * @param dropAction the user drop action.
141 * @param srcActions the source drop actions.
142 * @param isLocal True if the source is in the same JVM as the target
143 *
144 * @throws <code>NullPointerException</code> if cursorLocn is
145 * <code>null</code>
146 * @throws <code>IllegalArgumentException</code> if dropAction is not one of
147 * <code>DnDConstants</code>.
148 * @throws <code>IllegalArgumentException</code> if srcActions is not
149 * a bitwise mask of <code>DnDConstants</code>.
150 * @throws <code>IllegalArgumentException</code> if dtc is <code>null</code>.
151 */
152
153 public DropTargetDropEvent(DropTargetContext dtc, Point cursorLocn,
154 int dropAction, int srcActions, boolean isLocal) {
155 this (dtc, cursorLocn, dropAction, srcActions);
156
157 isLocalTx = isLocal;
158 }
159
160 /**
161 * This method returns a <code>Point</code>
162 * indicating the <code>Cursor</code>'s current
163 * location in the <code>Component</code>'s coordinates.
164 * <P>
165 * @return the current <code>Cursor</code> location in Component's coords.
166 */
167
168 public Point getLocation() {
169 return location;
170 }
171
172 /**
173 * This method returns the current DataFlavors.
174 * <P>
175 * @return current DataFlavors
176 */
177
178 public DataFlavor[] getCurrentDataFlavors() {
179 return getDropTargetContext().getCurrentDataFlavors();
180 }
181
182 /**
183 * This method returns the currently available
184 * <code>DataFlavor</code>s as a <code>java.util.List</code>.
185 * <P>
186 * @return the currently available DataFlavors as a java.util.List
187 */
188
189 public List<DataFlavor> getCurrentDataFlavorsAsList() {
190 return getDropTargetContext().getCurrentDataFlavorsAsList();
191 }
192
193 /**
194 * This method returns a <code>boolean</code> indicating if the
195 * specified <code>DataFlavor</code> is available
196 * from the source.
197 * <P>
198 * @param df the <code>DataFlavor</code> to test
199 * <P>
200 * @return if the DataFlavor specified is available from the source
201 */
202
203 public boolean isDataFlavorSupported(DataFlavor df) {
204 return getDropTargetContext().isDataFlavorSupported(df);
205 }
206
207 /**
208 * This method returns the source drop actions.
209 *
210 * @return the source drop actions.
211 */
212 public int getSourceActions() {
213 return actions;
214 }
215
216 /**
217 * This method returns the user drop action.
218 *
219 * @return the user drop actions.
220 */
221 public int getDropAction() {
222 return dropAction;
223 }
224
225 /**
226 * This method returns the <code>Transferable</code> object
227 * associated with the drop.
228 * <P>
229 * @return the <code>Transferable</code> associated with the drop
230 */
231
232 public Transferable getTransferable() {
233 return getDropTargetContext().getTransferable();
234 }
235
236 /**
237 * accept the drop, using the specified action.
238 * <P>
239 * @param dropAction the specified action
240 */
241
242 public void acceptDrop(int dropAction) {
243 getDropTargetContext().acceptDrop(dropAction);
244 }
245
246 /**
247 * reject the Drop.
248 */
249
250 public void rejectDrop() {
251 getDropTargetContext().rejectDrop();
252 }
253
254 /**
255 * This method notifies the <code>DragSource</code>
256 * that the drop transfer(s) are completed.
257 * <P>
258 * @param success a <code>boolean</code> indicating that the drop transfer(s) are completed.
259 */
260
261 public void dropComplete(boolean success) {
262 getDropTargetContext().dropComplete(success);
263 }
264
265 /**
266 * This method returns an <code>int</code> indicating if
267 * the source is in the same JVM as the target.
268 * <P>
269 * @return if the Source is in the same JVM
270 */
271
272 public boolean isLocalTransfer() {
273 return isLocalTx;
274 }
275
276 /*
277 * fields
278 */
279
280 static final private Point zero = new Point(0, 0);
281
282 /**
283 * The location of the drag cursor's hotspot in Component coordinates.
284 *
285 * @serial
286 */
287 private Point location = zero;
288
289 /**
290 * The source drop actions.
291 *
292 * @serial
293 */
294 private int actions = DnDConstants.ACTION_NONE;
295
296 /**
297 * The user drop action.
298 *
299 * @serial
300 */
301 private int dropAction = DnDConstants.ACTION_NONE;
302
303 /**
304 * <code>true</code> if the source is in the same JVM as the target.
305 *
306 * @serial
307 */
308 private boolean isLocalTx = false;
309 }
|