use of java.awt.datatransfer.Clipboard in project languagetool by languagetool-org.
the class Main method getClipboardText.
private String getClipboardText() {
// get text from clipboard or selection:
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemSelection();
if (clipboard == null) {
// on Windows
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
}
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;
}
use of java.awt.datatransfer.Clipboard in project screenbird by adamhub.
the class RecorderPanel method btnCopyActionPerformed.
//GEN-LAST:event_chkPublicActionPerformed
private void btnCopyActionPerformed(ActionEvent evt) {
//GEN-FIRST:event_btnCopyActionPerformed
StringSelection stringSelection = new StringSelection(Session.getInstance().user.getBaseURL() + this.outputMovieSlug);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
}
use of java.awt.datatransfer.Clipboard 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.Clipboard 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.Clipboard 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();
}
}
Aggregations