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();
}
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();
}
Aggregations