diff --git a/src/main/java/me/goudham/model/TransferableImage.java b/src/main/java/me/goudham/model/TransferableImage.java new file mode 100644 index 0000000..bd5bb5b --- /dev/null +++ b/src/main/java/me/goudham/model/TransferableImage.java @@ -0,0 +1,38 @@ +package me.goudham.model; + +import java.awt.Image; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; + +public class TransferableImage implements Transferable { + + private final Image i; + + public TransferableImage(Image i) { + this.i = i; + } + + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { + if (flavor.equals(DataFlavor.imageFlavor) && i != null) { + return i; + } else { + throw new UnsupportedFlavorException(flavor); + } + } + + public DataFlavor[] getTransferDataFlavors() { + return new DataFlavor[] {DataFlavor.imageFlavor}; + } + + public boolean isDataFlavorSupported(DataFlavor flavor) { + DataFlavor[] flavors = getTransferDataFlavors(); + for (DataFlavor dataFlavor : flavors) { + if (flavor.equals(dataFlavor)) { + return true; + } + } + + return false; + } +}