1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-21 23:38:50 -05:00

use string flavor with text/uri list as content instead of filelist flavor on non-windows operating systems

This commit is contained in:
Reinhard Pointner 2008-02-14 23:07:10 +00:00
parent 3edd879d7e
commit 298f1f7585
3 changed files with 49 additions and 10 deletions

View File

@ -32,4 +32,13 @@ public class FileBotUtil {
return filename.replaceAll("[\\\\/:*?\"<>|]", "");
}
public static boolean isFileListFlavorSupportedByWindowManager() {
String os = System.getProperty("os.name");
if (os.toLowerCase().contains("windows"))
return true;
return false;
}
}

View File

@ -10,9 +10,13 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.sourceforge.filebot.ui.FileBotUtil;
public class FileTransferable implements Transferable {
private static final boolean fileListFlavorSupported = FileBotUtil.isFileListFlavorSupportedByWindowManager();
private List<File> files;
@ -32,21 +36,47 @@ public class FileTransferable implements Transferable {
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (!isDataFlavorSupported(flavor))
if (flavor.isFlavorJavaFileListType())
return files;
else if (flavor.isFlavorTextType())
return getUriList();
else
throw new UnsupportedFlavorException(flavor);
}
/**
*
* @return line separated list of file uris
*/
private String getUriList() {
StringBuffer sb = new StringBuffer();
return files;
for (File file : files) {
sb.append(file.toURI());
sb.append("\n");
}
return sb.toString();
}
public DataFlavor[] getTransferDataFlavors() {
DataFlavor[] flavours = { DataFlavor.javaFileListFlavor };
return flavours;
if (fileListFlavorSupported) {
DataFlavor[] flavours = { DataFlavor.javaFileListFlavor };
return flavours;
} else {
DataFlavor[] flavours = { DataFlavor.javaFileListFlavor, DataFlavor.stringFlavor };
return flavours;
}
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.isFlavorJavaFileListType();
if (fileListFlavorSupported)
return flavor.isFlavorJavaFileListType();
else
return flavor.isFlavorJavaFileListType() || flavor.isFlavorTextType();
}
}

View File

@ -26,14 +26,14 @@ public class SaveableExportHandler implements ExportHandler {
}
@SuppressWarnings("unchecked")
@Override
public void exportDone(JComponent source, Transferable data, int action) {
try {
List<?> list = (List<?>) data.getTransferData(DataFlavor.javaFileListFlavor);
List<File> files = (List<File>) data.getTransferData(DataFlavor.javaFileListFlavor);
for (Object object : list) {
File temporaryFile = (File) object;
temporaryFile.deleteOnExit();
for (File file : files) {
file.deleteOnExit();
}
} catch (Exception e) {
e.printStackTrace();
@ -43,7 +43,7 @@ public class SaveableExportHandler implements ExportHandler {
@Override
public int getSourceActions(JComponent c) {
if (saveable == null || !saveable.isSaveable())
if ((saveable == null) || !saveable.isSaveable())
return TransferHandler.NONE;
return TransferHandler.MOVE | TransferHandler.COPY;