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) {
}
});
}
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);
}
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;
}
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) {
}
});
}
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);
}
}
Aggregations