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

Print this page

        

@@ -349,10 +349,12 @@
      *         is active and <code>dtde</code> is <code>null</code>
      *
      * @see #isActive
      */
     public synchronized void dragEnter(DropTargetDragEvent dtde) {
+        isDraggingInside = true;
+
         if (!active) return;
 
         if (dtListener != null) {
             dtListener.dragEnter(dtde);
         } else

@@ -419,10 +421,12 @@
      * @param dte the <code>DropTargetEvent</code>
      *
      * @see #isActive
      */
     public synchronized void dragExit(DropTargetEvent dte) {
+        isDraggingInside = false;
+
         if (!active) return;
 
         if (dtListener != null && active) dtListener.dragExit(dte);
 
         clearAutoscroll();

@@ -442,10 +446,12 @@
      *         no a <code>DropTargetListener</code> registered.
      *
      * @see #isActive
      */
     public synchronized void drop(DropTargetDropEvent dtde) {
+        isDraggingInside = false;
+
         clearAutoscroll();
 
         if (dtListener != null && active)
             dtListener.drop(dtde);
         else { // we should'nt get here ...

@@ -530,10 +536,14 @@
 
     public void removeNotify(ComponentPeer peer) {
         if (nativePeer != null)
             ((DropTargetPeer)nativePeer).removeDropTarget(this);
 
+        if (isDraggingInside) {
+            dragExit(new DropTargetEvent(getDropTargetContext()));
+        }
+
         componentPeer = nativePeer = null;
     }
 
     /**
      * Gets the <code>DropTargetContext</code> associated

@@ -853,6 +863,11 @@
     /*
      * The FlavorMap
      */
 
     private transient FlavorMap flavorMap;
+
+    /*
+     * If the dragging is currently inside this drop target
+     */
+    private transient boolean isDraggingInside;
 }