mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 08:18:52 -05:00
+ Preset Editor UI
This commit is contained in:
parent
a5d987dc08
commit
bb4a23cad6
@ -44,7 +44,7 @@ public class Preset {
|
||||
}
|
||||
|
||||
public File getInputFolder() {
|
||||
return new File(path);
|
||||
return path == null || path.isEmpty() ? null : new File(path);
|
||||
}
|
||||
|
||||
public ExpressionFilter getIncludeFilter() {
|
||||
@ -129,4 +129,9 @@ public class Preset {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,9 +51,17 @@ import org.fife.ui.rtextarea.RTextScrollPane;
|
||||
|
||||
public class PresetEditor extends JDialog {
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
new PresetEditor(null).setVisible(true);
|
||||
PresetEditor presetEditor = new PresetEditor(null);
|
||||
presetEditor.setVisible(true);
|
||||
try {
|
||||
System.out.println(presetEditor.getResult());
|
||||
System.out.println(presetEditor.getPreset());
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -82,7 +90,7 @@ public class PresetEditor extends JDialog {
|
||||
|
||||
presetNameHeader = new HeaderPanel();
|
||||
|
||||
inheritRadio = new JRadioButton("<html>Use <b>Original Files</b></html>");
|
||||
inheritRadio = new JRadioButton("<html>Use <b>Original Files</b> selection</html>");
|
||||
selectRadio = new JRadioButton("<html>Do <b>Select</b></html>");
|
||||
pathInput = new JTextField(40);
|
||||
|
||||
@ -151,13 +159,13 @@ public class PresetEditor extends JDialog {
|
||||
|
||||
public void setPreset(Preset p) {
|
||||
presetNameHeader.getTitleLabel().setText(p.getName());
|
||||
pathInput.setText(p.getInputFolder().getPath());
|
||||
filterEditor.setText(p.getIncludeFilter().getExpression());
|
||||
formatEditor.setText(p.getFormat().getExpression());
|
||||
providerCombo.setSelectedItem(p.getDatabase());
|
||||
sortOrderCombo.setSelectedItem(p.getSortOrder());
|
||||
matchModeCombo.setSelectedItem(p.getMatchMode());
|
||||
actionCombo.setSelectedItem(p.getRenameAction());
|
||||
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());
|
||||
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());
|
||||
}
|
||||
|
||||
public Preset getPreset() throws Exception {
|
||||
|
@ -48,6 +48,9 @@ import javax.swing.SwingWorker;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
import com.cedarsoftware.util.io.JsonReader;
|
||||
import com.cedarsoftware.util.io.JsonWriter;
|
||||
|
||||
import net.filebot.History;
|
||||
import net.filebot.HistorySpooler;
|
||||
import net.filebot.Language;
|
||||
@ -65,6 +68,7 @@ import net.filebot.ui.rename.FormatDialog.Mode;
|
||||
import net.filebot.ui.rename.RenameModel.FormattedFuture;
|
||||
import net.filebot.ui.transfer.BackgroundFileTransferablePolicy;
|
||||
import net.filebot.util.FileUtilities;
|
||||
import net.filebot.util.PreferencesMap;
|
||||
import net.filebot.util.PreferencesMap.PreferencesEntry;
|
||||
import net.filebot.util.ui.ActionPopup;
|
||||
import net.filebot.util.ui.LoadingOverlayPane;
|
||||
@ -379,16 +383,18 @@ public class RenamePanel extends JComponent {
|
||||
}
|
||||
|
||||
protected ActionPopup createPresetsPopup() {
|
||||
List<Preset> presets = new ArrayList<Preset>();
|
||||
PreferencesMap<String> persistentPresets = Settings.forPackage(RenamePanel.class).node("presets").asMap();
|
||||
ActionPopup actionPopup = new ActionPopup("Presets", ResourceManager.getIcon("action.script"));
|
||||
|
||||
// TODO load presets via prefs
|
||||
|
||||
final ActionPopup actionPopup = new ActionPopup("Presets", ResourceManager.getIcon("action.script"));
|
||||
|
||||
if (presets.size() > 0) {
|
||||
if (persistentPresets.size() > 0) {
|
||||
actionPopup.addDescription(new JLabel("Apply:"));
|
||||
for (Preset it : presets) {
|
||||
actionPopup.add(new ApplyPresetAction(it));
|
||||
for (String it : persistentPresets.values()) {
|
||||
try {
|
||||
Preset p = (Preset) JsonReader.jsonToJava(it);
|
||||
actionPopup.add(new ApplyPresetAction(p));
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -396,9 +402,44 @@ public class RenamePanel extends JComponent {
|
||||
actionPopup.add(new AbstractAction("Edit Presets", ResourceManager.getIcon("script.add")) {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
try {
|
||||
String newPresetOption = "New Preset …";
|
||||
List<String> presetNames = new ArrayList<String>(persistentPresets.keySet());
|
||||
presetNames.add(newPresetOption);
|
||||
|
||||
String selection = (String) JOptionPane.showInputDialog(getWindow(evt.getSource()), "Edit or create a preset:", "Edit Preset", JOptionPane.PLAIN_MESSAGE, null, presetNames.toArray(), newPresetOption);
|
||||
if (selection == null)
|
||||
return;
|
||||
|
||||
Preset preset = null;
|
||||
if (selection == newPresetOption) {
|
||||
selection = (String) JOptionPane.showInputDialog(getWindow(evt.getSource()), "Preset Name:", newPresetOption, JOptionPane.PLAIN_MESSAGE, null, null, "My Preset");
|
||||
if (selection == null)
|
||||
return;
|
||||
|
||||
preset = new Preset(selection, null, null, null, null, null, null, null, null);
|
||||
} else {
|
||||
preset = (Preset) JsonReader.jsonToJava(persistentPresets.get(selection.toString()));
|
||||
}
|
||||
|
||||
PresetEditor presetEditor = new PresetEditor(getWindow(evt.getSource()));
|
||||
presetEditor.setPreset(preset);
|
||||
presetEditor.setVisible(true);
|
||||
|
||||
switch (presetEditor.getResult()) {
|
||||
case DELETE:
|
||||
persistentPresets.remove(selection);
|
||||
break;
|
||||
case SET:
|
||||
persistentPresets.put(selection, JsonWriter.objectToJson(presetEditor.getPreset()));
|
||||
break;
|
||||
case CANCEL:
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user