Implement transferable for list of files

MYC-Refactor
Hammy 3 years ago
parent 992e396504
commit 5af7481679

@ -0,0 +1,43 @@
package me.goudham.domain;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.util.List;
import org.jetbrains.annotations.NotNull;
public class TransferableFileList implements Transferable {
private final List<File> fileList;
public TransferableFileList(@NotNull List<File> fileList) {
this.fileList = fileList;
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (flavor.equals(DataFlavor.javaFileListFlavor)) {
return fileList;
} else {
throw new UnsupportedFlavorException(flavor);
}
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { DataFlavor.javaFileListFlavor };
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
DataFlavor[] flavors = getTransferDataFlavors();
for (DataFlavor dataFlavor : flavors) {
if (flavor.equals(dataFlavor)) {
return true;
}
}
return false;
}
}
Loading…
Cancel
Save