Highlight error line in editor
This commit is contained in:
parent
f2049dd085
commit
37a802603f
@ -19,6 +19,7 @@ import javax.swing.JTextPane;
|
||||
import javax.swing.event.CaretEvent;
|
||||
import javax.swing.event.CaretListener;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Element;
|
||||
import javax.swing.text.JTextComponent;
|
||||
import javax.swing.text.Utilities;
|
||||
|
||||
@ -97,6 +98,7 @@ public final class AnalyzerPanel extends JPanel {
|
||||
try {
|
||||
syn.analyze();
|
||||
} catch (ExceptionWithLineNumber ex) {
|
||||
highlightErrorLine(ex.getLineNumber() - 1);
|
||||
showMessageBox("Error", ex.getMessage(), true);
|
||||
return;
|
||||
}
|
||||
@ -134,4 +136,13 @@ public final class AnalyzerPanel extends JPanel {
|
||||
} catch (IOException ex) {}
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
private void highlightErrorLine(int line) {
|
||||
final Element map = textPane.getDocument().getDefaultRootElement();
|
||||
final Element lineElem = map.getElement(line);
|
||||
int endOffset = lineElem.getEndOffset();
|
||||
if (line == map.getElementCount() - 1) endOffset--;
|
||||
textPane.requestFocusInWindow();
|
||||
textPane.select(lineElem.getStartOffset(), endOffset);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,10 @@ public abstract class ExceptionWithLineNumber extends Exception {
|
||||
super(message);
|
||||
this.lineNumber = lineNumber;
|
||||
}
|
||||
|
||||
public int getLineNumber() {
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
|
Loading…
Reference in New Issue
Block a user