Search in sources :

Example 91 with Transferable

use of java.awt.datatransfer.Transferable in project pcgen by PCGen.

the class NotesTreeNode method handleDropJavaFileList.

//Listener functions
/**
	 * handles a drop of a java file list
	 *
	 * @param dtde
	 *          drop target drop even - a java dile list has been dropped on
	 *          something that represents this node.
	 * @return returns true if the drop takes place, false if not
	 */
public boolean handleDropJavaFileList(DropTargetDropEvent dtde) {
    dtde.acceptDrop(dtde.getDropAction());
    Transferable t = dtde.getTransferable();
    try {
        List fileList = ((List) t.getTransferData(DataFlavor.javaFileListFlavor));
        for (int i = 0; i < fileList.size(); i++) {
            File newFile = (File) fileList.get(i);
            if (newFile.exists()) {
                MiscUtilities.copy(newFile, new File(dir.getAbsolutePath() + File.separator + newFile.getName()));
            }
        }
    } catch (Exception e) {
        Logging.errorPrint(e.getMessage(), e);
        return false;
    }
    return true;
}
Also used : Transferable(java.awt.datatransfer.Transferable) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) NoSuchElementException(java.util.NoSuchElementException)

Example 92 with Transferable

use of java.awt.datatransfer.Transferable in project vcell by virtualcell.

the class VirtualFrapBatchRunFrame method drop.

