* better matching behaviour

* remove trailing newline for string transferables in DefaultClipboardHandler
This commit is contained in:
Reinhard Pointner 2009-03-01 13:52:43 +00:00
parent 2c5375914b
commit 68968d84e6
5 changed files with 34 additions and 18 deletions

View File

@ -4,15 +4,11 @@ package net.sourceforge.filebot.similarity;
import java.io.File; import java.io.File;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import net.sourceforge.filebot.similarity.SeasonEpisodeMatcher.SxE; import net.sourceforge.filebot.similarity.SeasonEpisodeMatcher.SxE;
public class SeasonEpisodeSimilarityMetric implements SimilarityMetric { public class SeasonEpisodeSimilarityMetric implements SimilarityMetric {
private final NumericSimilarityMetric fallbackMetric = new NumericSimilarityMetric();
private final SeasonEpisodeMatcher seasonEpisodeMatcher = new SeasonEpisodeMatcher(); private final SeasonEpisodeMatcher seasonEpisodeMatcher = new SeasonEpisodeMatcher();
@ -23,16 +19,26 @@ public class SeasonEpisodeSimilarityMetric implements SimilarityMetric {
if (sxeVector1 == null || sxeVector2 == null) { if (sxeVector1 == null || sxeVector2 == null) {
// name does not match any known pattern, return numeric similarity // name does not match any known pattern, return numeric similarity
return fallbackMetric.getSimilarity(o1, o2);
}
if (Collections.disjoint(sxeVector1, sxeVector2)) {
// vectors have no episode matches in common
return 0; return 0;
} }
// vectors have at least one episode match in common float similarity = 0;
return 1;
for (SxE sxe1 : sxeVector1) {
for (SxE sxe2 : sxeVector2) {
if (sxe1.episode == sxe2.episode) {
if (sxe1.season == sxe2.season) {
// vectors have at least one perfect episode match in common
return 1;
}
// at least we have a partial match
similarity = 0.5f;
}
}
}
return similarity;
} }

View File

@ -30,7 +30,6 @@ import net.sourceforge.filebot.similarity.SeriesNameMatcher;
import net.sourceforge.filebot.web.SearchResult; import net.sourceforge.filebot.web.SearchResult;
import net.sourceforge.tuned.ExceptionUtilities; import net.sourceforge.tuned.ExceptionUtilities;
import net.sourceforge.tuned.ui.LabelProvider; import net.sourceforge.tuned.ui.LabelProvider;
import net.sourceforge.tuned.ui.SelectButtonTextField;
import net.sourceforge.tuned.ui.TunedUtilities; import net.sourceforge.tuned.ui.TunedUtilities;
import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.matchers.TextMatcherEditor; import ca.odell.glazedlists.matchers.TextMatcherEditor;

View File

@ -1,5 +1,5 @@
package net.sourceforge.tuned.ui; package net.sourceforge.filebot.ui;
import java.awt.Component; import java.awt.Component;
@ -30,6 +30,8 @@ import javax.swing.text.JTextComponent;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sourceforge.filebot.ResourceManager; import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.tuned.ui.SelectButton;
import net.sourceforge.tuned.ui.TunedUtilities;
public class SelectButtonTextField<T> extends JComponent { public class SelectButtonTextField<T> extends JComponent {

View File

@ -221,10 +221,10 @@ public class RenamePanel extends FileBotPanel {
model.files().addAll(remainingFiles()); model.files().addAll(remainingFiles());
} catch (Exception e) { } catch (Exception e) {
Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e); Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
} finally {
// auto-match finished
namesList.firePropertyChange(LOADING_PROPERTY, true, false);
} }
// auto-match finished
namesList.firePropertyChange(LOADING_PROPERTY, true, false);
} }
@ -234,7 +234,7 @@ public class RenamePanel extends FileBotPanel {
return searchResults.iterator().next(); return searchResults.iterator().next();
} }
List<SearchResult> probableMatches = new LinkedList<SearchResult>(); final List<SearchResult> probableMatches = new LinkedList<SearchResult>();
// use name similarity metric // use name similarity metric
SimilarityMetric metric = new NameSimilarityMetric(); SimilarityMetric metric = new NameSimilarityMetric();
@ -256,7 +256,7 @@ public class RenamePanel extends FileBotPanel {
@Override @Override
public SearchResult call() throws Exception { public SearchResult call() throws Exception {
// multiple results have been found, user must select one // multiple results have been found, user must select one
SelectDialog<SearchResult> selectDialog = new SelectDialog<SearchResult>(SwingUtilities.getWindowAncestor(RenamePanel.this), searchResults); SelectDialog<SearchResult> selectDialog = new SelectDialog<SearchResult>(SwingUtilities.getWindowAncestor(RenamePanel.this), probableMatches.isEmpty() ? searchResults : probableMatches);
selectDialog.getHeaderLabel().setText(String.format("Shows matching '%s':", query)); selectDialog.getHeaderLabel().setText(String.format("Shows matching '%s':", query));

View File

@ -36,6 +36,9 @@ public class DefaultClipboardHandler implements ClipboardHandler {
for (Object value : list.getSelectedValues()) { for (Object value : list.getSelectedValues()) {
sb.append(value == null ? "" : value).append(newLine); sb.append(value == null ? "" : value).append(newLine);
} }
// delete last newline
sb.delete(sb.length() - newLine.length(), sb.length());
} }
@ -45,6 +48,9 @@ public class DefaultClipboardHandler implements ClipboardHandler {
sb.append(value == null ? "" : value).append(newLine); sb.append(value == null ? "" : value).append(newLine);
} }
// delete last newline
sb.delete(sb.length() - newLine.length(), sb.length());
} }
@ -66,5 +72,8 @@ public class DefaultClipboardHandler implements ClipboardHandler {
sb.append(newLine); sb.append(newLine);
} }
// delete last newline
sb.delete(sb.length() - newLine.length(), sb.length());
} }
} }