diff --git a/source/net/sourceforge/filebot/FileBotUtil.java b/source/net/sourceforge/filebot/FileBotUtil.java index dd88ed6b..6ed11733 100644 --- a/source/net/sourceforge/filebot/FileBotUtil.java +++ b/source/net/sourceforge/filebot/FileBotUtil.java @@ -2,6 +2,8 @@ package net.sourceforge.filebot; +import java.util.Iterator; + import javax.swing.Action; import javax.swing.JComponent; import javax.swing.KeyStroke; @@ -46,4 +48,19 @@ public class FileBotUtil { return t; } + + public static String join(Iterable list, String delim) { + StringBuilder sb = new StringBuilder(); + + Iterator it = list.iterator(); + + while (it.hasNext()) { + sb.append(it.next().toString()); + + if (it.hasNext()) + sb.append(delim); + } + + return sb.toString(); + } } diff --git a/source/net/sourceforge/filebot/ui/FileBotList.java b/source/net/sourceforge/filebot/ui/FileBotList.java index e3f03206..5c779b82 100644 --- a/source/net/sourceforge/filebot/ui/FileBotList.java +++ b/source/net/sourceforge/filebot/ui/FileBotList.java @@ -28,9 +28,9 @@ import net.sourceforge.filebot.ui.transfer.ImportHandler; import net.sourceforge.filebot.ui.transfer.Saveable; import net.sourceforge.filebot.ui.transfer.SaveableExportHandler; import net.sourceforge.filebot.ui.transfer.TransferablePolicyImportHandler; +import net.sourceforge.filebot.ui.transfer.TransferablePolicySupport; import net.sourceforge.filebot.ui.transferablepolicies.NullTransferablePolicy; import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicy; -import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicySupport; import net.sourceforge.tuned.ui.FancyListCellRenderer; import net.sourceforge.tuned.ui.SimpleListModel; diff --git a/source/net/sourceforge/filebot/ui/FileBotTree.java b/source/net/sourceforge/filebot/ui/FileBotTree.java index c8ddcaed..0d00b9a0 100644 --- a/source/net/sourceforge/filebot/ui/FileBotTree.java +++ b/source/net/sourceforge/filebot/ui/FileBotTree.java @@ -26,9 +26,9 @@ import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; import net.sourceforge.filebot.resources.ResourceManager; +import net.sourceforge.filebot.ui.transfer.TransferablePolicySupport; import net.sourceforge.filebot.ui.transferablepolicies.NullTransferablePolicy; import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicy; -import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicySupport; public class FileBotTree extends JTree implements TransferablePolicySupport { @@ -49,7 +49,8 @@ public class FileBotTree extends JTree implements TransferablePolicySupport { public void clear() { - setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); + DefaultMutableTreeNode root = (DefaultMutableTreeNode) getModel().getRoot(); + root.removeAllChildren(); } diff --git a/source/net/sourceforge/filebot/ui/panel/analyze/FileTree.java b/source/net/sourceforge/filebot/ui/panel/analyze/FileTree.java index 78fba007..2d41edc0 100644 --- a/source/net/sourceforge/filebot/ui/panel/analyze/FileTree.java +++ b/source/net/sourceforge/filebot/ui/panel/analyze/FileTree.java @@ -6,7 +6,10 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.SwingWorker; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; @@ -14,7 +17,6 @@ import net.sourceforge.filebot.ui.FileBotTree; import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler; import net.sourceforge.filebot.ui.transfer.FileTransferable; import net.sourceforge.filebot.ui.transfer.TransferablePolicyImportHandler; -import net.sourceforge.filebot.ui.transferablepolicies.BackgroundFileTransferablePolicy; public class FileTree extends FileBotTree { @@ -22,9 +24,14 @@ public class FileTree extends FileBotTree { public static final String LOADING_PROPERTY = "loading"; public static final String CONTENT_PROPERTY = "content"; + private PostProcessor postProcessor; + public FileTree() { - setTransferablePolicy(new FileTreeTransferPolicy()); + FileTreeTransferPolicy transferPolicy = new FileTreeTransferPolicy((DefaultMutableTreeNode) getModel().getRoot()); + transferPolicy.addPropertyChangeListener(LOADING_PROPERTY, new LoadingPropertyChangeListener()); + + setTransferablePolicy(transferPolicy); setTransferHandler(new DefaultTransferHandler(new TransferablePolicyImportHandler(this), null)); } @@ -50,94 +57,73 @@ public class FileTree extends FileBotTree { } - private void contentChanged() { - List files = convertToList(); - firePropertyChange(CONTENT_PROPERTY, null, files); - } - - @Override public void clear() { - ((BackgroundFileTransferablePolicy) getTransferablePolicy()).cancelAll(); + FileTreeTransferPolicy transferPolicy = ((FileTreeTransferPolicy) getTransferablePolicy()); + boolean loading = transferPolicy.isActive(); + + if (loading) { + transferPolicy.cancelAll(); + } super.clear(); - contentChanged(); + + if (!loading) { + contentChanged(); + } + // else, contentChanged() will be called after when loading is finished } - - private class FileTreeTransferPolicy extends BackgroundFileTransferablePolicy implements PropertyChangeListener { - - public FileTreeTransferPolicy() { - addPropertyChangeListener(LOADING_PROPERTY, this); - } - - @Override - protected boolean accept(File file) { - return file.isFile() || file.isDirectory(); - } - - - @Override - protected void clear() { - FileTree.this.clear(); - } - - - @Override - protected void process(List chunks) { - DefaultMutableTreeNode root = (DefaultMutableTreeNode) getModel().getRoot(); + private void contentChanged() { + synchronized (this) { + if (postProcessor != null) + postProcessor.cancel(false); - for (DefaultMutableTreeNode node : chunks) { - root.add(node); + postProcessor = new PostProcessor(); + postProcessor.execute(); + } + }; + + + private class LoadingPropertyChangeListener implements PropertyChangeListener { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + Boolean loading = (Boolean) evt.getNewValue(); + + if (loading) { + firePropertyChange(FileTree.LOADING_PROPERTY, null, true); + } else { + contentChanged(); + } + } + } + + + private class PostProcessor extends SwingWorker, Object> { + + @Override + protected List doInBackground() throws Exception { + return convertToList(); + } + + + @Override + protected void done() { + if (isCancelled()) + return; + + try { + List files = get(); + FileTree.this.firePropertyChange(CONTENT_PROPERTY, null, files); + } catch (Exception e) { + Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e); } + FileTree.this.firePropertyChange(FileTree.LOADING_PROPERTY, null, false); updateUI(); } - - @Override - protected void load(List files) { - for (File file : files) { - publish(getTree(file)); - } - } - - - private DefaultMutableTreeNode getTree(File file) { - DefaultMutableTreeNode node = new DefaultMutableTreeNode(file); - - if (file.isDirectory() && !Thread.currentThread().isInterrupted()) { - // run through file tree - for (File f : file.listFiles()) { - node.add(getTree(f)); - } - } - - return node; - } - - - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName() == BackgroundFileTransferablePolicy.LOADING_PROPERTY) { - Boolean loading = (Boolean) evt.getNewValue(); - - if (loading) { - FileTree.this.firePropertyChange(FileTree.LOADING_PROPERTY, null, true); - } else { - FileTree.this.firePropertyChange(FileTree.LOADING_PROPERTY, null, false); - - contentChanged(); - } - } - } - - - @Override - public String getDescription() { - return "files and folders"; - } - } - } diff --git a/source/net/sourceforge/filebot/ui/panel/analyze/FileTreeTransferPolicy.java b/source/net/sourceforge/filebot/ui/panel/analyze/FileTreeTransferPolicy.java new file mode 100644 index 00000000..77e2e971 --- /dev/null +++ b/source/net/sourceforge/filebot/ui/panel/analyze/FileTreeTransferPolicy.java @@ -0,0 +1,70 @@ + +package net.sourceforge.filebot.ui.panel.analyze; + + +import java.io.File; +import java.util.List; + +import javax.swing.tree.DefaultMutableTreeNode; + +import net.sourceforge.filebot.ui.transferablepolicies.BackgroundFileTransferablePolicy; + + +class FileTreeTransferPolicy extends BackgroundFileTransferablePolicy { + + DefaultMutableTreeNode root; + + + public FileTreeTransferPolicy(DefaultMutableTreeNode root) { + this.root = root; + } + + + @Override + protected boolean accept(File file) { + return file.isFile() || file.isDirectory(); + } + + + @Override + protected void clear() { + root.removeAllChildren(); + } + + + @Override + protected void process(List chunks) { + for (DefaultMutableTreeNode node : chunks) { + root.add(node); + } + } + + + @Override + protected void load(List files) { + for (File file : files) { + publish(getTree(file)); + } + } + + + private DefaultMutableTreeNode getTree(File file) { + DefaultMutableTreeNode node = new DefaultMutableTreeNode(file); + + if (file.isDirectory() && !Thread.currentThread().isInterrupted()) { + // run through file tree + for (File f : file.listFiles()) { + node.add(getTree(f)); + } + } + + return node; + } + + + @Override + public String getDescription() { + return "files and folders"; + } + +} diff --git a/source/net/sourceforge/filebot/ui/panel/list/FileListTransferablePolicy.java b/source/net/sourceforge/filebot/ui/panel/list/FileListTransferablePolicy.java index 9228cae2..fd2b7d60 100644 --- a/source/net/sourceforge/filebot/ui/panel/list/FileListTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/panel/list/FileListTransferablePolicy.java @@ -13,7 +13,7 @@ import net.sourceforge.filebot.ui.FileBotList; import net.sourceforge.filebot.ui.transferablepolicies.FileTransferablePolicy; -public class FileListTransferablePolicy extends FileTransferablePolicy { +class FileListTransferablePolicy extends FileTransferablePolicy { private FileBotList list; diff --git a/source/net/sourceforge/filebot/ui/panel/rename/FilesRenameListTransferablePolicy.java b/source/net/sourceforge/filebot/ui/panel/rename/FilesListTransferablePolicy.java similarity index 85% rename from source/net/sourceforge/filebot/ui/panel/rename/FilesRenameListTransferablePolicy.java rename to source/net/sourceforge/filebot/ui/panel/rename/FilesListTransferablePolicy.java index 2d6af472..edd39431 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/FilesRenameListTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/FilesListTransferablePolicy.java @@ -10,12 +10,12 @@ import net.sourceforge.filebot.ui.transferablepolicies.FileTransferablePolicy; import net.sourceforge.tuned.ui.SimpleListModel; -public class FilesRenameListTransferablePolicy extends FileTransferablePolicy { +class FilesListTransferablePolicy extends FileTransferablePolicy { private SimpleListModel listModel; - public FilesRenameListTransferablePolicy(SimpleListModel listModel) { + public FilesListTransferablePolicy(SimpleListModel listModel) { this.listModel = listModel; } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/FilesRenameList.java b/source/net/sourceforge/filebot/ui/panel/rename/FilesRenameList.java index 0dc95c9b..aaea9fc6 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/FilesRenameList.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/FilesRenameList.java @@ -11,7 +11,7 @@ public class FilesRenameList extends RenameList { public FilesRenameList() { setTitle("Files"); - setTransferablePolicy(new FilesRenameListTransferablePolicy(getModel())); + setTransferablePolicy(new FilesListTransferablePolicy(getModel())); } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/NamesRenameListTransferablePolicy.java b/source/net/sourceforge/filebot/ui/panel/rename/NamesListTransferablePolicy.java similarity index 83% rename from source/net/sourceforge/filebot/ui/panel/rename/NamesRenameListTransferablePolicy.java rename to source/net/sourceforge/filebot/ui/panel/rename/NamesListTransferablePolicy.java index 33beb721..1e0dd617 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/NamesRenameListTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/NamesListTransferablePolicy.java @@ -16,23 +16,23 @@ import net.sourceforge.filebot.ui.panel.rename.entry.TorrentEntry; import net.sourceforge.filebot.ui.transferablepolicies.FileTransferablePolicy; import net.sourceforge.filebot.ui.transferablepolicies.MultiTransferablePolicy; import net.sourceforge.filebot.ui.transferablepolicies.TextTransferablePolicy; -import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicy; import net.sourceforge.tuned.ui.SimpleListModel; -public class NamesRenameListTransferablePolicy extends MultiTransferablePolicy { +class NamesListTransferablePolicy extends MultiTransferablePolicy { private SimpleListModel listModel; - public NamesRenameListTransferablePolicy(SimpleListModel listModel) { + public NamesListTransferablePolicy(SimpleListModel listModel) { this.listModel = listModel; - addPolicy(filePolicy); - addPolicy(textPolicy); + addPolicy(new FilePolicy()); + addPolicy(new TextPolicy()); } - private TransferablePolicy filePolicy = new FileTransferablePolicy() { + + private class FilePolicy extends FileTransferablePolicy { private long MAX_FILESIZE = 10 * FileFormat.MEGA; @@ -83,7 +83,8 @@ public class NamesRenameListTransferablePolicy extends MultiTransferablePolicy { }; - private TransferablePolicy textPolicy = new TextTransferablePolicy() { + + private class TextPolicy extends TextTransferablePolicy { @Override protected boolean load(String text) { @@ -107,7 +108,7 @@ public class NamesRenameListTransferablePolicy extends MultiTransferablePolicy { @Override public String getDescription() { - return "Lines of text"; + return "lines of text"; } }; diff --git a/source/net/sourceforge/filebot/ui/panel/rename/NamesRenameList.java b/source/net/sourceforge/filebot/ui/panel/rename/NamesRenameList.java index c163ce80..770f07a0 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/NamesRenameList.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/NamesRenameList.java @@ -11,7 +11,7 @@ public class NamesRenameList extends RenameList { public NamesRenameList() { setTitle("Names"); - setTransferablePolicy(new NamesRenameListTransferablePolicy(this.getModel())); + setTransferablePolicy(new NamesListTransferablePolicy(this.getModel())); } diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java index 468d2c0c..a5e64524 100644 --- a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java +++ b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java @@ -28,10 +28,10 @@ import net.sourceforge.filebot.ui.transfer.ImportHandler; import net.sourceforge.filebot.ui.transfer.Saveable; import net.sourceforge.filebot.ui.transfer.SaveableExportHandler; import net.sourceforge.filebot.ui.transfer.TransferablePolicyImportHandler; +import net.sourceforge.filebot.ui.transfer.TransferablePolicySupport; import net.sourceforge.filebot.ui.transferablepolicies.BackgroundFileTransferablePolicy; import net.sourceforge.filebot.ui.transferablepolicies.NullTransferablePolicy; import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicy; -import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicySupport; public class SfvTable extends JTable implements TransferablePolicySupport, Saveable { diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTransferablePolicy.java b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTransferablePolicy.java index 620c028d..6bf9f5ef 100644 --- a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTransferablePolicy.java @@ -17,7 +17,7 @@ import net.sourceforge.filebot.FileFormat; import net.sourceforge.filebot.ui.transferablepolicies.BackgroundFileTransferablePolicy; -public class SfvTransferablePolicy extends BackgroundFileTransferablePolicy { +class SfvTransferablePolicy extends BackgroundFileTransferablePolicy { private SfvTableModel tableModel; diff --git a/source/net/sourceforge/filebot/ui/transfer/LoadAction.java b/source/net/sourceforge/filebot/ui/transfer/LoadAction.java index 201631c7..e69181e4 100644 --- a/source/net/sourceforge/filebot/ui/transfer/LoadAction.java +++ b/source/net/sourceforge/filebot/ui/transfer/LoadAction.java @@ -9,7 +9,6 @@ import javax.swing.JFileChooser; import net.sourceforge.filebot.resources.ResourceManager; import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicy; -import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicySupport; public class LoadAction extends AbstractAction { diff --git a/source/net/sourceforge/filebot/ui/transfer/TransferablePolicyImportHandler.java b/source/net/sourceforge/filebot/ui/transfer/TransferablePolicyImportHandler.java index 4d4fee23..1cc26b01 100644 --- a/source/net/sourceforge/filebot/ui/transfer/TransferablePolicyImportHandler.java +++ b/source/net/sourceforge/filebot/ui/transfer/TransferablePolicyImportHandler.java @@ -10,7 +10,6 @@ import java.util.logging.Logger; import javax.swing.TransferHandler; import javax.swing.TransferHandler.TransferSupport; -import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicySupport; public class TransferablePolicyImportHandler implements ImportHandler { diff --git a/source/net/sourceforge/filebot/ui/transferablepolicies/TransferablePolicySupport.java b/source/net/sourceforge/filebot/ui/transfer/TransferablePolicySupport.java similarity index 59% rename from source/net/sourceforge/filebot/ui/transferablepolicies/TransferablePolicySupport.java rename to source/net/sourceforge/filebot/ui/transfer/TransferablePolicySupport.java index b7f1d541..59dde109 100644 --- a/source/net/sourceforge/filebot/ui/transferablepolicies/TransferablePolicySupport.java +++ b/source/net/sourceforge/filebot/ui/transfer/TransferablePolicySupport.java @@ -1,5 +1,8 @@ -package net.sourceforge.filebot.ui.transferablepolicies; +package net.sourceforge.filebot.ui.transfer; + + +import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicy; public interface TransferablePolicySupport { diff --git a/source/net/sourceforge/filebot/ui/transferablepolicies/BackgroundFileTransferablePolicy.java b/source/net/sourceforge/filebot/ui/transferablepolicies/BackgroundFileTransferablePolicy.java index 4316077f..c536ba49 100644 --- a/source/net/sourceforge/filebot/ui/transferablepolicies/BackgroundFileTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/transferablepolicies/BackgroundFileTransferablePolicy.java @@ -3,6 +3,8 @@ package net.sourceforge.filebot.ui.transferablepolicies; import java.awt.datatransfer.Transferable; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; import java.io.File; import java.util.Arrays; import java.util.List; @@ -47,7 +49,12 @@ public abstract class BackgroundFileTransferablePolicy extends FileTransferab public boolean isActive() { - return executor.isActive(); + synchronized (this) { + if (executor == null) + return false; + + return executor.isActive(); + } } @@ -169,4 +176,25 @@ public abstract class BackgroundFileTransferablePolicy extends FileTransferab } + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); + + + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + propertyChangeSupport.addPropertyChangeListener(propertyName, listener); + } + + + public void removePropertyChangeListener(PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(listener); + } + + + public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, listener); + } + + + protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); + } } diff --git a/source/net/sourceforge/filebot/ui/transferablepolicies/FileTransferablePolicy.java b/source/net/sourceforge/filebot/ui/transferablepolicies/FileTransferablePolicy.java index 393e2022..e37fbd50 100644 --- a/source/net/sourceforge/filebot/ui/transferablepolicies/FileTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/transferablepolicies/FileTransferablePolicy.java @@ -6,6 +6,7 @@ import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.net.URI; import java.util.ArrayList; @@ -17,13 +18,10 @@ import java.util.logging.Logger; import net.sourceforge.filebot.ui.transfer.FileTransferable; -public abstract class FileTransferablePolicy extends TransferablePolicy { +public abstract class FileTransferablePolicy implements TransferablePolicy { @Override public boolean accept(Transferable tr) { - if (!isEnabled()) - return false; - List files = getFilesFromTransferable(tr); if ((files == null) || files.isEmpty()) @@ -37,8 +35,10 @@ public abstract class FileTransferablePolicy extends TransferablePolicy { protected List getFilesFromTransferable(Transferable tr) { try { if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { + // file list flavor return (List) tr.getTransferData(DataFlavor.javaFileListFlavor); } else if (tr.isDataFlavorSupported(FileTransferable.uriListFlavor)) { + // file uri list flavor String transferString = (String) tr.getTransferData(FileTransferable.uriListFlavor); String lines[] = transferString.split("\r?\n"); @@ -53,10 +53,12 @@ public abstract class FileTransferablePolicy extends TransferablePolicy { try { File file = new File(new URI(line)); - if (file.exists()) - files.add(file); + if (!file.exists()) + throw new FileNotFoundException(file.toString()); + + files.add(file); } catch (Exception e) { - // URISyntaxException, IllegalArgumentException + // URISyntaxException, IllegalArgumentException, FileNotFoundException Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.WARNING, "Invalid file url: " + line); } } diff --git a/source/net/sourceforge/filebot/ui/transferablepolicies/MultiTransferablePolicy.java b/source/net/sourceforge/filebot/ui/transferablepolicies/MultiTransferablePolicy.java index 64111012..76dd6f3e 100644 --- a/source/net/sourceforge/filebot/ui/transferablepolicies/MultiTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/transferablepolicies/MultiTransferablePolicy.java @@ -3,15 +3,16 @@ package net.sourceforge.filebot.ui.transferablepolicies; import java.awt.datatransfer.Transferable; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.util.ArrayList; -import java.util.Iterator; +import java.util.Collections; +import java.util.List; + +import net.sourceforge.filebot.FileBotUtil; -public class MultiTransferablePolicy extends TransferablePolicy { +public class MultiTransferablePolicy implements TransferablePolicy { - private ArrayList policies = new ArrayList(); + private List policies = Collections.synchronizedList(new ArrayList()); public MultiTransferablePolicy() { @@ -21,21 +22,16 @@ public class MultiTransferablePolicy extends TransferablePolicy { public void addPolicy(TransferablePolicy policy) { policies.add(policy); - policy.addPropertyChangeListener(relayListener); } public void removePolicy(TransferablePolicy policy) { - policy.removePropertyChangeListener(relayListener); policies.remove(policy); } @Override public boolean accept(Transferable tr) { - if (!isEnabled()) - return false; - for (TransferablePolicy policy : policies) { if (policy.accept(tr)) return true; @@ -55,14 +51,7 @@ public class MultiTransferablePolicy extends TransferablePolicy { } } - private final PropertyChangeListener relayListener = new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(evt); - } - }; - - + @Override public String getDescription() { return getDescription(TransferablePolicy.class); @@ -70,9 +59,7 @@ public class MultiTransferablePolicy extends TransferablePolicy { public String getDescription(Class filter) { - StringBuffer sb = new StringBuffer(); - - ArrayList descriptions = new ArrayList(); + List descriptions = new ArrayList(); for (TransferablePolicy policy : policies) { String desc = policy.getDescription(); @@ -81,17 +68,7 @@ public class MultiTransferablePolicy extends TransferablePolicy { descriptions.add(desc); } - Iterator it = descriptions.iterator(); - - while (it.hasNext()) { - String desc = it.next(); - sb.append(desc); - - if (it.hasNext()) - sb.append(", "); - } - - return sb.toString(); + return FileBotUtil.join(descriptions, ", "); } } diff --git a/source/net/sourceforge/filebot/ui/transferablepolicies/NullTransferablePolicy.java b/source/net/sourceforge/filebot/ui/transferablepolicies/NullTransferablePolicy.java index affea9e2..985c4630 100644 --- a/source/net/sourceforge/filebot/ui/transferablepolicies/NullTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/transferablepolicies/NullTransferablePolicy.java @@ -5,7 +5,7 @@ package net.sourceforge.filebot.ui.transferablepolicies; import java.awt.datatransfer.Transferable; -public class NullTransferablePolicy extends TransferablePolicy { +public class NullTransferablePolicy implements TransferablePolicy { @Override public boolean accept(Transferable tr) { diff --git a/source/net/sourceforge/filebot/ui/transferablepolicies/TextTransferablePolicy.java b/source/net/sourceforge/filebot/ui/transferablepolicies/TextTransferablePolicy.java index 68be7475..a87d55e0 100644 --- a/source/net/sourceforge/filebot/ui/transferablepolicies/TextTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/transferablepolicies/TextTransferablePolicy.java @@ -8,13 +8,10 @@ import java.util.logging.Level; import java.util.logging.Logger; -public abstract class TextTransferablePolicy extends TransferablePolicy { +public abstract class TextTransferablePolicy implements TransferablePolicy { @Override public boolean accept(Transferable tr) { - if (!isEnabled()) - return false; - return tr.isDataFlavorSupported(DataFlavor.stringFlavor); } diff --git a/source/net/sourceforge/filebot/ui/transferablepolicies/TransferablePolicy.java b/source/net/sourceforge/filebot/ui/transferablepolicies/TransferablePolicy.java index 30bb2e11..933bdf49 100644 --- a/source/net/sourceforge/filebot/ui/transferablepolicies/TransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/transferablepolicies/TransferablePolicy.java @@ -3,68 +3,16 @@ package net.sourceforge.filebot.ui.transferablepolicies; import java.awt.datatransfer.Transferable; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -public abstract class TransferablePolicy { +public interface TransferablePolicy { - public abstract boolean accept(Transferable tr); + public boolean accept(Transferable tr); - public abstract void handleTransferable(Transferable tr, boolean add); - - private boolean enabled = true; - - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); - - public static final String ENABLED_PROPERTY = "enabled"; - - - public abstract String getDescription(); + public void handleTransferable(Transferable tr, boolean add); - //TODO remove enabled stuff - public boolean isEnabled() { - return enabled; - } - - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - - firePropertyChange(ENABLED_PROPERTY, null, enabled); - } - - - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(propertyName, listener); - } - - - public void removePropertyChangeListener(PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, listener); - } - - - protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); - } - - - protected void firePropertyChange(PropertyChangeEvent evt) { - propertyChangeSupport.firePropertyChange(evt); - } + public String getDescription(); }