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

* drop to file works on ubuntu now :D

This commit is contained in:
Reinhard Pointner 2008-02-15 18:57:18 +00:00
parent 298f1f7585
commit 036eefc5b9
12 changed files with 90 additions and 119 deletions

View File

@ -2,6 +2,8 @@
package net.sourceforge.filebot.ui;
import java.awt.datatransfer.DataFlavor;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
@ -32,13 +34,18 @@ public class FileBotUtil {
return filename.replaceAll("[\\\\/:*?\"<>|]", "");
}
public static boolean isFileListFlavorSupportedByWindowManager() {
String os = System.getProperty("os.name");
public static final DataFlavor uriListFlavor = createUriListFlavor();
private static DataFlavor createUriListFlavor() {
try {
return new DataFlavor("text/uri-list;class=java.lang.String");
} catch (ClassNotFoundException e) {
// will never happen
e.printStackTrace();
}
if (os.toLowerCase().contains("windows"))
return true;
return false;
return null;
}
}

View File

@ -100,15 +100,13 @@ public class FileTree extends FileBotTree {
@Override
protected boolean load(List<File> files) {
protected void load(List<File> files) {
DefaultMutableTreeNode root = (DefaultMutableTreeNode) getModel().getRoot();
File fileArray[] = new File[files.size()];
files.toArray(fileArray);
addFiles(root, fileArray);
return true;
}

View File

@ -50,7 +50,7 @@ public class SfvTransferablePolicy extends MultiTransferablePolicy {
@Override
protected boolean load(List<File> files) {
protected void load(List<File> files) {
synchronized (ChecksumComputationExecutor.getInstance()) {
ChecksumComputationExecutor.getInstance().pause();
@ -60,8 +60,6 @@ public class SfvTransferablePolicy extends MultiTransferablePolicy {
ChecksumComputationExecutor.getInstance().resume();
}
return true;
}
@ -134,16 +132,16 @@ public class SfvTransferablePolicy extends MultiTransferablePolicy {
@Override
protected boolean load(List<File> files) {
protected void load(List<File> files) {
if (files.isEmpty())
return true;
return;
synchronized (ChecksumComputationExecutor.getInstance()) {
ChecksumComputationExecutor.getInstance().pause();
File firstFile = files.get(0);
if (files.size() == 1 && firstFile.isDirectory()) {
if ((files.size() == 1) && firstFile.isDirectory()) {
for (File f : firstFile.listFiles()) {
load(f, firstFile, "");
}
@ -155,8 +153,6 @@ public class SfvTransferablePolicy extends MultiTransferablePolicy {
ChecksumComputationExecutor.getInstance().resume();
}
return true;
}

View File

@ -15,10 +15,10 @@ import net.sourceforge.filebot.ui.FileBotUtil;
public class FileTransferable implements Transferable {
private static final boolean fileListFlavorSupported = FileBotUtil.isFileListFlavorSupportedByWindowManager();
private List<File> files;
private DataFlavor[] supportedFlavors = { DataFlavor.javaFileListFlavor, FileBotUtil.uriListFlavor };
public FileTransferable(File... fileArray) {
files = new ArrayList<File>(fileArray.length);
@ -38,7 +38,7 @@ public class FileTransferable implements Transferable {
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (flavor.isFlavorJavaFileListType())
return files;
else if (flavor.isFlavorTextType())
else if (flavor.equals(FileBotUtil.uriListFlavor))
return getUriList();
else
throw new UnsupportedFlavorException(flavor);
@ -54,7 +54,7 @@ public class FileTransferable implements Transferable {
for (File file : files) {
sb.append(file.toURI());
sb.append("\n");
sb.append("\r\n");
}
return sb.toString();
@ -62,21 +62,16 @@ public class FileTransferable implements Transferable {
public DataFlavor[] getTransferDataFlavors() {
if (fileListFlavorSupported) {
DataFlavor[] flavours = { DataFlavor.javaFileListFlavor };
return flavours;
} else {
DataFlavor[] flavours = { DataFlavor.javaFileListFlavor, DataFlavor.stringFlavor };
return flavours;
}
return supportedFlavors;
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
if (fileListFlavorSupported)
return flavor.isFlavorJavaFileListType();
else
return flavor.isFlavorJavaFileListType() || flavor.isFlavorTextType();
for (DataFlavor supportedFlavor : supportedFlavors) {
if (flavor.equals(supportedFlavor))
return true;
}
return false;
}
}

View File

@ -33,7 +33,8 @@ public class SaveableExportHandler implements ExportHandler {
List<File> files = (List<File>) data.getTransferData(DataFlavor.javaFileListFlavor);
for (File file : files) {
file.deleteOnExit();
if (file.exists())
file.deleteOnExit();
}
} catch (Exception e) {
e.printStackTrace();

View File

@ -49,7 +49,9 @@ public class TransferablePolicyImportHandler implements ImportHandler {
Transferable t = support.getTransferable();
return transferablePolicySupport.getTransferablePolicy().handleTransferable(t, add);
transferablePolicySupport.getTransferablePolicy().handleTransferable(t, add);
return true;
}
}

View File

@ -20,11 +20,11 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
@Override
public boolean handleTransferable(Transferable tr, boolean add) {
public void handleTransferable(Transferable tr, boolean add) {
List<File> files = getFilesFromTransferable(tr);
if (files == null)
return false;
return;
if (!add)
clear();
@ -32,8 +32,6 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
backgroundWorker = new BackgroundWorker(files);
backgroundWorker.addPropertyChangeListener(new BackgroundWorkerListener());
backgroundWorker.execute();
return true;
}
@ -48,7 +46,8 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
/**
* Receives data chunks from the publish method asynchronously on the Event Dispatch Thread.
* Receives data chunks from the publish method asynchronously on the Event Dispatch
* Thread.
*
* @param chunks
*/

View File

@ -8,90 +8,59 @@ import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sourceforge.filebot.ui.FileBotUtil;
public abstract class FileTransferablePolicy extends TransferablePolicy {
@Override
public boolean accept(Transferable tr) {
if (!isEnabled())
return false;
List<File> files = getFilesFromTransferable(tr);
if (files == null || files.isEmpty())
if ((files == null) || files.isEmpty())
return false;
return accept(files);
}
@SuppressWarnings("unchecked")
protected List<File> getFilesFromTransferable(Transferable tr) {
List<File> files = getFilesFromFileTransferable(tr);
// if there is no file transferable, look if there is a string transferable that
// contains file uris
if (files == null)
files = getFilesFromStringTransferable(tr);
Collections.sort(files);
return files;
}
protected List<File> getFilesFromFileTransferable(Transferable tr) {
if (!tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
return null;
try {
List<?> list = (List<?>) tr.getTransferData(DataFlavor.javaFileListFlavor);
ArrayList<File> files = new ArrayList<File>(list.size());
for (Object object : list)
files.add((File) object);
if (!files.isEmpty())
return files;
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
protected List<File> getFilesFromStringTransferable(Transferable tr) {
if (!tr.isDataFlavorSupported(DataFlavor.stringFlavor))
return null;
try {
String transferString = (String) tr.getTransferData(DataFlavor.stringFlavor);
String lines[] = transferString.split("\r?\n");
ArrayList<File> files = new ArrayList<File>(lines.length);
for (String line : lines) {
try {
File file = new File(new URI(line));
if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
return (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
} else if (tr.isDataFlavorSupported(FileBotUtil.uriListFlavor)) {
String transferString = (String) tr.getTransferData(DataFlavor.stringFlavor);
String lines[] = transferString.split("\r?\n");
ArrayList<File> files = new ArrayList<File>(lines.length);
for (String line : lines) {
if (line.startsWith("#")) {
// the line is a comment (as per the RFC 2483)
continue;
}
if (file.exists())
files.add(file);
} catch (URISyntaxException e) {
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.WARNING, "Invalid file url: " + line, e);
try {
File file = new File(new URI(line));
if (file.exists())
files.add(file);
} catch (Exception e) {
// URISyntaxException, IllegalArgumentException
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.WARNING, "Invalid file url: " + line, e);
}
}
}
if (!files.isEmpty())
return files;
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
@ -102,16 +71,19 @@ public abstract class FileTransferablePolicy extends TransferablePolicy {
}
public boolean handleTransferable(Transferable tr, boolean add) {
@Override
public void handleTransferable(Transferable tr, boolean add) {
List<File> files = getFilesFromTransferable(tr);
if (files == null)
return false;
return;
Collections.sort(files);
if (!add)
clear();
return load(files);
load(files);
}
@ -124,14 +96,10 @@ public abstract class FileTransferablePolicy extends TransferablePolicy {
}
protected boolean load(List<File> files) {
boolean success = false;
protected void load(List<File> files) {
for (File file : files) {
success |= load(file);
load(file);
}
return success;
}

View File

@ -31,6 +31,7 @@ public class MultiTransferablePolicy extends TransferablePolicy {
}
@Override
public boolean accept(Transferable tr) {
if (!isEnabled())
return false;
@ -44,13 +45,14 @@ public class MultiTransferablePolicy extends TransferablePolicy {
}
public boolean handleTransferable(Transferable tr, boolean add) {
@Override
public void handleTransferable(Transferable tr, boolean add) {
for (TransferablePolicy policy : policies) {
if (policy.accept(tr))
return policy.handleTransferable(tr, add);
if (policy.accept(tr)) {
policy.handleTransferable(tr, add);
return;
}
}
return true;
}
private final PropertyChangeListener relayListener = new PropertyChangeListener() {

View File

@ -7,13 +7,15 @@ import java.awt.datatransfer.Transferable;
public class NullTransferablePolicy extends TransferablePolicy {
@Override
public boolean accept(Transferable tr) {
return false;
}
public boolean handleTransferable(Transferable tr, boolean add) {
return false;
@Override
public void handleTransferable(Transferable tr, boolean add) {
}

View File

@ -8,6 +8,7 @@ import java.awt.datatransfer.Transferable;
public abstract class TextTransferablePolicy extends TransferablePolicy {
@Override
public boolean accept(Transferable tr) {
if (!isEnabled())
return false;
@ -16,7 +17,8 @@ public abstract class TextTransferablePolicy extends TransferablePolicy {
}
public boolean handleTransferable(Transferable tr, boolean add) {
@Override
public void handleTransferable(Transferable tr, boolean add) {
try {
String string = (String) tr.getTransferData(DataFlavor.stringFlavor);
@ -24,10 +26,9 @@ public abstract class TextTransferablePolicy extends TransferablePolicy {
clear();
}
return load(string);
load(string);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

View File

@ -13,7 +13,7 @@ public abstract class TransferablePolicy {
public abstract boolean accept(Transferable tr);
public abstract boolean handleTransferable(Transferable tr, boolean add);
public abstract void handleTransferable(Transferable tr, boolean add);
private boolean enabled = true;