Search in sources :

Example 76 with Transferable

use of java.awt.datatransfer.Transferable in project otertool by wuntee.

the class GuiWorkshop method setClipboardContents.

public static void setClipboardContents(String s) {
    StringSelection stringSelection = new StringSelection(s);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(stringSelection, new ClipboardOwner() {

        public void lostOwnership(Clipboard arg0, Transferable arg1) {
        }
    });
}
Also used : Transferable(java.awt.datatransfer.Transferable) ClipboardOwner(java.awt.datatransfer.ClipboardOwner) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 77 with Transferable

use of java.awt.datatransfer.Transferable in project intellij-community by JetBrains.

the class GrCopyStringConcatenationContentIntention method processIntention.

@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    final StringBuilder buffer = new StringBuilder();
    getValue(element, buffer);
    final Transferable contents = new StringSelection(buffer.toString());
    CopyPasteManager.getInstance().setContents(contents);
}
Also used : Transferable(java.awt.datatransfer.Transferable) StringSelection(java.awt.datatransfer.StringSelection)

Example 78 with Transferable

use of java.awt.datatransfer.Transferable in project ACS by ACS-Community.

the class ClipboardHelper method getClipboardContents.

/**
     * Get the String in the clipboard.
     *
     * @return any text found on the Clipboard; if none found, return an
     * empty String.
     */
private String getClipboardContents() {
    String result = "";
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    //odd: the Object param of getContents is not currently used
    Transferable contents = clipboard.getContents(null);
    boolean hasTransferableText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
    if (hasTransferableText) {
        try {
            result = (String) contents.getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException ex) {
            //highly unlikely since we are using a standard DataFlavor
            System.out.println(ex);
        } catch (IOException ex) {
            System.out.println(ex);
        }
    }
    return result;
}
Also used : Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 79 with Transferable

use of java.awt.datatransfer.Transferable in project kotlin by JetBrains.

the class CopyAsDiagnosticTestAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
    assert editor != null && psiFile != null;
    BindingContext bindingContext = ResolutionUtils.analyzeFully((KtFile) psiFile);
    List<CheckerTestUtil.ActualDiagnostic> diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, psiFile, false, null, null);
    String result = CheckerTestUtil.addDiagnosticMarkersToText(psiFile, diagnostics).toString();
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(new StringSelection(result), new ClipboardOwner() {

        @Override
        public void lostOwnership(Clipboard clipboard, Transferable contents) {
        }
    });
}
Also used : Transferable(java.awt.datatransfer.Transferable) ClipboardOwner(java.awt.datatransfer.ClipboardOwner) PsiFile(com.intellij.psi.PsiFile) Clipboard(java.awt.datatransfer.Clipboard) Editor(com.intellij.openapi.editor.Editor) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) StringSelection(java.awt.datatransfer.StringSelection)

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

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