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("[\\\\/:*?\"<>|]", ""); 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.Collection;
import java.util.List; import java.util.List;
import net.sourceforge.filebot.ui.FileBotUtil;
public class FileTransferable implements Transferable { public class FileTransferable implements Transferable {
private static final boolean fileListFlavorSupported = FileBotUtil.isFileListFlavorSupportedByWindowManager();
private List<File> files; private List<File> files;
@ -32,21 +36,47 @@ public class FileTransferable implements Transferable {
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { 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); 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() { public DataFlavor[] getTransferDataFlavors() {
DataFlavor[] flavours = { DataFlavor.javaFileListFlavor }; if (fileListFlavorSupported) {
return flavours; DataFlavor[] flavours = { DataFlavor.javaFileListFlavor };
return flavours;
} else {
DataFlavor[] flavours = { DataFlavor.javaFileListFlavor, DataFlavor.stringFlavor };
return flavours;
}
} }
public boolean isDataFlavorSupported(DataFlavor flavor) { 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 @Override
public void exportDone(JComponent source, Transferable data, int action) { public void exportDone(JComponent source, Transferable data, int action) {
try { try {
List<?> list = (List<?>) data.getTransferData(DataFlavor.javaFileListFlavor); List<File> files = (List<File>) data.getTransferData(DataFlavor.javaFileListFlavor);
for (Object object : list) { for (File file : files) {
File temporaryFile = (File) object; file.deleteOnExit();
temporaryFile.deleteOnExit();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -43,7 +43,7 @@ public class SaveableExportHandler implements ExportHandler {
@Override @Override
public int getSourceActions(JComponent c) { public int getSourceActions(JComponent c) {
if (saveable == null || !saveable.isSaveable()) if ((saveable == null) || !saveable.isSaveable())
return TransferHandler.NONE; return TransferHandler.NONE;
return TransferHandler.MOVE | TransferHandler.COPY; return TransferHandler.MOVE | TransferHandler.COPY;