From e8cf2e7029077e4f22b42735fee4f308e6738f70 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 30 Jun 2009 12:57:09 +0000 Subject: [PATCH] * refactoring --- .../format/AssociativeScriptObject.java | 6 ++++- .../subtitle/SubStationAlphaReader.java | 4 ++- .../sourceforge/filebot/ui/SelectDialog.java | 10 ++++++++ .../filebot/ui/panel/rename/RenamePanel.java | 25 +++++++++++-------- .../subtitle/SubtitleDownloadComponent.java | 2 +- .../net/sourceforge/tuned/FileUtilities.java | 10 ++++++++ 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/source/net/sourceforge/filebot/format/AssociativeScriptObject.java b/source/net/sourceforge/filebot/format/AssociativeScriptObject.java index 8f21f238..4152dc99 100644 --- a/source/net/sourceforge/filebot/format/AssociativeScriptObject.java +++ b/source/net/sourceforge/filebot/format/AssociativeScriptObject.java @@ -164,7 +164,11 @@ public class AssociativeScriptObject implements Scriptable { public LenientLookup(Map source) { // populate entry map for (Entry entry : source.entrySet()) { - this.source.put(definingKey(entry.getKey()), entry); + String key = definingKey(entry.getKey()); + + if (key.length() > 0) { + this.source.put(key, entry); + } } } diff --git a/source/net/sourceforge/filebot/subtitle/SubStationAlphaReader.java b/source/net/sourceforge/filebot/subtitle/SubStationAlphaReader.java index e097cd99..b2850c88 100644 --- a/source/net/sourceforge/filebot/subtitle/SubStationAlphaReader.java +++ b/source/net/sourceforge/filebot/subtitle/SubStationAlphaReader.java @@ -72,7 +72,9 @@ public class SubStationAlphaReader extends SubtitleReader { long start = timeFormat.parse(row[format.get("Start")]).getTime(); long end = timeFormat.parse(row[format.get("End")]).getTime(); - String[] lines = row[format.get("Text")].trim().split(Pattern.quote("\\n")); + String text = row[format.get("Text")].trim(); + + String[] lines = Pattern.compile(Pattern.quote("\\N"), Pattern.CASE_INSENSITIVE).split(text); return new SubtitleElement(start, end, join(Arrays.asList(lines), "\n")); } diff --git a/source/net/sourceforge/filebot/ui/SelectDialog.java b/source/net/sourceforge/filebot/ui/SelectDialog.java index 84324b7f..34a86640 100644 --- a/source/net/sourceforge/filebot/ui/SelectDialog.java +++ b/source/net/sourceforge/filebot/ui/SelectDialog.java @@ -98,6 +98,16 @@ public class SelectDialog extends JDialog { } + public Action getSelectAction() { + return selectAction; + } + + + public Action getCancelAction() { + return cancelAction; + } + + private final Action selectAction = new AbstractAction("Select", ResourceManager.getIcon("dialog.continue")) { public void actionPerformed(ActionEvent e) { diff --git a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java index 298af4a9..87ede4f0 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java @@ -30,6 +30,9 @@ import javax.swing.JLabel; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; +import ca.odell.glazedlists.ListSelection; +import ca.odell.glazedlists.swing.EventSelectionModel; + import net.miginfocom.swing.MigLayout; import net.sourceforge.filebot.ResourceManager; import net.sourceforge.filebot.Settings; @@ -53,8 +56,6 @@ import net.sourceforge.tuned.PreferencesMap.PreferencesEntry; import net.sourceforge.tuned.PreferencesMap.SimpleAdapter; import net.sourceforge.tuned.ui.ActionPopup; import net.sourceforge.tuned.ui.LoadingOverlayPane; -import ca.odell.glazedlists.ListSelection; -import ca.odell.glazedlists.swing.EventSelectionModel; public class RenamePanel extends JComponent { @@ -71,7 +72,7 @@ public class RenamePanel extends JComponent { private final PreferencesEntry persistentPreserveExtension = Settings.userRoot().entry("rename.extension.preserve", SimpleAdapter.forClass(Boolean.class)); - + public RenamePanel() { namesList.setTitle("New Names"); namesList.setTransferablePolicy(new NamesListTransferablePolicy(renameModel.values())); @@ -220,6 +221,7 @@ public class RenamePanel extends JComponent { return actionPopup; } + protected final Action showPopupAction = new AbstractAction("Show Popup") { @Override @@ -234,12 +236,12 @@ public class RenamePanel extends JComponent { } }; - + protected class PreserveExtensionAction extends AbstractAction { private final boolean activate; - + private PreserveExtensionAction(boolean activate, String name, Icon icon) { super(name, icon); this.activate = activate; @@ -266,7 +268,7 @@ public class RenamePanel extends JComponent { private final EpisodeListProvider provider; - + public AutoFetchEpisodeListAction(EpisodeListProvider provider) { super(provider.getName(), provider.getIcon()); @@ -310,7 +312,7 @@ public class RenamePanel extends JComponent { // add remaining file entries renameModel.files().addAll(remainingFiles()); } catch (Exception e) { - Logger.getLogger("ui").warning(ExceptionUtilities.getRootCauseMessage(e)); + Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e); } finally { // auto-match finished namesList.firePropertyChange(LOADING_PROPERTY, true, false); @@ -324,7 +326,7 @@ public class RenamePanel extends JComponent { return searchResults.iterator().next(); } - final List probableMatches = new LinkedList(); + final LinkedList probableMatches = new LinkedList(); // use name similarity metric SimilarityMetric metric = new NameSimilarityMetric(); @@ -337,7 +339,7 @@ public class RenamePanel extends JComponent { } if (probableMatches.size() == 1) { - return probableMatches.get(0); + return probableMatches.getFirst(); } // show selection dialog on EDT @@ -351,8 +353,10 @@ public class RenamePanel extends JComponent { // multiple results have been found, user must select one SelectDialog selectDialog = new SelectDialog(getWindow(RenamePanel.this), selection); - selectDialog.getHeaderLabel().setText(String.format("Shows matching \"%s\":", query)); + 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 @@ -372,6 +376,7 @@ public class RenamePanel extends JComponent { } } + private final PreferencesEntry persistentExpressionFormatter = Settings.userRoot().entry("rename.format", new AbstractAdapter() { @Override diff --git a/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitleDownloadComponent.java b/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitleDownloadComponent.java index d2f34277..690a3b23 100644 --- a/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitleDownloadComponent.java +++ b/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitleDownloadComponent.java @@ -285,7 +285,7 @@ public class SubtitleDownloadComponent extends JComponent { final Object[] selection = list.getSelectedValues(); - Action downloadAction = new AbstractAction("Download", ResourceManager.getIcon("action.fetch")) { + Action downloadAction = new AbstractAction("Download", ResourceManager.getIcon("package.fetch")) { @Override public void actionPerformed(ActionEvent e) { diff --git a/source/net/sourceforge/tuned/FileUtilities.java b/source/net/sourceforge/tuned/FileUtilities.java index fa0dcf5e..e1a1088e 100644 --- a/source/net/sourceforge/tuned/FileUtilities.java +++ b/source/net/sourceforge/tuned/FileUtilities.java @@ -168,6 +168,16 @@ public final class FileUtilities { } + public boolean acceptExtension(String extension) { + for (String other : extensions) { + if (other.equalsIgnoreCase(extension)) + return true; + } + + return false; + } + + public List extensions() { return Arrays.asList(extensions); }