下面列出了java.awt.dnd.DragSourceDropEvent#getDropSuccess ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* {@inheritDoc}
*/
public void dragDropEnd(DragSourceDropEvent dsde) {
DragSourceContext dsc = dsde.getDragSourceContext();
JComponent c = (JComponent)dsc.getComponent();
if (dsde.getDropSuccess()) {
((DefaultTransferHandler)c.getTransferHandler()).exportDone(c,
dsc.getTransferable(), dsde.getDropAction());
} else {
((DefaultTransferHandler)c.getTransferHandler()).exportDone(c,
null, NONE);
}
c.setAutoscrolls(scrolls);
}
@Override
public void dragDropEnd(DragSourceDropEvent event) {
if (event.getDropSuccess()) {
if (!mDropReceived) {
if ((event.getDropAction() & mAllowedRowDragTypes) == DnDConstants.ACTION_MOVE) {
externalMoveDrop(event.getDragSourceContext().getTransferable());
}
}
}
setSourceDragColumn(null);
}
/**
* as the operation completes
*/
@Override
public void dragDropEnd(DragSourceDropEvent dsde) {
DragSourceContext dsc = dsde.getDragSourceContext();
JComponent c = (JComponent) dsc.getComponent();
if (dsde.getDropSuccess()) {
((AbstractPatchedTransferHandler) c.getTransferHandler()).exportDone(c, dsc.getTransferable(),
dsde.getDropAction());
} else {
((AbstractPatchedTransferHandler) c.getTransferHandler()).exportDone(c, dsc.getTransferable(), NONE);
}
c.setAutoscrolls(scrolls);
fireDragEnded();
}
@Override
public void dragDropEnd(final DragSourceDropEvent dsde) {
if (dsde.getDropSuccess() && (dsde.getDropAction() == DnDConstants.ACTION_MOVE)
&& (draggedNodeParent != null)) {
((DefaultTreeModel) tree.getModel()).nodeStructureChanged(draggedNodeParent);
}
}
public void dragDropEnd(DragSourceDropEvent dsde) {
gestureStarted = false;
if (dsde.getDropSuccess()) {
int row = columnsListBox.getSelectedIndex();
// System.out.println("row = " + row);
CheckListItem item = (CheckListItem) model.getElementAt(row);
// System.out.println("item = " + item.getText());
// item.setSelected(true);
model.setElementAt(item, row);
}
}
public void dragDropEnd(DragSourceDropEvent dsde) {
if (dsde.getDropSuccess() && dsde.getDropAction()==DnDConstants.ACTION_MOVE && draggedNodeParent != null) {
((DefaultTreeModel)tree.getModel()).nodeStructureChanged(draggedNodeParent);
tree.expandPath(new TreePath(draggedNodeParent.getPath()));
tree.expandPath(new TreePath(draggedNode.getPath()));
}
}
public void dragDropEnd(DragSourceDropEvent e) {
if( isButtonDrag ) {
Component sourceComponent = e.getDragSourceContext().getComponent();
if( sourceComponent instanceof JButton ) {
((JButton)sourceComponent).getModel().setRollover( false );
}
sourceComponent.repaint();
resetDropGesture();
if( e.getDropSuccess() == false &&
!isInToolbarPanel( WindowDnDManager.getLocationWorkaround(e) ) )
{
//TODO catch ESC key
removeButton( e.getDragSourceContext().getTransferable() );
}
} else if( isToolbarDrag ) {
Point newLocationOnScreen = null;
boolean save = false;
if( null != currentRow ) {
//the cursor is above some toolbar row, we can proceed with the drop
newLocationOnScreen = currentRow.drop();
if( sourceRow != currentRow ) {
//clean up the row which we dragged from
sourceRow.dragSuccess();
config.removeEmptyRows();
}
save = true;
} else if( null != sourceRow ) {
//cursor is outside the toolbar area, abort the drop
newLocationOnScreen = sourceRow.dragAbort();
save = true;
}
if( null != dragWindow ) {
if( null != newLocationOnScreen ) {
animateDragWindow(newLocationOnScreen);
} else {
dragWindow.dispose();
}
dragWindow = null;
}
config.maybeRemoveLastRow();
if( save ) {
config.refresh();
config.save();
}
}
isButtonDrag = false;
isToolbarDrag = false;
}
public void dragDropEnd(DragSourceDropEvent dsde) {
if (!dsde.getDropSuccess() && activeDragItem != null) {
activeDragItem.dragAccepted();
}
}
public void run() {
frame = new Frame();
final DragSourceListener dragSourceListener = new DragSourceAdapter() {
public void dragDropEnd(DragSourceDropEvent e) {
dropSuccess = e.getDropSuccess();
System.err.println("Drop was successful: " + dropSuccess);
}
};
DragGestureListener dragGestureListener = new DragGestureListener() {
public void dragGestureRecognized(DragGestureEvent dge) {
dge.startDrag(null, new StringSelection("OK"), dragSourceListener);
}
};
new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE,
dragGestureListener);
DropTargetAdapter dropTargetListener = new DropTargetAdapter() {
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(DnDConstants.ACTION_MOVE);
dtde.dropComplete(true);
System.err.println("Drop");
}
};
new DropTarget(frame, dropTargetListener);
//What would normally go into main() will probably go here.
//Use System.out.println for diagnostic messages that you want
//to read after the test is done.
frame.setUndecorated(true);
frame.setBounds(100, 100, 200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
Robot robot = Util.createRobot();
Util.waitForIdle(robot);
Point startPoint = frame.getLocationOnScreen();
Point endPoint = new Point(startPoint);
startPoint.translate(50, 50);
endPoint.translate(150, 150);
Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK);
Util.waitForIdle(robot);
robot.delay(500);
if (dropSuccess) {
System.err.println("test passed");
} else {
throw new RuntimeException("test failed: drop was not successful");
}
}