当前位置: 首页>>代码示例>>Java>>正文


Java StyleSpans类代码示例

本文整理汇总了Java中org.fxmisc.richtext.model.StyleSpans的典型用法代码示例。如果您正苦于以下问题:Java StyleSpans类的具体用法?Java StyleSpans怎么用?Java StyleSpans使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StyleSpans类属于org.fxmisc.richtext.model包,在下文中一共展示了StyleSpans类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compute

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
public void compute(String text, CodeArea parent) {

        Matcher matcher = getHighlightingPattern().matcher(text);

        while(matcher.find()) {

            String styleClass = getStyleClass(matcher);
            // For now lets setStyles for base style.
            parent.setStyle(matcher.start(), matcher.end(), Collections.singleton(styleClass));

            // Then we can grab the style from the document via subView and overlay
            for(HighlightStyle style : getChildStyles(styleClass, getText(matcher.start(), matcher.end(), parent))){
                StyleSpans spans = parent.getStyleSpans(matcher.start(), matcher.end()).subView(style.start, style.end).overlay(
                        StyleSpans.singleton(new StyleSpan<>(
                                Arrays.asList(style.styleClasses),
                                (style.end - style.start)
                        )),
                        (strings, strings2) -> {
                            Collection<String> coll = Streams.concat(strings.stream(), strings2.stream()).collect(Collectors.toList());
                            logger.debug(coll.toString());
                            return coll;
                        }
                );
                parent.setStyleSpans(matcher.start(), spans); // Reset styles
            }
        }

    }
 
开发者ID:jdesive,项目名称:textmd,代码行数:29,代码来源:SyntaxHighlighter.java

示例2: highlight

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
public StyleSpans<Collection<String>> highlight(String text) {
    Matcher matcher = PATTERN.matcher(text);
    int lastKeywordEnd = 0;
    StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
    while(matcher.find()) {
        String styleClass
                = matcher.group("KEYWORD") != null ? "keyword"
                : matcher.group("STRING") != null ? "string"
                : matcher.group("COMMENT") != null ? "comment"
                : matcher.group("LABEL") != null ? "label"
                : null;
        spansBuilder.add(Collections.emptyList(), matcher.start() - lastKeywordEnd);
        spansBuilder.add(Collections.singleton(styleClass), matcher.end() - matcher.start());
        lastKeywordEnd = matcher.end();
    }
    if(lastKeywordEnd == 0) {
        return highlightMisspelled(text);
    }
    spansBuilder.add(Collections.emptyList(), text.length() - lastKeywordEnd);
    return spansBuilder.create();
}
 
开发者ID:kasirgalabs,项目名称:ETUmulator,代码行数:22,代码来源:SyntaxHighlighter.java

示例3: highlightMisspelled

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
private StyleSpans<Collection<String>> highlightMisspelled(String text) {
    StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
    BreakIterator wb = BreakIterator.getWordInstance();
    wb.setText(text);
    int lastIndex = wb.first();
    int lastKeywordEnd = 0;
    while(lastIndex != BreakIterator.DONE) {
        int firstIndex = lastIndex;
        lastIndex = wb.next();
        if(lastIndex != BreakIterator.DONE
                && Character.isLetterOrDigit(text.charAt(firstIndex))) {
            String word = text.substring(firstIndex, lastIndex).toLowerCase();
            if(!dictionary.contains(word)) {
                spansBuilder.add(Collections.emptyList(), firstIndex - lastKeywordEnd);
                spansBuilder.add(Collections.singleton("underlined"), lastIndex - firstIndex);
                lastKeywordEnd = lastIndex;
            }
        }
    }
    spansBuilder.add(Collections.emptyList(), text.length() - lastKeywordEnd);
    return spansBuilder.create();
}
 
开发者ID:kasirgalabs,项目名称:ETUmulator,代码行数:23,代码来源:SyntaxHighlighter.java

示例4: computeHighlighting

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
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("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();
}
 
开发者ID:helios-decompiler,项目名称:standalone-app,代码行数:24,代码来源:DisassemblerView.java

