src/java.desktop/share/classes/java/awt/dnd/DragSource.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -33,17 +33,19 @@
 import java.awt.Point;
 import java.awt.Toolkit;
 import java.awt.datatransfer.FlavorMap;
 import java.awt.datatransfer.SystemFlavorMap;
 import java.awt.datatransfer.Transferable;
-import java.awt.dnd.peer.DragSourceContextPeer;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.security.AccessController;
 import java.util.EventListener;
+
+import sun.awt.AWTAccessor;
+import sun.awt.AWTAccessor.DragSourceContextAccessor;
 import sun.awt.dnd.SunDragSourceContextPeer;
 import sun.security.action.GetIntegerAction;
 
 
 /**

@@ -301,26 +303,20 @@
         SunDragSourceContextPeer.setDragDropInProgress(true);
 
         try {
             if (flavorMap != null) this.flavorMap = flavorMap;
 
-            DragSourceContextPeer dscp = Toolkit.getDefaultToolkit().createDragSourceContextPeer(trigger);
-
-            DragSourceContext     dsc = createDragSourceContext(dscp,
-                                                                trigger,
-                                                                dragCursor,
+            DragSourceContext dsc = createDragSourceContext(trigger, dragCursor,
                                                                 dragImage,
                                                                 imageOffset,
-                                                                transferable,
-                                                                dsl
-                                                                );
+                                                            transferable, dsl);
 
             if (dsc == null) {
                 throw new InvalidDnDOperationException();
             }
-
-            dscp.startDrag(dsc, dsc.getCursor(), dragImage, imageOffset); // may throw
+            DragSourceContextAccessor acc = AWTAccessor.getDragSourceContextAccessor();
+            acc.getPeer(dsc).startDrag(dsc, dsc.getCursor(), dragImage, imageOffset); // may throw
         } catch (RuntimeException e) {
             SunDragSourceContextPeer.setDragDropInProgress(false);
             throw e;
         }
     }

@@ -440,11 +436,10 @@
      * <p>
      * If <code>dsl</code> is <code>null</code>, no drag source listener
      * is registered with the created <code>DragSourceContext</code>,
      * but <code>NullPointerException</code> is not thrown.
      *
-     * @param dscp          The <code>DragSourceContextPeer</code> for this drag
      * @param dgl           The <code>DragGestureEvent</code> that triggered the
      *                      drag
      * @param dragCursor     The initial {@code Cursor} for this drag operation
      *                       or {@code null} for the default cursor handling;
      *                       see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a> class

@@ -471,12 +466,17 @@
      * @throws IllegalArgumentException if the source actions for the
      *         <code>DragGestureRecognizer</code> associated with the trigger
      *         event are equal to <code>DnDConstants.ACTION_NONE</code>.
      */
 
-    protected DragSourceContext createDragSourceContext(DragSourceContextPeer dscp, DragGestureEvent dgl, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable t, DragSourceListener dsl) {
-        return new DragSourceContext(dscp, dgl, dragCursor, dragImage, imageOffset, t, dsl);
+    protected DragSourceContext createDragSourceContext(DragGestureEvent dgl,
+                                                        Cursor dragCursor,
+                                                        Image dragImage,
+                                                        Point imageOffset,
+                                                        Transferable t,
+                                                        DragSourceListener dsl) {
+        return new DragSourceContext(dgl, dragCursor, dragImage, imageOffset, t, dsl);
     }
 
     /**
      * This method returns the
      * <code>FlavorMap</code> for this <code>DragSource</code>.