Home » openjdk-7 » java » awt » dnd » [javadoc | source]

    1   /*
    2    * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Oracle designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Oracle in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   22    * or visit www.oracle.com if you need additional information or have any
   23    * questions.
   24    */
   25   
   26   package java.awt.dnd;
   27   
   28   import java.awt.Point;
   29   
   30   import java.awt.datatransfer.DataFlavor;
   31   import java.awt.datatransfer.Transferable;
   32   
   33   import java.util.List;
   34   
   35   /**
   36    * The <code>DropTargetDropEvent</code> is delivered
   37    * via the <code>DropTargetListener</code> drop() method.
   38    * <p>
   39    * The <code>DropTargetDropEvent</code> reports the <i>source drop actions</i>
   40    * and the <i>user drop action</i> that reflect the current state of the
   41    * drag-and-drop operation.
   42    * <p>
   43    * <i>Source drop actions</i> is a bitwise mask of <code>DnDConstants</code>
   44    * that represents the set of drop actions supported by the drag source for
   45    * this drag-and-drop operation.
   46    * <p>
   47    * <i>User drop action</i> depends on the drop actions supported by the drag
   48    * source and the drop action selected by the user. The user can select a drop
   49    * action by pressing modifier keys during the drag operation:
   50    * <pre>
   51    *   Ctrl + Shift -> ACTION_LINK
   52    *   Ctrl         -> ACTION_COPY
   53    *   Shift        -> ACTION_MOVE
   54    * </pre>
   55    * If the user selects a drop action, the <i>user drop action</i> is one of
   56    * <code>DnDConstants</code> that represents the selected drop action if this
   57    * drop action is supported by the drag source or
   58    * <code>DnDConstants.ACTION_NONE</code> if this drop action is not supported
   59    * by the drag source.
   60    * <p>
   61    * If the user doesn't select a drop action, the set of
   62    * <code>DnDConstants</code> that represents the set of drop actions supported
   63    * by the drag source is searched for <code>DnDConstants.ACTION_MOVE</code>,
   64    * then for <code>DnDConstants.ACTION_COPY</code>, then for
   65    * <code>DnDConstants.ACTION_LINK</code> and the <i>user drop action</i> is the
   66    * first constant found. If no constant is found the <i>user drop action</i>
   67    * is <code>DnDConstants.ACTION_NONE</code>.
   68    *
   69    * @since 1.2
   70    */
   71   
   72   public class DropTargetDropEvent extends DropTargetEvent {
   73   
   74       private static final long serialVersionUID = -1721911170440459322L;
   75   
   76       /**
   77        * Construct a <code>DropTargetDropEvent</code> given
   78        * the <code>DropTargetContext</code> for this operation,
   79        * the location of the drag <code>Cursor</code>'s
   80        * hotspot in the <code>Component</code>'s coordinates,
   81        * the currently
   82        * selected user drop action, and the current set of
   83        * actions supported by the source.
   84        * By default, this constructor
   85        * assumes that the target is not in the same virtual machine as
   86        * the source; that is, {@link #isLocalTransfer()} will
   87        * return <code>false</code>.
   88        * <P>
   89        * @param dtc        The <code>DropTargetContext</code> for this operation
   90        * @param cursorLocn The location of the "Drag" Cursor's
   91        * hotspot in <code>Component</code> coordinates
   92        * @param dropAction the user drop action.
   93        * @param srcActions the source drop actions.
   94        *
   95        * @throws <code>NullPointerException</code>
   96        * if cursorLocn is <code>null</code>
   97        * @throws <code>IllegalArgumentException</code> if dropAction is not one of
   98        *         <code>DnDConstants</code>.
   99        * @throws <code>IllegalArgumentException</code> if srcActions is not
  100        *         a bitwise mask of <code>DnDConstants</code>.
  101        * @throws <code>IllegalArgumentException</code> if dtc is <code>null</code>.
  102        */
  103   
  104       public DropTargetDropEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions)  {
  105           super(dtc);
  106   
  107           if (cursorLocn == null) throw new NullPointerException("cursorLocn");
  108   
  109           if (dropAction != DnDConstants.ACTION_NONE &&
  110               dropAction != DnDConstants.ACTION_COPY &&
  111               dropAction != DnDConstants.ACTION_MOVE &&
  112               dropAction != DnDConstants.ACTION_LINK
  113           ) throw new IllegalArgumentException("dropAction = " + dropAction);
  114   
  115           if ((srcActions & ~(DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK)) != 0) throw new IllegalArgumentException("srcActions");
  116   
  117           location        = cursorLocn;
  118           actions         = srcActions;
  119           this.dropAction = dropAction;
  120       }
  121   
  122       /**
  123        * Construct a <code>DropTargetEvent</code> given the
  124        * <code>DropTargetContext</code> for this operation,
  125        * the location of the drag <code>Cursor</code>'s hotspot
  126        * in the <code>Component</code>'s
  127        * coordinates, the currently selected user drop action,
  128        * the current set of actions supported by the source,
  129        * and a <code>boolean</code> indicating if the source is in the same JVM
  130        * as the target.
  131        * <P>
  132        * @param dtc        The DropTargetContext for this operation
  133        * @param cursorLocn The location of the "Drag" Cursor's
  134        * hotspot in Component's coordinates
  135        * @param dropAction the user drop action.
  136        * @param srcActions the source drop actions.
  137        * @param isLocal  True if the source is in the same JVM as the target
  138        *
  139        * @throws <code>NullPointerException</code> if cursorLocn is
  140        *         <code>null</code>
  141        * @throws <code>IllegalArgumentException</code> if dropAction is not one of
  142        *         <code>DnDConstants</code>.
  143        * @throws <code>IllegalArgumentException</code> if srcActions is not
  144        *         a bitwise mask of <code>DnDConstants</code>.
  145        * @throws <code>IllegalArgumentException</code> if dtc is <code>null</code>.
  146        */
  147   
  148       public DropTargetDropEvent(DropTargetContext dtc, Point cursorLocn, int dropAction, int srcActions, boolean isLocal)  {
  149           this(dtc, cursorLocn, dropAction, srcActions);
  150   
  151           isLocalTx = isLocal;
  152       }
  153   
  154       /**
  155        * This method returns a <code>Point</code>
  156        * indicating the <code>Cursor</code>'s current
  157        * location in the <code>Component</code>'s coordinates.
  158        * <P>
  159        * @return the current <code>Cursor</code> location in Component's coords.
  160        */
  161   
  162       public Point getLocation() {
  163           return location;
  164       }
  165   
  166   
  167       /**
  168        * This method returns the current DataFlavors.
  169        * <P>
  170        * @return current DataFlavors
  171        */
  172   
  173       public DataFlavor[] getCurrentDataFlavors() {
  174           return getDropTargetContext().getCurrentDataFlavors();
  175       }
  176   
  177       /**
  178        * This method returns the currently available
  179        * <code>DataFlavor</code>s as a <code>java.util.List</code>.
  180        * <P>
  181        * @return the currently available DataFlavors as a java.util.List
  182        */
  183   
  184       public List<DataFlavor> getCurrentDataFlavorsAsList() {
  185           return getDropTargetContext().getCurrentDataFlavorsAsList();
  186       }
  187   
  188       /**
  189        * This method returns a <code>boolean</code> indicating if the
  190        * specified <code>DataFlavor</code> is available
  191        * from the source.
  192        * <P>
  193        * @param df the <code>DataFlavor</code> to test
  194        * <P>
  195        * @return if the DataFlavor specified is available from the source
  196        */
  197   
  198       public boolean isDataFlavorSupported(DataFlavor df) {
  199           return getDropTargetContext().isDataFlavorSupported(df);
  200       }
  201   
  202       /**
  203        * This method returns the source drop actions.
  204        *
  205        * @return the source drop actions.
  206        */
  207       public int getSourceActions() { return actions; }
  208   
  209       /**
  210        * This method returns the user drop action.
  211        *
  212        * @return the user drop actions.
  213        */
  214       public int getDropAction() { return dropAction; }
  215   
  216       /**
  217        * This method returns the <code>Transferable</code> object
  218        * associated with the drop.
  219        * <P>
  220        * @return the <code>Transferable</code> associated with the drop
  221        */
  222   
  223       public Transferable getTransferable() {
  224           return getDropTargetContext().getTransferable();
  225       }
  226   
  227       /**
  228        * accept the drop, using the specified action.
  229        * <P>
  230        * @param dropAction the specified action
  231        */
  232   
  233       public void acceptDrop(int dropAction) {
  234           getDropTargetContext().acceptDrop(dropAction);
  235       }
  236   
  237       /**
  238        * reject the Drop.
  239        */
  240   
  241       public void rejectDrop() {
  242           getDropTargetContext().rejectDrop();
  243       }
  244   
  245       /**
  246        * This method notifies the <code>DragSource</code>
  247        * that the drop transfer(s) are completed.
  248        * <P>
  249        * @param success a <code>boolean</code> indicating that the drop transfer(s) are completed.
  250        */
  251   
  252       public void dropComplete(boolean success) {
  253           getDropTargetContext().dropComplete(success);
  254       }
  255   
  256       /**
  257        * This method returns an <code>int</code> indicating if
  258        * the source is in the same JVM as the target.
  259        * <P>
  260        * @return if the Source is in the same JVM
  261        */
  262   
  263       public boolean isLocalTransfer() {
  264           return isLocalTx;
  265       }
  266   
  267       /*
  268        * fields
  269        */
  270   
  271       static final private Point  zero     = new Point(0,0);
  272   
  273       /**
  274        * The location of the drag cursor's hotspot in Component coordinates.
  275        *
  276        * @serial
  277        */
  278       private Point               location   = zero;
  279   
  280       /**
  281        * The source drop actions.
  282        *
  283        * @serial
  284        */
  285       private int                 actions    = DnDConstants.ACTION_NONE;
  286   
  287       /**
  288        * The user drop action.
  289        *
  290        * @serial
  291        */
  292       private int                 dropAction = DnDConstants.ACTION_NONE;
  293   
  294       /**
  295        * <code>true</code> if the source is in the same JVM as the target.
  296        *
  297        * @serial
  298        */
  299       private boolean             isLocalTx = false;
  300   }

Home » openjdk-7 » java » awt » dnd » [javadoc | source]