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;
}
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) {
}
});
}
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();
}
}
}
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 "";
}
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();
}
}
}
Aggregations