本文整理汇总了Java中org.fxmisc.richtext.CodeArea.replaceText方法的典型用法代码示例。如果您正苦于以下问题:Java CodeArea.replaceText方法的具体用法?Java CodeArea.replaceText怎么用?Java CodeArea.replaceText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.fxmisc.richtext.CodeArea
的用法示例。
在下文中一共展示了CodeArea.replaceText方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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"
)
);
}
示例2: 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;
}
示例3: 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();
}
示例4: 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();
}
示例5: 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();
}
示例6: setContent
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
public void setContent(String content) {
SimpleTextView currentPageView = this.view.getCurrentPageView();
if (currentPageView != null) {
CodeArea codeArea = currentPageView.getCodeArea();
codeArea.getUndoManager().mark();
codeArea.clear();
codeArea.replaceText(0, 0, content);
codeArea.getUndoManager().mark();
}
}
示例7: initialize
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
@Override
public void initialize(URL location, ResourceBundle resources) {
executor = Executors.newSingleThreadExecutor();
codeArea = new CodeArea();
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
OkButton.disableProperty().bind(Val.map(codeArea.lengthProperty(), n -> n == 0));
EventStream<?> richChanges = codeArea.richChanges();
richChanges
.successionEnds(Duration.ofMillis(500))
.supplyTask(this::computeHighlightingAsync)
.awaitLatest(richChanges)
.filterMap(t -> {
if (t.isSuccess()) {
return Optional.of(t.get());
} else {
t.getFailure().printStackTrace();
return Optional.empty();
}
})
.subscribe(this::applyHighlighting);
codeArea.replaceText(0, 0, getSampleCode());
borderPane.setCenter(codeArea);
borderPane.getStylesheets().add(getClass().getResource("/styles/JavaKeywords.css").toExternalForm());
JdkFolderLocation.setOnMouseClicked((event) -> {
if (event.getClickCount() == 2) {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Select JDK installation folder");
File file = new File("C:\\Program Files\\Java");
if (file.isDirectory()) { //check if it exists and a folder
directoryChooser.setInitialDirectory(file);
}
File directory = directoryChooser.showDialog(primaryStage);
if (directory != null) {
JdkFolderLocation.setText(directory.getAbsolutePath());
}
}
});
// borderPane.setCenter(new VirtualizedScrollPane<>(codeArea));
}
示例8: start
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
@Override
public void start(Stage primaryStage) {
executor = Executors.newSingleThreadExecutor();
codeArea = new CodeArea();
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
codeArea.richChanges()
.filter(ch -> !ch.getInserted().equals(ch.getRemoved())) // XXX
.successionEnds(Duration.ofMillis(500))
.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::applyHighlighting);
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 Async Demo");
primaryStage.show();
}
示例9: createResourceView
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
@Override
public ResourceView<Map<String, Object>> createResourceView() {
ConnectionSupplier connectionSupplier = getConnectionSupplier();
MssqlTableOpenResourceView tableOpenResourceView = new MssqlTableOpenResourceView(connectionSupplier, new Stage()) {
/*
* (non-Javadoc)
*
* @see
* com.kyj.fx.voeditor.visual.component.popup.TableOpenResourceView#
* close()
*/
@Override
public void close() {
CodeArea codeArea = getCodeArea();
codeArea.getPopupWindow().hide();
ResultDialog<Map<String, Object>> result = getResult();
if (result.getStatus() == ResultDialog.SELECT) {
Map<String, Object> data = result.getData();
if (data == null)
return;
String tableName = getTableName(data);
if (tableName == null)
return;
Object _tbCat = data.get("TABLE_CAT");
if(ValueUtil.isNotEmpty(_tbCat))
{
tableName = String.format("%s.%s", _tbCat.toString(), tableName);
}
// Object object = data.get("table_name");
// if (object == null)
// return;
String string = currentPragraph(codeArea);
int markTextColumnIndex = getIndexOfValideWhiteSpace(string);
if (markTextColumnIndex == -1) {
codeArea.getUndoManager().mark();
codeArea.appendText(tableName);
} else {
int anchor = codeArea.getAnchor();
int start = anchor - string.length() + markTextColumnIndex;
IndexRange normalize = IndexRange.normalize(start, anchor);
codeArea.getUndoManager().mark();
codeArea.replaceText(normalize, tableName);
}
}
}
};
return tableOpenResourceView.getView();
}