Example usage for java.awt.dnd DnDConstants ACTION_COPY

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

Introduction

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

Prototype

int ACTION_COPY

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

Click Source Link

Document

An int representing a "copy" action.

Usage

From source file:DropTest.java

public void drop(DropTargetDropEvent dtde) {
    try {/*w  ww. jav a  2 s  . com*/
        Transferable tr = dtde.getTransferable();
        DataFlavor[] flavors = tr.getTransferDataFlavors();
        for (int i = 0; i < flavors.length; i++) {
            System.out.println("Possible flavor: " + flavors[i].getMimeType());
            if (flavors[i].isFlavorJavaFileListType()) {
                dtde.acceptDrop(DnDConstants.ACTION_COPY);
                ta.setText("Successful file list drop.\n\n");

                java.util.List list = (java.util.List) tr.getTransferData(flavors[i]);
                for (int j = 0; j < list.size(); j++) {
                    ta.append(list.get(j) + "\n");
                }
                dtde.dropComplete(true);
                return;
            }
        }
        System.out.println("Drop failed: " + dtde);
        dtde.rejectDrop();
    } catch (Exception e) {
        e.printStackTrace();
        dtde.rejectDrop();
    }
}

From source file:net.sf.jabref.gui.fieldeditors.PreviewPanelTransferHandler.java

/**
 * LINK is unsupported as dropping into into Microsoft Word then leads to a link instead to a copy
 *//*www . j av  a  2 s .c  o  m*/
@Override
public int getSourceActions(JComponent component) {
    return DnDConstants.ACTION_COPY;
}

From source file:DropTest.java

public void drop(DropTargetDropEvent dtde) {
    try {/* w ww.  j av  a  2  s  .c o  m*/
        // Ok, get the dropped object and try to figure out what it is
        Transferable tr = dtde.getTransferable();
        DataFlavor[] flavors = tr.getTransferDataFlavors();
        for (int i = 0; i < flavors.length; i++) {
            System.out.println("Possible flavor: " + flavors[i].getMimeType());
            // Check for file lists specifically
            if (flavors[i].isFlavorJavaFileListType()) {
                // Great! Accept copy drops...
                dtde.acceptDrop(DnDConstants.ACTION_COPY);
                ta.setText("Successful file list drop.\n\n");

                // And add the list of file names to our text area
                java.util.List list = (java.util.List) tr.getTransferData(flavors[i]);
                for (int j = 0; j < list.size(); j++) {
                    ta.append(list.get(j) + "\n");
                }

                // If we made it this far, everything worked.
                dtde.dropComplete(true);
                return;
            }
        }
        // Hmm, the user must not have dropped a file list
        System.out.println("Drop failed: " + dtde);
        dtde.rejectDrop();
    } catch (Exception e) {
        e.printStackTrace();
        dtde.rejectDrop();
    }
}

From source file:javazoom.jlgui.player.amp.skin.DropTargetAdapter.java

protected boolean isDragOk(DropTargetDragEvent e) {
    // Check DataFlavor
    DataFlavor[] dfs = e.getCurrentDataFlavors();
    DataFlavor tdf = null;/*from w ww.  ja  v  a 2 s  .  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:net.sf.jabref.gui.fieldeditors.FileListEditorTransferHandler.java

/**
 * Overridden to indicate which types of drags are supported (only LINK + COPY).
 * COPY is supported as no support disables CTRL+C (copy of text)
 *//*from w  w  w.  j ava2  s  .c  o m*/
@Override
public int getSourceActions(JComponent c) {
    return DnDConstants.ACTION_LINK | DnDConstants.ACTION_COPY;
}

From source file:be.ugent.maf.cellmissy.gui.controller.load.generic.DragAndDropController.java

/**
 * Initialize the DnD//from  w w w .ja v a2s . c  o  m
 */
private void initDnD() {
    // create a new Drag Source
    DragSource ds = new DragSource();
    // get the directory tree from the parent controller
    JTree directoryTree = genericImagedPlateController.getLoadFromGenericInputPlatePanel().getDirectoryTree();
    // get the JPanel from the parent controller
    ImagedPlatePanel imagedPlatePanel = genericImagedPlateController.getImagedPlatePanel();
    // the DRAG gesture (source -- JTree) -- needs a DragGestureListener to notify
    ds.createDefaultDragGestureRecognizer(directoryTree, DnDConstants.ACTION_COPY,
            new JTreeDragGestureListener());
    // the DROP action onto the target
    JPanelDropTargetListener jPanelDropTargetListener = new JPanelDropTargetListener(imagedPlatePanel);
}

From source file:javazoom.jlgui.player.amp.skin.DropTargetAdapter.java

public void drop(DropTargetDropEvent e) {
    // Check DataFlavor
    DataFlavor[] dfs = e.getCurrentDataFlavors();
    DataFlavor tdf = null;/*from   www .j  ava  2s  .c  o  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;
        }
    }
    // Data Flavor available ?
    if (tdf != null) {
        // Accept COPY DnD only.
        if ((e.getSourceActions() & DnDConstants.ACTION_COPY) != 0) {
            e.acceptDrop(DnDConstants.ACTION_COPY);
        } else
            return;
        try {
            Transferable t = e.getTransferable();
            Object data = t.getTransferData(tdf);
            processDrop(data);
        } catch (IOException ioe) {
            log.info("Drop error", ioe);
            e.dropComplete(false);
            return;
        } catch (UnsupportedFlavorException ufe) {
            log.info("Drop error", ufe);
            e.dropComplete(false);
            return;
        } catch (Exception ex) {
            log.info("Drop error", ex);
            e.dropComplete(false);
            return;
        }
        e.dropComplete(true);
    }
}

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();/* www.j  av  a 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:javazoom.jlgui.player.amp.playlist.ui.PlaylistUI.java

public PlaylistUI() {
    super();/*from ww w .  j a  v  a 2s. co  m*/
    setDoubleBuffered(true);
    setLayout(new AbsoluteLayout());
    config = Config.getInstance();
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            handleMouseClick(e);
        }
    });
    // DnD support.
    DropTargetAdapter dnd = new DropTargetAdapter() {
        public void processDrop(Object data) {
            processDnD(data);
        }
    };
    DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, dnd, true);
}

From source file:MainClass.java

public void dragEnter(DragSourceDragEvent e) {
    System.out.println("Entering drop target #2");

    DragSourceContext ctx = e.getDragSourceContext();

    int action = e.getDropAction();
    if ((action & DnDConstants.ACTION_COPY) != 0)
        ctx.setCursor(DragSource.DefaultCopyDrop);
    else//from   w w  w. j  av  a 2s .c o m
        ctx.setCursor(DragSource.DefaultCopyNoDrop);
}