8049065: [JLightweightFrame] Support DnD for SwingNode
Delegate DnD operations to LightweightContent when appropriate Reviewed-by: ant, pchelko
This commit is contained in:
parent
a3cf5e1850
commit
2d67061cd9
@ -94,10 +94,12 @@ public class LWLightweightFramePeer extends LWWindowPeer {
|
||||
|
||||
@Override
|
||||
public void addDropTarget(DropTarget dt) {
|
||||
getLwTarget().addDropTarget(dt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDropTarget(DropTarget dt) {
|
||||
getLwTarget().removeDropTarget(dt);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -688,6 +688,11 @@ public final class LWCToolkit extends LWToolkit {
|
||||
@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 final class LWCToolkit extends LWToolkit {
|
||||
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:
|
||||
|
@ -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.MenuBar;
|
||||
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 @@ public abstract class LightweightFrame extends Frame {
|
||||
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);
|
||||
}
|
||||
|
@ -2014,6 +2014,19 @@ public abstract class SunToolkit extends Toolkit
|
||||
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
|
||||
|
@ -37,6 +37,13 @@ import java.awt.MouseInfo;
|
||||
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 @@ public final class JLightweightFrame extends LightweightFrame implements RootPan
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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 @@ public interface LightweightContent {
|
||||
* @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) {}
|
||||
}
|
||||
|
@ -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 class XLightweightFramePeer extends XFramePeer {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -927,6 +927,11 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
|
||||
}
|
||||
|
||||
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 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
|
||||
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
|
||||
|
@ -27,6 +27,7 @@ package sun.awt.windows;
|
||||
|
||||
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 class WLightweightFramePeer extends WFramePeer {
|
||||
public boolean isLightweightFramePeer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDropTarget(DropTarget dt) {
|
||||
getLwTarget().addDropTarget(dt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDropTarget(DropTarget dt) {
|
||||
getLwTarget().removeDropTarget(dt);
|
||||
}
|
||||
}
|
||||
|
@ -844,6 +844,11 @@ public final class WToolkit extends SunToolkit implements Runnable {
|
||||
|
||||
@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 @@ public final class WToolkit extends SunToolkit implements Runnable {
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user