From 0d314b786caa82009280e0b843808093810db12f Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 25 Jul 2015 22:47:35 +0000 Subject: [PATCH] * refactor --- .../net/filebot/ui/rename/FormatDialog.java | 15 +++++++++++++ source/net/filebot/ui/rename/Preset.java | 21 +------------------ .../net/filebot/ui/rename/PresetEditor.java | 16 ++------------ source/net/filebot/ui/rename/RenamePanel.java | 2 +- 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/source/net/filebot/ui/rename/FormatDialog.java b/source/net/filebot/ui/rename/FormatDialog.java index 766cce29..5489d3e0 100644 --- a/source/net/filebot/ui/rename/FormatDialog.java +++ b/source/net/filebot/ui/rename/FormatDialog.java @@ -63,6 +63,7 @@ import javax.swing.text.BadLocationException; import net.filebot.ResourceManager; import net.filebot.Settings; import net.filebot.UserFiles; +import net.filebot.WebServices; import net.filebot.format.BindingException; import net.filebot.format.ExpressionFormat; import net.filebot.format.MediaBindingBean; @@ -79,8 +80,12 @@ import net.filebot.util.ui.SwingUI; import net.filebot.util.ui.notification.SeparatorBorder; import net.filebot.util.ui.notification.SeparatorBorder.Position; import net.filebot.web.AudioTrackFormat; +import net.filebot.web.Datasource; import net.filebot.web.EpisodeFormat; +import net.filebot.web.EpisodeListProvider; import net.filebot.web.MovieFormat; +import net.filebot.web.MovieIdentificationService; +import net.filebot.web.MusicIdentificationService; import net.miginfocom.swing.MigLayout; import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; @@ -163,6 +168,16 @@ public class FormatDialog extends JDialog { } return examples.values(); } + + public static Mode getMode(Datasource datasource) { + if (datasource instanceof EpisodeListProvider) + return Mode.Episode; + if (datasource instanceof MovieIdentificationService) + return Mode.Movie; + if (datasource instanceof MusicIdentificationService) + return Mode.Music; + return Mode.File; + } } public FormatDialog(Window owner, Mode initMode, MediaBindingBean lockOnBinding) { diff --git a/source/net/filebot/ui/rename/Preset.java b/source/net/filebot/ui/rename/Preset.java index 14200534..e36d5ecc 100644 --- a/source/net/filebot/ui/rename/Preset.java +++ b/source/net/filebot/ui/rename/Preset.java @@ -63,7 +63,7 @@ public class Preset { } } - public Datasource getDatabase() { + public Datasource getDatasource() { return WebServices.getDatasourceByName(database); } @@ -86,25 +86,6 @@ public class Preset { throw new IllegalStateException(database); } - public Mode getMode() { - EpisodeListProvider sdb = WebServices.getEpisodeListProvider(database); - if (sdb != null) { - return Mode.Episode; - } - - MovieIdentificationService mdb = WebServices.getMovieIdentificationService(database); - if (mdb != null) { - return Mode.Movie; - } - - MusicIdentificationService adb = WebServices.getMusicIdentificationService(database); - if (adb != null) { - return Mode.Music; - } - - return Mode.File; - } - public String getMatchMode() { return matchMode == null || matchMode.isEmpty() ? null : matchMode; } diff --git a/source/net/filebot/ui/rename/PresetEditor.java b/source/net/filebot/ui/rename/PresetEditor.java index 1a2e7426..4f092b13 100644 --- a/source/net/filebot/ui/rename/PresetEditor.java +++ b/source/net/filebot/ui/rename/PresetEditor.java @@ -2,7 +2,6 @@ package net.filebot.ui.rename; import static java.awt.Font.*; import static javax.swing.BorderFactory.*; -import static javax.swing.SwingUtilities.*; import static net.filebot.ui.NotificationLogging.*; import static net.filebot.util.ui.SwingUI.*; @@ -39,11 +38,8 @@ import net.filebot.WebServices; import net.filebot.format.ExpressionFilter; import net.filebot.format.ExpressionFormat; import net.filebot.ui.HeaderPanel; -import net.filebot.ui.rename.FormatDialog.Mode; import net.filebot.web.Datasource; import net.filebot.web.EpisodeListProvider; -import net.filebot.web.MovieIdentificationService; -import net.filebot.web.MusicIdentificationService; import net.filebot.web.SortOrder; import net.miginfocom.swing.MigLayout; @@ -150,7 +146,7 @@ public class PresetEditor extends JDialog { pathInput.setText(p.getInputFolder() == null ? "" : p.getInputFolder().getPath()); filterEditor.setText(p.getIncludeFilter() == null ? "" : p.getIncludeFilter().getExpression()); formatEditor.setText(p.getFormat() == null ? "" : p.getFormat().getExpression()); - providerCombo.setSelectedItem(p.getDatabase() == null ? WebServices.TheTVDB : p.getDatabase()); + providerCombo.setSelectedItem(p.getDatasource() == null ? WebServices.TheTVDB : p.getDatasource()); sortOrderCombo.setSelectedItem(p.getSortOrder() == null ? SortOrder.Airdate : p.getSortOrder()); matchModeCombo.setSelectedItem(p.getMatchMode() == null ? RenamePanel.MATCH_MODE_OPPORTUNISTIC : p.getMatchMode()); actionCombo.setSelectedItem(p.getRenameAction() == null ? StandardRenameAction.MOVE : p.getRenameAction()); @@ -331,15 +327,7 @@ public class PresetEditor extends JDialog { @Override public void actionPerformed(ActionEvent evt) { - FormatDialog.Mode mode = FormatDialog.Mode.File; - if (providerCombo.getSelectedItem() instanceof EpisodeListProvider) { - mode = FormatDialog.Mode.Episode; - } else if (providerCombo.getSelectedItem() instanceof MovieIdentificationService) { - mode = FormatDialog.Mode.Movie; - } else if (providerCombo.getSelectedItem() instanceof MusicIdentificationService) { - mode = FormatDialog.Mode.Music; - } - + FormatDialog.Mode mode = FormatDialog.Mode.getMode((Datasource) providerCombo.getSelectedItem()); FormatDialog dialog = new FormatDialog(getWindow(evt.getSource()), mode, null); dialog.setFormatCode(formatEditor.getText()); dialog.setLocation(getOffsetLocation(dialog.getOwner())); diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index af232f9f..76d386d5 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -735,7 +735,7 @@ public class RenamePanel extends JComponent { @Override public void actionPerformed(ActionEvent evt) { if (preset.getFormat() != null) { - switch (preset.getMode()) { + switch (FormatDialog.Mode.getMode(preset.getDatasource())) { case Episode: renameModel.useFormatter(Episode.class, new ExpressionFormatter(preset.getFormat().getExpression(), EpisodeFormat.SeasonEpisode, Episode.class)); break;