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 abstract class DropTargetContextWrapper { 44 45 private DropTargetContextPeerProxy dcp; 46 public DropTargetContextWrapper() { 47 dcp = new DropTargetContextPeerProxy(); 48 } 49 50 public void setDropTargetContext(DropTargetContext dtc, 51 DropTargetContextWrapper dtcpw) { 52 AWTAccessor.getDropTargetContextAccessor(). 53 setDropTargetContextPeer(dtc, dtcpw.dcp); 54 } 55 56 public void reset(DropTargetContext dtc) { 57 AWTAccessor.getDropTargetContextAccessor().reset(dtc); 58 } 59 60 public abstract void setTargetActions(int actions); 61 62 public abstract int getTargetActions(); 63 64 public abstract DropTarget getDropTarget(); 65 66 public abstract DataFlavor[] getTransferDataFlavors(); 67 68 public abstract Transferable getTransferable() throws InvalidDnDOperationException; 69 70 public abstract boolean isTransferableJVMLocal(); 71 72 public abstract void acceptDrag(int dragAction); 73 74 public abstract void rejectDrag(); 75 76 public abstract void acceptDrop(int dropAction); 77 78 public abstract void rejectDrop(); 79 80 public abstract void dropComplete(boolean success); 81 82 private class DropTargetContextPeerProxy implements DropTargetContextPeer { 83 84 public void setTargetActions(int actions) { 85 DropTargetContextWrapper.this.setTargetActions(actions); 86 } 87 88 public int getTargetActions() { 89 return DropTargetContextWrapper.this.getTargetActions(); 90 } 91 92 public DropTarget getDropTarget() { 93 return DropTargetContextWrapper.this.getDropTarget(); 94 } 95 96 public DataFlavor[] getTransferDataFlavors() { 97 return DropTargetContextWrapper.this.getTransferDataFlavors(); 98 } 99 100 public Transferable getTransferable() throws InvalidDnDOperationException { 101 return DropTargetContextWrapper.this.getTransferable(); 102 } 103 104 public boolean isTransferableJVMLocal() { 105 return DropTargetContextWrapper.this.isTransferableJVMLocal(); 106 } 107 108 public void acceptDrag(int dragAction) { 109 DropTargetContextWrapper.this.acceptDrag(dragAction); 110 } 111 112 public void rejectDrag() { 113 DropTargetContextWrapper.this.rejectDrag(); 114 } 115 116 public void acceptDrop(int dropAction) { 117 DropTargetContextWrapper.this.acceptDrop(dropAction); 118 } 119 120 public void rejectDrop() { 121 DropTargetContextWrapper.this.rejectDrop(); 122 } 123 124 public void dropComplete(boolean success) { 125 DropTargetContextWrapper.this.dropComplete(success); 126 } 127 } 128 }