From 7601be3b46f75555ef75d153a0f24a00507cd445 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 24 May 2009 18:38:12 +0000 Subject: [PATCH] * refactoring --- .../sourceforge/filebot/FileBotUtilities.java | 14 -------------- source/net/sourceforge/filebot/Main.java | 17 +++++++++++++++++ .../format/EpisodeFormatBindingBean.java | 2 +- .../filebot/format/ExpressionFormat.global.js | 2 +- .../filebot/ui/AbstractSearchPanel.java | 1 - .../filebot/ui/panel/list/ListPanel.java | 2 +- .../rename/AutoFetchEpisodeListMatcher.java | 11 ++++++----- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/source/net/sourceforge/filebot/FileBotUtilities.java b/source/net/sourceforge/filebot/FileBotUtilities.java index 6075d7cb..7ce2a96a 100644 --- a/source/net/sourceforge/filebot/FileBotUtilities.java +++ b/source/net/sourceforge/filebot/FileBotUtilities.java @@ -2,13 +2,10 @@ package net.sourceforge.filebot; -import java.io.File; import java.io.FileFilter; import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.sourceforge.tuned.FileUtilities; - public final class FileBotUtilities { @@ -66,17 +63,6 @@ public final class FileBotUtilities { public static final FileFilter SUBTITLE_FILES = MediaTypes.getDefault().filter("subtitle"); public static final FileFilter SFV_FILES = MediaTypes.getDefault().filter("verification/sfv"); - /** - * This filter will accept all video files larger than 20 MB. - */ - public static final FileFilter MOVIE_FILES = new FileFilter() { - - @Override - public boolean accept(File file) { - return VIDEO_FILES.accept(file) && file.length() > 20 * FileUtilities.MEGA; - } - }; - /** * Dummy constructor to prevent instantiation. diff --git a/source/net/sourceforge/filebot/Main.java b/source/net/sourceforge/filebot/Main.java index be4b74b1..ad6b574c 100644 --- a/source/net/sourceforge/filebot/Main.java +++ b/source/net/sourceforge/filebot/Main.java @@ -18,6 +18,7 @@ import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.UIManager; +import net.sf.ehcache.CacheManager; import net.sourceforge.filebot.format.ExpressionFormat; import net.sourceforge.filebot.ui.MainFrame; import net.sourceforge.filebot.ui.NotificationLoggingHandler; @@ -51,6 +52,7 @@ public class Main { initializeLogging(); initializeSettings(); + initializeCache(); initializeSecurityManager(); try { @@ -109,6 +111,21 @@ public class Main { } + /** + * Shutdown {@link CacheManager} in case there are any persistent caches that need to be stored. + */ + private static void initializeCache() { + // shutdown CacheManager + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + + @Override + public void run() { + CacheManager.getInstance().shutdown(); + } + })); + } + + /** * Initialize default SecurityManager and grant all permissions via security policy. * Initialization is required in order to run {@link ExpressionFormat} in a secure sandbox. diff --git a/source/net/sourceforge/filebot/format/EpisodeFormatBindingBean.java b/source/net/sourceforge/filebot/format/EpisodeFormatBindingBean.java index 06434b0a..1fad28ec 100644 --- a/source/net/sourceforge/filebot/format/EpisodeFormatBindingBean.java +++ b/source/net/sourceforge/filebot/format/EpisodeFormatBindingBean.java @@ -200,7 +200,7 @@ public class EpisodeFormatBindingBean { String name = FileUtilities.getName(mediaFile); // find corresponding movie file - for (File movie : mediaFile.getParentFile().listFiles(MOVIE_FILES)) { + for (File movie : mediaFile.getParentFile().listFiles(VIDEO_FILES)) { if (name.startsWith(FileUtilities.getName(movie))) { return movie; } diff --git a/source/net/sourceforge/filebot/format/ExpressionFormat.global.js b/source/net/sourceforge/filebot/format/ExpressionFormat.global.js index 92abc73f..c2774751 100644 --- a/source/net/sourceforge/filebot/format/ExpressionFormat.global.js +++ b/source/net/sourceforge/filebot/format/ExpressionFormat.global.js @@ -23,7 +23,7 @@ String.prototype.pad = Number.prototype.pad = function(length, padding) { * e.g. "Doctor Who" -> "Doctor_Who" */ String.prototype.space = function(replacement) { - return this.replace(/\s/g, replacement); + return this.replace(/\s+/g, replacement); } diff --git a/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java b/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java index 2e5579f8..32b80c1a 100644 --- a/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java +++ b/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java @@ -55,7 +55,6 @@ public abstract class AbstractSearchPanel extends JComponent { public AbstractSearchPanel() { - historyPanel.setColumnHeader(2, "Duration"); JScrollPane historyScrollPane = new JScrollPane(historyPanel, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER); diff --git a/source/net/sourceforge/filebot/ui/panel/list/ListPanel.java b/source/net/sourceforge/filebot/ui/panel/list/ListPanel.java index eed93f09..06ad71f2 100644 --- a/source/net/sourceforge/filebot/ui/panel/list/ListPanel.java +++ b/source/net/sourceforge/filebot/ui/panel/list/ListPanel.java @@ -44,7 +44,7 @@ public class ListPanel extends JComponent { private FileBotList list = new FileBotList(); - private JTextField textField = new JTextField("Name - {i}", 25); + private JTextField textField = new JTextField("Name - {i}", 30); private SpinnerNumberModel fromSpinnerModel = new SpinnerNumberModel(1, 0, Integer.MAX_VALUE, 1); private SpinnerNumberModel toSpinnerModel = new SpinnerNumberModel(20, 0, Integer.MAX_VALUE, 1); diff --git a/source/net/sourceforge/filebot/ui/panel/rename/AutoFetchEpisodeListMatcher.java b/source/net/sourceforge/filebot/ui/panel/rename/AutoFetchEpisodeListMatcher.java index ffe90711..587fbd2f 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/AutoFetchEpisodeListMatcher.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/AutoFetchEpisodeListMatcher.java @@ -10,7 +10,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -113,7 +113,7 @@ class AutoFetchEpisodeListMatcher extends SwingWorker> protected List> doInBackground() throws Exception { // focus on movie and subtitle files - List mediaFiles = FileUtilities.filter(files, MOVIE_FILES, SUBTITLE_FILES); + List mediaFiles = FileUtilities.filter(files, VIDEO_FILES, SUBTITLE_FILES); // detect series name and fetch episode list List episodes = fetchEpisodeList(detectSeriesNames(mediaFiles)); @@ -121,7 +121,7 @@ class AutoFetchEpisodeListMatcher extends SwingWorker> List> matches = new ArrayList>(); // group by subtitles first and then by files in general - for (List filesPerType : mapByFileType(mediaFiles, MOVIE_FILES, SUBTITLE_FILES).values()) { + for (List filesPerType : mapByFileType(mediaFiles, VIDEO_FILES, SUBTITLE_FILES).values()) { Matcher matcher = new Matcher(filesPerType, episodes, metrics); matches.addAll(matcher.match()); } @@ -146,7 +146,7 @@ class AutoFetchEpisodeListMatcher extends SwingWorker> protected Map> mapByFileType(Collection files, FileFilter... filters) { // initialize map, keep filter order - Map> map = new HashMap>(filters.length); + Map> map = new LinkedHashMap>(filters.length); // initialize value lists for (FileFilter filter : filters) { @@ -156,8 +156,9 @@ class AutoFetchEpisodeListMatcher extends SwingWorker> for (File file : files) { for (FileFilter filter : filters) { if (filter.accept(file)) { - // put each value into one group only map.get(filter).add(file); + + // put each value into one group only break; } }