Create TransferableImage class for transferring images to system clipboard

osx
Hammy 3 years ago
parent 36b1d42fbe
commit bfb6ee0346

@ -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;
}
}
Loading…
Cancel
Save