1 /*
   2  * Copyright (c) 2018, 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 jdk.swing.interop;
  27 
  28 import java.awt.dnd.peer.DropTargetContextPeer;
  29 import java.awt.dnd.DropTarget;
  30 import java.awt.dnd.DnDConstants;
  31 import java.awt.dnd.InvalidDnDOperationException;
  32 import java.awt.dnd.DropTargetContext;
  33 import java.awt.datatransfer.DataFlavor;
  34 import java.awt.datatransfer.Transferable;
  35 import sun.awt.AWTAccessor;
  36 
  37 /**
  38  * This class provides a wrapper over inner class DropTargetContextPeerProxy
  39  * which implements jdk internal java.awt.dnd.peer.DropTargetContextPeer interface
  40  * and provides APIs to be used by FX swing interop to access and use
  41  * DropTargetContextPeer APIs.
  42  */
  43 public class DropTargetContextWrapper {
  44 
  45     private static DropTargetContextPeerProxy dcp;      
  46     public DropTargetContextWrapper() {
  47         dcp = new DropTargetContextPeerProxy();
  48     }
  49 
  50     public static void setDropTargetContextPeer(DropTargetContext dtc,
  51                                          DropTargetContextWrapper dtcpw) {
  52         AWTAccessor.getDropTargetContextAccessor().
  53                     setDropTargetContextPeer(dtc, dcp);
  54     }
  55 
  56     public static void reset(DropTargetContext dtc) {
  57         AWTAccessor.getDropTargetContextAccessor().reset(dtc);
  58     }
  59 
  60     public void setTargetActions(int actions) {}
  61 
  62     public int getTargetActions() {
  63         return DnDConstants.ACTION_NONE;
  64     }
  65 
  66     public DropTarget getDropTarget() {
  67         return null;
  68     }
  69 
  70     public DataFlavor[] getTransferDataFlavors() {
  71         return null;
  72     }
  73 
  74     public Transferable getTransferable() throws InvalidDnDOperationException {
  75         return null;
  76     }
  77 
  78     public boolean isTransferableJVMLocal() {
  79         return false;
  80     }
  81 
  82     public void acceptDrag(int dragAction) {}
  83 
  84     public void rejectDrag() {}
  85 
  86     public void acceptDrop(int dropAction) {}
  87 
  88     public void rejectDrop() {}
  89 
  90     public void dropComplete(boolean success) {}
  91 
  92     private class DropTargetContextPeerProxy implements DropTargetContextPeer {
  93 
  94         public void setTargetActions(int actions) {
  95             DropTargetContextWrapper.this.setTargetActions(actions);
  96         }
  97 
  98         public int getTargetActions() {
  99             return DropTargetContextWrapper.this.getTargetActions();
 100         }
 101 
 102         public DropTarget getDropTarget() {
 103             return DropTargetContextWrapper.this.getDropTarget();
 104         }
 105 
 106         public DataFlavor[] getTransferDataFlavors() {
 107             return DropTargetContextWrapper.this.getTransferDataFlavors();
 108         }
 109 
 110         public Transferable getTransferable() throws InvalidDnDOperationException {
 111             return DropTargetContextWrapper.this.getTransferable();
 112         }
 113 
 114         public boolean isTransferableJVMLocal() {
 115             return DropTargetContextWrapper.this.isTransferableJVMLocal();
 116         }
 117 
 118         public void acceptDrag(int dragAction) {
 119             DropTargetContextWrapper.this.acceptDrag(dragAction);
 120         }
 121 
 122         public void rejectDrag() {
 123             DropTargetContextWrapper.this.rejectDrag();
 124         }
 125 
 126         public void acceptDrop(int dropAction) {
 127             DropTargetContextWrapper.this.acceptDrop(dropAction);
 128         }
 129 
 130         public void rejectDrop() {
 131             DropTargetContextWrapper.this.rejectDrop();
 132         }
 133 
 134         public void dropComplete(boolean success) {
 135             DropTargetContextWrapper.this.dropComplete(success);
 136         }
 137     }  
 138 }