示例5: computeHighlighting

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
public static StyleSpans<Collection<String>> computeHighlighting(String text, Pattern pattern) {
    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("DIGIT") != null ? "digit" :
                                                                matcher.group("STRING") != null ? "string" :
                                                                        matcher.group("COMMENT") != null ? "comment" :
                                                                                null; /* never happens */
        spansBuilder.add(Collections.emptyList(), matcher.start() - lastKwEnd);
        spansBuilder.add(Collections.singletonList(styleClass), matcher.end() - matcher.start());
        lastKwEnd = matcher.end();
    }
    spansBuilder.add(Collections.emptyList(), text.length() - lastKwEnd);
    return spansBuilder.create();
}
 
开发者ID:iazarny,项目名称:gitember,代码行数:24,代码来源:HighlightProvider.java

示例6: computeHighlighting

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
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("KEYWORD") != null ? "keyword" :
                        matcher.group("PAREN") != null ? "paren" :
                                matcher.group("BRACE") != null ? "brace" :
                                        matcher.group("BRACKET") != null ? "bracket" :
                                                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();
}
 
开发者ID:AdrianBZG,项目名称:IEMLS,代码行数:23,代码来源:ScriptEditorView.java

示例7: replaceText

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
void replaceText(String text, StyleSpans<? extends Collection<String>> styleSpans) {
	// remember old selection range and scrollY
	IndexRange oldSelection = getSelection();
	double oldScrollY = getEstimatedScrollY();

	// replace text and styles
	doReplaceText(text);
	if (styleSpans != null)
		setStyleSpans(0, styleSpans);

	// restore old selection range and scrollY
	int newLength = getLength();
	selectRange(Math.min(oldSelection.getStart(), newLength), Math.min(oldSelection.getEnd(), newLength));
	Platform.runLater(() -> {
		estimatedScrollYProperty().setValue(oldScrollY);
	});
}
 
开发者ID:JFormDesigner,项目名称:markdown-writer-fx,代码行数:18,代码来源:PreviewStyledTextArea.java

示例8: computeHighlighting

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
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("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();
}
 
开发者ID:FXMisc,项目名称:RichTextFX,代码行数:23,代码来源:JavaKeywordsAsync.java

示例9: computeHighlightingByReg

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
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("COLON")     != null ? "colon"     :
//            matcher.group("SEMICOLON") != null ? "semicolon" :
//            matcher.group("COMMA")     != null ? "comma"     :
//            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();
    }
 
开发者ID:EricCanull,项目名称:fxexperience2,代码行数:28,代码来源:CSSFormatter.java

示例10: computeHighlighting

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
/**
 * Calculate highlighting for the code.
 *
 * @param pattern the pattern.
 * @param text    the text.
 * @return the highlight styles.
 */
@FXThread
protected @NotNull StyleSpans<Collection<String>> computeHighlighting(@NotNull final Pattern pattern,
                                                                      @NotNull final String text) {

    final Matcher matcher = pattern.matcher(text);
    final StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();

    int lastKwEnd = 0;

    while (matcher.find()) {

        String styleClass = null;

        for (final String[] availableClass : getAvailableClasses()) {

            try {
                styleClass = matcher.group(availableClass[0]) != null ? availableClass[1] : null;
            } catch (final IllegalArgumentException e) {
                continue;
            }

            if(styleClass != null) {
                break;
            }
        }

        assert styleClass != null;

        spansBuilder.add(singleton("plain-code"), matcher.start() - lastKwEnd);
        spansBuilder.add(singleton(styleClass), matcher.end() - matcher.start());

        lastKwEnd = matcher.end();
    }

    spansBuilder.add(singleton("plain-code"), text.length() - lastKwEnd);

    return spansBuilder.create();
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:46,代码来源:BaseCodeArea.java

示例11: computeHighlightingAsync

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
private Task<StyleSpans<Collection<String>>> computeHighlightingAsync(CodeArea codeArea) {
    String text = codeArea.getText();
    Task<StyleSpans<Collection<String>>> task = new Task<StyleSpans<Collection<String>>>() {
        @Override
        protected StyleSpans<Collection<String>> call() throws Exception {
            return computeHighlighting(text);
        }
    };
    Executors.newSingleThreadExecutor().execute(task);
    return task;
}
 
开发者ID:helios-decompiler,项目名称:standalone-app,代码行数:12,代码来源:DisassemblerView.java

示例12: computeHighlighting

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
private 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 = null;
		String s;
		if ((s = matcher.group("IDENTIFIER")) != null) {
			for (String command : ExpressionInterpreter.getSupportedCommands()) {
				if (s.equalsIgnoreCase(command)) {
					styleClass = "command";
					break;
				}
			}
			if (s.equals("_x")) {
				styleClass = "magic-var";
			}
		} else if (matcher.group("NUMBER") != null) {
			styleClass = "number";
		} else if (matcher.group("STRING") != null) {
			styleClass = "string";
		} else if (matcher.group("COMMENT") != null) {
			styleClass = "comment";
		}

		if (styleClass == null) {
			continue;
		}

		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();
}
 
