+ 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/**" />
|
||||
</zipfileset>
|
||||
|
||||
<zipfileset src="${dir.lib}/rsyntaxtextarea.jar">
|
||||
<include name="org/fife/**" />
|
||||
</zipfileset>
|
||||
|
||||
<zipfileset src="${dir.lib}/xmlrpc.jar">
|
||||
<include name="redstone/xmlrpc/**" />
|
||||
</zipfileset>
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<jar href="xercesImpl.jar" download="lazy" part="scraper" />
|
||||
<jar href="mediainfo.jar" download="lazy" part="native" />
|
||||
<jar href="sevenzipjbinding.jar" download="lazy" part="native" />
|
||||
<jar href="rsyntaxtextarea.jar" download="eager" />
|
||||
</resources>
|
||||
|
||||
<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;
|
||||
|
||||
|
||||
import static java.awt.Font.*;
|
||||
import static javax.swing.BorderFactory.*;
|
||||
import static net.sourceforge.filebot.ui.NotificationLogging.*;
|
||||
|
@ -52,9 +50,13 @@ import javax.swing.JTextField;
|
|||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
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.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.JsonWriter;
|
||||
|
||||
|
||||
class FormatDialog extends JDialog {
|
||||
public class FormatDialog extends JDialog {
|
||||
|
||||
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");
|
||||
|
||||
|
||||
public enum Mode {
|
||||
Episode, Movie, Music;
|
||||
|
||||
|
@ -115,12 +119,10 @@ class FormatDialog extends JDialog {
|
|||
return values()[0];
|
||||
}
|
||||
|
||||
|
||||
public String key() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
public Format getFormat() {
|
||||
switch (this) {
|
||||
case Episode:
|
||||
|
@ -132,18 +134,15 @@ class FormatDialog extends JDialog {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public PreferencesEntry<String> persistentSample() {
|
||||
return Settings.forPackage(FormatDialog.class).entry("format.sample." + key());
|
||||
}
|
||||
|
||||
|
||||
public PreferencesList<String> persistentFormatHistory() {
|
||||
return Settings.forPackage(FormatDialog.class).node("format.recent." + key()).asList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public FormatDialog(Window owner) {
|
||||
super(owner, ModalityType.DOCUMENT_MODAL);
|
||||
|
||||
|
@ -225,7 +224,6 @@ class FormatDialog extends JDialog {
|
|||
setSize(610, 430);
|
||||
}
|
||||
|
||||
|
||||
public void setMode(Mode mode) {
|
||||
this.mode = mode;
|
||||
|
||||
|
@ -246,7 +244,6 @@ class FormatDialog extends JDialog {
|
|||
fireSampleChanged();
|
||||
}
|
||||
|
||||
|
||||
private JComponent updateHelpPanel(Mode mode) {
|
||||
help.removeAll();
|
||||
|
||||
|
@ -259,13 +256,28 @@ class FormatDialog extends JDialog {
|
|||
return help;
|
||||
}
|
||||
|
||||
|
||||
private JTextComponent createEditor() {
|
||||
final JTextComponent editor = new JTextField(new ExpressionFormatDocument(), null, 0);
|
||||
editor.setFont(new Font(MONOSPACED, PLAIN, 14));
|
||||
final RSyntaxTextArea editor = new RSyntaxTextArea(new RSyntaxDocument(SyntaxConstants.SYNTAX_STYLE_GROOVY) {
|
||||
@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
|
||||
installUndoSupport(editor);
|
||||
editor.setAntiAliasingEnabled(true);
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
private JComponent createSyntaxPanel(Mode mode) {
|
||||
JPanel panel = new JPanel(new MigLayout("fill, nogrid"));
|
||||
|
||||
|
@ -317,7 +313,6 @@ class FormatDialog extends JDialog {
|
|||
return panel;
|
||||
}
|
||||
|
||||
|
||||
private JComponent createExamplesPanel(Mode mode) {
|
||||
JPanel panel = new JPanel(new MigLayout("fill, wrap 3"));
|
||||
|
||||
|
@ -359,7 +354,6 @@ class FormatDialog extends JDialog {
|
|||
return new ExpressionFormat(format).format(sample);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
|
@ -380,7 +374,6 @@ class FormatDialog extends JDialog {
|
|||
return panel;
|
||||
}
|
||||
|
||||
|
||||
private MediaBindingBean restoreSample(Mode mode) {
|
||||
Object info = null;
|
||||
File media = null;
|
||||
|
@ -413,7 +406,6 @@ class FormatDialog extends JDialog {
|
|||
return new MediaBindingBean(info, media, null);
|
||||
}
|
||||
|
||||
|
||||
private ExecutorService createExecutor() {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
private void checkFormatInBackground() {
|
||||
try {
|
||||
// check syntax in foreground
|
||||
|
@ -473,7 +464,6 @@ class FormatDialog extends JDialog {
|
|||
return format.format(sample);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
|
@ -531,22 +521,18 @@ class FormatDialog extends JDialog {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean submit() {
|
||||
return submit;
|
||||
}
|
||||
|
||||
|
||||
public Mode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
|
||||
public ExpressionFormat getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
|
||||
private void finish(boolean submit) {
|
||||
this.submit = submit;
|
||||
|
||||
|
@ -557,7 +543,6 @@ class FormatDialog extends JDialog {
|
|||
dispose();
|
||||
}
|
||||
|
||||
|
||||
private JPopupMenu createRecentFormatPopup() {
|
||||
JPopupMenu popup = new JPopupMenu();
|
||||
popup.addPopupMenuListener(new PopupMenuListener() {
|
||||
|
@ -581,14 +566,12 @@ class FormatDialog extends JDialog {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void popupMenuWillBecomeInvisible(PopupMenuEvent evt) {
|
||||
JPopupMenu popup = (JPopupMenu) evt.getSource();
|
||||
popup.removeAll();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void popupMenuCanceled(PopupMenuEvent evt) {
|
||||
popupMenuWillBecomeInvisible(evt);
|
||||
|
@ -680,7 +663,6 @@ class FormatDialog extends JDialog {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
protected void fireSampleChanged() {
|
||||
firePropertyChange("sample", null, sample);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue