Example usage for java.awt.dnd DragSourceDropEvent getDropAction

List of usage examples for java.awt.dnd DragSourceDropEvent getDropAction

Introduction

In this page you can find the example usage for java.awt.dnd DragSourceDropEvent getDropAction.

Prototype


public int getDropAction() 

Source Link

Document

This method returns an int representing the action performed by the target on the subject of the drop.

Usage

From source file:JLabelDragSource.java

public void dragDropEnd(DragSourceDropEvent dsde) {
    DnDUtils.debugPrintln("Drag Source: drop completed, drop action = "
            + DnDUtils.showActions(dsde.getDropAction()) + ", success: " + dsde.getDropSuccess());
}

From source file:Main.java

public void dragDropEnd(DragSourceDropEvent e) {
    System.out.println("Drag and drop end");

    if (e.getDropSuccess() == false) {
        System.out.println("unsuccessful");
        return;/*w ww .ja v a2s .com*/
    }

    int action = e.getDropAction();
    if ((action & DnDConstants.ACTION_MOVE) != 0)
        setText("");
}

From source file:TreeDragTest.java

public void dragDropEnd(DragSourceDropEvent dsde) {
    /*/* w w  w . j  a  v  a2 s  .c o m*/
     * to support move or copy, we have to check which occurred:
     */
    System.out.println("Drop Action: " + dsde.getDropAction());
    if (dsde.getDropSuccess() && (dsde.getDropAction() == DnDConstants.ACTION_MOVE)) {
        ((DefaultTreeModel) sourceTree.getModel()).removeNodeFromParent(oldNode);
    }

    /*
     * to support move only... if (dsde.getDropSuccess()) {
     * ((DefaultTreeModel)sourceTree.getModel()).removeNodeFromParent(oldNode); }
     */
}

From source file:FileTreeDragSource.java

public void dragDropEnd(DragSourceDropEvent dsde) {
    DnDUtils.debugPrintln("Drag Source: drop completed, drop action = "
            + DnDUtils.showActions(dsde.getDropAction()) + ", success: " + dsde.getDropSuccess());
    // If the drop action was ACTION_MOVE,
    // the tree might need to be updated.
    if (dsde.getDropAction() == DnDConstants.ACTION_MOVE) {
        final File[] draggedFiles = dragFiles;
        final TreePath[] draggedPaths = paths;

        Timer tm = new Timer(200, new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                // Check whether each of the dragged files exists.
                // If it does not, we need to remove the node
                // that represents it from the tree.
                for (int i = 0; i < draggedFiles.length; i++) {
                    if (draggedFiles[i].exists() == false) {
                        // Remove this node
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) draggedPaths[i]
                                .getLastPathComponent();
                        ((DefaultTreeModel) tree.getModel()).removeNodeFromParent(node);
                    }/*from  ww w . j a v  a  2  s.  c o m*/
                }
            }
        });
        tm.setRepeats(false);
        tm.start();
    }
}

From source file:ScribbleDragAndDrop.java

/**
 * This method, and the four unused methods that follow it implement the
 * DragSourceListener interface. dragDropEnd() is invoked when the user
 * drops the scribble she was dragging. If the drop was successful, and if
 * the user did a "move" rather than a "copy", then we delete the dragged
 * scribble from the list of scribbles to draw.
 */// ww w  . j a  v  a 2 s  .c om
public void dragDropEnd(DragSourceDropEvent e) {
    if (!e.getDropSuccess())
        return;
    int action = e.getDropAction();
    if (action == DnDConstants.ACTION_MOVE) {
        scribbles.remove(beingDragged);
        beingDragged = null;
        repaint();
    }
}