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