Example usage for java.awt.dnd DnDConstants ACTION_MOVE

List of usage examples for java.awt.dnd DnDConstants ACTION_MOVE

Introduction

In this page you can find the example usage for java.awt.dnd DnDConstants ACTION_MOVE.

Prototype

int ACTION_MOVE

To view the source code for java.awt.dnd DnDConstants ACTION_MOVE.

Click Source Link

Document

An int representing a "move" action.

Usage

From source file:DragDropList.java

public MyDragListener(DragDropList list) {
    this.list = list;
    DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer(list, DnDConstants.ACTION_MOVE, this);

}

From source file:DNDList.java

/**
 * constructor - initializes the DropTarget and DragSource.
 *//*w ww  .ja  va2  s  .c  om*/

public DNDList(ListModel dataModel) {
    super(dataModel);
    dropTarget = new DropTarget(this, this);
    dragSource = new DragSource();
    dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this);
}

From source file:DNDList.java

/**
 * is invoked when you are dragging over the DropSite
 * /*from   w  w w.j a  v a 2  s . com*/
 */

public void dragEnter(DropTargetDragEvent event) {

    // debug messages for diagnostics
    System.out.println("dragEnter");
    event.acceptDrag(DnDConstants.ACTION_MOVE);
}

From source file:DNDList.java

/**
 * a drop has occurred//from  w w  w  .j ava 2 s .  c  o  m
 * 
 */

public void drop(DropTargetDropEvent event) {

    try {
        Transferable transferable = event.getTransferable();

        // we accept only Strings
        if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {

            event.acceptDrop(DnDConstants.ACTION_MOVE);
            String s = (String) transferable.getTransferData(DataFlavor.stringFlavor);
            addElement(s);
            event.getDropTargetContext().dropComplete(true);
        } else {
            event.rejectDrop();
        }
    } catch (Exception exception) {
        System.err.println("Exception" + exception.getMessage());
        event.rejectDrop();
    }
}

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;//from  w w w  . j a  v a2 s.  c  o  m
    }

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

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);
                    }/* ww  w  .  j  a  v  a2 s  . com*/
                }
            }
        });
        tm.setRepeats(false);
        tm.start();
    }
}

From source file:PanelDropTarget.java

public static String showActions(int action) {
    String actions = "";
    if ((action & (DnDConstants.ACTION_LINK | DnDConstants.ACTION_COPY_OR_MOVE)) == 0) {
        return "None";
    }// w  ww .  j a va2s  .  c  o  m

    if ((action & DnDConstants.ACTION_COPY) != 0) {
        actions += "Copy ";
    }

    if ((action & DnDConstants.ACTION_MOVE) != 0) {
        actions += "Move ";
    }

    if ((action & DnDConstants.ACTION_LINK) != 0) {
        actions += "Link";
    }

    return actions;
}

From source file:TreeDragTest.java

public void dragDropEnd(DragSourceDropEvent dsde) {
    /*/*w  ww .ja v  a  2 s . com*/
     * 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:ScribbleDragAndDrop.java

/**
 * This method implements the DragGestureListener interface. It will be
 * invoked when the DragGestureRecognizer thinks that the user has initiated
 * a drag. If we're not in drawing mode, then this method will try to figure
 * out which Scribble object is being dragged, and will initiate a drag on
 * that object.//from  www  .j  a v a2 s .  c  om
 */
public void dragGestureRecognized(DragGestureEvent e) {
    // Don't drag if we're not in drag mode
    if (!dragMode)
        return;

    // Figure out where the drag started
    MouseEvent inputEvent = (MouseEvent) e.getTriggerEvent();
    int x = inputEvent.getX();
    int y = inputEvent.getY();

    // Figure out which scribble was clicked on, if any by creating a
    // small rectangle around the point and testing for intersection.
    Rectangle r = new Rectangle(x - LINEWIDTH, y - LINEWIDTH, LINEWIDTH * 2, LINEWIDTH * 2);
    int numScribbles = scribbles.size();
    for (int i = 0; i < numScribbles; i++) { // Loop through the scribbles
        Scribble s = (Scribble) scribbles.get(i);
        if (s.intersects(r)) {
            // The user started the drag on top of this scribble, so
            // start to drag it.

            // First, remember which scribble is being dragged, so we can
            // delete it later (if this is a move rather than a copy)
            beingDragged = s;

            // Next, create a copy that will be the one dragged
            Scribble dragScribble = (Scribble) s.clone();
            // Adjust the origin to the point the user clicked on.
            dragScribble.translate(-x, -y);

            // Choose a cursor based on the type of drag the user initiated
            Cursor cursor;
            switch (e.getDragAction()) {
            case DnDConstants.ACTION_COPY:
                cursor = DragSource.DefaultCopyDrop;
                break;
            case DnDConstants.ACTION_MOVE:
                cursor = DragSource.DefaultMoveDrop;
                break;
            default:
                return; // We only support move and copys
            }

            // Some systems allow us to drag an image along with the
            // cursor. If so, create an image of the scribble to drag
            if (dragSource.isDragImageSupported()) {
                Rectangle scribbleBox = dragScribble.getBounds();
                Image dragImage = this.createImage(scribbleBox.width, scribbleBox.height);
                Graphics2D g = (Graphics2D) dragImage.getGraphics();
                g.setColor(new Color(0, 0, 0, 0)); // transparent background
                g.fillRect(0, 0, scribbleBox.width, scribbleBox.height);
                g.setColor(Color.black);
                g.setStroke(linestyle);
                g.translate(-scribbleBox.x, -scribbleBox.y);
                g.draw(dragScribble);
                Point hotspot = new Point(-scribbleBox.x, -scribbleBox.y);

                // Now start dragging, using the image.
                e.startDrag(cursor, dragImage, hotspot, dragScribble, this);
            } else {
                // Or start the drag without an image
                e.startDrag(cursor, dragScribble, this);
            }
            // After we've started dragging one scribble, stop looking
            return;
        }
    }
}

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.
 *//* www  .  ja  va2 s. c  o m*/
public void dragDropEnd(DragSourceDropEvent e) {
    if (!e.getDropSuccess())
        return;
    int action = e.getDropAction();
    if (action == DnDConstants.ACTION_MOVE) {
        scribbles.remove(beingDragged);
        beingDragged = null;
        repaint();
    }
}