Search in sources :

Example 6 with MutableAttributeSet

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) {
    }
}
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

MutableAttributeSet (javax.swing.text.MutableAttributeSet)6 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)4 ParserDelegator (javax.swing.text.html.parser.ParserDelegator)4 IOException (java.io.IOException)3 HTML (javax.swing.text.html.HTML)3 FileReader (java.io.FileReader)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 NotNull (org.jetbrains.annotations.NotNull)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 Point (java.awt.Point)1 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)1 StyledDocument (javax.swing.text.StyledDocument)1 CountingLineReader (org.vcell.util.CountingLineReader)1