8049065: [JLightweightFrame] Support DnD for SwingNode
authoranthony
Tue, 12 Aug 2014 14:22:05 +0400
changeset 26342 3637212ae8f2
parent 26341 dff08260db73
child 26343 cf09debe8a4b
8049065: [JLightweightFrame] Support DnD for SwingNode Summary: Delegate DnD operations to LightweightContent when appropriate Reviewed-by: ant, pchelko
jdk/src/macosx/classes/sun/lwawt/LWLightweightFramePeer.java
jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
jdk/src/share/classes/sun/awt/LightweightFrame.java
jdk/src/share/classes/sun/awt/SunToolkit.java
jdk/src/share/classes/sun/swing/JLightweightFrame.java
jdk/src/share/classes/sun/swing/LightweightContent.java
jdk/src/solaris/classes/sun/awt/X11/XLightweightFramePeer.java
jdk/src/solaris/classes/sun/awt/X11/XToolkit.java
jdk/src/windows/classes/sun/awt/windows/WLightweightFramePeer.java
jdk/src/windows/classes/sun/awt/windows/WToolkit.java
--- a/jdk/src/macosx/classes/sun/lwawt/LWLightweightFramePeer.java	Mon Aug 11 10:42:51 2014 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWLightweightFramePeer.java	Tue Aug 12 14:22:05 2014 +0400
@@ -94,10 +94,12 @@
 
     @Override
     public void addDropTarget(DropTarget dt) {
+        getLwTarget().addDropTarget(dt);
     }
 
     @Override
     public void removeDropTarget(DropTarget dt) {
+        getLwTarget().removeDropTarget(dt);
     }
 
     @Override
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Mon Aug 11 10:42:51 2014 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Tue Aug 12 14:22:05 2014 +0400
@@ -688,6 +688,11 @@
     @Override
     public DragSourceContextPeer createDragSourceContextPeer(
             DragGestureEvent dge) throws InvalidDnDOperationException {
+        final LightweightFrame f = SunToolkit.getLightweightFrame(dge.getComponent());
+        if (f != null) {
+            return f.createDragSourceContextPeer(dge);
+        }
+
         return CDragSourceContextPeer.createDragSourceContextPeer(dge);
     }
 
@@ -696,6 +701,11 @@
     public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
             Class<T> abstractRecognizerClass, DragSource ds, Component c,
             int srcActions, DragGestureListener dgl) {
+        final LightweightFrame f = SunToolkit.getLightweightFrame(c);
+        if (f != null) {
+            return f.createDragGestureRecognizer(abstractRecognizerClass, ds, c, srcActions, dgl);
+        }
+
         DragGestureRecognizer dgr = null;
 
         // Create a new mouse drag gesture recognizer if we have a class match:
--- a/jdk/src/share/classes/sun/awt/LightweightFrame.java	Mon Aug 11 10:42:51 2014 +0400
+++ b/jdk/src/share/classes/sun/awt/LightweightFrame.java	Tue Aug 12 14:22:05 2014 +0400
@@ -25,6 +25,7 @@
 
 package sun.awt;
 
+import java.awt.Component;
 import java.awt.Container;
 import java.awt.Frame;
 import java.awt.Graphics;
@@ -33,6 +34,13 @@
 import java.awt.MenuComponent;
 import java.awt.Rectangle;
 import java.awt.Toolkit;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureListener;
+import java.awt.dnd.DragGestureRecognizer;
+import java.awt.dnd.DragSource;
+import java.awt.dnd.DropTarget;
+import java.awt.dnd.InvalidDnDOperationException;
+import java.awt.dnd.peer.DragSourceContextPeer;
 import java.awt.peer.FramePeer;
 
 /**
@@ -169,4 +177,27 @@
         hostW = w;
         hostH = h;
     }
+
+    /**
+     * Create a drag gesture recognizer for the lightweight frame.
+     */
+    public abstract <T extends DragGestureRecognizer> T createDragGestureRecognizer(
+            Class<T> abstractRecognizerClass,
+            DragSource ds, Component c, int srcActions,
+            DragGestureListener dgl);
+
+    /**
+     * Create a drag source context peer for the lightweight frame.
+     */
+    public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException;
+
+    /**
+     * Adds a drop target to the lightweight frame.
+     */
+    public abstract void addDropTarget(DropTarget dt);
+
+    /**
+     * Removes a drop target from the lightweight frame.
+     */
+    public abstract void removeDropTarget(DropTarget dt);
 }
