Search in sources :

Example 1 with CountingLineReader

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();
        }
    }
}
Also used : CountingLineReader(org.vcell.util.CountingLineReader) StringReader(java.io.StringReader)

Example 2 with CountingLineReader

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) {
    }
}
Also used : MutableAttributeSet(javax.swing.text.MutableAttributeSet) CountingLineReader(org.vcell.util.CountingLineReader) StyledDocument(javax.swing.text.StyledDocument) StringReader(java.io.StringReader) IOException(java.io.IOException) Point(java.awt.Point)

Aggregations

StringReader (java.io.StringReader)2 CountingLineReader (org.vcell.util.CountingLineReader)2 Point (java.awt.Point)1 IOException (java.io.IOException)1 MutableAttributeSet (javax.swing.text.MutableAttributeSet)1 StyledDocument (javax.swing.text.StyledDocument)1