diff --git a/source/net/sourceforge/filebot/Settings.java b/source/net/sourceforge/filebot/Settings.java index 63bf3257..c8ad7aef 100644 --- a/source/net/sourceforge/filebot/Settings.java +++ b/source/net/sourceforge/filebot/Settings.java @@ -56,11 +56,6 @@ public final class Settings { } - public static Settings forPackage(Object object) { - return forPackage(object.getClass()); - } - - private final Preferences prefs; diff --git a/source/net/sourceforge/filebot/ui/MainFrame.java b/source/net/sourceforge/filebot/ui/MainFrame.java index e4087cda..8c786c91 100644 --- a/source/net/sourceforge/filebot/ui/MainFrame.java +++ b/source/net/sourceforge/filebot/ui/MainFrame.java @@ -47,7 +47,7 @@ public class MainFrame extends JFrame { private HeaderPanel headerPanel = new HeaderPanel(); - private PreferencesEntry persistentSelectedPanel = Settings.forPackage(this).entry("panel.selected").defaultValue("1"); + private static final PreferencesEntry persistentSelectedPanel = Settings.forPackage(MainFrame.class).entry("panel.selected").defaultValue("1"); public MainFrame() { diff --git a/source/net/sourceforge/filebot/ui/panel/episodelist/EpisodeListPanel.java b/source/net/sourceforge/filebot/ui/panel/episodelist/EpisodeListPanel.java index 1ba618d0..44bb4215 100644 --- a/source/net/sourceforge/filebot/ui/panel/episodelist/EpisodeListPanel.java +++ b/source/net/sourceforge/filebot/ui/panel/episodelist/EpisodeListPanel.java @@ -88,7 +88,7 @@ public class EpisodeListPanel extends AbstractSearchPanel currentPreviewFuture; @@ -84,11 +85,11 @@ class EpisodeFormatDialog extends JDialog { private ProgressIndicator progressIndicator = new ProgressIndicator(); - private JTextField editor = new JTextField(); + private JTextComponent editor = createEditor(); - private PreferencesEntry persistentSampleEpisode = Settings.forPackage(this).entry("format.sample.episode"); - private PreferencesEntry persistentSampleFile = Settings.forPackage(this).entry("format.sample.file"); - private PreferencesList persistentFormatHistory = Settings.forPackage(this).node("format.recent").asList(); + private static final PreferencesEntry persistentSampleEpisode = Settings.forPackage(EpisodeFormatDialog.class).entry("format.sample.episode"); + private static final PreferencesEntry persistentSampleFile = Settings.forPackage(EpisodeFormatDialog.class).entry("format.sample.file"); + private static final PreferencesList persistentFormatHistory = Settings.forPackage(EpisodeFormatDialog.class).node("format.recent").asList(); public enum Option { @@ -101,16 +102,9 @@ class EpisodeFormatDialog extends JDialog { public EpisodeFormatDialog(Window owner) { super(owner, "Episode Format", ModalityType.DOCUMENT_MODAL); - sample = restoreSample(); - executor = createExecutor(); - - editor.setFont(new Font(MONOSPACED, PLAIN, 14)); + // initialize hidden progressIndicator.setVisible(false); - // image button - JButton changeSampleButton = new JButton(changeSampleAction); - changeSampleButton.setHideActionText(true); - // bold title label in header JLabel title = new JLabel(this.getTitle()); title.setFont(title.getFont().deriveFont(BOLD)); @@ -128,7 +122,7 @@ class EpisodeFormatDialog extends JDialog { JPanel content = new JPanel(new MigLayout("insets dialog, nogrid, fill")); content.add(editor, "w 120px:min(pref, 420px), h 40px!, growx, wrap 4px, id editor"); - content.add(changeSampleButton, "w 25!, h 19!, pos n editor.y2+1 editor.x2 n"); + content.add(createImageButton(changeSampleAction), "w 25!, h 19!, pos n editor.y2+1 editor.x2 n"); content.add(new JLabel("Syntax"), "gap indent+unrel, wrap 0"); content.add(createSyntaxPanel(), "gapx indent indent, wrap 8px"); @@ -146,18 +140,6 @@ class EpisodeFormatDialog extends JDialog { pane.add(header, "h 60px, growx, dock north"); pane.add(content, "grow"); - // enable undo/redo - TunedUtilities.installUndoSupport(editor); - - // update format on change - editor.getDocument().addDocumentListener(new LazyDocumentListener() { - - @Override - public void update(DocumentEvent e) { - checkFormatInBackground(); - } - }); - addPropertyChangeListener("sample", new PropertyChangeListener() { @Override @@ -187,9 +169,6 @@ class EpisodeFormatDialog extends JDialog { // install editor suggestions popup TunedUtilities.installAction(editor, KeyStroke.getKeyStroke("DOWN"), displayRecentFormatHistory); - // restore editor state - editor.setText(persistentFormatHistory.isEmpty() ? "" : persistentFormatHistory.get(0)); - // update preview to current format fireSampleChanged(); @@ -199,6 +178,44 @@ class EpisodeFormatDialog extends JDialog { } + private JTextComponent createEditor() { + final JTextComponent editor = new JTextField(new ExpressionFormatDocument(), null, 0); + editor.setFont(new Font(MONOSPACED, PLAIN, 14)); + + // restore editor state + editor.setText(persistentFormatHistory.isEmpty() ? "" : persistentFormatHistory.get(0)); + + // enable undo/redo + installUndoSupport(editor); + + // update format on change + editor.getDocument().addDocumentListener(new LazyDocumentListener() { + + @Override + public void update(DocumentEvent e) { + checkFormatInBackground(); + } + }); + + // improved cursor behaviour, use delayed listener, so we apply our cursor updates, after the text component is finished with its own + editor.getDocument().addDocumentListener(new LazyDocumentListener(0) { + + @Override + public void update(DocumentEvent evt) { + if (evt.getType() == DocumentEvent.EventType.INSERT) { + ExpressionFormatDocument document = (ExpressionFormatDocument) evt.getDocument(); + + if (document.getLastCompletion() != null) { + editor.setCaretPosition(editor.getCaretPosition() - 1); + } + } + } + }); + + return editor; + } + + private JComponent createSyntaxPanel() { JPanel panel = new JPanel(new MigLayout("fill, nogrid")); diff --git a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java index 592ec727..ff742fe7 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java @@ -59,8 +59,8 @@ public class RenamePanel extends JComponent { protected final RenameAction renameAction = new RenameAction(renameModel); - private final PreferencesEntry persistentPreserveExtension = Settings.forPackage(this).entry("rename.extension.preserve").defaultValue("true"); - private final PreferencesEntry persistentFormatExpression = Settings.forPackage(this).entry("rename.format"); + private static final PreferencesEntry persistentPreserveExtension = Settings.forPackage(RenamePanel.class).entry("rename.extension.preserve").defaultValue("true"); + private static final PreferencesEntry persistentFormatExpression = Settings.forPackage(RenamePanel.class).entry("rename.format"); public RenamePanel() { diff --git a/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java b/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java index d76a8e91..6066ba51 100644 --- a/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java @@ -36,8 +36,8 @@ public class SubtitlePanel extends AbstractSearchPanel persistentSelectedLanguage = Settings.forPackage(this).entry("language.selected"); - private final PreferencesList persistentFavoriteLanguages = Settings.forPackage(this).node("language.favorites").asList(); + private static final PreferencesEntry persistentSelectedLanguage = Settings.forPackage(SubtitlePanel.class).entry("language.selected"); + private static final PreferencesList persistentFavoriteLanguages = Settings.forPackage(SubtitlePanel.class).node("language.favorites").asList(); public SubtitlePanel() { @@ -114,7 +114,7 @@ public class SubtitlePanel extends AbstractSearchPanel initLanguageFilterMap() { - return Settings.forPackage(this).node("subtitles/subscene/languageFilterMap").asMap(); + return Settings.forPackage(SublightSubtitleClient.class).node("subtitles/subscene/languageFilterMap").asMap(); } diff --git a/source/net/sourceforge/tuned/ui/TunedUtilities.java b/source/net/sourceforge/tuned/ui/TunedUtilities.java index e571c723..0b66ce2a 100644 --- a/source/net/sourceforge/tuned/ui/TunedUtilities.java +++ b/source/net/sourceforge/tuned/ui/TunedUtilities.java @@ -19,6 +19,7 @@ import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.Icon; import javax.swing.ImageIcon; +import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.KeyStroke; import javax.swing.ListSelectionModel; @@ -47,6 +48,15 @@ public final class TunedUtilities { } + public static JButton createImageButton(Action action) { + JButton button = new JButton(action); + button.setHideActionText(true); + button.setOpaque(false); + + return button; + } + + public static void installAction(JComponent component, KeyStroke keystroke, Action action) { Object key = action.getValue(Action.NAME);