--- a/jdk/src/share/classes/sun/awt/SunToolkit.java	Mon Aug 11 10:42:51 2014 +0400
+++ b/jdk/src/share/classes/sun/awt/SunToolkit.java	Tue Aug 12 14:22:05 2014 +0400
@@ -2014,6 +2014,19 @@
         return isInstanceOf(cls.getSuperclass(), type);
     }
 
+    protected static LightweightFrame getLightweightFrame(Component c) {
+        for (; c != null; c = c.getParent()) {
+            if (c instanceof LightweightFrame) {
+                return (LightweightFrame)c;
+            }
+            if (c instanceof Window) {
+                // Don't traverse owner windows
+                return null;
+            }
+        }
+        return null;
+    }
+
     ///////////////////////////////////////////////////////////////////////////
     //
     // The following methods help set and identify whether a particular
--- a/jdk/src/share/classes/sun/swing/JLightweightFrame.java	Mon Aug 11 10:42:51 2014 +0400
+++ b/jdk/src/share/classes/sun/swing/JLightweightFrame.java	Tue Aug 12 14:22:05 2014 +0400
@@ -37,6 +37,13 @@
 import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.Window;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureListener;
+import java.awt.dnd.DragGestureRecognizer;
+import java.awt.dnd.DragSource;
+import java.awt.dnd.DropTarget;
+import java.awt.dnd.InvalidDnDOperationException;
+import java.awt.dnd.peer.DragSourceContextPeer;
 import java.awt.event.ContainerEvent;
 import java.awt.event.ContainerListener;
 import java.awt.image.BufferedImage;
@@ -472,4 +479,27 @@
             content.setCursor(target.getCursor());
         }
     }
+
+    public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
+            Class<T> abstractRecognizerClass,
+            DragSource ds, Component c, int srcActions,
+            DragGestureListener dgl)
+    {
+        return content == null ? null : content.createDragGestureRecognizer(
+                abstractRecognizerClass, ds, c, srcActions, dgl);
+    }
+
+    public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
+        return content == null ? null : content.createDragSourceContextPeer(dge);
+    }
+
+    public void addDropTarget(DropTarget dt) {
+        if (content == null) return;
+        content.addDropTarget(dt);
+    }
+
+    public void removeDropTarget(DropTarget dt) {
+        if (content == null) return;
+        content.removeDropTarget(dt);
+    }
 }
--- a/jdk/src/share/classes/sun/swing/LightweightContent.java	Mon Aug 11 10:42:51 2014 +0400
+++ b/jdk/src/share/classes/sun/swing/LightweightContent.java	Tue Aug 12 14:22:05 2014 +0400
@@ -26,7 +26,15 @@
 package sun.swing;
 
 import javax.swing.JComponent;
+import java.awt.Component;
 import java.awt.Cursor;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureListener;
+import java.awt.dnd.DragGestureRecognizer;
+import java.awt.dnd.DragSource;
+import java.awt.dnd.DropTarget;
+import java.awt.dnd.InvalidDnDOperationException;
+import java.awt.dnd.peer.DragSourceContextPeer;
 
 /**
  * The interface by means of which the {@link JLightweightFrame} class
@@ -209,4 +217,33 @@
      * @param cursor a cursor to set
      */
     default public void setCursor(Cursor cursor) { }
+
+    /**
+     * Create a drag gesture recognizer for the lightweight frame.
+     */
+    default public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
+            Class<T> abstractRecognizerClass,
+            DragSource ds, Component c, int srcActions,
+            DragGestureListener dgl)
+    {
+        return null;
+    }
+
+    /**
+     * Create a drag source context peer for the lightweight frame.
+     */
+    default public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException
+    {
+        return null;
+    }
+
+    /**
+     * Adds a drop target to the lightweight frame.
+     */
+    default public void addDropTarget(DropTarget dt) {}
+
+    /**
+     * Removes a drop target from the lightweight frame.
+     */
+    default public void removeDropTarget(DropTarget dt) {}
 }
