本文整理汇总了Java中org.fxmisc.richtext.CodeArea.setParagraphGraphicFactory方法的典型用法代码示例。如果您正苦于以下问题:Java CodeArea.setParagraphGraphicFactory方法的具体用法?Java CodeArea.setParagraphGraphicFactory怎么用?Java CodeArea.setParagraphGraphicFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.fxmisc.richtext.CodeArea
的用法示例。
在下文中一共展示了CodeArea.setParagraphGraphicFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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();
}
示例3: 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();
}
示例4: 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();
}
示例5: FXMLTextArea
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
public FXMLTextArea() {
codeArea = new CodeArea();
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
codeArea.richChanges().subscribe(change -> {
codeArea.setStyleSpans(0, computeHighlighting(codeArea.getText()));
});
codeArea.selectionProperty().addListener((oba, oldval, newval) -> {
int start = newval.getStart();
int end = newval.getEnd();
int caretColumn = codeArea.getCaretColumn();
String format = String.format("line : %d selectionStart : %d selectionEnd : %d column : %d anchor : %d",
codeArea.getCurrentParagraph() + 1, start + 1, end + 1, caretColumn + 1, codeArea.getAnchor());
lblLineInfo.setText(format);
});
codeArea.setOnKeyPressed(this::codeAreaKeyClick);
lblLineInfo.setPrefHeight(USE_COMPUTED_SIZE);
lblLineInfo.setMinHeight(USE_COMPUTED_SIZE);
lblLineInfo.setMaxHeight(USE_COMPUTED_SIZE);
this.setCenter(codeArea);
this.setBottom(lblLineInfo);
// this.getChildren().add(codeArea);
this.getStylesheets().add(FXMLTextArea.class.getResource("java-keywords.css").toExternalForm());
}
示例6: tabContents
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
@Override
public List<KeyNode> tabContents() {
CodeArea value = new CodeArea();
value.setParagraphGraphicFactory(LineNumberFactory.get(value));
WebView webView = new WebView();
return Arrays.asList(new KeyNode("Text", value), new KeyNode("WebView", webView));
}
示例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: initialize
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
private void initialize(boolean showLineNumbers) {
codeArea = new CodeArea();
if (showLineNumbers) {
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea, digits -> "%"+ (digits < 2 ? 2 : digits) + "d"));
}
codeArea.textProperty().addListener((obs, oldText, newText) -> {
codeArea.setStyleSpans(0, computeHighlighting(newText));
});
FXUtil.anchor(codeArea);
getChildren().add(codeArea);
}
示例9: 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();
}
示例10: JavaTextArea
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
public JavaTextArea(String content) {
codeArea = new CodeArea();
codeHelperDeligator = new JavaCodeAreaHelper(codeArea);
codeArea.setParagraphGraphicFactory(getLineFactory());
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.addEventHandler(KeyEvent.KEY_PRESSED, this::codeAreaKeyClick);
codeArea.setOnMouseClicked(defaultSelectionHandler);
codeArea.selectionProperty().addListener((oba, oldval, newval) -> {
int start = newval.getStart();
int end = newval.getEnd();
int caretColumn = codeArea.getCaretColumn();
String format = String.format(POSISION_FORMAT, codeArea.getCurrentParagraph() + 1, start + 1, end + 1, caretColumn + 1,
codeArea.getAnchor(), codeArea.getCaretPosition());
lblLineInfo.setText(format);
});
lblLineInfo.setPrefHeight(USE_COMPUTED_SIZE);
lblLineInfo.setMinHeight(USE_COMPUTED_SIZE);
lblLineInfo.setMaxHeight(USE_COMPUTED_SIZE);
this.setCenter(codeArea);
this.setBottom(lblLineInfo);
// this.getChildren().add(codeArea);
// this.getStylesheets().add(JavaKeywordsAsync.class.getResource("java-keywords.css").toExternalForm());
this.getStylesheets().add(JavaTextArea.class.getResource("java-keywords.css").toExternalForm());
this.codeArea.appendText(content);
UndoManager undoManager = codeArea.getUndoManager();
undoManager.forgetHistory();
undoManager.mark();
this.codeArea.selectRange(0, 0);
}
示例11: BehaviorTextArea
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
public BehaviorTextArea(String content) {
codeArea = new CodeArea();
codeHelperDeligator = new BehaviorCodeAreaHelper(codeArea);
codeArea.setParagraphGraphicFactory(getLineFactory());
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.addEventHandler(KeyEvent.KEY_PRESSED, this::codeAreaKeyClick);
codeArea.setOnMouseClicked(defaultSelectionHandler);
codeArea.selectionProperty().addListener((oba, oldval, newval) -> {
int start = newval.getStart();
int end = newval.getEnd();
int caretColumn = codeArea.getCaretColumn();
String format = String.format(POSISION_FORMAT, codeArea.getCurrentParagraph() + 1, start + 1, end + 1, caretColumn + 1,
codeArea.getAnchor(), codeArea.getCaretPosition());
lblLineInfo.setText(format);
});
lblLineInfo.setPrefHeight(USE_COMPUTED_SIZE);
lblLineInfo.setMinHeight(USE_COMPUTED_SIZE);
lblLineInfo.setMaxHeight(USE_COMPUTED_SIZE);
this.setCenter(codeArea);
this.setBottom(lblLineInfo);
// this.getChildren().add(codeArea);
// this.getStylesheets().add(JavaKeywordsAsync.class.getResource("java-keywords.css").toExternalForm());
this.getStylesheets().add(BehaviorTextArea.class.getResource("behavior-keywords.css").toExternalForm());
this.codeArea.appendText(content);
UndoManager undoManager = codeArea.getUndoManager();
undoManager.forgetHistory();
undoManager.mark();
this.codeArea.selectRange(0, 0);
}
示例12: initialize
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
@FXML
public void initialize() {
codeArea = new CodeArea();
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
codeArea.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
// Tab 없이 처리되는 클래스들도 있음....
DockTab tab2 = SimpleTextView.this.tab;
if (tab2 != null) {
if (tab2.getText().charAt(0) == '*') {
return;
}
String modifyTabName = "*".concat(tab2.getText());
tab2.setText(modifyTabName);
}
}
});
codeArea.setOnKeyPressed(ev -> {
if (ev.getCode() == KeyCode.S && ev.isControlDown()) {
if (ev.isConsumed())
return;
miSaveOnAction();
ev.consume();
} else if (ev.getCode() == KeyCode.N && ev.isControlDown()) {
if (ev.isConsumed())
return;
miNewOnAction();
ev.consume();
}
});
initHelpers();
initGraphics();
// miSaveAs.setAccelerator(new KeyCodeCombination(KeyCode.S,
// KeyCombination.CONTROL_DOWN));
}
示例13: SqlKeywords
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
public SqlKeywords() {
codeArea = new CodeArea();
codeHelperDeligator = new SqlCodeAreaHelper(codeArea);
codeArea.appendText("");
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
// codeArea.richChanges().subscribe(change -> {
// Platform.runLater(() -> {
// codeArea.setStyleSpans(0, computeHighlighting(codeArea.getText()));
//
// });
// });
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 'Tab' Size handler *************************************************************/
//17.01.14 Deprecated
//codeArea.addEventHandler(KeyEvent.KEY_PRESSED, new CodeAreaTabSizeHandler(codeArea));
// 마우스 클릭이벤트 정의
codeArea.addEventHandler(KeyEvent.KEY_PRESSED, this::codeAreaKeyClick);
codeArea.setOnKeyPressed(this::codeAreaKeyClick);
//
// codeArea.setOnMouseClicked(defaultSelectionHandler);
// 선택라인정보 보여주는 기능 추가.
codeArea.selectionProperty().addListener((oba, oldval, newval) -> {
int start = newval.getStart();
int end = newval.getEnd();
int caretColumn = codeArea.getCaretColumn();
String format = String.format("line : %d selectionStart : %d selectionEnd : %d column : %d ",
codeArea.getCurrentParagraph() + 1, start + 1, end + 1, caretColumn + 1);
lblLineInfo.setText(format);
});
lblLineInfo.setPrefHeight(USE_COMPUTED_SIZE);
this.setCenter(codeArea);
this.setBottom(lblLineInfo);
// this.getChildren().add();
this.getStylesheets().add(SqlKeywords.class.getResource("java-keywords.css").toExternalForm());
}
示例14: FileViewController
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
public FileViewController() {
super();
codeArea = new CodeArea();
codeArea.setParagraphGraphicFactory(DiffLineNumberFactory.get(codeArea, Collections.EMPTY_LIST));
codeArea.setEditable(false);
Button button = new Button("Save as ...");
scene = new Scene(
new BorderPane(
new VirtualizedScrollPane(codeArea),
new ToolBar(button),
null,null,null
),
1024, 768);
scene.getStylesheets().add(this.getClass().getResource(Const.KEYWORDS_CSS).toExternalForm());
button.setOnAction(
event -> {
FileChooser fileChooser = new FileChooser();
//Set extension filter
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("Any files (*.*)", "*.*");
fileChooser.getExtensionFilters().add(extFilter);
//Show save file dialog
File file = fileChooser.showSaveDialog(scene.getWindow());
if (file != null) {
try {
Files.copy(Paths.get(fileName), file.toPath());
} catch (IOException e) {
e.printStackTrace();
}
}
}
);
}
示例15: DiffViewController
import org.fxmisc.richtext.CodeArea; //导入方法依赖的package包/类
public DiffViewController() {
super();
oldLinesToHighlight = new ArrayList<>();
oldCodeArea = new CodeArea();
oldCodeArea.setEditable(false);
oldCodeArea.setParagraphGraphicFactory(DiffLineNumberFactory.get(oldCodeArea, oldLinesToHighlight));
oldLabel = new ShaTextField();
oldVSPane = new VirtualizedScrollPane<>(oldCodeArea, ScrollPane.ScrollBarPolicy.AS_NEEDED, ScrollPane.ScrollBarPolicy.NEVER);
StackPane oldStackPane = new StackPane(oldVSPane);
scrollPane = new Pane();
scrollPane.setPrefWidth(75);
newLinesToHighlight = new ArrayList<>();
newCodeArea = new CodeArea();
newCodeArea.setEditable(false);
newCodeArea.setParagraphGraphicFactory(DiffLineNumberFactory.get(newCodeArea, newLinesToHighlight));
newLabel = new ShaTextField();
newVSPane = new VirtualizedScrollPane<>(newCodeArea);
StackPane newStackPane = new StackPane(newVSPane);
newStackPane.setPrefHeight(2000);
gridPanel = new GridPane();
ColumnConstraints oldColumn = new ColumnConstraints();
oldColumn.setPercentWidth(45);
gridPanel.getColumnConstraints().add(oldColumn);
ColumnConstraints scrollColumn = new ColumnConstraints();
scrollColumn.setPercentWidth(10);
scrollColumn.setHalignment(HPos.CENTER);
gridPanel.getColumnConstraints().add(scrollColumn);
ColumnConstraints newlColumn = new ColumnConstraints();
newlColumn.setPercentWidth(45);
gridPanel.getColumnConstraints().add(newlColumn);
buttonNext = new Button();
buttonNext.setTooltip(new Tooltip("Next"));
buttonNext.setGraphic(new FontIcon(FontAwesome.FORWARD));
buttonPrev = new Button();
buttonPrev.setTooltip(new Tooltip("Prev"));
buttonPrev.setGraphic(new FontIcon(FontAwesome.BACKWARD));
gridPanel.add(new ToolBar(new HBox(new Label("Revision: "), oldLabel)), 0, 0);
gridPanel.add(new ToolBar(new HBox(new Label("Revision: "), newLabel)), 2, 0);
gridPanel.add(scrollPane, 1, 1);
gridPanel.add(oldStackPane, 0, 1);
gridPanel.add(newStackPane, 2, 1);
Region leftr = new Region();
Region leftl = new Region();
HBox.setHgrow(leftr, Priority.ALWAYS);
HBox.setHgrow(leftl, Priority.ALWAYS);
gridPanel.add(new HBox(leftl, buttonPrev, buttonNext, leftr), 1, 0);
Field field = FieldUtils.getField(oldCodeArea.getClass(), "virtualFlow", true);
try {
oldVirtualFlow = (VirtualFlow) field.get(oldCodeArea);
newVirtualFlow = (VirtualFlow) field.get(newCodeArea);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}