0N/A/*
2362N/A * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.awt.dnd;
0N/A
0N/Aimport java.awt.Point;
0N/A
0N/Aimport java.awt.datatransfer.DataFlavor;
0N/Aimport java.awt.datatransfer.Transferable;
0N/A
0N/Aimport java.util.List;
0N/A
0N/A/**
0N/A * The <code>DropTargetDropEvent</code> is delivered
0N/A * via the <code>DropTargetListener</code> drop() method.
0N/A * <p>
0N/A * The <code>DropTargetDropEvent</code> reports the <i>source drop actions</i>
0N/A * and the <i>user drop action</i> that reflect the current state of the
0N/A * drag-and-drop operation.
0N/A * <p>
0N/A * <i>Source drop actions</i> is a bitwise mask of <code>DnDConstants</code>
0N/A * that represents the set of drop actions supported by the drag source for
0N/A * this drag-and-drop operation.
0N/A * <p>
0N/A * <i>User drop action</i> depends on the drop actions supported by the drag
0N/A * source and the drop action selected by the user. The user can select a drop
0N/A * action by pressing modifier keys during the drag operation:
0N/A * <pre>
0N/A * Ctrl + Shift -> ACTION_LINK
0N/A * Ctrl -> ACTION_COPY
0N/A * Shift -> ACTION_MOVE
0N/A * </pre>
0N/A * If the user selects a drop action, the <i>user drop action</i> is one of
0N/A * <code>DnDConstants</code> that represents the selected drop action if this
0N/A * drop action is supported by the drag source or
0N/A * <code>DnDConstants.ACTION_NONE</code> if this drop action is not supported
0N/A * by the drag source.
0N/A * <p>
0N/A * If the user doesn't select a drop action, the set of
0N/A * <code>DnDConstants</code> that represents the set of drop actions supported
0N/A * by the drag source is searched for <code>DnDConstants.ACTION_MOVE</code>,
0N/A * then for <code>DnDConstants.ACTION_COPY</code>, then for
0N/A * <code>DnDConstants.ACTION_LINK</code> and the <i>user drop action</i> is the
0N/A * first constant found. If no constant is found the <i>user drop action</i>
0N/A * is <code>DnDConstants.ACTION_NONE</code>.
0N/A *
0N/A * @since 1.2
0N/A */
0N/A
0N/Apublic class DropTargetDropEvent extends DropTargetEvent {
0N/A
0N/A private static final long serialVersionUID = -1721911170440459322L;
0N/A
0N/A /**
0N/A * Construct a <code>DropTargetDropEvent</code> given
0N/A * the <code>DropTargetContext</code> for this operation,
0N/A * the location of the drag <code>Cursor</code>'s
0N/A * hotspot in the <code>Component</code>'s coordinates,
0N/A * the currently
0N/A * selected user drop action, and the current set of
0N/A * actions supported by the source.
0N/A * By default, this constructor
0N/A * assumes that the target is not in the same virtual machine as
0N/A * the source; that is, {@link #isLocalTransfer()} will
0N/A * return <code>false</code>.
0N/A * <P>
0N/A * @param dtc The <code>DropTargetContext</code> for this operation
0N/A * @param cursorLocn The location of the "Drag" Cursor's
0N/A * hotspot in <code>Component</code> coordinates
0N/A * @param dropAction the user drop action.
0N/A * @param srcActions the source drop actions.
0N/A *
0N/A * @throws <code>NullPointerException</code>
0N/A * if cursorLocn is <code>null</code>
0N/A * @throws <code>IllegalArgumentException</code> if dropAction is not one of
0N/A * <code>DnDConstants</code>.
0N/A * @throws <code>IllegalArgumentException</code> if srcActions is not
0N/A * a bitwise mask of <code>DnDConstants</code>.
0N/A * @throws <code>IllegalArgumentException</code> if dtc is <code>null</code>.
0N/A */
0N/A
0N/A public DropTargetDropEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions) {
0N/A super(dtc);
0N/A
0N/A if (cursorLocn == null) throw new NullPointerException("cursorLocn");
0N/A
0N/A if (dropAction != DnDConstants.ACTION_NONE &&
0N/A dropAction != DnDConstants.ACTION_COPY &&
0N/A dropAction != DnDConstants.ACTION_MOVE &&
0N/A dropAction != DnDConstants.ACTION_LINK
0N/A ) throw new IllegalArgumentException("dropAction = " + dropAction);
0N/A
0N/A if ((srcActions & ~(DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK)) != 0) throw new IllegalArgumentException("srcActions");
0N/A
0N/A location = cursorLocn;
0N/A actions = srcActions;
0N/A this.dropAction = dropAction;
0N/A }
0N/A
0N/A /**
0N/A * Construct a <code>DropTargetEvent</code> given the
0N/A * <code>DropTargetContext</code> for this operation,
0N/A * the location of the drag <code>Cursor</code>'s hotspot
0N/A * in the <code>Component</code>'s
0N/A * coordinates, the currently selected user drop action,
0N/A * the current set of actions supported by the source,
0N/A * and a <code>boolean</code> indicating if the source is in the same JVM
0N/A * as the target.
0N/A * <P>
0N/A * @param dtc The DropTargetContext for this operation
0N/A * @param cursorLocn The location of the "Drag" Cursor's
0N/A * hotspot in Component's coordinates
0N/A * @param dropAction the user drop action.
0N/A * @param srcActions the source drop actions.
0N/A * @param isLocal True if the source is in the same JVM as the target
0N/A *
0N/A * @throws <code>NullPointerException</code> if cursorLocn is
0N/A * <code>null</code>
0N/A * @throws <code>IllegalArgumentException</code> if dropAction is not one of
0N/A * <code>DnDConstants</code>.
0N/A * @throws <code>IllegalArgumentException</code> if srcActions is not
0N/A * a bitwise mask of <code>DnDConstants</code>.
0N/A * @throws <code>IllegalArgumentException</code> if dtc is <code>null</code>.
0N/A */
0N/A
0N/A public DropTargetDropEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions, boolean isLocal) {
0N/A this(dtc, cursorLocn, dropAction, srcActions);
0N/A
0N/A isLocalTx = isLocal;
0N/A }
0N/A
0N/A /**
0N/A * This method returns a <code>Point</code>
0N/A * indicating the <code>Cursor</code>'s current
0N/A * location in the <code>Component</code>'s coordinates.
0N/A * <P>
0N/A * @return the current <code>Cursor</code> location in Component's coords.
0N/A */
0N/A
0N/A public Point getLocation() {
0N/A return location;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * This method returns the current DataFlavors.
0N/A * <P>
0N/A * @return current DataFlavors
0N/A */
0N/A
0N/A public DataFlavor[] getCurrentDataFlavors() {
0N/A return getDropTargetContext().getCurrentDataFlavors();
0N/A }
0N/A
0N/A /**
0N/A * This method returns the currently available
0N/A * <code>DataFlavor</code>s as a <code>java.util.List</code>.
0N/A * <P>
0N/A * @return the currently available DataFlavors as a java.util.List
0N/A */
0N/A
0N/A public List<DataFlavor> getCurrentDataFlavorsAsList() {
0N/A return getDropTargetContext().getCurrentDataFlavorsAsList();
0N/A }
0N/A
0N/A /**
0N/A * This method returns a <code>boolean</code> indicating if the
0N/A * specified <code>DataFlavor</code> is available
0N/A * from the source.
0N/A * <P>
0N/A * @param df the <code>DataFlavor</code> to test
0N/A * <P>
0N/A * @return if the DataFlavor specified is available from the source
0N/A */
0N/A
0N/A public boolean isDataFlavorSupported(DataFlavor df) {
0N/A return getDropTargetContext().isDataFlavorSupported(df);
0N/A }
0N/A
0N/A /**
0N/A * This method returns the source drop actions.
0N/A *
0N/A * @return the source drop actions.
0N/A */
0N/A public int getSourceActions() { return actions; }
0N/A
0N/A /**
0N/A * This method returns the user drop action.
0N/A *
0N/A * @return the user drop actions.
0N/A */
0N/A public int getDropAction() { return dropAction; }
0N/A
0N/A /**
0N/A * This method returns the <code>Transferable</code> object
0N/A * associated with the drop.
0N/A * <P>
0N/A * @return the <code>Transferable</code> associated with the drop
0N/A */
0N/A
0N/A public Transferable getTransferable() {
0N/A return getDropTargetContext().getTransferable();
0N/A }
0N/A
0N/A /**
0N/A * accept the drop, using the specified action.
0N/A * <P>
0N/A * @param dropAction the specified action
0N/A */
0N/A
0N/A public void acceptDrop(int dropAction) {
0N/A getDropTargetContext().acceptDrop(dropAction);
0N/A }
0N/A
0N/A /**
0N/A * reject the Drop.
0N/A */
0N/A
0N/A public void rejectDrop() {
0N/A getDropTargetContext().rejectDrop();
0N/A }
0N/A
0N/A /**
0N/A * This method notifies the <code>DragSource</code>
0N/A * that the drop transfer(s) are completed.
0N/A * <P>
0N/A * @param success a <code>boolean</code> indicating that the drop transfer(s) are completed.
0N/A */
0N/A
0N/A public void dropComplete(boolean success) {
0N/A getDropTargetContext().dropComplete(success);
0N/A }
0N/A
0N/A /**
0N/A * This method returns an <code>int</code> indicating if
0N/A * the source is in the same JVM as the target.
0N/A * <P>
0N/A * @return if the Source is in the same JVM
0N/A */
0N/A
0N/A public boolean isLocalTransfer() {
0N/A return isLocalTx;
0N/A }
0N/A
0N/A /*
0N/A * fields
0N/A */
0N/A
0N/A static final private Point zero = new Point(0,0);
0N/A
0N/A /**
0N/A * The location of the drag cursor's hotspot in Component coordinates.
0N/A *
0N/A * @serial
0N/A */
0N/A private Point location = zero;
0N/A
0N/A /**
0N/A * The source drop actions.
0N/A *
0N/A * @serial
0N/A */
0N/A private int actions = DnDConstants.ACTION_NONE;
0N/A
0N/A /**
0N/A * The user drop action.
0N/A *
0N/A * @serial
0N/A */
0N/A private int dropAction = DnDConstants.ACTION_NONE;
0N/A
0N/A /**
0N/A * <code>true</code> if the source is in the same JVM as the target.
0N/A *
0N/A * @serial
0N/A */
0N/A private boolean isLocalTx = false;
0N/A}