use of java.awt.datatransfer.Clipboard in project suite by stupidsing.
the class ClipboardUtil method setClipboardText.
public void setClipboardText(String text) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(text), null);
}
use of java.awt.datatransfer.Clipboard in project suite by stupidsing.
the class ClipboardUtil method getClipboardText.
public String getClipboardText() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
String text;
if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor))
try {
text = contents.getTransferData(DataFlavor.stringFlavor).toString();
} catch (UnsupportedFlavorException ex) {
LogUtil.error(ex);
text = "";
} catch (IOException ex) {
LogUtil.error(ex);
text = "";
}
else
text = "";
return text;
}
use of java.awt.datatransfer.Clipboard in project Payara by payara.
the class ErrorDisplayDialog method showText.
/**
* Manages the dialog box to display whatever error information has already
* been formatted.
*
* @param text message to display
* @param rb ResourceBundle containing the i18n strings
*/
private static void showText(final String text, final ResourceBundle rb) {
ErrorDisplayDialog.rb = rb;
/*
*The JOptionPane class will accept other Components as elements of
*the dialog box. Build a JTextArea containing the stack trace. Do not
*let the user edit the text.
*/
JTextArea stackTraceArea = new JTextArea();
stackTraceArea.setEditable(false);
stackTraceArea.setRows(16);
stackTraceArea.setText(text);
/*
*Place the text area inside a scroll pane.
*/
JScrollPane sp = new JScrollPane(stackTraceArea);
/*
*Build a check box for the user to click to copy the error information
*to the platform's clipboard.
*/
JCheckBox copyToClipboardCB = new JCheckBox(getString("jwsacc.errorDialog.copyToClipboardLabel"));
/*
*Display the dialog box that also contains the text area's scroll
*pane and the checkbox and then wait for the user to close it.
*/
boolean copyToClipboard = showDialog(getString("jwsacc.errorDialog.mainMessage.1") + LINE_SEP + getString("jwsacc.errorDialog.mainMessage.2"), sp, copyToClipboardCB);
if (copyToClipboard) {
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection ss = new StringSelection(stackTraceArea.getText());
try {
cb.setContents(ss, null);
} catch (Throwable e) {
/*
*If we cannot copy the text to the clipboard, tell the user that
*and suggest that he or she manually copy it.
*/
showDialog(getString("jwsacc.errorDialog.errorCopyingMessage.1") + LINE_SEP + getString("jwsacc.errorDialog.errorCopyingMessage.2"), sp, null);
}
}
}
Aggregations