Example usage for java.awt.datatransfer Transferable toString

List of usage examples for java.awt.datatransfer Transferable toString

Introduction

In this page you can find the example usage for java.awt.datatransfer Transferable toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.languagetool.gui.Main.java

private String getClipboardText() {
    // get text from clipboard or selection:
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemSelection();
    if (clipboard == null) { // on Windows
        clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    }/*from w ww  . java 2s. c om*/
    String s;
    Transferable data = clipboard.getContents(this);
    try {
        if (data != null && data.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor())) {
            DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor();
            try (Reader sr = df.getReaderForText(data)) {
                s = StringTools.readerToString(sr);
            }
        } else {
            s = "";
        }
    } catch (Exception ex) {
        s = data.toString();
    }
    return s;
}