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>DropTargetDragEvent</code> is delivered to a
0N/A * <code>DropTargetListener</code> via its
0N/A * dragEnter() and dragOver() methods.
0N/A * <p>
0N/A * The <code>DropTargetDragEvent</code> reports the <i>source drop actions</i>
0N/A * and the <i>user drop action</i> that reflect the current state of
0N/A * the drag 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 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 DropTargetDragEvent extends DropTargetEvent {
0N/A
0N/A private static final long serialVersionUID = -8422265619058953682L;
0N/A
0N/A /**
0N/A * Construct a <code>DropTargetDragEvent</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 coordinates, the
0N/A * user drop action, and the source drop actions.
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 coordinates
0N/A * @param dropAction The user drop action
0N/A * @param srcActions The source drop actions
0N/A *
0N/A * @throws NullPointerException if cursorLocn is null
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 DropTargetDragEvent(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 * This method returns a <code>Point</code>
0N/A * indicating the <code>Cursor</code>'s current
0N/A * location within the <code>Component'</code>s
0N/A * coordinates.
0N/A * <P>
0N/A * @return the current cursor location in
0N/A * <code>Component</code>'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 <code>DataFlavor</code>s from the
0N/A * <code>DropTargetContext</code>.
0N/A * <P>
0N/A * @return current DataFlavors from the DropTargetContext
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 current <code>DataFlavor</code>s
0N/A * as a <code>java.util.List</code>
0N/A * <P>
0N/A * @return a <code>java.util.List</code> of the Current <code>DataFlavor</code>s
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
0N/A * if the specified <code>DataFlavor</code> is supported.
0N/A * <P>
0N/A * @param df the <code>DataFlavor</code> to test
0N/A * <P>
0N/A * @return if a particular DataFlavor is supported
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 action
0N/A */
0N/A public int getDropAction() { return dropAction; }
0N/A
0N/A /**
0N/A * This method returns the Transferable object that represents
0N/A * the data associated with the current drag operation.
0N/A *
0N/A * @return the Transferable associated with the drag operation
0N/A * @throws InvalidDnDOperationException if the data associated with the drag
0N/A * operation is not available
0N/A *
0N/A * @since 1.5
0N/A */
0N/A public Transferable getTransferable() {
0N/A return getDropTargetContext().getTransferable();
0N/A }
0N/A
0N/A /**
0N/A * Accepts the drag.
0N/A *
0N/A * This method should be called from a
0N/A * <code>DropTargetListeners</code> <code>dragEnter</code>,
0N/A * <code>dragOver</code>, and <code>dropActionChanged</code>
0N/A * methods if the implementation wishes to accept an operation
0N/A * from the srcActions other than the one selected by
0N/A * the user as represented by the <code>dropAction</code>.
0N/A *
0N/A * @param dragOperation the operation accepted by the target
0N/A */
0N/A public void acceptDrag(int dragOperation) {
0N/A getDropTargetContext().acceptDrag(dragOperation);
0N/A }
0N/A
0N/A /**
0N/A * Rejects the drag as a result of examining either the
0N/A * <code>dropAction</code> or the available <code>DataFlavor</code>
0N/A * types.
0N/A */
0N/A public void rejectDrag() {
0N/A getDropTargetContext().rejectDrag();
0N/A }
0N/A
0N/A /*
0N/A * fields
0N/A */
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;
0N/A
0N/A /**
0N/A * The source drop actions.
0N/A *
0N/A * @serial
0N/A */
0N/A private int actions;
0N/A
0N/A /**
0N/A * The user drop action.
0N/A *
0N/A * @serial
0N/A */
0N/A private int dropAction;
0N/A}