From 0e2c1ecf3632d27c7cbcbef77fda2ace3b8128cf Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 17 Jul 2012 17:47:07 +0000 Subject: [PATCH] * allow auto-select or auto-ignore in movie mode to make it possible to skip all user interaction --- .../filebot/resources/button.repeat.png | Bin 0 -> 422 bytes .../resources/button.repeat.selected.png | Bin 0 -> 750 bytes .../sourceforge/filebot/ui/SelectDialog.java | 6 +- .../filebot/ui/rename/EpisodeListMatcher.java | 2 +- .../filebot/ui/rename/MovieHashMatcher.java | 91 ++++++++++++------ 5 files changed, 65 insertions(+), 34 deletions(-) create mode 100644 source/net/sourceforge/filebot/resources/button.repeat.png create mode 100644 source/net/sourceforge/filebot/resources/button.repeat.selected.png diff --git a/source/net/sourceforge/filebot/resources/button.repeat.png b/source/net/sourceforge/filebot/resources/button.repeat.png new file mode 100644 index 0000000000000000000000000000000000000000..1c4f57a16126b203bfa12caf50f4b3fe725f9bc1 GIT binary patch literal 422 zcmV;X0a^ZuP)2#b| zLX6^UF84fh?wy$kBLC~BD2js0>zp+XR}r`}LU#$3n|fVSTQ&_fqK z-dP1W_0w_)Fx(96Hd?S$6Ag!Gb0{2;SA#|hQKxxo4lC@GkWvoF>433OT)ML_c*YrK zxk(GV+5xw=j}C#*d_)ZQm|^vSE$e_Rfi{EB*{sr@#u0%!GuA`kT6eip5)*9h(VoI2 z7I~jC*1{1PRmB(0C&t&XN#G6@eBuONxMW%!n+~_GQB^!(14SOFz%!m0KGcES_nU0K zx*VUU%kcb!9C_-b+%XxB2spb0jf9EGvCrBTt7=&<*|?4A1r-;+e)BJV19u#CG)&jc Qk^lez07*qoM6N<$f+7R3%K!iX literal 0 HcmV?d00001 diff --git a/source/net/sourceforge/filebot/resources/button.repeat.selected.png b/source/net/sourceforge/filebot/resources/button.repeat.selected.png new file mode 100644 index 0000000000000000000000000000000000000000..406ec333bc036690d4639cbec70e8f586e977699 GIT binary patch literal 750 zcmV`dI4bfJkF0x@cXCL|Igq$5O2KprVjQ%O+X7O;#( z4BD1bI(<+cEez0UoerJ8pvUZH<2j7y zcZNUt)xrxJYFpmPCdcPpZrKy&*VZ>ApFbcitp@qg#TeIQPnn2A+}{k&#TSQNduHE8 zR1lLg6t#%bX_+CDEg*4_f_v33^v*=h#I2ZA3~EX24{j>CdV}A=`*V zT4vz!`I!OrPI2eFNk)w9XPLPE(JbD&MP{&ll+#ia(bqqy8yG)*4e)6tkBnME*Ypl9 z-y3DbfrSJUUwt@@D-R}c|4op+OgNr~#cI=AsIxgE+;$>~av4mxb*QrFQBlRSu^2P( z#4-pavM8REG5;k1bN7TkM8nPocv)tTbCDe=Sn=D!1EK%memuVc8qO zwkWfiP|txa2~#c~+AY08Q|E`jSGoE#-RjvgwZ5L>o_F>0mY3bqi%w2z>#*|89S-gW g7yS2U`k(Lo6ZXgk;$VJhmjD0&07*qoM6N<$g5UmA*#H0l literal 0 HcmV?d00001 diff --git a/source/net/sourceforge/filebot/ui/SelectDialog.java b/source/net/sourceforge/filebot/ui/SelectDialog.java index 84c8d3e6..828414b9 100644 --- a/source/net/sourceforge/filebot/ui/SelectDialog.java +++ b/source/net/sourceforge/filebot/ui/SelectDialog.java @@ -65,13 +65,13 @@ public class SelectDialog extends JDialog { JComponent c = (JComponent) getContentPane(); - c.setLayout(new MigLayout("insets 1.5mm, nogrid, fill", "", "[pref!][fill][pref!]")); + c.setLayout(new MigLayout("insets 1.5mm 1.5mm 2.7mm 1.5mm, nogrid, fill", "", "[pref!][fill][pref!]")); c.add(headerLabel, "wrap"); c.add(new JScrollPane(list), "grow, wrap 2mm"); - c.add(new JButton(selectAction), "align center"); - c.add(new JButton(cancelAction), "gap unrel, wrap 1.2mm"); + c.add(new JButton(selectAction), "align center, id select"); + c.add(new JButton(cancelAction), "gap unrel, id cancel"); // set default size and location setSize(new Dimension(210, 210)); diff --git a/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java b/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java index a03993bb..e4c9e9f8 100644 --- a/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java +++ b/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java @@ -171,7 +171,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher { return episodes; } finally { // destroy background threads - executor.shutdown(); + executor.shutdownNow(); } } diff --git a/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java b/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java index 87613b8b..01a35e4d 100644 --- a/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java +++ b/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java @@ -2,6 +2,7 @@ package net.sourceforge.filebot.ui.rename; +import static java.awt.Cursor.*; import static java.util.Collections.*; import static net.sourceforge.filebot.MediaTypes.*; import static net.sourceforge.filebot.Settings.*; @@ -38,10 +39,13 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.Action; +import javax.swing.JCheckBox; +import javax.swing.JComponent; import javax.swing.SwingUtilities; import net.sourceforge.filebot.Analytics; import net.sourceforge.filebot.MediaTypes; +import net.sourceforge.filebot.ResourceManager; import net.sourceforge.filebot.similarity.Match; import net.sourceforge.filebot.similarity.NameSimilarityMetric; import net.sourceforge.filebot.similarity.SimilarityMetric; @@ -150,18 +154,21 @@ class MovieHashMatcher implements AutoCompleteMatcher { } // remember user decisions and only bother user once - Map selectionMemory = new TreeMap(getLenientCollator(locale)); - Map inputMemory = new TreeMap(getLenientCollator(locale)); + Map memory = new HashMap(); + memory.put("input", new TreeMap(getLenientCollator(locale))); + memory.put("selection", new TreeMap(getLenientCollator(locale))); try { for (Future>> it : grabMovieJobs) { // auto-select movie or ask user File movieFile = it.get().getKey(); - Movie movie = grabMovieName(movieFile, it.get().getValue(), locale, autodetect, selectionMemory, inputMemory, parent); - movieByFile.put(movieFile, movie); + Movie movie = grabMovieName(movieFile, it.get().getValue(), locale, autodetect, memory, parent); + if (movie != null) { + movieByFile.put(movieFile, movie); + } } } finally { - executor.shutdown(); + executor.shutdownNow(); } // map movies to (possibly multiple) files (in natural order) @@ -215,20 +222,23 @@ class MovieHashMatcher implements AutoCompleteMatcher { } - protected Movie grabMovieName(File movieFile, Collection options, Locale locale, boolean autodetect, Map selectionMemory, Map inputMemory, Component parent) throws Exception { + protected Movie grabMovieName(File movieFile, Collection options, Locale locale, boolean autodetect, Map memory, Component parent) throws Exception { // allow manual user input - if (options.isEmpty() || !autodetect) { + if (!autodetect || options.isEmpty()) { + if (autodetect && memory.containsKey("repeat")) { + return null; + } + String suggestion = options.isEmpty() ? stripReleaseInfo(getName(movieFile)) : options.iterator().next().getName(); - String input = null; - synchronized (inputMemory) { - synchronized (this) { - input = inputMemory.get(suggestion); - if (input == null || suggestion == null || suggestion.isEmpty()) { - input = showInputDialog("Enter movie name:", suggestion, String.format("%s/%s", movieFile.getParentFile().getName(), movieFile.getName()), parent); - inputMemory.put(suggestion, input); - } - } + @SuppressWarnings("unchecked") + Map inputMemory = (Map) memory.get("input"); + + String input = inputMemory.get(suggestion); + if (input == null || suggestion == null || suggestion.isEmpty()) { + File movieFolder = guessMovieFolder(movieFile); + input = showInputDialog("Enter movie name:", suggestion, movieFolder == null ? movieFile.getName() : String.format("%s/%s", movieFolder.getName(), movieFile.getName()), parent); + inputMemory.put(suggestion, input); } if (input != null) { @@ -236,11 +246,11 @@ class MovieHashMatcher implements AutoCompleteMatcher { } } - return options.isEmpty() ? null : selectMovie(movieFile, options, selectionMemory, parent); + return options.isEmpty() ? null : selectMovie(movieFile, options, memory, parent); } - protected Movie selectMovie(final File movieFile, final Collection options, final Map selectionMemory, final Component parent) throws Exception { + protected Movie selectMovie(final File movieFile, final Collection options, final Map memory, final Component parent) throws Exception { // 1. movie by filename final String fileQuery = stripReleaseInfo(getName(movieFile)); @@ -296,28 +306,49 @@ class MovieHashMatcher implements AutoCompleteMatcher { selectDialog.setMinimumSize(new Dimension(280, 300)); selectDialog.pack(); + // add repeat button + JCheckBox checkBox = new JCheckBox(); + checkBox.setCursor(getPredefinedCursor(HAND_CURSOR)); + checkBox.setIcon(ResourceManager.getIcon("button.repeat")); + checkBox.setSelectedIcon(ResourceManager.getIcon("button.repeat.selected")); + JComponent c = (JComponent) selectDialog.getContentPane(); + c.add(checkBox, "pos 1al select.y n select.y2"); + // show dialog selectDialog.setLocation(getOffsetLocation(selectDialog.getOwner())); selectDialog.setVisible(true); + // remember if we should auto-repeat the chosen action in the future + if (checkBox.isSelected()) { + memory.put("repeat", selectDialog.getSelectedValue() != null ? "select" : "ignore"); + } + // selected value or null if the dialog was canceled by the user return selectDialog.getSelectedValue(); } }); // allow only one select dialog at a time - synchronized (selectionMemory) { - synchronized (this) { - if (selectionMemory.containsKey(fileQuery)) { - return selectionMemory.get(fileQuery); - } - - SwingUtilities.invokeAndWait(showSelectDialog); - - // cache selected value - selectionMemory.put(fileQuery, showSelectDialog.get()); - return showSelectDialog.get(); - } + @SuppressWarnings("unchecked") + Map selectionMemory = (Map) memory.get("selection"); + + if (selectionMemory.containsKey(fileQuery)) { + return selectionMemory.get(fileQuery); } + + // check auto-selection settings + if ("select".equals(memory.get("repeat"))) { + return options.iterator().next(); + } + if ("ignore".equals(memory.get("repeat"))) { + return null; + } + + // ask for user input + SwingUtilities.invokeAndWait(showSelectDialog); + + // cache selected value + selectionMemory.put(fileQuery, showSelectDialog.get()); + return showSelectDialog.get(); } }