1 package de.lathanda.eos.common.gui;
4 import java.util.LinkedList;
6 import javax.swing.SwingUtilities;
7 import javax.swing.text.SimpleAttributeSet;
8 import javax.swing.text.StyleConstants;
10 import de.lathanda.eos.base.util.GuiToolkit;
11 import de.lathanda.eos.baseparser.InfoToken;
12 import de.lathanda.eos.vm.Marker;
25 private final SimpleAttributeSet attributeSetBase =
new SimpleAttributeSet();
29 private final SimpleAttributeSet attributeSetMark =
new SimpleAttributeSet();
33 private final SimpleAttributeSet attributeSetUnmark =
new SimpleAttributeSet();
37 private final SimpleAttributeSet attributeSetError =
new SimpleAttributeSet();
41 private final SimpleAttributeSet attributeSetComment =
new SimpleAttributeSet();
45 private final SimpleAttributeSet attributeSetLiteral =
new SimpleAttributeSet();
49 private final SimpleAttributeSet attributeSetKeyword =
new SimpleAttributeSet();
57 private Marker newCodePointer;
61 private Marker codePointer;
65 private boolean codePointerDirty =
false;
71 this.codePointer =
new Marker();
72 StyleConstants.setBackground(attributeSetBase, Color.WHITE);
73 StyleConstants.setForeground(attributeSetBase, Color.BLACK);
74 StyleConstants.setUnderline(attributeSetBase,
false);
75 StyleConstants.setBold(attributeSetBase,
false);
76 StyleConstants.setForeground(attributeSetComment,
new Color(0, 160, 0));
77 StyleConstants.setForeground(attributeSetLiteral, Color.BLUE);
78 StyleConstants.setForeground(attributeSetKeyword, Color.BLACK);
79 StyleConstants.setForeground(attributeSetError, Color.RED);
80 StyleConstants.setBold(attributeSetKeyword,
true);
81 StyleConstants.setBackground(attributeSetMark, Color.YELLOW);
82 StyleConstants.setBackground(attributeSetUnmark, Color.WHITE);
105 sourceCode.setCharacterAttributes(0, sourceCode.getLength(), attributeSetBase,
true);
111 sourceCode.setCharacterAttributes(0, sourceCode.getLength(), attributeSetBase,
true);
113 switch (t.getFormat()) {
115 sourceCode.setCharacterAttributes(t.getBegin(), t.getLength(), attributeSetComment,
true);
118 sourceCode.setCharacterAttributes(t.getBegin(), t.getLength(), attributeSetLiteral,
true);
121 sourceCode.setCharacterAttributes(t.getBegin(), t.getLength(), attributeSetKeyword,
true);
134 private synchronized void markExecutionPoint() {
135 if (codePointer !=
null) {
137 attributeSetUnmark,
false);
139 codePointer = newCodePointer;
140 codePointerDirty =
false;
142 if (codePointer !=
null) {
153 if (codePointer !=
null) {
156 sourceCode.setCharacterAttributes(begin, length, attributeSetUnmark,
false);
178 newCodePointer = codeRange;
179 if (!codePointerDirty) {
180 codePointerDirty =
true;
181 SwingUtilities.invokeLater(() -> markExecutionPoint());
187 this.sourceCode = source;
void setFontSize(int size)
synchronized void unmarkExecutionPoint()
void init(SourceCode source)
synchronized void markExecutionPoint(Marker codeRange)
void markError(Marker code)
AbstractProgram getProgram()
LinkedList< InfoToken > getTokenList()