use of org.vcell.util.CountingLineReader in project vcell by virtualcell.
the class CountingLineReaderTest method execute.
private void execute(String s) throws IOException {
System.out.println("## " + s + "##");
try (CountingLineReader flr = new CountingLineReader(new StringReader(s))) {
String line = flr.readLine();
while (line != null) {
System.out.println(line);
System.out.println(flr.lastStringPosition());
System.out.println(s.charAt(flr.lastStringPosition()));
line = flr.readLine();
}
}
}
use of org.vcell.util.CountingLineReader 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