diff --git a/source/net/filebot/Settings.java b/source/net/filebot/Settings.java index 80c23b4e..80139c3f 100644 --- a/source/net/filebot/Settings.java +++ b/source/net/filebot/Settings.java @@ -235,7 +235,7 @@ public final class Settings { return PreferencesMap.map(prefs); } - public PreferencesMap asTypedMap(Class cls) { + public PreferencesMap asMap(Class cls) { return PreferencesMap.map(prefs, new JsonAdapter(cls)); } @@ -243,7 +243,7 @@ public final class Settings { return PreferencesList.map(prefs); } - public PreferencesList asTypedList(Class cls) { + public PreferencesList asList(Class cls) { return PreferencesList.map(prefs, new JsonAdapter(cls)); } diff --git a/source/net/filebot/ui/MainFrame.java b/source/net/filebot/ui/MainFrame.java index fc7414b1..190b4049 100644 --- a/source/net/filebot/ui/MainFrame.java +++ b/source/net/filebot/ui/MainFrame.java @@ -2,6 +2,8 @@ package net.filebot.ui; import static java.awt.event.InputEvent.*; import static java.awt.event.KeyEvent.*; +import static java.util.Arrays.*; +import static java.util.Comparator.*; import static javax.swing.KeyStroke.*; import static javax.swing.ScrollPaneConstants.*; import static net.filebot.Logging.*; @@ -33,8 +35,6 @@ import javax.swing.Timer; import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import com.google.common.eventbus.Subscribe; @@ -65,7 +65,7 @@ public class MainFrame extends JFrame { try { selectionList.setSelectedIndex(Integer.parseInt(persistentSelectedPanel.getValue())); } catch (Exception e) { - debug.warning(e.getMessage()); + debug.warning(e::getMessage); } JScrollPane selectionListScrollPane = new JScrollPane(selectionList, VERTICAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_NEVER); @@ -88,15 +88,11 @@ public class MainFrame extends JFrame { // show initial panel showPanel((PanelBuilder) selectionList.getSelectedValue()); - selectionList.addListSelectionListener(new ListSelectionListener() { + selectionList.addListSelectionListener(evt -> { + showPanel((PanelBuilder) selectionList.getSelectedValue()); - @Override - public void valueChanged(ListSelectionEvent e) { - showPanel((PanelBuilder) selectionList.getSelectedValue()); - - if (!e.getValueIsAdjusting()) { - persistentSelectedPanel.setValue(Integer.toString(selectionList.getSelectedIndex())); - } + if (!evt.getValueIsAdjusting()) { + persistentSelectedPanel.setValue(Integer.toString(selectionList.getSelectedIndex())); } }); @@ -185,9 +181,10 @@ public class MainFrame extends JFrame { public PanelSelectionList(PanelBuilder[] builders) { super(builders); + setPrototypeCellValue(stream(builders).max(comparingInt(p -> p.getName().length())).get()); setCellRenderer(new PanelCellRenderer()); - setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setBorder(new EmptyBorder(4, 5, 4, 5)); // initialize "drag over" panel selection diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index 2db5eb0f..df6cef42 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -109,7 +109,7 @@ public class RenamePanel extends JComponent { private static final PreferencesEntry persistentPreferredLanguage = Settings.forPackage(RenamePanel.class).entry("rename.language").defaultValue("en"); private static final PreferencesEntry persistentPreferredEpisodeOrder = Settings.forPackage(RenamePanel.class).entry("rename.episode.order").defaultValue("Airdate"); - private static final Map persistentPresets = Settings.forPackage(RenamePanel.class).node("presets").asTypedMap(Preset.class); + private static final Map persistentPresets = Settings.forPackage(RenamePanel.class).node("presets").asMap(Preset.class); public RenamePanel() { namesList.setTitle("New Names");