1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-16 06:15:02 -05:00

* added some slight auto-completion to editor in EpisodeFormatDialog

* make all Settings-related members static final
This commit is contained in:
Reinhard Pointner 2009-08-03 23:51:31 +00:00
parent 118e0368ae
commit b7c1086c4d
9 changed files with 65 additions and 52 deletions

View File

@ -56,11 +56,6 @@ public final class Settings {
} }
public static Settings forPackage(Object object) {
return forPackage(object.getClass());
}
private final Preferences prefs; private final Preferences prefs;

View File

@ -47,7 +47,7 @@ public class MainFrame extends JFrame {
private HeaderPanel headerPanel = new HeaderPanel(); private HeaderPanel headerPanel = new HeaderPanel();
private PreferencesEntry<String> persistentSelectedPanel = Settings.forPackage(this).entry("panel.selected").defaultValue("1"); private static final PreferencesEntry<String> persistentSelectedPanel = Settings.forPackage(MainFrame.class).entry("panel.selected").defaultValue("1");
public MainFrame() { public MainFrame() {

View File

@ -88,7 +88,7 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
@Override @Override
protected Settings getSettings() { protected Settings getSettings() {
return Settings.forPackage(this); return Settings.forPackage(EpisodeListPanel.class);
} }

View File

@ -165,15 +165,6 @@ class EpisodeBindingDialog extends JDialog {
} }
private JButton createImageButton(Action action) {
JButton button = new JButton(action);
button.setHideActionText(true);
button.setOpaque(false);
return button;
}
private JTable createBindingTable(TableModel model) { private JTable createBindingTable(TableModel model) {
JTable table = new JTable(model); JTable table = new JTable(model);
table.setAutoCreateRowSorter(true); table.setAutoCreateRowSorter(true);

View File

@ -45,6 +45,7 @@ import javax.swing.KeyStroke;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import javax.swing.Timer; import javax.swing.Timer;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.text.JTextComponent;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sourceforge.filebot.ResourceManager; import net.sourceforge.filebot.ResourceManager;
@ -72,9 +73,9 @@ class EpisodeFormatDialog extends JDialog {
private ExpressionFormat selectedFormat; private ExpressionFormat selectedFormat;
private EpisodeBindingBean sample; private EpisodeBindingBean sample = restoreSample();
private ExecutorService executor; private ExecutorService executor = createExecutor();
private RunnableFuture<String> currentPreviewFuture; private RunnableFuture<String> currentPreviewFuture;
@ -84,11 +85,11 @@ class EpisodeFormatDialog extends JDialog {
private ProgressIndicator progressIndicator = new ProgressIndicator(); private ProgressIndicator progressIndicator = new ProgressIndicator();
private JTextField editor = new JTextField(); private JTextComponent editor = createEditor();
private PreferencesEntry<String> persistentSampleEpisode = Settings.forPackage(this).entry("format.sample.episode"); private static final PreferencesEntry<String> persistentSampleEpisode = Settings.forPackage(EpisodeFormatDialog.class).entry("format.sample.episode");
private PreferencesEntry<String> persistentSampleFile = Settings.forPackage(this).entry("format.sample.file"); private static final PreferencesEntry<String> persistentSampleFile = Settings.forPackage(EpisodeFormatDialog.class).entry("format.sample.file");
private PreferencesList<String> persistentFormatHistory = Settings.forPackage(this).node("format.recent").asList(); private static final PreferencesList<String> persistentFormatHistory = Settings.forPackage(EpisodeFormatDialog.class).node("format.recent").asList();
public enum Option { public enum Option {
@ -101,16 +102,9 @@ class EpisodeFormatDialog extends JDialog {
public EpisodeFormatDialog(Window owner) { public EpisodeFormatDialog(Window owner) {
super(owner, "Episode Format", ModalityType.DOCUMENT_MODAL); super(owner, "Episode Format", ModalityType.DOCUMENT_MODAL);
sample = restoreSample(); // initialize hidden
executor = createExecutor();
editor.setFont(new Font(MONOSPACED, PLAIN, 14));
progressIndicator.setVisible(false); progressIndicator.setVisible(false);
// image button
JButton changeSampleButton = new JButton(changeSampleAction);
changeSampleButton.setHideActionText(true);
// bold title label in header // bold title label in header
JLabel title = new JLabel(this.getTitle()); JLabel title = new JLabel(this.getTitle());
title.setFont(title.getFont().deriveFont(BOLD)); title.setFont(title.getFont().deriveFont(BOLD));
@ -128,7 +122,7 @@ class EpisodeFormatDialog extends JDialog {
JPanel content = new JPanel(new MigLayout("insets dialog, nogrid, fill")); 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(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(new JLabel("Syntax"), "gap indent+unrel, wrap 0");
content.add(createSyntaxPanel(), "gapx indent indent, wrap 8px"); 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(header, "h 60px, growx, dock north");
pane.add(content, "grow"); 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() { addPropertyChangeListener("sample", new PropertyChangeListener() {
@Override @Override
@ -187,9 +169,6 @@ class EpisodeFormatDialog extends JDialog {
// install editor suggestions popup // install editor suggestions popup
TunedUtilities.installAction(editor, KeyStroke.getKeyStroke("DOWN"), displayRecentFormatHistory); TunedUtilities.installAction(editor, KeyStroke.getKeyStroke("DOWN"), displayRecentFormatHistory);
// restore editor state
editor.setText(persistentFormatHistory.isEmpty() ? "" : persistentFormatHistory.get(0));
// update preview to current format // update preview to current format
fireSampleChanged(); 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() { private JComponent createSyntaxPanel() {
JPanel panel = new JPanel(new MigLayout("fill, nogrid")); JPanel panel = new JPanel(new MigLayout("fill, nogrid"));

View File

@ -59,8 +59,8 @@ public class RenamePanel extends JComponent {
protected final RenameAction renameAction = new RenameAction(renameModel); protected final RenameAction renameAction = new RenameAction(renameModel);
private final PreferencesEntry<String> persistentPreserveExtension = Settings.forPackage(this).entry("rename.extension.preserve").defaultValue("true"); private static final PreferencesEntry<String> persistentPreserveExtension = Settings.forPackage(RenamePanel.class).entry("rename.extension.preserve").defaultValue("true");
private final PreferencesEntry<String> persistentFormatExpression = Settings.forPackage(this).entry("rename.format"); private static final PreferencesEntry<String> persistentFormatExpression = Settings.forPackage(RenamePanel.class).entry("rename.format");
public RenamePanel() { public RenamePanel() {

View File

@ -36,8 +36,8 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
private final LanguageComboBoxModel languageModel = new LanguageComboBoxModel(); private final LanguageComboBoxModel languageModel = new LanguageComboBoxModel();
private final PreferencesEntry<String> persistentSelectedLanguage = Settings.forPackage(this).entry("language.selected"); private static final PreferencesEntry<String> persistentSelectedLanguage = Settings.forPackage(SubtitlePanel.class).entry("language.selected");
private final PreferencesList<String> persistentFavoriteLanguages = Settings.forPackage(this).node("language.favorites").asList(); private static final PreferencesList<String> persistentFavoriteLanguages = Settings.forPackage(SubtitlePanel.class).node("language.favorites").asList();
public SubtitlePanel() { public SubtitlePanel() {
@ -114,7 +114,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
@Override @Override
protected Settings getSettings() { protected Settings getSettings() {
return Settings.forPackage(this); return Settings.forPackage(SubtitlePanel.class);
} }

View File

@ -168,7 +168,7 @@ public class SubsceneSubtitleClient implements SubtitleProvider {
protected Map<String, String> initLanguageFilterMap() { protected Map<String, String> initLanguageFilterMap() {
return Settings.forPackage(this).node("subtitles/subscene/languageFilterMap").asMap(); return Settings.forPackage(SublightSubtitleClient.class).node("subtitles/subscene/languageFilterMap").asMap();
} }

View File

@ -19,6 +19,7 @@ import javax.swing.AbstractAction;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel; 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) { public static void installAction(JComponent component, KeyStroke keystroke, Action action) {
Object key = action.getValue(Action.NAME); Object key = action.getValue(Action.NAME);