* include Format Editor in Preset Editor

This commit is contained in:
Reinhard Pointner 2015-07-25 22:47:30 +00:00
parent b019cd9827
commit a475becffb
2 changed files with 49 additions and 26 deletions

View File

@ -2,6 +2,7 @@ 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.*;
@ -38,8 +39,11 @@ 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;
@ -88,15 +92,13 @@ public class PresetEditor extends JDialog {
matchModeCombo = createMatchModeCombo(); matchModeCombo = createMatchModeCombo();
languageCombo = createLanguageCombo(); languageCombo = createLanguageCombo();
JButton pathButton = createImageButton(selectInputFolder);
JPanel inputPanel = new JPanel(new MigLayout("insets 0, fill")); JPanel inputPanel = new JPanel(new MigLayout("insets 0, fill"));
inputPanel.setOpaque(false); inputPanel.setOpaque(false);
inputPanel.add(new JLabel("Input Folder:"), "gap indent"); inputPanel.add(new JLabel("Input Folder:"), "gap indent");
inputPanel.add(pathInput, "growx, gap rel"); inputPanel.add(pathInput, "growx, gap rel");
inputPanel.add(pathButton, "gap rel, wrap"); inputPanel.add(createImageButton(selectInputFolder), "gap 0px, wrap");
inputPanel.add(new JLabel("Includes:"), "gap indent, skip 1, split 2"); inputPanel.add(new JLabel("Includes:"), "gap indent, skip 1, split 2");
inputPanel.add(wrapEditor(filterEditor), "growx, gap rel, gap after indent"); inputPanel.add(wrapEditor(filterEditor), "growx, gap rel, gap after 40px");
JPanel inputGroup = createGroupPanel("Files"); JPanel inputGroup = createGroupPanel("Files");
inputGroup.add(selectRadio); inputGroup.add(selectRadio);
@ -106,6 +108,7 @@ public class PresetEditor extends JDialog {
JPanel formatGroup = createGroupPanel("Format"); JPanel formatGroup = createGroupPanel("Format");
formatGroup.add(new JLabel("Expression:")); formatGroup.add(new JLabel("Expression:"));
formatGroup.add(wrapEditor(formatEditor), "growx, gap rel"); formatGroup.add(wrapEditor(formatEditor), "growx, gap rel");
formatGroup.add(createImageButton(editFormatExpression), "gap 10px");
JPanel searchGroup = createGroupPanel("Options"); JPanel searchGroup = createGroupPanel("Options");
searchGroup.add(new JLabel("Datasource:"), "sg label"); searchGroup.add(new JLabel("Datasource:"), "sg label");
@ -126,21 +129,20 @@ public class PresetEditor extends JDialog {
c.add(searchGroup, "growx, wrap push"); c.add(searchGroup, "growx, wrap push");
c.add(new JButton(ok), "tag apply"); c.add(new JButton(ok), "tag apply");
c.add(new JButton(delete), "tag cancel"); c.add(new JButton(delete), "tag cancel");
setSize(650, 570);
ButtonGroup inputButtonGroup = new ButtonGroup(); ButtonGroup inputButtonGroup = new ButtonGroup();
inputButtonGroup.add(inheritRadio); inputButtonGroup.add(inheritRadio);
inputButtonGroup.add(selectRadio); inputButtonGroup.add(selectRadio);
inheritRadio.setSelected(true);
inputPanel.setVisible(false);
selectRadio.addItemListener((evt) -> { selectRadio.addItemListener((evt) -> {
inputPanel.setVisible(selectRadio.isSelected()); inputPanel.setVisible(selectRadio.isSelected());
}); });
providerCombo.addItemListener((evt) -> { providerCombo.addItemListener((evt) -> {
sortOrderCombo.setEnabled(evt.getItem() instanceof EpisodeListProvider); sortOrderCombo.setEnabled(evt.getItem() instanceof EpisodeListProvider);
}); });
inheritRadio.setSelected(true);
inputPanel.setVisible(false);
presetNameHeader.getTitleLabel().setText("Preset"); setSize(650, 570);
} }
public void setPreset(Preset p) { public void setPreset(Preset p) {
@ -170,17 +172,6 @@ public class PresetEditor extends JDialog {
return new Preset(name, path, includes, format, database, sortOrder, matchMode, language, action); return new Preset(name, path, includes, format, database, sortOrder, matchMode, language, action);
} }
private final Action selectInputFolder = new AbstractAction("Select Input Folder", ResourceManager.getIcon("action.load")) {
@Override
public void actionPerformed(ActionEvent evt) {
File f = UserFiles.showOpenDialogSelectFolder(null, "Select Input Folder", evt);
if (f != null) {
pathInput.setText(f.getAbsolutePath());
}
}
};
private JPanel createGroupPanel(String title) { private JPanel createGroupPanel(String title) {
JPanel inputGroup = new JPanel(new MigLayout("insets dialog, hidemode 3, nogrid, fill")); JPanel inputGroup = new JPanel(new MigLayout("insets dialog, hidemode 3, nogrid, fill"));
inputGroup.setBorder(createTitledBorder(title)); inputGroup.setBorder(createTitledBorder(title));
@ -325,6 +316,41 @@ public class PresetEditor extends JDialog {
return result; return result;
} }
private final Action selectInputFolder = new AbstractAction("Select Input Folder", ResourceManager.getIcon("action.load")) {
@Override
public void actionPerformed(ActionEvent evt) {
File f = UserFiles.showOpenDialogSelectFolder(null, "Select Input Folder", evt);
if (f != null) {
pathInput.setText(f.getAbsolutePath());
}
}
};
private final Action editFormatExpression = new AbstractAction("Open Format Editor", ResourceManager.getIcon("action.format")) {
@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 dialog = new FormatDialog(getWindow(evt.getSource()), mode, null);
dialog.setFormatCode(formatEditor.getText());
dialog.setLocation(getOffsetLocation(dialog.getOwner()));
dialog.setVisible(true);
if (dialog.submit()) {
formatEditor.setText(dialog.getFormat().getExpression());
}
}
};
private final Action ok = new AbstractAction("Preset", ResourceManager.getIcon("dialog.continue")) { private final Action ok = new AbstractAction("Preset", ResourceManager.getIcon("dialog.continue")) {
@Override @Override

View File

@ -12,7 +12,6 @@ import static net.filebot.util.ui.SwingUI.*;
import java.awt.Component; import java.awt.Component;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Insets; import java.awt.Insets;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -61,12 +60,10 @@ import net.filebot.format.MediaBindingBean;
import net.filebot.mac.MacAppUtilities; import net.filebot.mac.MacAppUtilities;
import net.filebot.media.MediaDetection; import net.filebot.media.MediaDetection;
import net.filebot.similarity.Match; import net.filebot.similarity.Match;
import net.filebot.ui.SelectDialog;
import net.filebot.ui.rename.FormatDialog.Mode; import net.filebot.ui.rename.FormatDialog.Mode;
import net.filebot.ui.rename.RenameModel.FormattedFuture; import net.filebot.ui.rename.RenameModel.FormattedFuture;
import net.filebot.ui.transfer.BackgroundFileTransferablePolicy; import net.filebot.ui.transfer.BackgroundFileTransferablePolicy;
import net.filebot.util.FileUtilities; import net.filebot.util.FileUtilities;
import net.filebot.util.PreferencesMap;
import net.filebot.util.PreferencesMap.PreferencesEntry; import net.filebot.util.PreferencesMap.PreferencesEntry;
import net.filebot.util.ui.ActionPopup; import net.filebot.util.ui.ActionPopup;
import net.filebot.util.ui.LoadingOverlayPane; import net.filebot.util.ui.LoadingOverlayPane;
@ -384,7 +381,7 @@ public class RenamePanel extends JComponent {
} }
protected ActionPopup createPresetsPopup() { protected ActionPopup createPresetsPopup() {
PreferencesMap<String> persistentPresets = Settings.forPackage(RenamePanel.class).node("presets").asMap(); Map<String, String> persistentPresets = Settings.forPackage(RenamePanel.class).node("presets").asMap();
ActionPopup actionPopup = new ActionPopup("Presets", ResourceManager.getIcon("action.script")); ActionPopup actionPopup = new ActionPopup("Presets", ResourceManager.getIcon("action.script"));
if (persistentPresets.size() > 0) { if (persistentPresets.size() > 0) {
@ -428,14 +425,14 @@ public class RenamePanel extends JComponent {
presetEditor.setVisible(true); presetEditor.setVisible(true);
switch (presetEditor.getResult()) { switch (presetEditor.getResult()) {
case DELETE:
persistentPresets.remove(selection);
break;
case SET: case SET:
preset = presetEditor.getPreset(); preset = presetEditor.getPreset();
persistentPresets.put(selection, JsonWriter.objectToJson(preset)); persistentPresets.put(selection, JsonWriter.objectToJson(preset));
new ApplyPresetAction(preset).actionPerformed(evt); new ApplyPresetAction(preset).actionPerformed(evt);
break; break;
case DELETE:
persistentPresets.remove(selection);
break;
case CANCEL: case CANCEL:
break; break;
} }