use of org.fxmisc.richtext.model.StyleSpansBuilder in project org.csstudio.display.builder by kasemir.
the class PythonHighlighter method computeHighlighting.
@Override
public 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("KEYWORD") != null ? "keyword" : matcher.group("PAREN") != null ? "paren" : matcher.group("BRACE") != null ? "brace" : matcher.group("BRACKET") != null ? "bracket" : matcher.group("COLON") != null ? "colon" : matcher.group("STRING") != null ? "string" : matcher.group("COMMENT") != null ? "comment" : null;
// It should never happen.
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();
}
use of org.fxmisc.richtext.model.StyleSpansBuilder in project org.csstudio.display.builder by kasemir.
the class JavaHighlighter method computeHighlighting.
@Override
public 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("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;
// It should never happen.
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();
}
use of org.fxmisc.richtext.model.StyleSpansBuilder in project RichTextFX by FXMisc.
the class XMLEditor method computeHighlighting.
private static StyleSpans<Collection<String>> computeHighlighting(String text) {
Matcher matcher = XML_TAG.matcher(text);
int lastKwEnd = 0;
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
while (matcher.find()) {
spansBuilder.add(Collections.emptyList(), matcher.start() - lastKwEnd);
if (matcher.group("COMMENT") != null) {
spansBuilder.add(Collections.singleton("comment"), matcher.end() - matcher.start());
} else {
if (matcher.group("ELEMENT") != null) {
String attributesText = matcher.group(GROUP_ATTRIBUTES_SECTION);
spansBuilder.add(Collections.singleton("tagmark"), matcher.end(GROUP_OPEN_BRACKET) - matcher.start(GROUP_OPEN_BRACKET));
spansBuilder.add(Collections.singleton("anytag"), matcher.end(GROUP_ELEMENT_NAME) - matcher.end(GROUP_OPEN_BRACKET));
if (!attributesText.isEmpty()) {
lastKwEnd = 0;
Matcher amatcher = ATTRIBUTES.matcher(attributesText);
while (amatcher.find()) {
spansBuilder.add(Collections.emptyList(), amatcher.start() - lastKwEnd);
spansBuilder.add(Collections.singleton("attribute"), amatcher.end(GROUP_ATTRIBUTE_NAME) - amatcher.start(GROUP_ATTRIBUTE_NAME));
spansBuilder.add(Collections.singleton("tagmark"), amatcher.end(GROUP_EQUAL_SYMBOL) - amatcher.end(GROUP_ATTRIBUTE_NAME));
spansBuilder.add(Collections.singleton("avalue"), amatcher.end(GROUP_ATTRIBUTE_VALUE) - amatcher.end(GROUP_EQUAL_SYMBOL));
lastKwEnd = amatcher.end();
}
if (attributesText.length() > lastKwEnd)
spansBuilder.add(Collections.emptyList(), attributesText.length() - lastKwEnd);
}
lastKwEnd = matcher.end(GROUP_ATTRIBUTES_SECTION);
spansBuilder.add(Collections.singleton("tagmark"), matcher.end(GROUP_CLOSE_BRACKET) - lastKwEnd);
}
}
lastKwEnd = matcher.end();
}
spansBuilder.add(Collections.emptyList(), text.length() - lastKwEnd);
return spansBuilder.create();
}
use of org.fxmisc.richtext.model.StyleSpansBuilder in project fxexperience2 by EricCanull.
the class CSSFormatter method computeHighlightingByReg.
public static StyleSpans<Collection<String>> computeHighlightingByReg(String text) {
Matcher matcher = PATTERN.matcher(text);
System.out.println(CSS_PATTERN);
System.out.println(MUTI_COMMENT_REGEX);
int lastKwEnd = 0;
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
while (matcher.find()) {
String styleClass = matcher.group("CSS") != null ? "css" : matcher.group("COMMENT") != null ? "multicomment" : matcher.group("ENTRY") != null ? "entries" : matcher.group("SELECTOR") != null ? "selector" : // matcher.group("STRING") != null ? "string" :
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();
}
use of org.fxmisc.richtext.model.StyleSpansBuilder in project fxexperience2 by EricCanull.
the class CSSFormatter method computeHighlightingByRegex.
private static StyleSpans<Collection<String>> computeHighlightingByRegex(String text) {
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
Matcher cssMatcher = CSS_PATTERN.matcher(text);
cssMatcher.toString();
int lastKwEnd = 0;
while (cssMatcher.find()) {
spansBuilder.add(Collections.emptyList(), cssMatcher.start() - lastKwEnd);
if (cssMatcher.group(MUTI_COMMENT) != null) {
spansBuilder.add(Collections.singleton(MUTI_COMMENT), cssMatcher.end() - cssMatcher.start());
} else {
if (cssMatcher.group(CSS) != null) {
String selectorText = cssMatcher.group(GROUP_SELECTOR);
if (!selectorText.isEmpty()) {
lastKwEnd = 0;
Matcher selectorMatcher = SELECTOR_PATTERN.matcher(selectorText);
while (selectorMatcher.find()) {
spansBuilder.add(Collections.emptyList(), selectorMatcher.start() - lastKwEnd);
spansBuilder.add(Collections.emptyList(), selectorMatcher.end(1) - selectorMatcher.start(1));
String prefix = selectorMatcher.group(1);
List<String> list = new ArrayList<>();
switch(prefix) {
case "#":
list.add(SELECTOR_ID);
break;
case ".":
list.add(SELECTOR_CLASS);
break;
case ":":
list.add(SELECTOR_STATE);
break;
case " ":
case "\n":
list.add(SELECTOR_JAVACLASS);
break;
}
spansBuilder.add(list, selectorMatcher.end(2) - selectorMatcher.start(2));
lastKwEnd = selectorMatcher.end();
}
if (selectorText.length() > lastKwEnd) {
spansBuilder.add(Collections.emptyList(), selectorText.length() - lastKwEnd);
}
}
spansBuilder.add(Collections.singleton(LEFT_BRACE), cssMatcher.end(GROUP_LEFT_BRACE) - cssMatcher.start(GROUP_LEFT_BRACE));
String entriesText = cssMatcher.group(GROUP_VALUES);
if (!entriesText.isEmpty()) {
lastKwEnd = 0;
Matcher entryMatcher = ENTRY_PATTERN.matcher(entriesText);
while (entryMatcher.find()) {
spansBuilder.add(Collections.emptyList(), entryMatcher.start() - lastKwEnd);
if (entryMatcher.group(MUTI_COMMENT) != null) {
spansBuilder.add(Collections.singleton(MUTI_COMMENT), entryMatcher.end() - entryMatcher.start());
} else {
if (entryMatcher.group(ENTRY) != null) {
spansBuilder.add(Collections.singleton(KEY), entryMatcher.end(GROUP_KEY) - entryMatcher.start(GROUP_KEY));
spansBuilder.add(Collections.singleton(COLON), entryMatcher.end(GROUP_COLON) - entryMatcher.start(GROUP_COLON));
spansBuilder.add(Collections.singleton(VALUE), entryMatcher.end(GROUP_VALUE) - entryMatcher.start(GROUP_VALUE));
spansBuilder.add(Collections.singleton(SEMICOLON), entryMatcher.end(GROUP_SEMICOLON) - entryMatcher.start(GROUP_SEMICOLON));
}
}
lastKwEnd = entryMatcher.end();
}
if (entriesText.length() > lastKwEnd) {
spansBuilder.add(Collections.emptyList(), entriesText.length() - lastKwEnd);
}
}
lastKwEnd = cssMatcher.end(GROUP_VALUES);
spansBuilder.add(Collections.singleton(RIGHT_BRACE), cssMatcher.end(GROUP_RIGHT_BRACE) - lastKwEnd);
}
}
lastKwEnd = cssMatcher.end();
}
spansBuilder.add(Collections.emptyList(), text.length() - lastKwEnd);
return spansBuilder.create();
}
Aggregations