mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 00:38:52 -05:00
* support dropping of large / slow folders into Rename panel (Files list)
This commit is contained in:
parent
124e7471db
commit
98633f7364
@ -7,7 +7,6 @@ import java.text.ParseException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.JSpinner.DefaultEditor;
|
||||
import javax.swing.SwingConstants;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.filebot.ui.rename;
|
||||
|
||||
import static net.filebot.MediaTypes.*;
|
||||
import static net.filebot.ui.NotificationLogging.*;
|
||||
import static net.filebot.ui.transfer.FileTransferable.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
|
||||
@ -14,10 +15,11 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.filebot.media.MediaDetection;
|
||||
import net.filebot.ui.transfer.FileTransferablePolicy;
|
||||
import net.filebot.ui.transfer.BackgroundFileTransferablePolicy;
|
||||
import net.filebot.util.ExceptionUtilities;
|
||||
import net.filebot.util.FastFile;
|
||||
|
||||
class FilesListTransferablePolicy extends FileTransferablePolicy {
|
||||
class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File> {
|
||||
|
||||
private final List<File> model;
|
||||
|
||||
@ -93,7 +95,7 @@ class FilesListTransferablePolicy extends FileTransferablePolicy {
|
||||
}
|
||||
}
|
||||
|
||||
model.addAll(FastFile.create(entries));
|
||||
publish(FastFile.create(entries).toArray(new File[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -101,4 +103,14 @@ class FilesListTransferablePolicy extends FileTransferablePolicy {
|
||||
return "files and folders";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void process(List<File> chunks) {
|
||||
model.addAll(FastFile.create(chunks));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void process(Exception e) {
|
||||
UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -179,6 +179,10 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
}
|
||||
|
||||
protected float getMatchProbablity(Match<Object, File> match) {
|
||||
if (match.getValue() == null || match.getCandidate() == null) {
|
||||
return 1; // assume match is ok
|
||||
}
|
||||
|
||||
if (match.getValue() instanceof Episode) {
|
||||
float f = verificationMetric().getSimilarity(match.getValue(), match.getCandidate());
|
||||
return (f + 1) / 2; // normalize -1..1 to 0..1
|
||||
|
@ -58,6 +58,7 @@ import net.filebot.media.MediaDetection;
|
||||
import net.filebot.similarity.Match;
|
||||
import net.filebot.ui.rename.FormatDialog.Mode;
|
||||
import net.filebot.ui.rename.RenameModel.FormattedFuture;
|
||||
import net.filebot.ui.transfer.BackgroundFileTransferablePolicy;
|
||||
import net.filebot.util.PreferencesMap.PreferencesEntry;
|
||||
import net.filebot.util.ui.ActionPopup;
|
||||
import net.filebot.util.ui.LoadingOverlayPane;
|
||||
@ -287,7 +288,18 @@ public class RenamePanel extends JComponent {
|
||||
});
|
||||
|
||||
setLayout(new MigLayout("fill, insets dialog, gapx 10px", "[fill][align center, pref!][fill]", "align 33%"));
|
||||
add(filesList, "grow, sizegroupx list");
|
||||
add(new LoadingOverlayPane(filesList, filesList, "32px", "30px"), "grow, sizegroupx list");
|
||||
|
||||
BackgroundFileTransferablePolicy<?> transferablePolicy = (BackgroundFileTransferablePolicy<?>) filesList.getTransferablePolicy();
|
||||
transferablePolicy.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (BackgroundFileTransferablePolicy.LOADING_PROPERTY.equals(evt.getPropertyName())) {
|
||||
filesList.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, (boolean) evt.getOldValue(), (boolean) evt.getNewValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// make buttons larger
|
||||
matchButton.setMargin(new Insets(3, 14, 2, 14));
|
||||
|
@ -1,7 +1,5 @@
|
||||
|
||||
package net.filebot.ui.transfer;
|
||||
|
||||
|
||||
import static net.filebot.ui.transfer.FileTransferable.*;
|
||||
|
||||
import java.awt.datatransfer.Transferable;
|
||||
@ -15,42 +13,37 @@ import javax.swing.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.event.SwingPropertyChangeSupport;
|
||||
|
||||
|
||||
public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferablePolicy {
|
||||
|
||||
|
||||
public static final String LOADING_PROPERTY = "loading";
|
||||
|
||||
|
||||
private final ThreadLocal<BackgroundWorker> threadLocalWorker = new ThreadLocal<BackgroundWorker>();
|
||||
|
||||
|
||||
private final List<BackgroundWorker> workers = new ArrayList<BackgroundWorker>(2);
|
||||
|
||||
|
||||
@Override
|
||||
public void handleTransferable(Transferable tr, TransferAction action) throws Exception {
|
||||
List<File> files = getFilesFromTransferable(tr);
|
||||
|
||||
|
||||
if (action != TransferAction.ADD) {
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
prepare(files);
|
||||
|
||||
|
||||
// create and start worker
|
||||
new BackgroundWorker(files).execute();
|
||||
}
|
||||
|
||||
|
||||
protected void prepare(List<File> files) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void clear() {
|
||||
// stop other workers on clear (before starting new worker)
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
public void reset() {
|
||||
synchronized (workers) {
|
||||
@ -63,52 +56,45 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isLoading() {
|
||||
synchronized (workers) {
|
||||
return !workers.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected abstract void process(List<V> chunks);
|
||||
|
||||
|
||||
protected abstract void process(Exception exception);
|
||||
|
||||
|
||||
protected final void publish(V... chunks) {
|
||||
BackgroundWorker worker = threadLocalWorker.get();
|
||||
|
||||
|
||||
if (worker == null) {
|
||||
// fail if a non-background-worker thread is trying to access the thread-local worker object
|
||||
throw new IllegalThreadStateException("Illegal access thread");
|
||||
}
|
||||
|
||||
|
||||
worker.offer(chunks);
|
||||
}
|
||||
|
||||
|
||||
protected final void publish(final Exception exception) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
process(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
protected class BackgroundWorker extends SwingWorker<Object, V> {
|
||||
|
||||
|
||||
private final List<File> files;
|
||||
|
||||
|
||||
public BackgroundWorker(List<File> files) {
|
||||
this.files = files;
|
||||
|
||||
|
||||
// register this worker
|
||||
synchronized (workers) {
|
||||
if (workers.add(this) && workers.size() == 1) {
|
||||
@ -116,29 +102,26 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object doInBackground() throws Exception {
|
||||
// associate this worker with the current (background) thread
|
||||
threadLocalWorker.set(this);
|
||||
|
||||
|
||||
try {
|
||||
load(files);
|
||||
} finally {
|
||||
threadLocalWorker.remove();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void offer(V... chunks) {
|
||||
if (!isCancelled()) {
|
||||
publish(chunks);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void process(List<V> chunks) {
|
||||
@ -146,7 +129,6 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
||||
BackgroundFileTransferablePolicy.this.process(chunks);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
@ -158,7 +140,7 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
||||
BackgroundFileTransferablePolicy.this.process(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// unregister worker
|
||||
synchronized (workers) {
|
||||
if (workers.remove(this) && workers.isEmpty()) {
|
||||
@ -167,15 +149,12 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected final PropertyChangeSupport swingPropertyChangeSupport = new SwingPropertyChangeSupport(this, true);
|
||||
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
swingPropertyChangeSupport.addPropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
swingPropertyChangeSupport.removePropertyChangeListener(listener);
|
||||
|
@ -1,7 +1,5 @@
|
||||
|
||||
package net.filebot.ui.transfer;
|
||||
|
||||
|
||||
import static net.filebot.ui.transfer.FileTransferable.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
|
||||
@ -11,51 +9,45 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public abstract class FileTransferablePolicy extends TransferablePolicy {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean accept(Transferable tr) throws Exception {
|
||||
try {
|
||||
List<File> files = getFilesFromTransferable(tr);
|
||||
|
||||
|
||||
// ignore temporary files (may not work on all platforms since the DnD data may not be accessible during the drag)
|
||||
if (files != null && files.size() > 0 && containsOnly(files, TEMPORARY)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return accept(files);
|
||||
} catch (UnsupportedFlavorException e) {
|
||||
// no file list flavor
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void handleTransferable(Transferable tr, TransferAction action) throws Exception {
|
||||
List<File> files = getFilesFromTransferable(tr);
|
||||
|
||||
|
||||
if (action == TransferAction.PUT) {
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
load(files);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected abstract boolean accept(List<File> files);
|
||||
|
||||
|
||||
|
||||
protected abstract void load(List<File> files) throws IOException;
|
||||
|
||||
|
||||
|
||||
protected abstract void clear();
|
||||
|
||||
|
||||
|
||||
public String getFileFilterDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user