< prev index next >
modules/javafx.swing/src/main/java/javafx/embed/swing/FXDnD.java
Print this page
@@ -42,12 +42,10 @@
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.dnd.InvalidDnDOperationException;
import java.awt.dnd.MouseDragGestureRecognizer;
-import java.awt.dnd.peer.DragSourceContextPeer;
-import java.awt.dnd.peer.DropTargetContextPeer;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
import javafx.application.Platform;
@@ -56,14 +54,15 @@
import javafx.scene.input.DataFormat;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
-import sun.awt.AWTAccessor;
-import sun.awt.dnd.SunDragSourceContextPeer;
-import sun.swing.JLightweightFrame;
+import jdk.swing.interop.LightweightFrameWrapper;
+import jdk.swing.interop.SwingInterOpUtils;
+import jdk.swing.interop.DragSourceContextWrapper;
+import jdk.swing.interop.DropTargetContextWrapper;
/**
* A utility class to connect DnD mechanism of Swing and FX.
* It allows Swing content to use the FX machinery for performing DnD.
*/
@@ -97,13 +96,12 @@
private ComponentMapper(Map<Component, T> map, int xArg, int yArg) {
this.x = xArg;
this.y = yArg;
- final JLightweightFrame lwFrame = node.getLightweightFrame();
- Component c = AWTAccessor.getContainerAccessor().findComponentAt(
- lwFrame, x, y, false);
+ final LightweightFrameWrapper lwFrame = node.getLightweightFrame();
+ Component c = lwFrame.findComponentAt(lwFrame, x, y, false);
if (c == null) return;
synchronized (c.getTreeLock()) {
do {
object = map.get(c);
@@ -112,11 +110,11 @@
if (object != null) {
// The object is either a DropTarget or a DragSource, so:
//assert c == object.getComponent();
// Translate x, y from lwFrame to component coordinates
- while (c != lwFrame && c != null) {
+ while ((lwFrame.isCompEqual(c,lwFrame)) && c != null) {
x -= c.getX();
y -= c.getY();
c = c.getParent();
}
}
@@ -195,11 +193,11 @@
appendEvent(new java.awt.event.MouseEvent(getComponent(), java.awt.event.MouseEvent.MOUSE_PRESSED,
evTime, modifiers, x, y, 0, false));
// Also, the modifiers here should've actually come from the last known mouse event (last MOVE or DRAG).
// But we're OK with using the initial PRESS modifiers for now
- int initialAction = SunDragSourceContextPeer.convertModifiersToDropAction(
+ int initialAction = DragSourceContextWrapper.convertModifiersToDropAction(
modifiers, getSourceActions());
fireDragGestureRecognized(initialAction, new java.awt.Point(x, y));
}
}
@@ -279,11 +277,11 @@
(int)event.getX(), (int)event.getY());
}
};
- private final class FXDragSourceContextPeer extends SunDragSourceContextPeer {
+ private final class FXDragSourceContextPeer extends DragSourceContextWrapper {
private volatile int sourceActions = 0;
private final CachingTransferable transferable = new CachingTransferable();
@Override public void startSecondaryEventLoop(){
@@ -335,19 +333,21 @@
}
}
}
};
+ //@Override
public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
Class<T> abstractRecognizerClass,
DragSource ds, Component c, int srcActions,
DragGestureListener dgl)
{
return (T) new FXDragGestureRecognizer(ds, c, srcActions, dgl);
}
- public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException
+ //@Override
+ public DragSourceContextWrapper createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException
{
return new FXDragSourceContextPeer(dge);
}
@@ -416,11 +416,11 @@
}
activeDTContextPeer = null;
};
- private final class FXDropTargetContextPeer implements DropTargetContextPeer {
+ private final class FXDropTargetContextPeer extends DropTargetContextWrapper {
private int targetActions = DnDConstants.ACTION_NONE;
private int currentAction = DnDConstants.ACTION_NONE;
private DropTarget dt = null;
private DropTargetContext ctx = null;
@@ -467,22 +467,22 @@
DropTarget target = mapper.object != null ? mapper.object : dt;
SwingFXUtils.runOnEDTAndWait(FXDnD.this, () -> {
if (target != dt) {
if (ctx != null) {
- AWTAccessor.getDropTargetContextAccessor().reset(ctx);
+ DropTargetContextWrapper.reset(ctx);
}
ctx = null;
currentAction = dropAction = DnDConstants.ACTION_NONE;
}
if (target != null) {
if (ctx == null) {
ctx = target.getDropTargetContext();
- AWTAccessor.getDropTargetContextAccessor()
- .setDropTargetContextPeer(ctx, FXDropTargetContextPeer.this);
+ DropTargetContextWrapper.setDropTargetContextPeer(ctx,
+ new FXDropTargetContextPeer());
}
DropTargetListener dtl = (DropTargetListener)target;
if (DragEvent.DRAG_DROPPED.equals(fxEvType)) {
< prev index next >