Example usage for java.awt.dnd DropTargetDragEvent getSourceActions

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

Introduction

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

Prototype

public int getSourceActions() 

Source Link

Document

This method returns the source drop actions.

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();/*w w w. j a va 2 s .  c  o  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: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 w  ww.  j a  va 2  s  .  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

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  .c om
    } 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:javazoom.jlgui.player.amp.skin.DropTargetAdapter.java

protected boolean isDragOk(DropTargetDragEvent e) {
    // Check DataFlavor
    DataFlavor[] dfs = e.getCurrentDataFlavors();
    DataFlavor tdf = null;/*  ww  w  . j a v  a  2s.  co  m*/
    for (int i = 0; i < dfs.length; i++) {
        if (DataFlavor.javaFileListFlavor.equals(dfs[i])) {
            tdf = dfs[i];
            break;
        } else if (DataFlavor.stringFlavor.equals(dfs[i])) {
            tdf = dfs[i];
            break;
        }
    }
    // Only file list allowed.
    if (tdf != null) {
        // Only DnD COPY allowed.
        if ((e.getSourceActions() & DnDConstants.ACTION_COPY) != 0) {
            return true;
        } else
            return false;
    } else
        return false;
}

From source file:FileTreeDropTarget.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));

    Point location = dtde.getLocation();
    boolean acceptableDropLocation = isAcceptableDropLocation(location);

    // 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  ava2  s  .c  o m*/
    } else if (!tree.isEditable()) {
        // Can't drag to a read-only FileTree
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();
    } else if (!acceptableDropLocation) {
        // Can only drag to writable directory
        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:DragDropTreeExample.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));

    Point location = dtde.getLocation();
    boolean acceptableDropLocation = isAcceptableDropLocation(location);

    // 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  ww .j av a2  s.c o  m*/
    } else if (!tree.isEditable()) {
        // Can't drag to a read-only FileTree
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();
    } else if (!acceptableDropLocation) {
        // Can only drag to writable directory
        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:javazoom.jlgui.player.amp.Player.java

/**
 * Checks if Drag allowed./*w  ww  . ja v  a2 s  . co  m*/
 */
protected boolean isDragOk(DropTargetDragEvent e) {
    // Check DataFlavor
    DataFlavor[] dfs = e.getCurrentDataFlavors();
    DataFlavor tdf = null;
    for (int i = 0; i < dfs.length; i++) {
        if (DataFlavor.javaFileListFlavor.equals(dfs[i])) {
            tdf = dfs[i];
            break;
        }
    }
    // Only file list allowed.
    if (tdf != null) {
        // Only DnD COPY allowed.
        if ((e.getSourceActions() & DnDConstants.ACTION_COPY) != 0) {
            return true;
        } else
            return false;
    } else
        return false;
}