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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2004, 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

@@ -37,10 +37,12 @@
 import java.io.Serializable;
 
 import java.util.Arrays;
 import java.util.List;
 
+import sun.awt.AWTAccessor;
+import sun.awt.AWTAccessor.DropTargetContextAccessor;
 
 /**
  * A <code>DropTargetContext</code> is created
  * whenever the logical cursor associated
  * with a Drag and Drop operation coincides with the visible geometry of

@@ -56,10 +58,23 @@
 
 public class DropTargetContext implements Serializable {
 
     private static final long serialVersionUID = -634158968993743371L;
 
+    static {
+        AWTAccessor.setDropTargetContextAccessor(new DropTargetContextAccessor() {
+            @Override
+            public void reset(DropTargetContext dtc) {
+                dtc.reset();
+            }
+            @Override
+            public void setDropTargetContextPeer(DropTargetContext dtc,
+                                                 DropTargetContextPeer dtcp) {
+                dtc.setDropTargetContextPeer(dtcp);
+            }
+        });
+    }
     /**
      * Construct a <code>DropTargetContext</code>
      * given a specified <code>DropTarget</code>.
      *
      * @param dt the DropTarget to associate with

@@ -88,24 +103,13 @@
      */
 
     public Component getComponent() { return dropTarget.getComponent(); }
 
     /**
-     * Called when associated with the <code>DropTargetContextPeer</code>.
-     *
-     * @param dtcp the <code>DropTargetContextPeer</code>
-     */
-
-    public void addNotify(DropTargetContextPeer dtcp) {
-        dropTargetContextPeer = dtcp;
-    }
-
-    /**
      * Called when disassociated with the <code>DropTargetContextPeer</code>.
      */
-
-    public void removeNotify() {
+    void reset() {
         dropTargetContextPeer = null;
         transferable          = null;
     }
 
     /**

@@ -280,16 +284,22 @@
     /**
      * Get the <code>DropTargetContextPeer</code>
      *
      * @return the platform peer
      */
-
     DropTargetContextPeer getDropTargetContextPeer() {
         return dropTargetContextPeer;
     }
 
     /**
+     * Sets the {@code DropTargetContextPeer}
+     */
+    void setDropTargetContextPeer(final DropTargetContextPeer dtcp) {
+        dropTargetContextPeer = dtcp;
+    }
+
+    /**
      * Creates a TransferableProxy to proxy for the specified
      * Transferable.
      *
      * @param t the <tt>Transferable</tt> to be proxied
      * @param local <tt>true</tt> if <tt>t</tt> represents

@@ -410,11 +420,11 @@
     /**
      * The DropTarget associated with this DropTargetContext.
      *
      * @serial
      */
-    private DropTarget dropTarget;
+    private final DropTarget dropTarget;
 
     private transient DropTargetContextPeer dropTargetContextPeer;
 
     private transient Transferable transferable;
 }