Search in sources :

Example 86 with Transferable

use of java.awt.datatransfer.Transferable in project JMRI by JMRI.

the class DropJLabel method drop.

@Override
public void drop(DropTargetDropEvent e) {
    try {
        Transferable tr = e.getTransferable();
        if (e.isDataFlavorSupported(_dataFlavor)) {
            NamedIcon newIcon = new NamedIcon((NamedIcon) tr.getTransferData(_dataFlavor));
            accept(e, newIcon);
        } else if (e.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String text = (String) tr.getTransferData(DataFlavor.stringFlavor);
            if (log.isDebugEnabled()) {
                log.debug("drop for stringFlavor " + text);
            }
            NamedIcon newIcon = new NamedIcon(text, text);
            accept(e, newIcon);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("DropJLabel.drop REJECTED!");
            }
            e.rejectDrop();
        }
    } catch (IOException ioe) {
        if (log.isDebugEnabled()) {
            log.debug("DropPanel.drop REJECTED!");
        }
        e.rejectDrop();
    } catch (UnsupportedFlavorException ufe) {
        if (log.isDebugEnabled()) {
            log.debug("DropJLabel.drop REJECTED!");
        }
        e.rejectDrop();
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 87 with Transferable

use of java.awt.datatransfer.Transferable in project jabref by JabRef.

the class ClipBoardManager method getClipboardContents.

/**
     * Get the String residing on the clipboard.
     *
     * @return any text found on the Clipboard; if none found, return an
     * empty String.
     */
public String getClipboardContents() {
    String result = "";
    //odd: the Object param of getContents is not currently used
    Transferable contents = CLIPBOARD.getContents(null);
    if ((contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            result = (String) contents.getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException | IOException e) {
            //highly unlikely since we are using a standard DataFlavor
            LOGGER.info("problem with getting clipboard contents", e);
        }
    }
    return result;
}
Also used : Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 88 with Transferable

use of java.awt.datatransfer.Transferable in project jabref by JabRef.

the class CitationStyleToClipboardWorker method done.

@Override
public void done() {
    try {
        List<String> citations = get();
        // if it's not a citation style take care of the preview
        if (!CitationStyle.isCitationStyleFile(style)) {
            new ClipBoardManager().setTransferableClipboardContents(processPreview(citations));
        } else {
            // if it's generated by a citation style take care of each output format
            Transferable transferable;
            switch(outputFormat) {
                case HTML:
                    transferable = processHtml(citations);
                    break;
                case RTF:
                    transferable = processRtf(citations);
                    break;
                case XSL_FO:
                    transferable = processXslFo(citations);
                    break;
                case ASCII_DOC:
                case TEXT:
                    transferable = processText(citations);
                    break;
                default:
                    LOGGER.warn("unknown output format: '" + outputFormat + "', processing it via the default.");
                    transferable = processText(citations);
                    break;
            }
            new ClipBoardManager().setTransferableClipboardContents(transferable);
        }
        basePanel.frame().setStatus(Localization.lang("Copied %0 citations.", String.valueOf(selectedEntries.size())));
    } catch (InterruptedException | ExecutionException e) {
        LOGGER.error("Error while copying citations to the clipboard", e);
    }
}
Also used : ClipBoardManager(org.jabref.gui.ClipBoardManager) Transferable(java.awt.datatransfer.Transferable) XmlTransferable(org.jabref.gui.fieldeditors.XmlTransferable) HtmlTransferable(org.jabref.gui.fieldeditors.HtmlTransferable) RtfTransferable(org.jabref.gui.exporter.RtfTransferable) ExecutionException(java.util.concurrent.ExecutionException)

Example 89 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)

Aggregations

Transferable (java.awt.datatransfer.Transferable)89 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)28 IOException (java.io.IOException)27 List (java.util.List)15 ArrayList (java.util.ArrayList)13 Clipboard (java.awt.datatransfer.Clipboard)11 DataFlavor (java.awt.datatransfer.DataFlavor)11 File (java.io.File)10 Point (java.awt.Point)8 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 DataContext (com.intellij.openapi.actionSystem.DataContext)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2