use of javax.swing.text.MutableAttributeSet in project vcell by virtualcell.
the class MultiPurposeTextPanel method highlightComments.
private void highlightComments() {
String text = getTextPane().getText();
StyledDocument doc = (StyledDocument) getTextPane().getDocument();
MutableAttributeSet cstyle = getCommentStyle();
boolean inComment = false;
try (CountingLineReader reader = new CountingLineReader(new StringReader(text))) {
String line = reader.readLine();
while (line != null) {
if (!inComment) {
int cstart = line.indexOf(Commented.BEFORE_COMMENT);
if (cstart != NOT_THERE) {
inComment = parseAndMarkEndComment(doc, line, reader.lastStringPosition(), cstart);
}
int start = line.indexOf(Commented.AFTER_COMMENT);
if (start != NOT_THERE) {
int length = line.length() - start;
doc.setCharacterAttributes(reader.lastStringPosition() + start, length, cstyle, true);
}
} else {
// currently inside a /* */. comment
inComment = parseAndMarkEndComment(doc, line, reader.lastStringPosition(), 0);
}
line = reader.readLine();
}
} catch (IOException e) {
}
}
Aggregations