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.Cursor;
  29 import java.awt.Image;
  30 import java.awt.Point;
  31 import java.awt.dnd.DragGestureEvent;
  32 import java.awt.dnd.DragSourceContext;
  33 import java.awt.dnd.InvalidDnDOperationException;
  34 import java.awt.dnd.peer.DragSourceContextPeer;
  35 import java.awt.datatransfer.Transferable;
  36 import java.awt.datatransfer.DataFlavor;
  37 import java.util.Map;
  38 import sun.awt.dnd.SunDragSourceContextPeer;
  39 
  40 /**
  41  * This class provides a wrapper over inner DragSourceContextPeerProxy class
  42  * which extends jdk internal sun.awt.dnd.SunDragSourceContextPeer class
  43  * and provides APIs to be used by FX swing interop to access and use 
  44  * DragSourceContextPeer APIs.
  45  */
  46 public class DragSourceContextWrapper {
  47     private DragSourceContextPeerProxy dsp;
  48 
  49     public DragSourceContextWrapper(DragGestureEvent e) {
  50         dsp = new DragSourceContextPeerProxy(e);
  51     }
  52 
  53     DragSourceContextPeer getPeer() {
  54         return dsp;
  55     }
  56 
  57     public static int convertModifiersToDropAction(int modifiers, 
  58                                                    int supportedActions) {
  59         return DragSourceContextPeerProxy.
  60                 convertModifiersToDropAction(modifiers, supportedActions);
  61     }
  62 
  63     protected void setNativeCursor(long nativeCtxt, Cursor c, int cType) {}
  64 
  65     protected void startDrag(Transferable trans, long[] formats, 
  66                              Map<Long, DataFlavor> formatMap) {}
  67 
  68     public void startSecondaryEventLoop() {}
  69 
  70     public void quitSecondaryEventLoop() {}
  71 
  72     public void dragDropFinished(final boolean success,
  73                                  final int operations,
  74                                  final int x, final int y) {
  75         dsp.dragDropFinishedCall(success, operations, x, y);
  76     }
  77 
  78     public DragSourceContext getDragSourceContext() {
  79         return dsp.getDragSourceContextCall();
  80     }
  81 
  82     private class DragSourceContextPeerProxy extends SunDragSourceContextPeer {
  83 
  84         public DragSourceContextPeerProxy(DragGestureEvent e) {
  85             super(e);
  86         }
  87 
  88         protected void startDrag(Transferable trans, long[] formats, 
  89                              Map<Long, DataFlavor> formatMap) {
  90             DragSourceContextWrapper.this.startDrag(trans, formats, formatMap);
  91         }
  92 
  93         protected void setNativeCursor(long nativeCtxt, Cursor c, int cType) {
  94             DragSourceContextWrapper.this.setNativeCursor(nativeCtxt, c, cType);
  95         }
  96 
  97         public void startSecondaryEventLoop(){
  98             DragSourceContextWrapper.this.startSecondaryEventLoop();
  99         }
 100 
 101         public void quitSecondaryEventLoop(){
 102             DragSourceContextWrapper.this.quitSecondaryEventLoop();
 103         }
 104 
 105         protected void dragDropFinishedCall(final boolean success,
 106                                  final int operations,
 107                                  final int x, final int y) {
 108             dragDropFinished(success, operations, x, y);
 109         }
 110 
 111         protected DragSourceContext getDragSourceContextCall() {
 112             return getDragSourceContext();
 113         } 
 114     }
 115 }