use of java.awt.dnd.DropTargetDropEvent in project GCViewer by chewiebug.
the class TestGCModelLoaderController method dropOnDesktopPane.
/**
* Test drag and drop action on GCViewerGui.
*/
@Test
public void dropOnDesktopPane() throws Exception {
// TODO SWINGWORKER: test drag and drop on GCDocument
assertThat("number of gcdocuments before", controller.getGCViewerGui().getDesktopPane().getAllFrames().length, is(0));
List<File> fileList = new ArrayList<File>();
fileList.add(new File(UnittestHelper.getResource(UnittestHelper.FOLDER_OPENJDK, "SampleSun1_6_0G1_MarkStackFull.txt").getPath()));
Transferable tr = Mockito.mock(Transferable.class);
Mockito.when(tr.getTransferData(DataFlavor.javaFileListFlavor)).thenReturn(fileList);
DropTargetDropEvent dte = Mockito.mock(DropTargetDropEvent.class);
Mockito.when(dte.isDataFlavorSupported(DataFlavor.javaFileListFlavor)).thenReturn(true);
Mockito.when(dte.getTransferable()).thenReturn(tr);
DropTarget target = controller.getGCViewerGui().getDesktopPane().getDropTarget();
target.drop(dte);
assertThat("number of gcdocuments after drop", controller.getGCViewerGui().getDesktopPane().getAllFrames().length, is(1));
}
use of java.awt.dnd.DropTargetDropEvent in project jna by java-native-access.
the class DropHandler method getDropAction.
/** Calculate the effective action. The default implementation
* checks whether any {@link DataFlavor}s are supported, and if so,
* will change the current action from {@link DnDConstants#ACTION_NONE} to
* something in common between the source and destination. Refuse
* user-requested actions if they are not supported (rather than silently
* accepting a non-user-requested action, which is the Java's DnD default
* behavior). The drop action is forced to {@link DnDConstants#ACTION_NONE}
* if there is no supported data flavor.
* @param e {@link DropTargetEvent}
* @return effective drop action
* @see #isSupported(DataFlavor[])
* @see #getDropActionsForFlavors
* @see #getDropAction(DropTargetEvent, int, int, int)
* @see #canDrop(DropTargetEvent, int, Point)
*/
protected int getDropAction(DropTargetEvent e) {
int currentAction = DragHandler.NONE;
int sourceActions = DragHandler.NONE;
Point location = null;
DataFlavor[] flavors = new DataFlavor[0];
if (e instanceof DropTargetDragEvent) {
DropTargetDragEvent ev = (DropTargetDragEvent) e;
currentAction = ev.getDropAction();
sourceActions = ev.getSourceActions();
flavors = ev.getCurrentDataFlavors();
location = ev.getLocation();
} else if (e instanceof DropTargetDropEvent) {
DropTargetDropEvent ev = (DropTargetDropEvent) e;
currentAction = ev.getDropAction();
sourceActions = ev.getSourceActions();
flavors = ev.getCurrentDataFlavors();
location = ev.getLocation();
}
if (isSupported(flavors)) {
int availableActions = getDropActionsForFlavors(flavors);
currentAction = getDropAction(e, currentAction, sourceActions, availableActions);
if (currentAction != DragHandler.NONE) {
if (canDrop(e, currentAction, location)) {
return currentAction;
}
}
}
return DragHandler.NONE;
}
use of java.awt.dnd.DropTargetDropEvent in project jdk8u_jdk by JetBrains.
the class ExtraDragEnterTest method initAndShowUI.
private static void initAndShowUI() {
f = new Frame("Test frame");
f.setBounds(FRAME_LOCATION, FRAME_LOCATION, FRAME_SIZE, FRAME_SIZE);
mainPanel = new Panel();
mainPanel.setBounds(0, 0, FRAME_SIZE, FRAME_SIZE);
mainPanel.setBackground(Color.black);
mainPanel.setLayout(new GridLayout(2, 1));
final DraggablePanel dragSource = new DraggablePanel();
dragSource.setBackground(Color.yellow);
dragSource.setDropTarget(null);
mainPanel.add(dragSource);
Panel dropTarget = new Panel();
dropTarget.setBackground(Color.red);
DropTarget dt = new DropTarget(dropTarget, new DropTargetAdapter() {
@Override
public void drop(DropTargetDropEvent dtde) {
}
@Override
public void dragEnter(DropTargetDragEvent dtde) {
dragEnterCalled.incrementAndGet();
}
});
dropTarget.setDropTarget(dt);
mainPanel.add(dropTarget);
f.add(mainPanel);
f.setVisible(true);
}
use of java.awt.dnd.DropTargetDropEvent in project jdk8u_jdk by JetBrains.
the class MissedDragExitTest method initAndShowUI.
private static void initAndShowUI() {
f = new Frame("Test frame");
f.setBounds(FRAME_LOCATION, FRAME_LOCATION, FRAME_SIZE, FRAME_SIZE);
final DraggablePanel dragSource = new DraggablePanel();
dragSource.setBackground(Color.yellow);
DropTarget dt = new DropTarget(dragSource, new DropTargetAdapter() {
@Override
public void drop(DropTargetDropEvent dtde) {
}
@Override
public void dragExit(DropTargetEvent dte) {
dragExitCalled = true;
}
@Override
public void dragOver(DropTargetDragEvent dtde) {
Panel newDropTarget = new Panel();
newDropTarget.setDropTarget(new DropTarget());
newDropTarget.setBackground(Color.red);
newDropTarget.setBounds(0, 0, FRAME_SIZE, FRAME_SIZE);
dragSource.add(newDropTarget);
}
});
dragSource.setDropTarget(dt);
f.add(dragSource);
f.setVisible(true);
}
Aggregations