use of java.awt.dnd.DropTargetDropEvent 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();
}
}
use of java.awt.dnd.DropTargetDropEvent in project android by JetBrains.
the class DropTargetDropEventBuilder method build.
public DropTargetDropEvent build() {
DropTargetDropEvent event = mock(DropTargetDropEvent.class);
when(event.getSource()).thenReturn(mySource);
when(event.getLocation()).thenReturn(new Point(myX, myY));
when(event.getDropTargetContext()).thenReturn(myDropTargetContext);
when(event.getDropAction()).thenReturn(myDropAction);
when(event.getSourceActions()).thenReturn(mySourceActions);
when(event.getTransferable()).thenReturn(myTransferable);
DataFlavor[] flavors = myTransferable.getTransferDataFlavors();
when(event.getCurrentDataFlavors()).thenReturn(flavors);
when(event.getCurrentDataFlavorsAsList()).thenReturn(Arrays.asList(flavors));
return event;
}
use of java.awt.dnd.DropTargetDropEvent 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.DropTargetDropEvent in project jdk8u_jdk by JetBrains.
the class DisposeFrameOnDragTest method constructTestUI.
private static void constructTestUI() {
final JFrame frame = new JFrame("Test frame");
textArea = new JTextArea("Drag Me!");
try {
textArea.getDropTarget().addDropTargetListener(new DropTargetAdapter() {
@Override
public void drop(DropTargetDropEvent dtde) {
//IGNORE
}
@Override
public void dragOver(DropTargetDragEvent dtde) {
frame.dispose();
}
});
} catch (TooManyListenersException ex) {
throw new RuntimeException(ex);
}
textArea.setSize(100, 100);
textArea.setDragEnabled(true);
textArea.select(0, textArea.getText().length());
frame.add(textArea);
frame.setBounds(100, 100, 100, 100);
frame.setVisible(true);
}
use of java.awt.dnd.DropTargetDropEvent in project cayenne by apache.
the class CayenneModelerController method initBindings.
protected void initBindings() {
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
PROJECT_STATE_UTIL.saveLastState(projectController);
getApplication().getActionManager().getAction(ExitAction.class).exit();
}
});
// This is in Mac OSX only.
if (System.getProperty("os.name").startsWith("Mac OS")) {
Runnable runner = new Runnable() {
@Override
public void run() {
PROJECT_STATE_UTIL.saveLastState(projectController);
}
};
Runtime.getRuntime().addShutdownHook(new Thread(runner, "Window Prefs Hook"));
}
new DropTarget(frame, new DropTargetAdapter() {
@Override
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(dtde.getDropAction());
Transferable transferable = dtde.getTransferable();
dtde.dropComplete(processDropAction(transferable));
}
});
ComponentGeometry geometry = new ComponentGeometry(frame.getClass(), null);
geometry.bind(frame, 1200, 720, 0);
}
Aggregations