+ Preset Editor UI
This commit is contained in:
parent
bb4a23cad6
commit
6c22b3e502
|
@ -1,8 +1,8 @@
|
||||||
package net.filebot.ui.rename;
|
package net.filebot.ui.rename;
|
||||||
|
|
||||||
import static net.filebot.ui.NotificationLogging.*;
|
|
||||||
import static java.awt.Font.*;
|
import static java.awt.Font.*;
|
||||||
import static javax.swing.BorderFactory.*;
|
import static javax.swing.BorderFactory.*;
|
||||||
|
import static net.filebot.ui.NotificationLogging.*;
|
||||||
import static net.filebot.util.ui.SwingUI.*;
|
import static net.filebot.util.ui.SwingUI.*;
|
||||||
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
@ -26,7 +26,6 @@ import javax.swing.JPanel;
|
||||||
import javax.swing.JRadioButton;
|
import javax.swing.JRadioButton;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.ListCellRenderer;
|
import javax.swing.ListCellRenderer;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.text.AttributeSet;
|
import javax.swing.text.AttributeSet;
|
||||||
import javax.swing.text.BadLocationException;
|
import javax.swing.text.BadLocationException;
|
||||||
|
|
||||||
|
@ -51,20 +50,6 @@ import org.fife.ui.rtextarea.RTextScrollPane;
|
||||||
|
|
||||||
public class PresetEditor extends JDialog {
|
public class PresetEditor extends JDialog {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Result {
|
enum Result {
|
||||||
SET, DELETE, CANCEL;
|
SET, DELETE, CANCEL;
|
||||||
}
|
}
|
||||||
|
@ -106,6 +91,7 @@ public class PresetEditor extends JDialog {
|
||||||
JButton pathButton = createImageButton(selectInputFolder);
|
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.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(pathButton, "gap rel, wrap");
|
||||||
|
@ -140,7 +126,7 @@ public class PresetEditor extends JDialog {
|
||||||
c.add(searchGroup, "growx, wrap push");
|
c.add(searchGroup, "growx, wrap push");
|
||||||
c.add(new JButton(set), "tag apply");
|
c.add(new JButton(set), "tag apply");
|
||||||
c.add(new JButton(delete), "tag cancel");
|
c.add(new JButton(delete), "tag cancel");
|
||||||
setSize(650, 550);
|
setSize(650, 570);
|
||||||
|
|
||||||
ButtonGroup inputButtonGroup = new ButtonGroup();
|
ButtonGroup inputButtonGroup = new ButtonGroup();
|
||||||
inputButtonGroup.add(inheritRadio);
|
inputButtonGroup.add(inheritRadio);
|
||||||
|
@ -166,6 +152,8 @@ public class PresetEditor extends JDialog {
|
||||||
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());
|
||||||
|
|
||||||
|
selectRadio.setSelected(p.getInputFolder() != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Preset getPreset() throws Exception {
|
public Preset getPreset() throws Exception {
|
||||||
|
|
|
@ -12,6 +12,7 @@ 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;
|
||||||
|
@ -20,7 +21,6 @@ import java.awt.event.MouseEvent;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -48,9 +48,6 @@ import javax.swing.SwingWorker;
|
||||||
import javax.swing.border.CompoundBorder;
|
import javax.swing.border.CompoundBorder;
|
||||||
import javax.swing.border.TitledBorder;
|
import javax.swing.border.TitledBorder;
|
||||||
|
|
||||||
import com.cedarsoftware.util.io.JsonReader;
|
|
||||||
import com.cedarsoftware.util.io.JsonWriter;
|
|
||||||
|
|
||||||
import net.filebot.History;
|
import net.filebot.History;
|
||||||
import net.filebot.HistorySpooler;
|
import net.filebot.HistorySpooler;
|
||||||
import net.filebot.Language;
|
import net.filebot.Language;
|
||||||
|
@ -64,6 +61,7 @@ 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;
|
||||||
|
@ -88,6 +86,9 @@ import ca.odell.glazedlists.EventList;
|
||||||
import ca.odell.glazedlists.ListSelection;
|
import ca.odell.glazedlists.ListSelection;
|
||||||
import ca.odell.glazedlists.swing.EventSelectionModel;
|
import ca.odell.glazedlists.swing.EventSelectionModel;
|
||||||
|
|
||||||
|
import com.cedarsoftware.util.io.JsonReader;
|
||||||
|
import com.cedarsoftware.util.io.JsonWriter;
|
||||||
|
|
||||||
public class RenamePanel extends JComponent {
|
public class RenamePanel extends JComponent {
|
||||||
|
|
||||||
public static final String MATCH_MODE_OPPORTUNISTIC = "Opportunistic";
|
public static final String MATCH_MODE_OPPORTUNISTIC = "Opportunistic";
|
||||||
|
@ -393,7 +394,7 @@ public class RenamePanel extends JComponent {
|
||||||
Preset p = (Preset) JsonReader.jsonToJava(it);
|
Preset p = (Preset) JsonReader.jsonToJava(it);
|
||||||
actionPopup.add(new ApplyPresetAction(p));
|
actionPopup.add(new ApplyPresetAction(p));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.getMessage(), e);
|
Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -408,7 +409,13 @@ public class RenamePanel extends JComponent {
|
||||||
List<String> presetNames = new ArrayList<String>(persistentPresets.keySet());
|
List<String> presetNames = new ArrayList<String>(persistentPresets.keySet());
|
||||||
presetNames.add(newPresetOption);
|
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);
|
SelectDialog<String> selectDialog = new SelectDialog<String>(getWindow(evt.getSource()), presetNames);
|
||||||
|
selectDialog.setLocation(getOffsetLocation(selectDialog.getOwner()));
|
||||||
|
selectDialog.setMinimumSize(new Dimension(250, 150));
|
||||||
|
selectDialog.setTitle("Edit Preset");
|
||||||
|
selectDialog.getHeaderLabel().setText("Edit or create a preset:");
|
||||||
|
selectDialog.setVisible(true);
|
||||||
|
String selection = selectDialog.getSelectedValue();
|
||||||
if (selection == null)
|
if (selection == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -438,7 +445,7 @@ public class RenamePanel extends JComponent {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.getMessage(), e);
|
Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -698,20 +705,18 @@ public class RenamePanel extends JComponent {
|
||||||
public List<File> getFiles(ActionEvent evt) {
|
public List<File> getFiles(ActionEvent evt) {
|
||||||
List<File> input = new ArrayList<File>();
|
List<File> input = new ArrayList<File>();
|
||||||
if (preset.getInputFolder() != null) {
|
if (preset.getInputFolder() != null) {
|
||||||
List<File> selection = FileUtilities.listFiles(preset.getInputFolder());
|
input.addAll(FileUtilities.listFiles(preset.getInputFolder()));
|
||||||
ExpressionFilter filter = preset.getIncludeFilter();
|
ExpressionFilter filter = preset.getIncludeFilter();
|
||||||
if (filter != null) {
|
if (filter != null) {
|
||||||
selection = FileUtilities.filter(selection, (File f) -> {
|
input = FileUtilities.filter(input, (File f) -> {
|
||||||
try {
|
try {
|
||||||
return filter.matches(new MediaBindingBean(null, f));
|
return filter.matches(new MediaBindingBean(f, f));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.toString());
|
Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.toString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
input.addAll(selection);
|
|
||||||
|
|
||||||
renameModel.clear();
|
renameModel.clear();
|
||||||
renameModel.files().addAll(input);
|
renameModel.files().addAll(input);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue