本文整理汇总了Java中org.fxmisc.richtext.CodeArea类的典型用法代码示例。如果您正苦于以下问题:Java CodeArea类的具体用法?Java CodeArea怎么用?Java CodeArea使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeArea类属于org.fxmisc.richtext包,在下文中一共展示了CodeArea类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AutoCompletionCodeAreaBind
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
/**
*
* @param codeArea
* @param suggestionProvider
* @param replaceTextProvider
* When a suggestion entered, which range of text should be replaced.
*/
public AutoCompletionCodeAreaBind(CodeArea codeArea,
BiFunction<String, Integer, Collection<String>> suggestionProvider,
BiFunction<String, Integer, IndexRange> replaceTextProvider) {
this.codeArea = codeArea;
this.suggestionProvider = suggestionProvider;
this.replaceTextProvider = replaceTextProvider;
this.popup = new AutoCompletePopup<>();
codeArea.textProperty().addListener(textChangeListener);
codeArea.focusedProperty().addListener(focusChangedListener);
codeArea.setPopupWindow(popup);
codeArea.setPopupAlignment(PopupAlignment.CARET_BOTTOM);
popup.setOnSuggestion(sce -> {
completeUserInput(sce.getSuggestion());
hidePopup();
});
}
示例2: fillCodeArea
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
protected void fillCodeArea(CodeArea area, String fileName) throws IOException {
area.richChanges()
.filter(ch -> !ch.getInserted().equals(ch.getRemoved())) // XXX
.subscribe(change -> {
area.setStyleSpans(
0,
HighlightProvider.computeHighlighting(
area.getText(),
HighlightProvider.resolvePattern(fileName)
)
);
}
);
area.replaceText(0, 0, new String(
Files.readAllBytes((new File(fileName)).toPath()),
"UTF-8"
)
);
}
示例3: compute
import org.fxmisc.richtext.CodeArea; //导入依赖的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
}
}
}
示例4: configureTextArea
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
private void configureTextArea() {
CodeArea codeArea = view.getCodeArea();
code.sourcecodeProperty().bind(codeArea.textProperty());
codeArea.richChanges()
.filter(ch -> !ch.getInserted().equals(ch.getRemoved()))
.successionEnds(Duration.ofMillis(500))
.hook(collectionRichTextChange -> codeArea.getUndoManager()
.mark()).supplyTask(this::computeHighlightingAsync)
.awaitLatest(codeArea.richChanges()).filterMap(t -> {
if (t.isSuccess()) {
return Optional.of(t.get());
}
else {
t.getFailure().printStackTrace();
return Optional.empty();
}
}).subscribe(this::handleTextChange);
}
示例5: EditorPane
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
/**
* <p>
* Creates an editable EditorPane with the given code as initial source code text.
* </p>
*
* @param code the string to initialize the {@link CodeArea} to
* @param syntaxErrors the initial list of {@link SyntaxError}s.
* @param showLineNumbers whether to show line numbers in the {@link CodeArea}
*/
public EditorPane(String code, ObservableList<SyntaxError> syntaxErrors,
boolean showLineNumbers) {
super();
this.syntaxErrors = syntaxErrors;
ViewUtils.setupView(this);
codeArea = new CodeArea(code);
lineNumberFactory = LineNumberFactory.get(codeArea);
if (showLineNumbers) {
codeArea.setParagraphGraphicFactory(this::createLinePrefixForLine);
}
this.getItems().addAll(codeArea);
this.setOrientation(Orientation.VERTICAL);
this.setDividerPositions(0.8);
}
示例6: GroovyEditorComponent
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
/**
* Instantiates a new Groovy editor component.
*
* @param editable the editable
*/
public GroovyEditorComponent(final boolean editable) {
codeArea = new CodeArea();
codeArea.richChanges()
.filter(ch -> !ch.getInserted().equals(ch.getRemoved()))
.subscribe(change -> codeArea.setStyleSpans(0, getStyleSpans(codeArea.getText())));
codeArea.prefHeightProperty().bind(heightProperty());
codeArea.prefWidthProperty().bind(widthProperty());
codeArea.setEditable(editable);
codeArea.setOnKeyReleased(UIUtils::consumeIfIsNotHotKey);
codeArea.setOnKeyPressed(UIUtils::consumeIfIsNotHotKey);
FXUtils.addToPane(codeArea, this);
FXUtils.addClassesTo(this, CSSClasses.TEXT_EDITOR_TEXT_AREA, CSSClasses.GROOVY_EDITOR_COMPONENT);
}
示例7: getNewConsole
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
@Override
protected ScriptEditorControl getNewConsole() {
try {
CodeArea codeArea = new CodeArea();
codeArea.richChanges().subscribe(change -> {
// If anything was removed, do full reformatting
if (change.getRemoved().length() != 0 || change.getPosition() == 0) {
if (!change.getRemoved().getText().equals(change.getInserted().getText()))
// System.err.println("Slow version!");
codeArea.setStyleSpans(0, computeConsoleHighlighting(codeArea.getText()));
} else {
// System.err.println("FAST version!");
// Otherwise format only from changed position onwards
codeArea.setStyleSpans(change.getPosition(), computeConsoleHighlighting(change.getInserted().getText()));
}
// codeArea.setStyleSpans(0, computeConsoleHighlighting(codeArea.getText()));
});
codeArea.getStylesheets().add(getClass().getClassLoader().getResource("scripting_styles.css").toExternalForm());
return new CodeAreaControl(codeArea);
} catch (Exception e) {
// Default to superclass implementation
logger.error("Unable to create console area", e);
return super.getNewEditor();
}
}
示例8: editDocument
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
public Optional<String> editDocument(String formattedJson, int cursorPosition) {
Dialog<String> dialog = new Dialog<>();
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
dialog.setTitle("MongoFX - edit document");
dialog.setResizable(true);
dialog.getDialogPane().getStylesheets().add(getClass().getResource("/ui/editor.css").toExternalForm());
CodeArea codeArea = setupEditorArea(formattedJson, dialog, cursorPosition);
dialog.setResultConverter(bt -> {
if (ButtonData.OK_DONE == bt.getButtonData()) {
return codeArea.getText();
}
return null;
});
return dialog.showAndWait();
}
示例9: setupEditorArea
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
private CodeArea setupEditorArea(String formattedJson, Dialog<String> dialog, int cursorPosition) {
URL url = getClass().getResource("/ui/Editor.fxml");
final FXMLLoader loader = createLoader(url);
BorderPane root = load(url, loader);
EditorController editorController = loader.getController();
CodeArea codeArea = editorController.getCodeArea();
codeArea.setPrefSize(500, 400);
codeArea.replaceText(formattedJson);
codeArea.getUndoManager().forgetHistory();
// stackpane is workaround https://github.com/TomasMikula/RichTextFX/issues/196
dialog.getDialogPane().setContent(new StackPane(root));
Platform.runLater(() -> {
codeArea.selectRange(cursorPosition, cursorPosition);
codeArea.requestFocus();
});
return codeArea;
}
示例10: start
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
@Override
public void start(Stage stage) throws Exception {
area = new CodeArea();
area.appendText("some example\n text to go here\n across a couple of \n lines....");
JabRefPreferences preferences = mock(JabRefPreferences.class, Answers.RETURNS_DEEP_STUBS);
sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), preferences, new DummyFileUpdateMonitor());
pane = new TabPane(
new Tab("main area", area),
new Tab("other tab", new Label("some text")),
sourceTab
);
scene = new Scene(pane);
this.stage = stage;
stage.setScene(scene);
stage.setWidth(400);
stage.setHeight(400);
stage.show();
// select the area's tab
pane.getSelectionModel().select(0);
}
示例11: start
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
@Override
public void start(Stage primaryStage) {
CodeArea codeArea = new CodeArea();
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
codeArea.textProperty().addListener((obs, oldText, newText) -> {
codeArea.setStyleSpans(0, computeHighlighting(newText));
});
codeArea.replaceText(0, 0, sampleCode);
Scene scene = new Scene(new StackPane(new VirtualizedScrollPane<>(codeArea)), 600, 400);
scene.getStylesheets().add(XMLEditor.class.getResource("xml-highlighting.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("XML Editor Demo");
primaryStage.show();
}
示例12: start
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
@Override
public void start(Stage primaryStage) {
CodeArea codeArea = new CodeArea();
IntFunction<Node> numberFactory = LineNumberFactory.get(codeArea);
IntFunction<Node> arrowFactory = new ArrowFactory(codeArea.currentParagraphProperty());
IntFunction<Node> graphicFactory = line -> {
HBox hbox = new HBox(
numberFactory.apply(line),
arrowFactory.apply(line));
hbox.setAlignment(Pos.CENTER_LEFT);
return hbox;
};
codeArea.setParagraphGraphicFactory(graphicFactory);
codeArea.replaceText("The green arrow will only be on the line where the caret appears.\n\nTry it.");
codeArea.moveTo(0, 0);
primaryStage.setScene(new Scene(new StackPane(codeArea), 600, 400));
primaryStage.show();
}
示例13: start
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
@Override
public void start(Stage primaryStage) {
CodeArea codeArea = new CodeArea();
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
codeArea.richChanges()
.filter(ch -> !ch.getInserted().equals(ch.getRemoved())) // XXX
.subscribe(change -> {
codeArea.setStyleSpans(0, computeHighlighting(codeArea.getText()));
});
codeArea.replaceText(0, 0, sampleCode);
Scene scene = new Scene(new StackPane(new VirtualizedScrollPane<>(codeArea)), 600, 400);
scene.getStylesheets().add(JavaKeywordsAsync.class.getResource("java-keywords.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("Java Keywords Demo");
primaryStage.show();
}
示例14: computeHighlighting
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
public static void computeHighlighting(String text, CodeArea parent) {
Matcher matcher = HIGHLIGHTING_PATTERN.matcher(text);
List<StyleIndex> styleChanges = Lists.newArrayList();
while(matcher.find()) {
String styleClass =
matcher.group("HRULE") != null ? "hrule" :
matcher.group("HEADING1") != null ? "heading1" :
matcher.group("HEADING2") != null ? "heading2" :
matcher.group("HEADING3") != null ? "heading3" :
matcher.group("HEADING4") != null ? "heading4" :
matcher.group("HEADING5") != null ? "heading5" :
matcher.group("HEADING6") != null ? "heading6" :
matcher.group("BOLD") != null ? "bold" :
matcher.group("ITALICS") != null ? "italics" :
matcher.group("STRIKE") != null ? "strikethrough" :
matcher.group("INLINECODE") != null ? "inline-code" :
matcher.group("IMAGE") != null ? "image" :
matcher.group("LINK") != null ? "link" :
matcher.group("CODE") != null ? "code" :
null;
parent.setStyle(matcher.start(), matcher.end(), Collections.singleton(styleClass));
/*StyleIndex index = new StyleIndex(matcher.start(), matcher.end());
index.addStyle(styleClass);
styleChanges.add(index);*/
}
}
示例15: run
import org.fxmisc.richtext.CodeArea; //导入依赖的package包/类
@Override
public void run() {
tabs.stream()
.map(tab -> {
Path path = (Path) tab.getUserData();
VirtualizedScrollPane scrollPane = (VirtualizedScrollPane) tab.getContent();
CodeArea codeArea = (CodeArea) scrollPane.getContent();
String lines = codeArea.getText();
return new ExistFileToSave(lines, path);
})
.forEach(ExistFileToSave::save);
}