* 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,7 +13,6 @@ 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";
|
||||
|
@ -24,7 +21,6 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
|||
|
||||
private final List<BackgroundWorker> workers = new ArrayList<BackgroundWorker>(2);
|
||||
|
||||
|
||||
@Override
|
||||
public void handleTransferable(Transferable tr, TransferAction action) throws Exception {
|
||||
List<File> files = getFilesFromTransferable(tr);
|
||||
|
@ -39,19 +35,16 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
|||
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) {
|
||||
if (workers.size() > 0) {
|
||||
|
@ -64,20 +57,16 @@ 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();
|
||||
|
||||
|
@ -89,7 +78,6 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
|||
worker.offer(chunks);
|
||||
}
|
||||
|
||||
|
||||
protected final void publish(final Exception exception) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
|
@ -100,12 +88,10 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
protected class BackgroundWorker extends SwingWorker<Object, V> {
|
||||
|
||||
private final List<File> files;
|
||||
|
||||
|
||||
public BackgroundWorker(List<File> files) {
|
||||
this.files = files;
|
||||
|
||||
|
@ -117,7 +103,6 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object doInBackground() throws Exception {
|
||||
// associate this worker with the current (background) thread
|
||||
|
@ -132,14 +117,12 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void offer(V... chunks) {
|
||||
if (!isCancelled()) {
|
||||
publish(chunks);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void process(List<V> chunks) {
|
||||
if (!isCancelled()) {
|
||||
|
@ -147,7 +130,6 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
if (!isCancelled()) {
|
||||
|
@ -168,15 +150,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,7 +9,6 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public abstract class FileTransferablePolicy extends TransferablePolicy {
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +29,6 @@ public abstract class FileTransferablePolicy extends TransferablePolicy {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleTransferable(Transferable tr, TransferAction action) throws Exception {
|
||||
List<File> files = getFilesFromTransferable(tr);
|
||||
|
@ -44,16 +40,12 @@ public abstract class FileTransferablePolicy extends TransferablePolicy {
|
|||
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