1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04: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.ResourceManager;
import net.filebot.Settings; import net.filebot.Settings;
import net.filebot.UserFiles; import net.filebot.UserFiles;
import net.filebot.WebServices;
import net.filebot.format.BindingException; import net.filebot.format.BindingException;
import net.filebot.format.ExpressionFormat; import net.filebot.format.ExpressionFormat;
import net.filebot.format.MediaBindingBean; 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;
import net.filebot.util.ui.notification.SeparatorBorder.Position; import net.filebot.util.ui.notification.SeparatorBorder.Position;
import net.filebot.web.AudioTrackFormat; import net.filebot.web.AudioTrackFormat;
import net.filebot.web.Datasource;
import net.filebot.web.EpisodeFormat; import net.filebot.web.EpisodeFormat;
import net.filebot.web.EpisodeListProvider;
import net.filebot.web.MovieFormat; import net.filebot.web.MovieFormat;
import net.filebot.web.MovieIdentificationService;
import net.filebot.web.MusicIdentificationService;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
@ -163,6 +168,16 @@ public class FormatDialog extends JDialog {
} }
return examples.values(); 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) { 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); return WebServices.getDatasourceByName(database);
} }
@ -86,25 +86,6 @@ public class Preset {
throw new IllegalStateException(database); 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() { public String getMatchMode() {
return matchMode == null || matchMode.isEmpty() ? null : matchMode; 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 java.awt.Font.*;
import static javax.swing.BorderFactory.*; import static javax.swing.BorderFactory.*;
import static javax.swing.SwingUtilities.*;
import static net.filebot.ui.NotificationLogging.*; import static net.filebot.ui.NotificationLogging.*;
import static net.filebot.util.ui.SwingUI.*; import static net.filebot.util.ui.SwingUI.*;
@ -39,11 +38,8 @@ import net.filebot.WebServices;
import net.filebot.format.ExpressionFilter; import net.filebot.format.ExpressionFilter;
import net.filebot.format.ExpressionFormat; import net.filebot.format.ExpressionFormat;
import net.filebot.ui.HeaderPanel; import net.filebot.ui.HeaderPanel;
import net.filebot.ui.rename.FormatDialog.Mode;
import net.filebot.web.Datasource; import net.filebot.web.Datasource;
import net.filebot.web.EpisodeListProvider; import net.filebot.web.EpisodeListProvider;
import net.filebot.web.MovieIdentificationService;
import net.filebot.web.MusicIdentificationService;
import net.filebot.web.SortOrder; import net.filebot.web.SortOrder;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
@ -150,7 +146,7 @@ public class PresetEditor extends JDialog {
pathInput.setText(p.getInputFolder() == null ? "" : p.getInputFolder().getPath()); pathInput.setText(p.getInputFolder() == null ? "" : p.getInputFolder().getPath());
filterEditor.setText(p.getIncludeFilter() == null ? "" : p.getIncludeFilter().getExpression()); filterEditor.setText(p.getIncludeFilter() == null ? "" : p.getIncludeFilter().getExpression());
formatEditor.setText(p.getFormat() == null ? "" : p.getFormat().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()); sortOrderCombo.setSelectedItem(p.getSortOrder() == null ? SortOrder.Airdate : p.getSortOrder());
matchModeCombo.setSelectedItem(p.getMatchMode() == null ? RenamePanel.MATCH_MODE_OPPORTUNISTIC : p.getMatchMode()); matchModeCombo.setSelectedItem(p.getMatchMode() == null ? RenamePanel.MATCH_MODE_OPPORTUNISTIC : p.getMatchMode());
actionCombo.setSelectedItem(p.getRenameAction() == null ? StandardRenameAction.MOVE : p.getRenameAction()); actionCombo.setSelectedItem(p.getRenameAction() == null ? StandardRenameAction.MOVE : p.getRenameAction());
@ -331,15 +327,7 @@ public class PresetEditor extends JDialog {
@Override @Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
FormatDialog.Mode mode = FormatDialog.Mode.File; FormatDialog.Mode mode = FormatDialog.Mode.getMode((Datasource) providerCombo.getSelectedItem());
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 dialog = new FormatDialog(getWindow(evt.getSource()), mode, null); FormatDialog dialog = new FormatDialog(getWindow(evt.getSource()), mode, null);
dialog.setFormatCode(formatEditor.getText()); dialog.setFormatCode(formatEditor.getText());
dialog.setLocation(getOffsetLocation(dialog.getOwner())); dialog.setLocation(getOffsetLocation(dialog.getOwner()));

View File

@ -735,7 +735,7 @@ public class RenamePanel extends JComponent {
@Override @Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
if (preset.getFormat() != null) { if (preset.getFormat() != null) {
switch (preset.getMode()) { switch (FormatDialog.Mode.getMode(preset.getDatasource())) {
case Episode: case Episode:
renameModel.useFormatter(Episode.class, new ExpressionFormatter(preset.getFormat().getExpression(), EpisodeFormat.SeasonEpisode, Episode.class)); renameModel.useFormatter(Episode.class, new ExpressionFormatter(preset.getFormat().getExpression(), EpisodeFormat.SeasonEpisode, Episode.class));
break; break;