001/**
002 * 
003 */
004package icy.clipboard;
005
006import java.awt.Image;
007import java.awt.datatransfer.DataFlavor;
008import java.awt.datatransfer.Transferable;
009import java.awt.datatransfer.UnsupportedFlavorException;
010import java.io.IOException;
011
012/**
013 * @author Stephane
014 */
015public class TransferableImage implements Transferable
016{
017    public Image image;
018
019    public TransferableImage(Image img)
020    {
021        super();
022
023        image = img;
024    }
025
026    @Override
027    public DataFlavor[] getTransferDataFlavors()
028    {
029        return new DataFlavor[] {DataFlavor.imageFlavor};
030    }
031
032    @Override
033    public boolean isDataFlavorSupported(DataFlavor flavor)
034    {
035        return DataFlavor.imageFlavor.equals(flavor);
036    }
037
038    @Override
039    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
040    {
041        if (isDataFlavorSupported(flavor) && (image != null))
042            return image;
043
044        throw new UnsupportedFlavorException(flavor);
045    }
046}