Example usage for java.awt.dnd DropTargetDragEvent getDropAction

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

Introduction

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

Prototype

public int getDropAction() 

Source Link

Document

This method returns the user drop action.

Usage

From source file:PanelDropTarget.java

protected boolean acceptOrRejectDrag(DropTargetDragEvent dtde) {
    int dropAction = dtde.getDropAction();
    int sourceActions = dtde.getSourceActions();
    boolean acceptedDrag = false;

    DnDUtils.debugPrintln("\tSource actions are " + DnDUtils.showActions(sourceActions) + ", drop action is "
            + DnDUtils.showActions(dropAction));

    // Reject if the object being transferred
    // or the operations available are not acceptable.
    if (!acceptableType || (sourceActions & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();//from w  w  w  .  j  a v a 2 s. co  m
    } else if ((dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
        // Not offering copy or move - suggest a copy
        DnDUtils.debugPrintln("Drop target offering COPY");
        dtde.acceptDrag(DnDConstants.ACTION_COPY);
        acceptedDrag = true;
    } else {
        // Offering an acceptable operation: accept
        DnDUtils.debugPrintln("Drop target accepting drag");
        dtde.acceptDrag(dropAction);
        acceptedDrag = true;
    }

    return acceptedDrag;
}

From source file:PanelDropTarget.java

public void dragEnter(DropTargetDragEvent dtde) {
    DnDUtils.debugPrintln("dragEnter, drop action = " + DnDUtils.showActions(dtde.getDropAction()));

    // Get the type of object being transferred and determine
    // whether it is appropriate.
    checkTransferType(dtde);/*from  w ww  .  j  av  a2s .c o m*/

    // Accept or reject the drag.
    acceptOrRejectDrag(dtde);
}

From source file:PanelDropTarget.java

public void dragOver(DropTargetDragEvent dtde) {
    DnDUtils.debugPrintln("DropTarget dragOver, drop action = " + DnDUtils.showActions(dtde.getDropAction()));

    // Accept or reject the drag
    acceptOrRejectDrag(dtde);//w  w w  .j ava  2 s .co m
}

From source file:PanelDropTarget.java

public void dropActionChanged(DropTargetDragEvent dtde) {
    DnDUtils.debugPrintln(/*w w  w. j av a  2s.  com*/
            "DropTarget dropActionChanged, drop action = " + DnDUtils.showActions(dtde.getDropAction()));

    // Accept or reject the drag
    acceptOrRejectDrag(dtde);
}

From source file:EditorDropTarget2.java

protected boolean acceptOrRejectDrag(DropTargetDragEvent dtde) {
    int dropAction = dtde.getDropAction();
    int sourceActions = dtde.getSourceActions();
    boolean acceptedDrag = false;

    DnDUtils.debugPrintln("\tSource actions are " + DnDUtils.showActions(sourceActions) + ", drop action is "
            + DnDUtils.showActions(dropAction));

    // Reject if the object being transferred
    // or the operations available are not acceptable
    if (!acceptableType || (sourceActions & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();/*from   www.j a  v a 2  s  . co m*/
    } else if (!draggingFile && !pane.isEditable()) {
        // Can't drag text to a read-only JEditorPane
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();
    } else if ((dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
        // Not offering copy or move - suggest a copy
        DnDUtils.debugPrintln("Drop target offering COPY");
        dtde.acceptDrag(DnDConstants.ACTION_COPY);
        acceptedDrag = true;
    } else {
        // Offering an acceptable operation: accept
        DnDUtils.debugPrintln("Drop target accepting drag");
        dtde.acceptDrag(dropAction);
        acceptedDrag = true;
    }

    return acceptedDrag;
}

From source file:EditorDropTarget4.java

protected boolean acceptOrRejectDrag(DropTargetDragEvent dtde) {
    int dropAction = dtde.getDropAction();
    int sourceActions = dtde.getSourceActions();
    boolean acceptedDrag = false;

    DnDUtils.debugPrintln("\tSource actions are " + DnDUtils.showActions(sourceActions) + ", drop action is "
            + DnDUtils.showActions(dropAction));

    // Reject if the object being transferred
    // or the operations available are not acceptable.
    if (!acceptableType || (sourceActions & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();/* w w  w . j a v a  2s.c  o  m*/
    } else if (!draggingFile && !pane.isEditable()) {
        // Can't drag text to a read-only JEditorPane
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();
    } else if ((dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
        // Not offering copy or move - suggest a copy
        DnDUtils.debugPrintln("Drop target offering COPY");
        dtde.acceptDrag(DnDConstants.ACTION_COPY);
        acceptedDrag = true;
    } else {
        // Offering an acceptable operation: accept
        DnDUtils.debugPrintln("Drop target accepting drag");
        dtde.acceptDrag(dropAction);
        acceptedDrag = true;
    }

    return acceptedDrag;
}

From source file:EditorDropTarget4.java

public void dragEnter(DropTargetDragEvent dtde) {
    DnDUtils.debugPrintln("dragEnter, drop action = " + DnDUtils.showActions(dtde.getDropAction()));

    // Get the type of object being transferred and determine
    // whether it is appropriate.
    checkTransferType(dtde);// ww w  .j  av  a  2 s. c o m

    // Accept or reject the drag.
    boolean acceptedDrag = acceptOrRejectDrag(dtde);

    // Do drag-under feedback
    dragUnderFeedback(dtde, acceptedDrag);
}

From source file:EditorDropTarget4.java

public void dragOver(DropTargetDragEvent dtde) {
    DnDUtils.debugPrintln("DropTarget dragOver, drop action = " + DnDUtils.showActions(dtde.getDropAction()));

    // Accept or reject the drag
    boolean acceptedDrag = acceptOrRejectDrag(dtde);

    // Do drag-under feedback
    dragUnderFeedback(dtde, acceptedDrag);
}

From source file:EditorDropTarget4.java

public void dropActionChanged(DropTargetDragEvent dtde) {
    DnDUtils.debugPrintln(//from  ww  w.j ava  2s.  c  om
            "DropTarget dropActionChanged, drop action = " + DnDUtils.showActions(dtde.getDropAction()));

    // Accept or reject the drag
    boolean acceptedDrag = acceptOrRejectDrag(dtde);

    // Do drag-under feedback
    dragUnderFeedback(dtde, acceptedDrag);
}

From source file:TreeDragTest.java

public void dragEnter(DropTargetDragEvent dtde) {
    TreeNode node = getNodeForEvent(dtde);
    if (node.isLeaf()) {
        dtde.rejectDrag();/*from  w w  w  . j  a  va  2 s.co  m*/
    } else {
        // start by supporting move operations
        //dtde.acceptDrag(DnDConstants.ACTION_MOVE);
        dtde.acceptDrag(dtde.getDropAction());
    }
}