Search in sources :

Example 61 with Transferable

use of java.awt.datatransfer.Transferable in project binnavi by google.

the class ClipboardHelpers method getClipboardString.

/**
   * Returns the string that is currently stored in the system clipboard.
   *
   * @return The string from the system clipboard or null if there is no string currently stored in
   *         the clipboard.
   */
public static String getClipboardString() {
    final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    final Transferable contents = clipboard.getContents(null);
    final boolean hasTransferableText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
    if (!hasTransferableText) {
        return null;
    }
    try {
        return (String) contents.getTransferData(DataFlavor.stringFlavor);
    } catch (UnsupportedFlavorException | IOException ex) {
    // Eat, cannot happen as we're checking above
    }
    return null;
}
Also used : Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 62 with Transferable

use of java.awt.datatransfer.Transferable in project binnavi by google.

the class ClipboardHelpers method copyToClipboard.

/**
   * Copies a string to the system clipboard.
   *
   * @param string The string to be copied to the system clipboard.
   */
public static void copyToClipboard(final String string) {
    Preconditions.checkNotNull(string, "Error: String argument can not be null");
    final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(new StringSelection(string), new ClipboardOwner() {

        @Override
        public void lostOwnership(final Clipboard clipboard, final Transferable contents) {
        }
    });
}
Also used : Transferable(java.awt.datatransfer.Transferable) ClipboardOwner(java.awt.datatransfer.ClipboardOwner) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 63 with Transferable

use of java.awt.datatransfer.Transferable in project binnavi by google.

the class AbstractTreeTransferHandler method dragOver.

@Override
public final void dragOver(final DropTargetDragEvent dtde) {
    final Point pt = dtde.getLocation();
    final int action = dtde.getDropAction();
    tree.autoscroll(pt);
    if (drawImage) {
        paintImage(pt);
    }
    final Transferable transferable = dtde.getTransferable();
    if (!transferable.isDataFlavorSupported(TransferableNode.NODE_FLAVOR)) {
        if (canPerformAction(tree, dtde.getCurrentDataFlavorsAsList().get(0), dtde.getTransferable(), action, pt)) {
            dtde.acceptDrag(action);
        } else {
            dtde.rejectDrag();
        }
    } else {
        if (canPerformAction(tree, draggedNode, action, pt)) {
            dtde.acceptDrag(action);
        } else {
            dtde.rejectDrag();
        }
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) Point(java.awt.Point) Point(java.awt.Point)

Example 64 with Transferable

use of java.awt.datatransfer.Transferable in project hid-serial by rayshobby.

the class GClip method pasteString.

/**
	 * Gets a string from the clipboard. If there is no Clipboard
	 * then create it.
	 * @return if possible the string on the clipboard else an empty string
	 */
private String pasteString() {
    // If there is no clipboard then there is nothing to paste
    if (clipboard == null) {
        makeClipboardObject();
        return "";
    }
    // We have a clipboard so get the string if we can
    Transferable clipboardContent = clipboard.getContents(this);
    if ((clipboardContent != null) && (clipboardContent.isDataFlavorSupported(DataFlavor.stringFlavor))) {
        try {
            String tempString;
            tempString = (String) clipboardContent.getTransferData(DataFlavor.stringFlavor);
            return tempString;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return "";
}
Also used : Transferable(java.awt.datatransfer.Transferable)

Example 65 with Transferable

use of java.awt.datatransfer.Transferable in project otapij by FellowTraveler.

the class DepositChequeDialog method jButton2ActionPerformed.

//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_jButton2ActionPerformed
    Transferable clipboardContent = getToolkit().getSystemClipboard().getContents(this);
    if ((clipboardContent != null) && (clipboardContent.isDataFlavorSupported(DataFlavor.stringFlavor))) {
        try {
            String tempString;
            tempString = (String) clipboardContent.getTransferData(DataFlavor.stringFlavor);
            jTextArea1.setText(tempString);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable)

Aggregations

Transferable (java.awt.datatransfer.Transferable)96 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)30 IOException (java.io.IOException)30 List (java.util.List)18 DataFlavor (java.awt.datatransfer.DataFlavor)14 ArrayList (java.util.ArrayList)14 File (java.io.File)13 Clipboard (java.awt.datatransfer.Clipboard)12 Point (java.awt.Point)9 StringSelection (java.awt.datatransfer.StringSelection)5 Project (com.intellij.openapi.project.Project)4 ClipboardOwner (java.awt.datatransfer.ClipboardOwner)4 TransferHandler (javax.swing.TransferHandler)4 Editor (com.intellij.openapi.editor.Editor)3 ActionEvent (java.awt.event.ActionEvent)3 JComponent (javax.swing.JComponent)3 TreePath (javax.swing.tree.TreePath)3 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 PsiElement (com.intellij.psi.PsiElement)2