Search in sources :

Example 6 with StyleSpansBuilder

use of org.fxmisc.richtext.StyleSpansBuilder in project Gargoyle by callakrsos.

the class SqlKeywords method computeHighlighting.

private static StyleSpans<Collection<String>> computeHighlighting(String _text) {
    String text = _text;
    text = StringUtils.replace(text, "\"", "'");
    StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
    try {
        Matcher matcher = PATTERN.matcher(text);
        int lastKwEnd = 0;
        while (matcher.find(lastKwEnd)) {
            String styleClass = matcher.group("KEYWORD") != null ? "keyword" : matcher.group("PAREN") != null ? "paren" : matcher.group("BRACE") != null ? "brace" : matcher.group("BRACKET") != null ? "bracket" : matcher.group("SEMICOLON") != null ? "semicolon" : matcher.group("STRING") != null ? "string" : matcher.group("COMMENT") != null ? "comment" : null;
            /*
																														 * never
																														 * happens
																														 */
            assert styleClass != null;
            spansBuilder.add(Collections.emptyList(), matcher.start() - lastKwEnd);
            spansBuilder.add(Collections.singleton(styleClass), matcher.end() - matcher.start());
            lastKwEnd = matcher.end();
        }
        spansBuilder.add(Collections.emptyList(), text.length() - lastKwEnd);
        return spansBuilder.create();
    } catch (Exception e) {
        LOGGER.error(ValueUtil.toString(e));
    }
    return spansBuilder.create();
}
Also used : Matcher(java.util.regex.Matcher) Collection(java.util.Collection) StyleSpansBuilder(org.fxmisc.richtext.StyleSpansBuilder)

Example 7 with StyleSpansBuilder

use of org.fxmisc.richtext.StyleSpansBuilder in project Gargoyle by callakrsos.

the class ThreadDumpTextArea method computeHighlighting.

private static StyleSpans<Collection<String>> computeHighlighting(String text) {
    Matcher matcher = PATTERN.matcher(text);
    int lastKwEnd = 0;
    StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
    while (matcher.find()) {
        String styleClass = matcher.group("METHODPAREN") != null ? "method-paren" : matcher.group("BRACE") != null ? "brace" : matcher.group("BRACKET") != null ? "bracket" : matcher.group("SEMICOLON") != null ? "semicolon" : matcher.group("STRING") != null ? "string" : matcher.group("COMMENT") != null ? "comment" : null;
        /* never happens */
        assert styleClass != null;
        spansBuilder.add(Collections.emptyList(), matcher.start() - lastKwEnd);
        spansBuilder.add(Collections.singleton(styleClass), matcher.end() - matcher.start());
        lastKwEnd = matcher.end();
    }
    spansBuilder.add(Collections.emptyList(), text.length() - lastKwEnd);
    return spansBuilder.create();
}
Also used : Matcher(java.util.regex.Matcher) Collection(java.util.Collection) StyleSpansBuilder(org.fxmisc.richtext.StyleSpansBuilder)

Aggregations

Collection (java.util.Collection)7 StyleSpansBuilder (org.fxmisc.richtext.StyleSpansBuilder)7 Matcher (java.util.regex.Matcher)6 HOGMLexer (com.sri.ai.praise.model.v1.hogm.antlr.HOGMLexer)1 Pattern (java.util.regex.Pattern)1 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 Token (org.antlr.v4.runtime.Token)1