Skip to content
59 changes: 0 additions & 59 deletions src/main/java/org/quiltmc/syntaxpain/DefaultSyntaxAction.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/org/quiltmc/syntaxpain/DocumentSearchData.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public boolean doFindPrev(JTextComponent target) {
return false;
}

SyntaxDocument sDoc = Util.getSyntaxDocument(target);
SyntaxDocument sDoc = SyntaxDocument.getFrom(target);
if (sDoc == null) {
return false;
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public boolean doFindNext(JTextComponent target) {
return false;
}

SyntaxDocument sDoc = Util.getSyntaxDocument(target);
SyntaxDocument sDoc = SyntaxDocument.getFrom(target);
if (sDoc == null) {
return false;
}
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/org/quiltmc/syntaxpain/EscapeListener.java

This file was deleted.

111 changes: 28 additions & 83 deletions src/main/java/org/quiltmc/syntaxpain/JavaSyntaxKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,111 +17,56 @@

import org.quiltmc.syntaxpain.generated.JavaLexer;

import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JEditorPane;
import javax.swing.KeyStroke;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.JTextComponent;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import java.awt.Color;
import java.awt.Font;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;

@SuppressWarnings("unused")
public class JavaSyntaxKit extends DefaultEditorKit implements ViewFactory {
public static final String CONTENT_TYPE = "text/enigma-sources";

private static SyntaxStyleMap styles = new SyntaxStyleMap(
new Color(0x3333EE),
new Color(0xCC6600),
new Color(0x999933),
new Color(0x000000),
new Color(0x000000),
new Color(0x000000),
new Color(0x000000),
new Color(0x339933),
new Color(0x000000),
new Color(0xcc6600)
);

public static void setSyntaxColors(
Color highlight, Color string, Color number, Color operator, Color delimiter,
Color type, Color identifier, Color comment, Color text, Color regex
) {
styles = new SyntaxStyleMap(
highlight, string, number, operator, delimiter,
type, identifier, comment, text, regex
);
}

private final Lexer lexer;
private final Map<JEditorPane, List<SyntaxComponent>> editorComponents = new WeakHashMap<>();
private static Font font = null;

public JavaSyntaxKit() {
super();
// JavaLexer is generated automagically by jflex based on the java.jflex file
this.lexer = new JavaLexer();
}

public void addComponents(JEditorPane editorPane) {
this.installComponent(editorPane, new PairsMarker());
this.installComponent(editorPane, new LineNumbersRuler());
}

public void installComponent(JEditorPane pane, SyntaxComponent comp) {
comp.configure();
comp.install(pane);
this.editorComponents.computeIfAbsent(pane, k -> new ArrayList<>());
this.editorComponents.get(pane).add(comp);
}

public static void setFont(Font newFont) {
font = newFont;
}

@Override
public ViewFactory getViewFactory() {
return this;
}

@Override
public View create(Element element) {
return new SyntaxView(element);
}

@Override
public void install(JEditorPane editorPane) {
super.install(editorPane);

if (font == null) {
font = SyntaxpainConfiguration.getEditorFont();
}

editorPane.setFont(font);

Color caretColor = SyntaxpainConfiguration.getTextColor();
editorPane.setCaretColor(caretColor);

if (SyntaxpainConfiguration.isQuickFindDialogEnabled()) {
this.addQuickFindDialogAction(editorPane);
}

this.addComponents(editorPane);
}

@Override
public void deinstall(JEditorPane editorPane) {
for (SyntaxComponent c : this.editorComponents.get(editorPane)) {
c.deinstall(editorPane);
}

this.editorComponents.clear();
editorPane.getInputMap().clear();
ActionMap m = editorPane.getActionMap();
m.clear();
}

/**
* Sets up the quick find action.
*/
public void addQuickFindDialogAction(JEditorPane editorPane) {
InputMap inputMap = new InputMap();
inputMap.setParent(editorPane.getInputMap());
ActionMap actionMap = new ActionMap();
actionMap.setParent(editorPane.getActionMap());

QuickFindDialogAction action = new QuickFindDialogAction();
actionMap.put(action.getClass().getSimpleName(), action);

KeyStroke stroke = KeyStroke.getKeyStroke("control F");
action.putValue(Action.ACCELERATOR_KEY, stroke);
inputMap.put(stroke, action.getClass().getSimpleName());

editorPane.setActionMap(actionMap);
editorPane.setInputMap(JTextComponent.WHEN_FOCUSED, inputMap);
return new SyntaxView(element, styles);
}

@Override
Expand All @@ -131,6 +76,6 @@ public Document createDefaultDocument() {

@Override
public String getContentType() {
return "text/enigma-sources";
return CONTENT_TYPE;
}
}
Loading