1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-16 14:25:02 -05:00

* refactor

This commit is contained in:
Reinhard Pointner 2015-07-25 22:47:35 +00:00
parent a475becffb
commit 0d314b786c
4 changed files with 19 additions and 35 deletions

View File

@ -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) {

View File

@ -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;
}

View File

@ -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()));

View File

@ -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;