Search in sources :

Example 76 with StringSelection

use of java.awt.datatransfer.StringSelection in project zaproxy by zaproxy.

the class ExtensionStdMenus method setClipboardContents.

private void setClipboardContents(String str) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(new StringSelection(str), this);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 77 with StringSelection

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

the class LiveTemplateTree method performCopy.

@Override
public void performCopy(@NotNull DataContext dataContext) {
    final Set<TemplateImpl> templates = myConfigurable.getSelectedTemplates().keySet();
    TemplateSettings templateSettings = TemplateSettings.getInstance();
    CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.join(templates, template -> JDOMUtil.writeElement(TemplateSettings.serializeTemplate(template, templateSettings.getDefaultTemplate(template), TemplateContext.getIdToType())), SystemProperties.getLineSeparator())));
}
Also used : StringSelection(java.awt.datatransfer.StringSelection)

Example 78 with StringSelection

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

the class CopyReferenceAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    List<PsiElement> elements = getElementsToCopy(editor, dataContext);
    if (!doCopy(elements, project, editor) && editor != null && project != null) {
        Document document = editor.getDocument();
        PsiFile file = PsiDocumentManager.getInstance(project).getCachedPsiFile(document);
        if (file != null) {
            String toCopy = getFileFqn(file) + ":" + (editor.getCaretModel().getLogicalPosition().line + 1);
            CopyPasteManager.getInstance().setContents(new StringSelection(toCopy));
            setStatusBarText(project, toCopy + " has been copied");
        }
        return;
    }
    HighlightManager highlightManager = HighlightManager.getInstance(project);
    EditorColorsManager manager = EditorColorsManager.getInstance();
    TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    if (elements.size() == 1 && editor != null && project != null) {
        PsiElement element = elements.get(0);
        PsiElement nameIdentifier = IdentifierUtil.getNameIdentifier(element);
        if (nameIdentifier != null) {
            highlightManager.addOccurrenceHighlights(editor, new PsiElement[] { nameIdentifier }, attributes, true, null);
        } else {
            PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
            if (reference != null) {
                highlightManager.addOccurrenceHighlights(editor, new PsiReference[] { reference }, attributes, true, null);
            } else if (element != PsiDocumentManager.getInstance(project).getCachedPsiFile(editor.getDocument())) {
                highlightManager.addOccurrenceHighlights(editor, new PsiElement[] { element }, attributes, true, null);
            }
        }
    }
}
Also used : HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) Document(com.intellij.openapi.editor.Document) StringSelection(java.awt.datatransfer.StringSelection) Project(com.intellij.openapi.project.Project) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Editor(com.intellij.openapi.editor.Editor)

Example 79 with StringSelection

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

the class ClipboardHelper method setClipboardContents.

/**
    * Place a String on the clipboard, and make this class the
    * owner of the Clipboard's contents.
    */
public void setClipboardContents(String str) {
    StringSelection stringSelection = new StringSelection(str);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    try {
        clipboard.setContents(stringSelection, stringSelection);
    } catch (IllegalStateException e) {
        // This exception may be returned in some cases
        // It is a temporary situation: we do nothing here
        // and the user will retry again or most likely 
        // submit an SPR ;-)
        e.printStackTrace();
    }
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 80 with StringSelection

use of java.awt.datatransfer.StringSelection 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)

Aggregations

StringSelection (java.awt.datatransfer.StringSelection)99 Clipboard (java.awt.datatransfer.Clipboard)28 ActionEvent (java.awt.event.ActionEvent)11 Transferable (java.awt.datatransfer.Transferable)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 JTextArea (javax.swing.JTextArea)7 Test (org.junit.Test)7 JPanel (javax.swing.JPanel)6 ActionListener (java.awt.event.ActionListener)5 JScrollPane (javax.swing.JScrollPane)5 Editor (com.intellij.openapi.editor.Editor)4 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 ClipboardOwner (java.awt.datatransfer.ClipboardOwner)4 JMenuItem (javax.swing.JMenuItem)4 BibEntry (org.jabref.model.entry.BibEntry)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 PsiElement (com.intellij.psi.PsiElement)3 BorderLayout (java.awt.BorderLayout)3