Search in sources :

Example 86 with Clipboard

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;
}
Also used : Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) PortBindingException(org.languagetool.server.PortBindingException) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 87 with Clipboard

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

Example 88 with Clipboard

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

Example 89 with Clipboard

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

Example 90 with Clipboard

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

Aggregations

Clipboard (java.awt.datatransfer.Clipboard)181 StringSelection (java.awt.datatransfer.StringSelection)117 Transferable (java.awt.datatransfer.Transferable)44 IOException (java.io.IOException)30 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)16 JDialog (javax.swing.JDialog)12 JOptionPane (javax.swing.JOptionPane)12 ActionEvent (java.awt.event.ActionEvent)11 Flame (org.jwildfire.create.tina.base.Flame)10 ActionListener (java.awt.event.ActionListener)8 JButton (javax.swing.JButton)8 JScrollPane (javax.swing.JScrollPane)8 JMenuItem (javax.swing.JMenuItem)7 JPanel (javax.swing.JPanel)7 JTextArea (javax.swing.JTextArea)7 Foundation (org.concord.energy3d.model.Foundation)7 HousePart (org.concord.energy3d.model.HousePart)7 FlameReader (org.jwildfire.create.tina.io.FlameReader)7 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)7 Point (java.awt.Point)6