public void drop(DropTargetDropEvent dtde) {
    try {
        // get the dropped object and try to figure out what it is
        Transferable tr = dtde.getTransferable();
        DataFlavor[] flavors = tr.getTransferDataFlavors();
        boolean bFileSelected = false;
        if (flavors.length > 0) {
            for (DataFlavor flavor : flavors) {
                // Check for file lists specifically
                if (flavor.isFlavorJavaFileListType()) {
                    // Accept copy and move drops...
                    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
                    @SuppressWarnings("unchecked") List<File> tData = (List<File>) tr.getTransferData(flavor);
                    for (Object dataElement : tData) {
                        if (dataElement instanceof File) {
                            File inputFile = (File) dataElement;
                            // check file extension, we'll open only .vfrap
                            if (VirtualFrapLoader.filter_vfbatch.accept(inputFile)) {
                                bFileSelected = true;
                                AsynchClientTask[] openTasks = open(inputFile);
                                ClientTaskDispatcher.dispatch(VirtualFrapBatchRunFrame.this, new Hashtable<String, Object>(), openTasks, true);
                            } else {
                                String msg = "Unkown file type of " + inputFile.getName() + ". Virtual FRAP Batchrun document names must have an extension of \'." + VirtualFrapLoader.VFRAP_BATCH_EXTENSION + "\'.";
                                DialogUtils.showErrorDialog(this, msg);
                                return;
                            }
                        }
                        if (bFileSelected) {
                            break;
                        }
                    }
                }
                // If we made it this far, everything worked.
                dtde.dropComplete(true);
                return;
            // other cases can be....
            // else if (flavor.isFlavorSerializedObjectType()) {
            // java object
            // }
            // else if (flavor.isRepresentationClassInputStream()) {
            // input stream
            // }
            }
        }
        // the user must not have dropped a file list
        System.out.println("Drop failed: " + dtde);
        dtde.rejectDrop();
    } catch (Exception e) {
        e.printStackTrace(System.out);
        dtde.rejectDrop();
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Transferable(java.awt.datatransfer.Transferable) UserCancelException(org.vcell.util.UserCancelException) DataFlavor(java.awt.datatransfer.DataFlavor) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File)

Example 93 with Transferable

use of java.awt.datatransfer.Transferable in project vcell by virtualcell.

the class DropTest2 method drop.

public void drop(DropTargetDropEvent dtde) {
    try {
        // 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_OR_MOVE);
                ta.setText("Successful file list drop.\n\n");
                // And add the list of file names to our text area
                @SuppressWarnings("unchecked") List<File> list = (List<File>) 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;
            } else // Ok, is it another Java object?
            if (flavors[i].isFlavorSerializedObjectType()) {
                dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
                ta.setText("Successful text drop.\n\n");
                Object o = tr.getTransferData(flavors[i]);
                ta.append("Object: " + o);
                dtde.dropComplete(true);
                return;
            } else // How about an input stream?
            if (flavors[i].isRepresentationClassInputStream()) {
                dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
                ta.setText("Successful text drop.\n\n");
                ta.read(new InputStreamReader((InputStream) tr.getTransferData(flavors[i])), "from system clipboard");
                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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Transferable(java.awt.datatransfer.Transferable) List(java.util.List) File(java.io.File) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 94 with Transferable

use of java.awt.datatransfer.Transferable in project vcell by virtualcell.

the class VirtualFrapMainFrame method drop.

public void drop(DropTargetDropEvent dtde) {
    try {
        // get the dropped object and try to figure out what it is
        Transferable tr = dtde.getTransferable();
        DataFlavor[] flavors = tr.getTransferDataFlavors();
        boolean bFileSelected = false;
        if (flavors.length > 0) {
            for (DataFlavor flavor : flavors) {
                // Check for file lists specifically
                if (flavor.isFlavorJavaFileListType()) {
                    // Accept copy and move drops...
                    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
                    @SuppressWarnings("unchecked") List<File> tData = (List<File>) tr.getTransferData(flavor);
                    for (Object dataElement : tData) {
                        if (dataElement instanceof File) {
                            File inputFile = (File) dataElement;
                            // check file extension, we'll open only .vfrap
                            if (VirtualFrapLoader.filter_vfrap.accept(inputFile)) {
                                bFileSelected = true;
                                AsynchClientTask[] openTasks = frapStudyPanel.open(inputFile);
                                ClientTaskDispatcher.dispatch(VirtualFrapMainFrame.this, new Hashtable<String, Object>(), openTasks, true);
                            } else {
                                String msg = "Unkown file type of " + inputFile.getName() + ". Virtual FRAP document names must have an extension of \'." + VirtualFrapLoader.VFRAP_EXTENSION + "\'.";
                                DialogUtils.showErrorDialog(this, msg);
                                return;
                            }
                        }
                        if (bFileSelected) {
                            break;
                        }
                    }
                }
                // If we made it this far, everything worked.
                dtde.dropComplete(true);
                return;
            // other cases can be....
            // else if (flavor.isFlavorSerializedObjectType()) {
            // java object
            // }
            // else if (flavor.isRepresentationClassInputStream()) {
            // input stream
            // }
            }
        }
        // the user must not have dropped a file list
        System.out.println("Drop failed: " + dtde);
        dtde.rejectDrop();
    } catch (Exception e) {
        e.printStackTrace(System.out);
        dtde.rejectDrop();
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) DataFlavor(java.awt.datatransfer.DataFlavor) List(java.util.List) File(java.io.File)

Example 95 with Transferable

use of java.awt.datatransfer.Transferable in project knime-core by knime.

the class DnDTransferHandlerProxy method createTransferable.

@Override
protected Transferable createTransferable(final JComponent c) {
    Point locationOnScreen = c.getLocationOnScreen();
    Point mousePosition = c.getMousePosition();
    if (mousePosition != null) {
        locationOnScreen.y += mousePosition.y;
    }
    Transferable transferable = getTransferable();
    m_dsl.dragStartedAt(locationOnScreen, transferable);
    return transferable;
}
Also used : Transferable(java.awt.datatransfer.Transferable) Point(java.awt.Point)

Aggregations

Transferable (java.awt.datatransfer.Transferable)96 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)30 IOException (java.io.IOException)30 List (java.util.List)18 DataFlavor (java.awt.datatransfer.DataFlavor)14 ArrayList (java.util.ArrayList)14 File (java.io.File)13 Clipboard (java.awt.datatransfer.Clipboard)12 Point (java.awt.Point)9 StringSelection (java.awt.datatransfer.StringSelection)5 Project (com.intellij.openapi.project.Project)4 ClipboardOwner (java.awt.datatransfer.ClipboardOwner)4 TransferHandler (javax.swing.TransferHandler)4 Editor (com.intellij.openapi.editor.Editor)3 ActionEvent (java.awt.event.ActionEvent)3 JComponent (javax.swing.JComponent)3 TreePath (javax.swing.tree.TreePath)3 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 PsiElement (com.intellij.psi.PsiElement)2