开发者ID:kayler-renslow,项目名称:arma-dialog-creator,代码行数:38,代码来源:ExpressionEvaluatorPopup.java

示例13: computeHighlighting

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
private static StyleSpans<Collection<String>> computeHighlighting(String text) {
	text = text.replaceAll("%%", "__");//prevent matching %%1 or %%%%1. We can't remove the %% however because that would mess with the indexes
	Matcher matcher = PATTERN.matcher(text);
	int lastKwEnd = 0;
	StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
	while (matcher.find()) {
		spansBuilder.add(Collections.emptyList(), matcher.start() - lastKwEnd);
		spansBuilder.add(Collections.singleton("param"), matcher.end() - matcher.start());
		lastKwEnd = matcher.end();
	}
	spansBuilder.add(Collections.emptyList(), text.length() - lastKwEnd);
	return spansBuilder.create();
}
 
开发者ID:kayler-renslow,项目名称:arma-dialog-creator,代码行数:14,代码来源:StringTableLanguageTokenEditor.java

示例14: computeHighlighting

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
private static StyleSpans<Collection<String>> computeHighlighting(String text) {
	StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
	SyntaxHighlighter.highlight(text, "html", (length, style) -> {
		spansBuilder.add(toSpanStyle(style), length);
	});
	return spansBuilder.create();
}
 
开发者ID:JFormDesigner,项目名称:markdown-writer-fx,代码行数:8,代码来源:HtmlSourcePreview.java

示例15: editorSelectionChanged

import org.fxmisc.richtext.model.StyleSpans; //导入依赖的package包/类
@Override
public void editorSelectionChanged(PreviewContext context, IndexRange range) {
	if (range.equals(lastEditorSelection))
		return;
	lastEditorSelection = range;

	List<Range> sequences = context.getRenderer().findSequences(range.getStart(), range.getEnd());

	// restore old styles
	for (Map.Entry<Integer, StyleSpans<Collection<String>>> e : oldSelectionStylesMap.entrySet())
		textArea.setStyleSpans(e.getKey(), e.getValue());
	oldSelectionStylesMap.clear();

	// set new selection styles
	String text = textArea.getText();
	for (Range sequence : sequences) {
		String rangeStr = "[" + sequence.start + ", " + sequence.end;
		int index = 0;
		while ((index = text.indexOf(rangeStr, index)) >= 0) {
			int endIndex = index + rangeStr.length() + 1;
			char after = text.charAt(endIndex - 1);
			if ((after == ']' || after == ',') && !oldSelectionStylesMap.containsKey(index)) {
				oldSelectionStylesMap.put(index, textArea.getStyleSpans(index, endIndex));
				textArea.setStyle(index, endIndex, STYLE_SELECTION);
			}
			index = endIndex;
		}
	}
}
 
开发者ID:JFormDesigner,项目名称:markdown-writer-fx,代码行数:30,代码来源:ASTPreview.java


注:本文中的org.fxmisc.richtext.model.StyleSpans类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。