import java.awt.datatransfer.*;
import java.awt.*;
import java.io.*;

/**
 * 
 * @author JPR
 *
 */
public class ServiceClipboard implements ClipboardOwner
{
	public void setClipboardContents(String s)
	{
		StringSelection ss = new StringSelection(s);
		//System.out.println("setClipboardContents: Nouveau contenu : " + s );
		Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, this);
	}

	public String getClipboardContents()
	{
		Transferable t= Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
		
		try
		{
			if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor))
			{
				String text = (String)t.getTransferData(DataFlavor.stringFlavor);
				//System.out.println("getClipboardContents: Contenu actuel du presse-papiers : " + text );
				return text;
			}
		}
		catch (UnsupportedFlavorException e)
		{
			System.out.println(e);
		}
		catch (IOException e)
		{
			System.out.println(e);
		}
		return null;
	}

	public void lostOwnership(Clipboard clipboard, Transferable contents)
	{
		//System.out.println("lostOwnership : " + contents);
	}
}
