io.github.duoduobabi.javafx.control.TextEditorDialog Maven / Gradle / Ivy
The newest version!
package io.github.duoduobabi.javafx.control;
import javafx.application.Platform;
import javafx.beans.NamedArg;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.DialogPane;
import static io.github.duoduobabi.javafx.util.ThemeUtils.getThemeResource;
/**
* 文本编辑器对话框
*
* @author cuiyang
*/
public class TextEditorDialog extends Dialog {
public TextEditorDialog() {
this("");
}
public TextEditorDialog(@NamedArg("defaultValue") String defaultValue) {
TextEditor textEditor = new TextEditor();
textEditor.setText(defaultValue);
textEditor.setPrefWidth(800);
textEditor.setPrefHeight(600);
DialogPane dialogPane = getDialogPane();
dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
dialogPane.getStylesheets().addAll(getThemeResource());
dialogPane.setContent(textEditor);
this.setDialogPane(dialogPane);
Platform.runLater(textEditor::requestFocus);
setResultConverter((dialogButton) -> {
ButtonBar.ButtonData data = dialogButton == null ? null : dialogButton.getButtonData();
return data == ButtonBar.ButtonData.OK_DONE ? textEditor.getText() : null;
});
}
}