+ use RSyntaxTextArea as Groovy editor so we get neat highlighting and bracket matching :)
This commit is contained in:
parent
0408a17ddb
commit
07173fabf0
|
@ -101,6 +101,10 @@
|
||||||
<include name="net/miginfocom/**" />
|
<include name="net/miginfocom/**" />
|
||||||
</zipfileset>
|
</zipfileset>
|
||||||
|
|
||||||
|
<zipfileset src="${dir.lib}/rsyntaxtextarea.jar">
|
||||||
|
<include name="org/fife/**" />
|
||||||
|
</zipfileset>
|
||||||
|
|
||||||
<zipfileset src="${dir.lib}/xmlrpc.jar">
|
<zipfileset src="${dir.lib}/xmlrpc.jar">
|
||||||
<include name="redstone/xmlrpc/**" />
|
<include name="redstone/xmlrpc/**" />
|
||||||
</zipfileset>
|
</zipfileset>
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
<jar href="xercesImpl.jar" download="lazy" part="scraper" />
|
<jar href="xercesImpl.jar" download="lazy" part="scraper" />
|
||||||
<jar href="mediainfo.jar" download="lazy" part="native" />
|
<jar href="mediainfo.jar" download="lazy" part="native" />
|
||||||
<jar href="sevenzipjbinding.jar" download="lazy" part="native" />
|
<jar href="sevenzipjbinding.jar" download="lazy" part="native" />
|
||||||
|
<jar href="rsyntaxtextarea.jar" download="eager" />
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
<resources os="Windows" arch="x86">
|
<resources os="Windows" arch="x86">
|
||||||
|
|
Binary file not shown.
|
@ -1,94 +0,0 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot.ui.rename;
|
|
||||||
|
|
||||||
|
|
||||||
import javax.swing.event.DocumentEvent;
|
|
||||||
import javax.swing.text.AttributeSet;
|
|
||||||
import javax.swing.text.BadLocationException;
|
|
||||||
import javax.swing.text.Document;
|
|
||||||
import javax.swing.text.PlainDocument;
|
|
||||||
|
|
||||||
|
|
||||||
class ExpressionFormatDocument extends PlainDocument {
|
|
||||||
|
|
||||||
private Completion lastCompletion;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void insertString(int offset, String text, AttributeSet attributes) throws BadLocationException {
|
|
||||||
if (text == null || text.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignore user input that matches the last auto-completion
|
|
||||||
if (lastCompletion != null && lastCompletion.didComplete(this, offset, text)) {
|
|
||||||
lastCompletion = null;
|
|
||||||
|
|
||||||
// behave as if something was inserted (e.g. update caret position)
|
|
||||||
fireInsertUpdate(new DefaultDocumentEvent(offset, text.length(), DocumentEvent.EventType.INSERT));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to auto-complete input
|
|
||||||
lastCompletion = Completion.getCompletion(this, offset, text);
|
|
||||||
|
|
||||||
if (lastCompletion != null) {
|
|
||||||
text = lastCompletion.complete(this, offset, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.insertString(offset, text, attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Completion getLastCompletion() {
|
|
||||||
return lastCompletion;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public enum Completion {
|
|
||||||
RoundBrackets("()"),
|
|
||||||
SquareBrackets("[]"),
|
|
||||||
CurlyBrackets("{}"),
|
|
||||||
SingleQuoteStringLiteral("''"),
|
|
||||||
DoubleQuoteStringLiteral("\"\"");
|
|
||||||
|
|
||||||
public final String pattern;
|
|
||||||
|
|
||||||
|
|
||||||
private Completion(String pattern) {
|
|
||||||
this.pattern = pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean canComplete(Document document, int offset, String input) {
|
|
||||||
return pattern.startsWith(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean didComplete(Document document, int offset, String input) {
|
|
||||||
try {
|
|
||||||
return document.getText(0, offset).concat(input).endsWith(pattern);
|
|
||||||
} catch (BadLocationException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String complete(Document document, int offset, String input) {
|
|
||||||
return pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Completion getCompletion(Document document, int offset, String input) {
|
|
||||||
for (Completion completion : values()) {
|
|
||||||
if (completion.canComplete(document, offset, input)) {
|
|
||||||
return completion;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot.ui.rename;
|
package net.sourceforge.filebot.ui.rename;
|
||||||
|
|
||||||
|
|
||||||
import static java.awt.Font.*;
|
import static java.awt.Font.*;
|
||||||
import static javax.swing.BorderFactory.*;
|
import static javax.swing.BorderFactory.*;
|
||||||
import static net.sourceforge.filebot.ui.NotificationLogging.*;
|
import static net.sourceforge.filebot.ui.NotificationLogging.*;
|
||||||
|
@ -52,9 +50,13 @@ import javax.swing.JTextField;
|
||||||
import javax.swing.KeyStroke;
|
import javax.swing.KeyStroke;
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
import javax.swing.Timer;
|
import javax.swing.Timer;
|
||||||
|
import javax.swing.border.CompoundBorder;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentEvent;
|
||||||
import javax.swing.event.PopupMenuEvent;
|
import javax.swing.event.PopupMenuEvent;
|
||||||
import javax.swing.event.PopupMenuListener;
|
import javax.swing.event.PopupMenuListener;
|
||||||
|
import javax.swing.text.AttributeSet;
|
||||||
|
import javax.swing.text.BadLocationException;
|
||||||
import javax.swing.text.JTextComponent;
|
import javax.swing.text.JTextComponent;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
@ -78,11 +80,14 @@ import net.sourceforge.tuned.ui.TunedUtilities;
|
||||||
import net.sourceforge.tuned.ui.notification.SeparatorBorder;
|
import net.sourceforge.tuned.ui.notification.SeparatorBorder;
|
||||||
import net.sourceforge.tuned.ui.notification.SeparatorBorder.Position;
|
import net.sourceforge.tuned.ui.notification.SeparatorBorder.Position;
|
||||||
|
|
||||||
|
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
|
||||||
|
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
|
||||||
|
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
|
||||||
|
|
||||||
import com.cedarsoftware.util.io.JsonReader;
|
import com.cedarsoftware.util.io.JsonReader;
|
||||||
import com.cedarsoftware.util.io.JsonWriter;
|
import com.cedarsoftware.util.io.JsonWriter;
|
||||||
|
|
||||||
|
public class FormatDialog extends JDialog {
|
||||||
class FormatDialog extends JDialog {
|
|
||||||
|
|
||||||
private boolean submit = false;
|
private boolean submit = false;
|
||||||
|
|
||||||
|
@ -104,7 +109,6 @@ class FormatDialog extends JDialog {
|
||||||
|
|
||||||
private static final PreferencesEntry<String> persistentSampleFile = Settings.forPackage(FormatDialog.class).entry("format.sample.file");
|
private static final PreferencesEntry<String> persistentSampleFile = Settings.forPackage(FormatDialog.class).entry("format.sample.file");
|
||||||
|
|
||||||
|
|
||||||
public enum Mode {
|
public enum Mode {
|
||||||
Episode, Movie, Music;
|
Episode, Movie, Music;
|
||||||
|
|
||||||
|
@ -115,35 +119,30 @@ class FormatDialog extends JDialog {
|
||||||
return values()[0];
|
return values()[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String key() {
|
public String key() {
|
||||||
return this.name().toLowerCase();
|
return this.name().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Format getFormat() {
|
public Format getFormat() {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case Episode:
|
case Episode:
|
||||||
return new EpisodeFormat(true, true);
|
return new EpisodeFormat(true, true);
|
||||||
case Movie: // case Movie
|
case Movie: // case Movie
|
||||||
return new MovieFormat(true, true, false);
|
return new MovieFormat(true, true, false);
|
||||||
default:
|
default:
|
||||||
return new AudioTrackFormat();
|
return new AudioTrackFormat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public PreferencesEntry<String> persistentSample() {
|
public PreferencesEntry<String> persistentSample() {
|
||||||
return Settings.forPackage(FormatDialog.class).entry("format.sample." + key());
|
return Settings.forPackage(FormatDialog.class).entry("format.sample." + key());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public PreferencesList<String> persistentFormatHistory() {
|
public PreferencesList<String> persistentFormatHistory() {
|
||||||
return Settings.forPackage(FormatDialog.class).node("format.recent." + key()).asList();
|
return Settings.forPackage(FormatDialog.class).node("format.recent." + key()).asList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public FormatDialog(Window owner) {
|
public FormatDialog(Window owner) {
|
||||||
super(owner, ModalityType.DOCUMENT_MODAL);
|
super(owner, ModalityType.DOCUMENT_MODAL);
|
||||||
|
|
||||||
|
@ -225,7 +224,6 @@ class FormatDialog extends JDialog {
|
||||||
setSize(610, 430);
|
setSize(610, 430);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setMode(Mode mode) {
|
public void setMode(Mode mode) {
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
|
|
||||||
|
@ -246,7 +244,6 @@ class FormatDialog extends JDialog {
|
||||||
fireSampleChanged();
|
fireSampleChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private JComponent updateHelpPanel(Mode mode) {
|
private JComponent updateHelpPanel(Mode mode) {
|
||||||
help.removeAll();
|
help.removeAll();
|
||||||
|
|
||||||
|
@ -259,13 +256,28 @@ class FormatDialog extends JDialog {
|
||||||
return help;
|
return help;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private JTextComponent createEditor() {
|
private JTextComponent createEditor() {
|
||||||
final JTextComponent editor = new JTextField(new ExpressionFormatDocument(), null, 0);
|
final RSyntaxTextArea editor = new RSyntaxTextArea(new RSyntaxDocument(SyntaxConstants.SYNTAX_STYLE_GROOVY) {
|
||||||
editor.setFont(new Font(MONOSPACED, PLAIN, 14));
|
@Override
|
||||||
|
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
|
||||||
|
super.insertString(offs, str.replaceAll("\\s", " "), a); // FORCE SINGLE LINE
|
||||||
|
}
|
||||||
|
}, null, 1, 80);
|
||||||
|
|
||||||
// enable undo/redo
|
editor.setAntiAliasingEnabled(true);
|
||||||
installUndoSupport(editor);
|
editor.setAnimateBracketMatching(false);
|
||||||
|
editor.setAutoIndentEnabled(false);
|
||||||
|
editor.setClearWhitespaceLinesEnabled(false);
|
||||||
|
editor.setBracketMatchingEnabled(true);
|
||||||
|
editor.setCloseCurlyBraces(false);
|
||||||
|
editor.setCodeFoldingEnabled(false);
|
||||||
|
editor.setHyperlinksEnabled(false);
|
||||||
|
editor.setUseFocusableTips(false);
|
||||||
|
editor.setHighlightCurrentLine(false);
|
||||||
|
editor.setLineWrap(false);
|
||||||
|
|
||||||
|
editor.setBorder(new CompoundBorder(new JTextField().getBorder(), new EmptyBorder(7, 2, 7, 2)));
|
||||||
|
editor.setFont(new Font(MONOSPACED, PLAIN, 14));
|
||||||
|
|
||||||
// update format on change
|
// update format on change
|
||||||
editor.getDocument().addDocumentListener(new LazyDocumentListener() {
|
editor.getDocument().addDocumentListener(new LazyDocumentListener() {
|
||||||
|
@ -276,25 +288,9 @@ class FormatDialog extends JDialog {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 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;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private JComponent createSyntaxPanel(Mode mode) {
|
private JComponent createSyntaxPanel(Mode mode) {
|
||||||
JPanel panel = new JPanel(new MigLayout("fill, nogrid"));
|
JPanel panel = new JPanel(new MigLayout("fill, nogrid"));
|
||||||
|
|
||||||
|
@ -317,7 +313,6 @@ class FormatDialog extends JDialog {
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private JComponent createExamplesPanel(Mode mode) {
|
private JComponent createExamplesPanel(Mode mode) {
|
||||||
JPanel panel = new JPanel(new MigLayout("fill, wrap 3"));
|
JPanel panel = new JPanel(new MigLayout("fill, wrap 3"));
|
||||||
|
|
||||||
|
@ -359,7 +354,6 @@ class FormatDialog extends JDialog {
|
||||||
return new ExpressionFormat(format).format(sample);
|
return new ExpressionFormat(format).format(sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void done() {
|
protected void done() {
|
||||||
try {
|
try {
|
||||||
|
@ -380,7 +374,6 @@ class FormatDialog extends JDialog {
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private MediaBindingBean restoreSample(Mode mode) {
|
private MediaBindingBean restoreSample(Mode mode) {
|
||||||
Object info = null;
|
Object info = null;
|
||||||
File media = null;
|
File media = null;
|
||||||
|
@ -413,7 +406,6 @@ class FormatDialog extends JDialog {
|
||||||
return new MediaBindingBean(info, media, null);
|
return new MediaBindingBean(info, media, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private ExecutorService createExecutor() {
|
private ExecutorService createExecutor() {
|
||||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(1), new DefaultThreadFactory("PreviewFormatter")) {
|
ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(1), new DefaultThreadFactory("PreviewFormatter")) {
|
||||||
|
|
||||||
|
@ -447,7 +439,6 @@ class FormatDialog extends JDialog {
|
||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void checkFormatInBackground() {
|
private void checkFormatInBackground() {
|
||||||
try {
|
try {
|
||||||
// check syntax in foreground
|
// check syntax in foreground
|
||||||
|
@ -473,7 +464,6 @@ class FormatDialog extends JDialog {
|
||||||
return format.format(sample);
|
return format.format(sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void done() {
|
protected void done() {
|
||||||
try {
|
try {
|
||||||
|
@ -531,22 +521,18 @@ class FormatDialog extends JDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean submit() {
|
public boolean submit() {
|
||||||
return submit;
|
return submit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Mode getMode() {
|
public Mode getMode() {
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ExpressionFormat getFormat() {
|
public ExpressionFormat getFormat() {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void finish(boolean submit) {
|
private void finish(boolean submit) {
|
||||||
this.submit = submit;
|
this.submit = submit;
|
||||||
|
|
||||||
|
@ -557,7 +543,6 @@ class FormatDialog extends JDialog {
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private JPopupMenu createRecentFormatPopup() {
|
private JPopupMenu createRecentFormatPopup() {
|
||||||
JPopupMenu popup = new JPopupMenu();
|
JPopupMenu popup = new JPopupMenu();
|
||||||
popup.addPopupMenuListener(new PopupMenuListener() {
|
popup.addPopupMenuListener(new PopupMenuListener() {
|
||||||
|
@ -581,14 +566,12 @@ class FormatDialog extends JDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void popupMenuWillBecomeInvisible(PopupMenuEvent evt) {
|
public void popupMenuWillBecomeInvisible(PopupMenuEvent evt) {
|
||||||
JPopupMenu popup = (JPopupMenu) evt.getSource();
|
JPopupMenu popup = (JPopupMenu) evt.getSource();
|
||||||
popup.removeAll();
|
popup.removeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void popupMenuCanceled(PopupMenuEvent evt) {
|
public void popupMenuCanceled(PopupMenuEvent evt) {
|
||||||
popupMenuWillBecomeInvisible(evt);
|
popupMenuWillBecomeInvisible(evt);
|
||||||
|
@ -680,7 +663,6 @@ class FormatDialog extends JDialog {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
protected void fireSampleChanged() {
|
protected void fireSampleChanged() {
|
||||||
firePropertyChange("sample", null, sample);
|
firePropertyChange("sample", null, sample);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue