diff --git a/source/net/filebot/ui/rename/PresetEditor.java b/source/net/filebot/ui/rename/PresetEditor.java index 1c2c937e..9529603c 100644 --- a/source/net/filebot/ui/rename/PresetEditor.java +++ b/source/net/filebot/ui/rename/PresetEditor.java @@ -1,8 +1,8 @@ package net.filebot.ui.rename; -import static net.filebot.ui.NotificationLogging.*; import static java.awt.Font.*; import static javax.swing.BorderFactory.*; +import static net.filebot.ui.NotificationLogging.*; import static net.filebot.util.ui.SwingUI.*; import java.awt.Component; @@ -26,7 +26,6 @@ import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.ListCellRenderer; -import javax.swing.SwingUtilities; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; @@ -51,20 +50,6 @@ import org.fife.ui.rtextarea.RTextScrollPane; 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 { SET, DELETE, CANCEL; } @@ -106,6 +91,7 @@ public class PresetEditor extends JDialog { JButton pathButton = createImageButton(selectInputFolder); JPanel inputPanel = new JPanel(new MigLayout("insets 0, fill")); + inputPanel.setOpaque(false); inputPanel.add(new JLabel("Input Folder:"), "gap indent"); inputPanel.add(pathInput, "growx, gap rel"); inputPanel.add(pathButton, "gap rel, wrap"); @@ -140,7 +126,7 @@ public class PresetEditor extends JDialog { c.add(searchGroup, "growx, wrap push"); c.add(new JButton(set), "tag apply"); c.add(new JButton(delete), "tag cancel"); - setSize(650, 550); + setSize(650, 570); ButtonGroup inputButtonGroup = new ButtonGroup(); inputButtonGroup.add(inheritRadio); @@ -166,6 +152,8 @@ public class PresetEditor extends JDialog { 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()); + + selectRadio.setSelected(p.getInputFolder() != null); } public Preset getPreset() throws Exception { diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index 2f1c557f..422c8578 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -12,6 +12,7 @@ import static net.filebot.util.ui.SwingUI.*; import java.awt.Component; import java.awt.Cursor; +import java.awt.Dimension; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -20,7 +21,6 @@ import java.awt.event.MouseEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; -import java.io.FileFilter; import java.util.ArrayList; import java.util.EnumSet; import java.util.LinkedList; @@ -48,9 +48,6 @@ 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; @@ -64,6 +61,7 @@ import net.filebot.format.MediaBindingBean; import net.filebot.mac.MacAppUtilities; import net.filebot.media.MediaDetection; import net.filebot.similarity.Match; +import net.filebot.ui.SelectDialog; import net.filebot.ui.rename.FormatDialog.Mode; import net.filebot.ui.rename.RenameModel.FormattedFuture; import net.filebot.ui.transfer.BackgroundFileTransferablePolicy; @@ -88,6 +86,9 @@ import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.ListSelection; import ca.odell.glazedlists.swing.EventSelectionModel; +import com.cedarsoftware.util.io.JsonReader; +import com.cedarsoftware.util.io.JsonWriter; + public class RenamePanel extends JComponent { public static final String MATCH_MODE_OPPORTUNISTIC = "Opportunistic"; @@ -393,7 +394,7 @@ public class RenamePanel extends JComponent { 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); + Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.toString()); } } } @@ -408,7 +409,13 @@ public class RenamePanel extends JComponent { List presetNames = new ArrayList(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); + SelectDialog selectDialog = new SelectDialog(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) return; @@ -438,7 +445,7 @@ public class RenamePanel extends JComponent { break; } } 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 getFiles(ActionEvent evt) { List input = new ArrayList(); if (preset.getInputFolder() != null) { - List selection = FileUtilities.listFiles(preset.getInputFolder()); + input.addAll(FileUtilities.listFiles(preset.getInputFolder())); ExpressionFilter filter = preset.getIncludeFilter(); if (filter != null) { - selection = FileUtilities.filter(selection, (File f) -> { + input = FileUtilities.filter(input, (File f) -> { try { - return filter.matches(new MediaBindingBean(null, f)); + return filter.matches(new MediaBindingBean(f, f)); } catch (Exception e) { Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.toString()); return false; } }); } - input.addAll(selection); - renameModel.clear(); renameModel.files().addAll(input); } else {