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

Print this page

        

@@ -27,25 +27,24 @@
 
 import java.awt.Component;
 import java.awt.Cursor;
 import java.awt.Image;
 import java.awt.Point;
-
+import java.awt.Toolkit;
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
 import java.awt.datatransfer.UnsupportedFlavorException;
-
 import java.awt.dnd.peer.DragSourceContextPeer;
-
 import java.io.IOException;
 import java.io.InvalidObjectException;
-import java.io.ObjectOutputStream;
 import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.io.Serializable;
-
 import java.util.TooManyListenersException;
 
+import sun.awt.AWTAccessor;
+
 /**
  * The <code>DragSourceContext</code> class is responsible for managing the
  * initiator side of the Drag and Drop protocol. In particular, it is responsible
  * for managing drag event notifications to the
  * {@linkplain DragSourceListener DragSourceListeners}

@@ -121,10 +120,14 @@
      * indicating that the user operation has changed.
      */
 
     protected static final int CHANGED = 3;
 
+    static {
+        AWTAccessor.setDragSourceContextAccessor(dsc -> dsc.peer);
+    }
+
     /**
      * Called from <code>DragSource</code>, this constructor creates a new
      * <code>DragSourceContext</code> given the
      * <code>DragSourceContextPeer</code> for this Drag, the
      * <code>DragGestureEvent</code> that triggered the Drag, the initial

@@ -153,11 +156,10 @@
      * <code>NullPointerException</code> is thrown.
      * <br>
      * If <code>DragSourceListener</code> is <code>null</code> no exception
      * is thrown.
      *
-     * @param dscp       the <code>DragSourceContextPeer</code> for this drag
      * @param trigger    the triggering event
      * @param dragCursor     the initial {@code Cursor} for this drag operation
      *                       or {@code null} for the default cursor handling;
      *                       see <a href="DragSourceContext.html#defaultCursor">class level documentation</a>
      *                       for more details on the cursor handling mechanism during drag and drop

@@ -177,14 +179,16 @@
      *         <code>DragGestureRecognizer</code> associated with the trigger
      *         event are equal to <code>DnDConstants.ACTION_NONE</code>.
      * @throws NullPointerException if dscp, trigger, or t are null, or
      *         if dragImage is non-null and offset is null
      */
-    public DragSourceContext(DragSourceContextPeer dscp,
-                             DragGestureEvent trigger, Cursor dragCursor,
+    public DragSourceContext(DragGestureEvent trigger, Cursor dragCursor,
                              Image dragImage, Point offset, Transferable t,
                              DragSourceListener dsl) {
+        DragSourceContextPeer dscp = Toolkit.getDefaultToolkit()
+                .createDragSourceContextPeer(trigger);
+
         if (dscp == null) {
             throw new NullPointerException("DragSourceContextPeer");
         }
 
         if (trigger == null) {

@@ -621,12 +625,11 @@
     private static Transferable emptyTransferable;
 
     /*
      * fields
      */
-
-    private transient DragSourceContextPeer peer;
+    private final transient DragSourceContextPeer peer;
 
     /**
      * The event which triggered the start of the drag.
      *
      * @serial