package clipHtml;

import sun.awt.windows.*;
import java.lang.reflect.*;

/**
 * Access the native clipboard, windows only, write only.
 * Needs work to become fool-proof, you may look into WClipboard.
 * Since this class hacks a private method, it may be harmfull if
 * the underlying implementation is changed.
 *
 * Also, if you want to push more than one format into the
 * clipboard in the Jdk way, you have to do some work.
 * <pre>
 * Here is some pseudocode:
 *	public synchronized void setContents(Transferable contents, ClipboardOwner owner) {
 *		...
 *		Map formatMap = ...getFormatsForTransferable(contents, flavorMap);
 *		openClipboard(this);
 *		...
 *		for (format in formatMap.keySet()){
 *			DataFlavor flavor = (DataFlavor)formatMap.get(format);
 *			...
 *			myPublishClipboardData(format, ... translateTransferable(contents, flavor, format););
 *
 *		...
 *  closeClipboard();
 * </pre>
 *
 * @author Peter Büttner <info@PeterBuettner.de>
 * @version 11.04.2003 23:58:53
 */

public class PEBClip extends WClipboard{
	private Method m=null;

public PEBClip() throws NoSuchMethodException{
	m= WClipboard.class.getDeclaredMethod("publishClipboardData",
			new Class[]  {Long.TYPE, (new byte[0]).getClass()});
	m.setAccessible(true);
}// ----------------------------------------------------------------------------------
public synchronized void setData(long format, byte[] data) throws IllegalAccessException, InvocationTargetException {
	setData(new long[]{format}, new byte[][]{data});
}// ----------------------------------------------------------------------------------

public synchronized void setData(long[] format, byte[][] data) throws IllegalAccessException, InvocationTargetException {
	openClipboard(this);
	try{
		for(int i=0;i<format.length && i<data.length;i++)
			myPublishClipboardData(format[i], data[i]);
		}
	finally {closeClipboard();}
}// ----------------------------------------------------------------------------------


protected void myPublishClipboardData(long format, byte[] bytes) throws IllegalAccessException, InvocationTargetException{
	m.invoke(this, new Object[]{new Long(format),bytes});
}// ----------------------------------------------------------------------------------
}