--- a/jdk/src/solaris/classes/sun/awt/X11/XLightweightFramePeer.java	Mon Aug 11 10:42:51 2014 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XLightweightFramePeer.java	Tue Aug 12 14:22:05 2014 +0400
@@ -26,6 +26,7 @@
 package sun.awt.X11;
 
 import java.awt.Graphics;
+import java.awt.dnd.DropTarget;
 
 import sun.awt.LightweightFrame;
 import sun.swing.JLightweightFrame;
@@ -69,4 +70,14 @@
     public void updateCursorImmediately() {
         SwingAccessor.getJLightweightFrameAccessor().updateCursor((JLightweightFrame)getLwTarget());
     }
+
+    @Override
+    public void addDropTarget(DropTarget dt) {
+        getLwTarget().addDropTarget(dt);
+    }
+
+    @Override
+    public void removeDropTarget(DropTarget dt) {
+        getLwTarget().removeDropTarget(dt);
+    }
 }
--- a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java	Mon Aug 11 10:42:51 2014 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java	Tue Aug 12 14:22:05 2014 +0400
@@ -927,6 +927,11 @@
     }
 
     public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
+        final LightweightFrame f = SunToolkit.getLightweightFrame(dge.getComponent());
+        if (f != null) {
+            return f.createDragSourceContextPeer(dge);
+        }
+
         return XDragSourceContextPeer.createDragSourceContextPeer(dge);
     }
 
@@ -938,6 +943,11 @@
                     int srcActions,
                     DragGestureListener dgl)
     {
+        final LightweightFrame f = SunToolkit.getLightweightFrame(c);
+        if (f != null) {
+            return f.createDragGestureRecognizer(recognizerClass, ds, c, srcActions, dgl);
+        }
+
         if (MouseDragGestureRecognizer.class.equals(recognizerClass))
             return (T)new XMouseDragGestureRecognizer(ds, c, srcActions, dgl);
         else
--- a/jdk/src/windows/classes/sun/awt/windows/WLightweightFramePeer.java	Mon Aug 11 10:42:51 2014 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WLightweightFramePeer.java	Tue Aug 12 14:22:05 2014 +0400
@@ -27,6 +27,7 @@
 
 import java.awt.Component;
 import java.awt.Graphics;
+import java.awt.dnd.DropTarget;
 import java.awt.event.ComponentEvent;
 import java.awt.event.MouseEvent;
 
@@ -94,4 +95,14 @@
     public boolean isLightweightFramePeer() {
         return true;
     }
+
+    @Override
+    public void addDropTarget(DropTarget dt) {
+        getLwTarget().addDropTarget(dt);
+    }
+
+    @Override
+    public void removeDropTarget(DropTarget dt) {
+        getLwTarget().removeDropTarget(dt);
+    }
 }
--- a/jdk/src/windows/classes/sun/awt/windows/WToolkit.java	Mon Aug 11 10:42:51 2014 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WToolkit.java	Tue Aug 12 14:22:05 2014 +0400
@@ -844,6 +844,11 @@
 
     @Override
     public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
+        final LightweightFrame f = SunToolkit.getLightweightFrame(dge.getComponent());
+        if (f != null) {
+            return f.createDragSourceContextPeer(dge);
+        }
+
         return WDragSourceContextPeer.createDragSourceContextPeer(dge);
     }
 
@@ -854,6 +859,11 @@
                                     DragSource ds, Component c, int srcActions,
                                     DragGestureListener dgl)
     {
+        final LightweightFrame f = SunToolkit.getLightweightFrame(c);
+        if (f != null) {
+            return f.createDragGestureRecognizer(abstractRecognizerClass, ds, c, srcActions, dgl);
+        }
+
         if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass))
             return (T)new WMouseDragGestureRecognizer(ds, c, srcActions, dgl);
         else