use of java.awt.dnd.DropTargetListener in project android by JetBrains.
the class LayoutTestUtilities method dragDrop.
public static void dragDrop(InteractionManager manager, int x1, int y1, int x2, int y2, Transferable transferable) {
Object listener = manager.getListener();
assertTrue(listener instanceof DropTargetListener);
DropTargetListener dropListener = (DropTargetListener) listener;
int frames = 5;
double x = x1;
double y = y1;
double xSlope = (x2 - x) / frames;
double ySlope = (y2 - y) / frames;
DropTargetContext context = createDropTargetContext();
dropListener.dragEnter(new DropTargetDragEventBuilder(context, (int) x, (int) y, transferable).build());
for (int i = 0; i < frames + 1; i++) {
dropListener.dragOver(new DropTargetDragEventBuilder(context, (int) x, (int) y, transferable).build());
x += xSlope;
y += ySlope;
}
DropTargetDropEvent dropEvent = new DropTargetDropEventBuilder(context, (int) x, (int) y, transferable).build();
dropListener.drop(dropEvent);
verify(dropEvent, times(1)).acceptDrop(anyInt());
verify(dropEvent, times(1)).dropComplete(true);
}
use of java.awt.dnd.DropTargetListener in project jdk8u_jdk by JetBrains.
the class SunDropTargetContextPeer method processEnterMessage.
/**
* actual processing on EventQueue Thread
*/
protected void processEnterMessage(SunDropTargetEvent event) {
Component c = (Component) event.getSource();
DropTarget dt = c.getDropTarget();
Point hots = event.getPoint();
local = getJVMLocalSourceTransferable();
if (currentDTC != null) {
// some wreckage from last time
currentDTC.removeNotify();
currentDTC = null;
}
if (c.isShowing() && dt != null && dt.isActive()) {
currentDT = dt;
currentDTC = currentDT.getDropTargetContext();
currentDTC.addNotify(this);
currentA = dt.getDefaultActions();
try {
((DropTargetListener) dt).dragEnter(new DropTargetDragEvent(currentDTC, hots, currentDA, currentSA));
} catch (Exception e) {
e.printStackTrace();
currentDA = DnDConstants.ACTION_NONE;
}
} else {
currentDT = null;
currentDTC = null;
currentDA = DnDConstants.ACTION_NONE;
currentSA = DnDConstants.ACTION_NONE;
currentA = DnDConstants.ACTION_NONE;
}
}
use of java.awt.dnd.DropTargetListener in project jdk8u_jdk by JetBrains.
the class SunDropTargetContextPeer method processMotionMessage.
/**
*
*/
protected void processMotionMessage(SunDropTargetEvent event, boolean operationChanged) {
Component c = (Component) event.getSource();
Point hots = event.getPoint();
int id = event.getID();
DropTarget dt = c.getDropTarget();
DropTargetContext dtc = null;
if (c.isShowing() && (dt != null) && dt.isActive()) {
if (currentDT != dt) {
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDT = dt;
currentDTC = null;
}
dtc = currentDT.getDropTargetContext();
if (dtc != currentDTC) {
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDTC = dtc;
currentDTC.addNotify(this);
}
currentA = currentDT.getDefaultActions();
try {
DropTargetDragEvent dtde = new DropTargetDragEvent(dtc, hots, currentDA, currentSA);
DropTargetListener dtl = (DropTargetListener) dt;
if (operationChanged) {
dtl.dropActionChanged(dtde);
} else {
dtl.dragOver(dtde);
}
if (dragRejected) {
currentDA = DnDConstants.ACTION_NONE;
}
} catch (Exception e) {
e.printStackTrace();
currentDA = DnDConstants.ACTION_NONE;
}
} else {
currentDA = DnDConstants.ACTION_NONE;
}
}
use of java.awt.dnd.DropTargetListener in project jdk8u_jdk by JetBrains.
the class SunDropTargetContextPeer method processDropMessage.
/**
*
*/
protected void processDropMessage(SunDropTargetEvent event) {
Component c = (Component) event.getSource();
Point hots = event.getPoint();
DropTarget dt = c.getDropTarget();
// drop pending ACK
dropStatus = STATUS_WAIT;
dropComplete = false;
if (c.isShowing() && dt != null && dt.isActive()) {
DropTargetContext dtc = dt.getDropTargetContext();
currentDT = dt;
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDTC = dtc;
currentDTC.addNotify(this);
currentA = dt.getDefaultActions();
synchronized (_globalLock) {
if ((local = getJVMLocalSourceTransferable()) != null)
setCurrentJVMLocalSourceTransferable(null);
}
dropInProcess = true;
try {
((DropTargetListener) dt).drop(new DropTargetDropEvent(dtc, hots, currentDA, currentSA, local != null));
} finally {
if (dropStatus == STATUS_WAIT) {
rejectDrop();
} else if (dropComplete == false) {
dropComplete(false);
}
dropInProcess = false;
}
} else {
rejectDrop();
}
}
Aggregations