* open series selection dialogs one after another

This commit is contained in:
Reinhard Pointner 2009-07-15 09:22:40 +00:00
parent 48cac46fef
commit c81cd50fc9
3 changed files with 66 additions and 66 deletions

View File

@ -18,13 +18,19 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.RunnableFuture;
import javax.swing.Action;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.similarity.Matcher;
import net.sourceforge.filebot.similarity.NameSimilarityMetric;
import net.sourceforge.filebot.similarity.SeriesNameMatcher;
import net.sourceforge.filebot.similarity.SimilarityMetric;
import net.sourceforge.filebot.ui.SelectDialog;
import net.sourceforge.filebot.web.Episode;
import net.sourceforge.filebot.web.EpisodeListProvider;
import net.sourceforge.filebot.web.SearchResult;
@ -39,7 +45,7 @@ class AutoFetchEpisodeListMatcher extends SwingWorker<List<Match<File, Episode>>
private final List<SimilarityMetric> metrics;
public AutoFetchEpisodeListMatcher(EpisodeListProvider provider, Collection<File> files, Collection<SimilarityMetric> metrics) {
this.provider = provider;
this.files = new LinkedList<File>(files);
@ -63,9 +69,56 @@ class AutoFetchEpisodeListMatcher extends SwingWorker<List<Match<File, Episode>>
}
protected SearchResult selectSearchResult(String query, List<SearchResult> searchResults) throws Exception {
// select first by default
return searchResults.iterator().next();
protected SearchResult selectSearchResult(final String query, final List<SearchResult> searchResults) throws Exception {
if (searchResults.size() == 1) {
return searchResults.iterator().next();
}
final LinkedList<SearchResult> probableMatches = new LinkedList<SearchResult>();
// use name similarity metric
SimilarityMetric metric = new NameSimilarityMetric();
// find probable matches using name similarity > 0.9
for (SearchResult result : searchResults) {
if (metric.getSimilarity(query, result.getName()) > 0.9) {
probableMatches.add(result);
}
}
if (probableMatches.size() == 1) {
return probableMatches.getFirst();
}
// show selection dialog on EDT
final RunnableFuture<SearchResult> showSelectDialog = new FutureTask<SearchResult>(new Callable<SearchResult>() {
@Override
public SearchResult call() throws Exception {
// display only probable matches if any
List<SearchResult> selection = probableMatches.isEmpty() ? searchResults : probableMatches;
// multiple results have been found, user must select one
SelectDialog<SearchResult> selectDialog = new SelectDialog<SearchResult>(null, selection);
selectDialog.getHeaderLabel().setText(String.format("Shows matching '%s':", query));
selectDialog.getCancelAction().putValue(Action.NAME, "Ignore");
// show dialog
selectDialog.setVisible(true);
// selected value or null if the dialog was canceled by the user
return selectDialog.getSelectedValue();
}
});
// allow only one select dialog at a time
synchronized (this) {
SwingUtilities.invokeAndWait(showSelectDialog);
}
// selected value or null
return showSelectDialog.get();
}

View File

@ -11,11 +11,7 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.RunnableFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
@ -37,16 +33,12 @@ import net.miginfocom.swing.MigLayout;
import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.filebot.Settings;
import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.similarity.NameSimilarityMetric;
import net.sourceforge.filebot.similarity.SimilarityMetric;
import net.sourceforge.filebot.ui.EpisodeFormatDialog;
import net.sourceforge.filebot.ui.SelectDialog;
import net.sourceforge.filebot.ui.panel.rename.RenameModel.FormattedFuture;
import net.sourceforge.filebot.web.AnidbClient;
import net.sourceforge.filebot.web.Episode;
import net.sourceforge.filebot.web.EpisodeListProvider;
import net.sourceforge.filebot.web.IMDbClient;
import net.sourceforge.filebot.web.SearchResult;
import net.sourceforge.filebot.web.TVDotComClient;
import net.sourceforge.filebot.web.TVRageClient;
import net.sourceforge.filebot.web.TheTVDBClient;
@ -318,58 +310,6 @@ public class RenamePanel extends JComponent {
namesList.firePropertyChange(LOADING_PROPERTY, true, false);
}
}
@Override
protected SearchResult selectSearchResult(final String query, final List<SearchResult> searchResults) throws Exception {
if (searchResults.size() == 1) {
return searchResults.iterator().next();
}
final LinkedList<SearchResult> probableMatches = new LinkedList<SearchResult>();
// use name similarity metric
SimilarityMetric metric = new NameSimilarityMetric();
// find probable matches using name similarity > 0.9
for (SearchResult result : searchResults) {
if (metric.getSimilarity(query, result.getName()) > 0.9) {
probableMatches.add(result);
}
}
if (probableMatches.size() == 1) {
return probableMatches.getFirst();
}
// show selection dialog on EDT
final RunnableFuture<SearchResult> showSelectDialog = new FutureTask<SearchResult>(new Callable<SearchResult>() {
@Override
public SearchResult call() throws Exception {
// display only probable matches if any
List<SearchResult> selection = probableMatches.isEmpty() ? searchResults : probableMatches;
// multiple results have been found, user must select one
SelectDialog<SearchResult> selectDialog = new SelectDialog<SearchResult>(getWindow(RenamePanel.this), selection);
selectDialog.getHeaderLabel().setText(String.format("Shows matching '%s':", query));
selectDialog.getCancelAction().putValue(Action.NAME, "Ignore");
// show dialog
selectDialog.setVisible(true);
// selected value or null if the dialog was canceled by the user
return selectDialog.getSelectedValue();
}
});
// run on EDT
SwingUtilities.invokeAndWait(showSelectDialog);
// selected value or null
return showSelectDialog.get();
}
};
worker.execute();

View File

@ -103,8 +103,15 @@ public final class TunedUtilities {
public static Point getPreferredLocation(JDialog dialog) {
Window owner = dialog.getOwner();
if (owner == null)
return new Point(120, 80);
if (owner == null) {
Window[] toplevel = Window.getOwnerlessWindows();
if (toplevel.length == 0)
return new Point(120, 80);
// assume first top-level window as point of reference
owner = toplevel[0];
}
Point p = owner.getLocation();
Dimension d = owner.getSize();