Search in sources :

Example 1 with ATESyntaxEngine

use of org.antlr.works.ate.syntax.generic.ATESyntaxEngine in project antlrworks by antlr.

the class ATERenderingView method renderText.

/**
     * This method renders the text using the token information to set up the display attribute
     * of each token.
     *
     */
protected int renderText(TextOperation action, Graphics g, int x, int y, int p0, int p1) throws BadLocationException {
    if (p0 == p1)
        return x;
    if (!textEditor.isSyntaxColoring()) {
        return super.drawUnselectedText(g, x, y, p0, p1);
    }
    // Note: the tokens are not contiguous (e.g. white spaces are ignored)
    final Document doc = getDocument();
    final ATESyntaxEngine engine = textEditor.getParserEngine();
    tokens = engine.getTokens();
    int p = p0;
    final int start = findStartingTokenIndex(p0, 0, tokens.size(), 0);
    for (int i = start; i < tokens.size(); i++) {
        ATEToken t = tokens.get(i);
        AttributeSet attribute = engine.getAttributeForToken(t);
        if (t.start >= p0 && t.start <= p1) {
            // Fill any non-contiguous token with default color
            if (t.start > p) {
                x = action.renderTextPortion(g, x, y, p, t.start, p1, doc, null);
            }
            x = action.renderTextPortion(g, x, y, t.start, t.end, p1, doc, attribute);
            p = t.end;
        } else if (t.end >= p0 && t.start < p0) {
            x = action.renderTextPortion(g, x, y, p0, t.end, p1, doc, attribute);
            p = t.end;
        } else if (t.start > p1) {
            break;
        }
    }
    // Fill any remaining range with default color
    if (p < p1) {
        x = action.renderTextPortion(g, x, y, p, p1, p1, doc, null);
    }
    return x;
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken) ATESyntaxEngine(org.antlr.works.ate.syntax.generic.ATESyntaxEngine)

Aggregations

ATESyntaxEngine (org.antlr.works.ate.syntax.generic.ATESyntaxEngine)1 ATEToken (org.antlr.works.ate.syntax.misc.ATEToken)1