Search in sources :

Example 46 with Clipboard

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);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 47 with Clipboard

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;
}
Also used : Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 48 with Clipboard

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);
        }
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JCheckBox(javax.swing.JCheckBox) JTextArea(javax.swing.JTextArea) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Aggregations

Clipboard (java.awt.datatransfer.Clipboard)48 StringSelection (java.awt.datatransfer.StringSelection)27 Transferable (java.awt.datatransfer.Transferable)11 IOException (java.io.IOException)9 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)7 JScrollPane (javax.swing.JScrollPane)6 JTextArea (javax.swing.JTextArea)6 ActionEvent (java.awt.event.ActionEvent)5 JPanel (javax.swing.JPanel)5 DataFlavor (java.awt.datatransfer.DataFlavor)4 ActionListener (java.awt.event.ActionListener)4 ArrayList (java.util.ArrayList)4 JButton (javax.swing.JButton)4 JMenuItem (javax.swing.JMenuItem)4 ClipboardOwner (java.awt.datatransfer.ClipboardOwner)3 MouseListener (java.awt.event.MouseListener)3 JCheckBox (javax.swing.JCheckBox)3 JPopupMenu (javax.swing.JPopupMenu)3 Color (java.awt.Color)2 MouseEvent (java.awt.event.MouseEvent)2