本文整理汇总了Java中org.fxmisc.richtext.StyleSpansBuilder类的典型用法代码示例。如果您正苦于以下问题:Java StyleSpansBuilder类的具体用法?Java StyleSpansBuilder怎么用?Java StyleSpansBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StyleSpansBuilder类属于org.fxmisc.richtext包,在下文中一共展示了StyleSpansBuilder类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeHighlighting
import org.fxmisc.richtext.StyleSpansBuilder; //导入依赖的package包/类
public static StyleSpans<Collection<String>> computeHighlighting(final String text) {
final Matcher matcher = UPPAAL.matcher(text);
int lastKwEnd = 0;
final StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
while (matcher.find()) {
spansBuilder.add(Collections.emptyList(), matcher.start() - lastKwEnd);
if (matcher.group(1) != null) {
spansBuilder.add(Collections.singleton("uppaal-keyword"), matcher.end(1) - matcher.start(1));
} else if (matcher.group(2) != null) {
spansBuilder.add(Collections.singleton("c-keyword"), matcher.end(2) - matcher.start(2));
} else if (matcher.group(3) != null) {
spansBuilder.add(Collections.singleton("comment"), matcher.end(3) - matcher.start(3));
}
lastKwEnd = matcher.end();
}
spansBuilder.add(Collections.emptyList(), text.length() - lastKwEnd);
return spansBuilder.create();
}
示例2: groupBackgroundColor
import org.fxmisc.richtext.StyleSpansBuilder; //导入依赖的package包/类
private static StyleSpans<Collection<String>> groupBackgroundColor(String text, int point) {
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
Pattern pattern = Pattern.compile("\\([^)]+\\)");
Matcher matcher = pattern.matcher(text);
int lastKwEnd = 0;
while (matcher.find()) {
String styleClass = "unGroup";
if (matcher.start() < point && matcher.end() > point) {
styleClass = "inGroup";
}
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();
}
示例3: processHighlighting
import org.fxmisc.richtext.StyleSpansBuilder; //导入依赖的package包/类
private void processHighlighting(List<Span> spans) {
if (!spans.isEmpty()) {
spans.sort((s1, s2) -> Integer.valueOf(s1.from).compareTo(s2.from));
StyleSpansBuilder<Collection<String>> spansBuilder
= new StyleSpansBuilder<>();
int last = 0;
int textLength = codeArea.getText().length();
for (Span s : spans) {
int newFrom = Math.min(s.from,textLength);
if (newFrom > last) {
spansBuilder.add(Collections.emptyList(), newFrom - last);
}
spansBuilder.add(Collections.singleton(s.style()), s.len);
last = s.from + s.len;
}
if (last < textLength) {
spansBuilder.add(Collections.emptyList(), textLength - last);
}
try {
codeArea.setStyleSpans(0, spansBuilder.create());
} catch (IllegalArgumentException ignored) {
}
}
}
示例4: computeHighlighting
import org.fxmisc.richtext.StyleSpansBuilder; //导入依赖的package包/类
public static StyleSpans<Collection<String>> computeHighlighting(String text) {
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
Matcher matcher = HIGHLIGHT_PATTERN.matcher(text);
int lastMatchEnd = 0;
while(matcher.find()) {
String styleClass =
matcher.group(GROUP_KEYWORD) != null ? CSS_KEYWORD :
matcher.group(GROUP_PAREN) != null ? CSS_PAREN :
matcher.group(GROUP_BRACE) != null ? CSS_BRACE :
matcher.group(GROUP_BRACKET) != null ? CSS_BRACKET :
matcher.group(GROUP_DOT) != null ? CSS_DOT :
matcher.group(GROUP_STRING) != null ? CSS_STRING :
matcher.group(GROUP_COMMENT) != null ? CSS_COMMENT :
null;
spansBuilder.add(new ArrayList<String>(), matcher.start() - lastMatchEnd);
spansBuilder.add(new ArrayList<String>(Arrays.asList(styleClass)), matcher.end() - matcher.start());
lastMatchEnd = matcher.end();
}
spansBuilder.add(new ArrayList<String>(), text.length() - lastMatchEnd);
return spansBuilder.create();
}
示例5: computeHighlighting
import org.fxmisc.richtext.StyleSpansBuilder; //导入依赖的package包/类
private static StyleSpans<Collection<String>> computeHighlighting(Grammar g, Map<String, String> styles, String text){
System.out.println("Starting to compute highlighting");
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
if(text.length() > 0){
LexerInterpreter lex = g.createLexerInterpreter(new ANTLRInputStream(text));
CommonTokenStream tokenStream = new CommonTokenStream(lex);
// parse
int lastEnd = 0;
for(Token t: lex.getAllTokens()){
int spacer = t.getStartIndex() - lastEnd;
if(spacer > 0) {
spansBuilder.add(Collections.emptyList(), spacer);
int gap = t.getText().length();
spansBuilder.add(Collections.singleton(getStyleClass(lex,styles,t)), gap);
lastEnd = t.getStopIndex() + 1;
}
}
}else{
spansBuilder.add(Collections.emptyList(), 0);
}
return spansBuilder.create();
}
示例6: computeHighlighting
import org.fxmisc.richtext.StyleSpansBuilder; //导入依赖的package包/类
private StyleSpans<Collection<String>> computeHighlighting(
String sourcecode) {
List<Token> tokens = new ArrayList<>();
List<SyntaxError> syntaxErrors = new ArrayList<>();
// Short-circuit setting parsed code properties on code, since we're in another thread.
ParsedCode.parseCode(sourcecode, newTokens -> {
tokens.addAll(newTokens);
Platform.runLater(() -> code.tokensProperty().setAll(newTokens));
}, synErrs -> {
syntaxErrors.addAll(synErrs);
Platform.runLater(
() -> code.syntaxErrorsProperty().setAll(synErrs));
}, parsedCode -> Platform
.runLater(() -> code.parsedCodeProperty().set(parsedCode)));
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
if (tokens.isEmpty()) {
spansBuilder.add(Collections.emptyList(), 0);
return spansBuilder.create();
}
tokens.forEach(token ->
// replaceAll is a work-around for a bug when ANTLR has a
// different character count than this CodeArea.
spansBuilder.add(getStyleClassesFor(token, syntaxErrors),
token.getText().replaceAll("\\r", "").length()));
return spansBuilder.create();
}
示例7: computeHighlighting
import org.fxmisc.richtext.StyleSpansBuilder; //导入依赖的package包/类
private static StyleSpans<Collection<String>> computeHighlighting(String text) {
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
int lastTokenEnd = 0;
ANTLRInputStream input = new ANTLRInputStream(text);
HOGMLexer lexer = new HOGMLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
tokens.fill();
for (int i = 0; i < tokens.size(); i++) {
Token t = tokens.get(i);
if (t.getType() == Token.EOF) {
break;
}
String styleClass;
if (t.getType() == HOGMLexer.COMMENT || t.getType() == HOGMLexer.LINE_COMMENT) {
styleClass = "hogmCodeComment";
}
else if (HOGMTerminalSymbols.isTerminalSymbol(t.getText())) {
styleClass = "hogmCodeKeyword";
}
else {
styleClass = "hogmCodeOther";
}
int spacing = t.getStartIndex() - lastTokenEnd;
if (spacing > 0) {
spansBuilder.add(Collections.emptyList(), spacing);
}
int stylesize = (t.getStopIndex() - t.getStartIndex()) +1;
spansBuilder.add(Collections.singleton(styleClass), stylesize);
lastTokenEnd = t.getStopIndex()+1;
}
return spansBuilder.create();
}
示例8: computeHighlightingAsync
import org.fxmisc.richtext.StyleSpansBuilder; //导入依赖的package包/类
private Task<StyleSpans<Collection<String>>> computeHighlightingAsync() {
val text = editor.getText();
val task = new Task<StyleSpans<Collection<String>>>() {
@Override
protected StyleSpans<Collection<String>> call() throws Exception {
val spans = new StyleSpansBuilder<Collection<String>>();
for (val t : new HotaruLexer(text).tokenize()) {
val category = t.getType().getPrimaryCategory();
switch (category) {
case "string":
case "keyword":
case "comment":
case "number":
spans.add(Collections.singleton(category), t.getLength());
break;
case "identifier":
if (nodeFunctions.contains(t.getText())) {
spans.add(Collections.singleton("node-function"), t.getLength());
} else {
spans.add(Collections.emptyList(), t.getLength());
}
break;
case "operator":
val className = operatorClasses.get(t.getType());
if (className != null) {
spans.add(Collections.singleton(className), t.getLength());
} else {
spans.add(Collections.emptyList(), t.getLength());
}
break;
default:
spans.add(Collections.emptyList(), t.getLength());
break;
}
}
return spans.create();
}
};
executor.execute(task);
return task;
}
示例9: computeHighlighting
import org.fxmisc.richtext.StyleSpansBuilder; //导入依赖的package包/类
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();
}
示例10: initEditor
import org.fxmisc.richtext.StyleSpansBuilder; //导入依赖的package包/类
private void initEditor() {
codeArea.textProperty().addListener(
(ov, oldText, newText) -> {
Matcher matcher = KEYWORD_PATTERN.matcher(newText);
int lastKwEnd = 0;
StyleSpansBuilder<Collection<String>> spansBuilder
= new StyleSpansBuilder<>();
while (matcher.find()) {
spansBuilder.add(Collections.emptyList(),
matcher.start() - lastKwEnd);
spansBuilder.add(Collections.singleton("keyword"),
matcher.end() - matcher.start());
lastKwEnd = matcher.end();
}
spansBuilder.add(Collections.emptyList(),
newText.length() - lastKwEnd);
codeArea.setStyleSpans(0, spansBuilder.create());
});
// EventStream<Change<String>> textEvents
// = EventStreams.changesOf(codeArea.textProperty());
// textEvents.reduceSuccessions((a, b) -> b, Duration.ofMillis(500)).
// subscribe(code -> compile(code.getNewValue()));
codeArea.replaceText(
"// use api object\n");
interactionContainer.getChildren().add(codeArea);
// logContainer.setContent(logView);
// // redirect sout
// RedirectableStream sout = new RedirectableStream(
// RedirectableStream.ORIGINAL_SOUT, logView);
// sout.setRedirectToUi(true);
// System.setOut(sout);
//
// // redirect err
// RedirectableStream serr = new RedirectableStream(
// RedirectableStream.ORIGINAL_SERR, logView);
// serr.setRedirectToUi(true);
// System.setErr(serr);
}
示例11: initialize
import org.fxmisc.richtext.StyleSpansBuilder; //导入依赖的package包/类
/**
* Initializes the controller class.
*
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
//
codeArea.textProperty().addListener(
(ov, oldText, newText) -> {
Matcher matcher = KEYWORD_PATTERN.matcher(newText);
int lastKwEnd = 0;
StyleSpansBuilder<Collection<String>> spansBuilder
= new StyleSpansBuilder<>();
while (matcher.find()) {
spansBuilder.add(Collections.emptyList(),
matcher.start() - lastKwEnd);
spansBuilder.add(Collections.singleton("keyword"),
matcher.end() - matcher.start());
lastKwEnd = matcher.end();
}
spansBuilder.add(Collections.emptyList(),
newText.length() - lastKwEnd);
codeArea.setStyleSpans(0, spansBuilder.create());
});
EventStream<Change<String>> textEvents
= EventStreams.changesOf(codeArea.textProperty());
textEvents.reduceSuccessions((a, b) -> b, Duration.ofMillis(500)).
subscribe(code -> {
if (autoCompile) {
compile(code.getNewValue());
}
});
codeArea.replaceText(
"CSG cube = new Cube(2).toCSG()\n"
+ "CSG sphere = new Sphere(1.25).toCSG()\n"
+ "\n"
+ "cube.difference(sphere)");
editorContainer.setContent(codeArea);
subScene = new SubScene(viewGroup, 100, 100, true,
SceneAntialiasing.BALANCED);
subScene.widthProperty().bind(viewContainer.widthProperty());
subScene.heightProperty().bind(viewContainer.heightProperty());
PerspectiveCamera subSceneCamera = new PerspectiveCamera(false);
subScene.setCamera(subSceneCamera);
viewContainer.getChildren().add(subScene);
}