package com.redpois0n.gscrot;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;

public class ClipboardHelper {
	
	/**
	 * @return returns the system clipboard
	 */
	public static Clipboard getClipboard() {
		return Toolkit.getDefaultToolkit().getSystemClipboard();
	}
	
	/**
	 * Sets string in clipboard
	 * @param s
	 */
	public static void setString(String s) {
		StringSelection selection = new StringSelection(s);
	    getClipboard().setContents(selection, selection);
	}

}

@@ -24,16 +24,39 @@
 scrot;%0A%0A
+import java.awt.Image;%0A
 import j
@@ -72,16 +72,16 @@
 oolkit;%0A
-
 import j
@@ -112,16 +112,57 @@
 pboard;%0A
+import java.awt.datatransfer.DataFlavor;%0A
 import j
@@ -198,16 +198,116 @@
 lection;
+%0Aimport java.awt.datatransfer.Transferable;%0Aimport java.awt.datatransfer.UnsupportedFlavorException;
 %0A%0Apublic
@@ -331,18 +331,17 @@
 elper %7B%0A
-%09
 %0A
+
 %09/**%0A%09 *
@@ -491,10 +491,9 @@
 %0A%09%7D%0A
-%09
 %0A
+
 %09/**
@@ -522,16 +522,21 @@
 ipboard%0A
+%09 * %0A
 %09 * @par
@@ -646,61 +646,1079 @@
 );%0A%09
-    getClipboard().setContents(selection, selection);
+%09getClipboard().setContents(selection, selection);%0A%09%7D%0A%0A%09/**%0A%09 * Sets image in clipboard%0A%09 * @param image%0A%09 */%0A%09public static void setImage(Image image) %7B%0A%09%09ImageTransferable transferable = new ImageTransferable(image);%0A%09%09Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferable, null);%0A%09%7D%0A%0A%09/**%0A%09 * http://www.java2s.com/Code/Java/2D-Graphics-GUI/ThisprogramdemonstratesthetransferofimagesbetweenaJavaapplicationandthesystemclipboard.htm%0A%09 *%0A%09 */%0A%09private static class ImageTransferable implements Transferable %7B%0A%0A%09%09private Image image;%0A%0A%09%09public ImageTransferable(Image image) %7B%0A%09%09%09this.image = image;%0A%09%09%7D%0A%0A%09%09public DataFlavor%5B%5D getTransferDataFlavors() %7B%0A%09%09%09return new DataFlavor%5B%5D %7B DataFlavor.imageFlavor %7D;%0A%09%09%7D%0A%0A%09%09public boolean isDataFlavorSupported(DataFlavor flavor) %7B%0A%09%09%09return flavor.equals(DataFlavor.imageFlavor);%0A%09%09%7D%0A%0A%09%09public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException %7B%0A%09%09%09if (flavor.equals(DataFlavor.imageFlavor)) %7B%0A%09%09%09%09return image;%0A%09%09%09%7D else %7B%0A%09%09%09%09throw new UnsupportedFlavorException(flavor);%0A%09%09%09%7D%0A%09%09%7D
 %0A%09%7D%0A

Set image in clipboard