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

Print this page

        

@@ -205,33 +205,27 @@
 
     public synchronized void setComponent(Component c) {
         if (component == c || component != null && component.equals(c))
             return;
 
-        Component     old;
-        ComponentPeer oldPeer = null;
+        final Component old = component;
 
-        if ((old = component) != null) {
+        if (old  != null) {
             clearAutoscroll();
 
             component = null;
-
-            if (componentPeer != null) {
-                oldPeer = componentPeer;
-                removeNotify(componentPeer);
-            }
-
+            removeNotify();
             old.setDropTarget(null);
 
         }
 
         if ((component = c) != null) try {
             c.setDropTarget(this);
         } catch (Exception e) { // undo the change
             if (old != null) {
                 old.setDropTarget(this);
-                addNotify(oldPeer);
+                addNotify();
             }
         }
     }
 
     /**

@@ -495,28 +489,28 @@
      *
      * Calling this method, other than to notify this DropTarget of the
      * association of the ComponentPeer with the Component may result in
      * a malfunction of the DnD system.
      **********************************************************************
-     *
-     * @param peer The Peer of the Component we are associated with!
-     *
      */
-
-    public void addNotify(ComponentPeer peer) {
-        if (peer == componentPeer) return;
+    public void addNotify() {
+        final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
+        ComponentPeer peer = acc.getPeer(component);
+        if (peer == null || peer == componentPeer) {
+            return;
+        }
 
         componentPeer = peer;
-        final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
+
 
         for (Component c = component;
              c != null && peer instanceof LightweightPeer; c = c.getParent()) {
             peer = acc.getPeer(c);
         }
 
         if (peer instanceof DropTargetPeer) {
-            nativePeer = peer;
+            nativePeer = (DropTargetPeer) peer;
             ((DropTargetPeer)peer).addDropTarget(this);
         } else {
             nativePeer = null;
         }
     }

@@ -531,19 +525,18 @@
      *
      * Calling this method, other than to notify this DropTarget of the
      * disassociation of the ComponentPeer from the Component may result in
      * a malfunction of the DnD system.
      **********************************************************************
-     *
-     * @param peer The Peer of the Component we are being disassociated from!
      */
 
-    public void removeNotify(ComponentPeer peer) {
-        if (nativePeer != null)
-            ((DropTargetPeer)nativePeer).removeDropTarget(this);
-
-        componentPeer = nativePeer = null;
+    public void removeNotify() {
+        if (nativePeer != null) {
+            nativePeer.removeDropTarget(this);
+        }
+        componentPeer = null;
+        nativePeer = null;
 
         synchronized (this) {
             if (isDraggingInside) {
                 dragExit(new DropTargetEvent(getDropTargetContext()));
             }

@@ -835,11 +828,11 @@
     private transient ComponentPeer componentPeer;
 
     /*
      * That Component's "native" Peer
      */
-    private transient ComponentPeer nativePeer;
+    private transient DropTargetPeer nativePeer;
 
 
     /**
      * Default permissible actions supported by this DropTarget.
      *