package application;import java.util.function.Consumer;import javafx.collections.ObservableList;import javafx.concurrent.Task;import javafx.fxml.FXML;import javafx.scene.Node;import javafx.scene.control.CheckBox;import javafx.scene.control.Label;import javafx.scene.control.TextField;import javafx.scene.layout.HBox;import javafx.scene.layout.Pane;import javafx.scene.layout.Priority;import javafx.scene.layout.VBox;import javafx.stage.Stage;public class TextProController {private final static double DEFAULT_SPACING = 55;private final static double CONTROL_HEIGHT = 132;private final static double SPACE_DIV = 8.5;private final static double BUTTON_WIDTH = 160.0;private final static double RBOX_THRESHOLD = 520; // threshold to change spacing of right VBox// used when showing new stage/sceneprivate MainApp mainApp;// used for getting new objectsprivate LaunchClass launch;// UI Controlsprivate AutoSpellingTextArea textBox;@FXMLprivate VBox leftPane;@FXMLprivate VBox rightBox;@FXMLprivate HBox container;@FXMLprivate Label fLabel;@FXMLprivate Pane bufferPane;@FXMLprivate TextField fleschField;@FXMLprivate CheckBox autocompleteBox;@FXMLprivate CheckBox spellingBox;//private Node/*** Initializes the controller class. This method is automatically called* after the fxml file has been loaded.** Initialize and add text area to application*/@FXMLprivate void initialize() {// make field displaying flesch score read-onlyfleschField.setEditable(false);launch = new LaunchClass();// instantiate and add custom text areaspelling.Dictionary dic = launch.getDictionary();textBox = new AutoSpellingTextArea(launch.getAutoComplete(), launch.getSpellingSuggest(dic), dic);textBox.setPrefSize(570, 492);textBox.setStyle("-fx-font-size: 14px");textBox.setWrapText(true);// add text area as first child of left VBoxObservableList<Node> nodeList = leftPane.getChildren();Node firstChild = nodeList.get(0);nodeList.set(0, textBox);nodeList.add(firstChild);VBox.setVgrow(textBox, Priority.ALWAYS);// ADD LISTENERS FOR ADJUSTING ON RESIZEcontainer.widthProperty().addListener(li -> {if((container.getWidth() - leftPane.getPrefWidth()) < BUTTON_WIDTH) {rightBox.setVisible(false);}else {rightBox.setVisible(true);}});// function for setting spacing of rightBoxConsumer<VBox> adjustSpacing = box -> {if(container.getHeight() < RBOX_THRESHOLD) {rightBox.setSpacing((container.getHeight() - CONTROL_HEIGHT)/SPACE_DIV);}else {rightBox.setSpacing(DEFAULT_SPACING);}};container.heightProperty().addListener(li -> {adjustSpacing.accept(rightBox);});rightBox.visibleProperty().addListener( li -> {if(rightBox.isVisible()) {container.getChildren().add(rightBox);adjustSpacing.accept(rightBox);}else {container.getChildren().remove(rightBox);}});}/*** Is called by the main application to give a reference back to itself.* Also give reference to AutoSpellingTextArea*** @param mainApp*/public void setMainApp(MainApp mainApp) {this.mainApp = mainApp;}@FXMLprivate void handleFleschIndex() {String text = textBox.getText();double fIndex = 0;// check if text inputif(!text.equals("")) {// create Document representation of current textdocument.Document doc = launch.getDocument(text);fIndex = doc.getFleschScore();//get string with two decimal places for index toString fString = String.format("%.2f", fIndex);// display string in text fieldfleschField.setText(fString);}else {// reset text fieldfleschField.setText("");mainApp.showInputErrorDialog("No text entered.");}}@FXMLprivate void handleLoadText() {//return string??mainApp.showLoadFileDialog(textBox);//textBox.appendText(text);}@FXMLprivate void handleEditDistance() {String selectedText = textBox.getSelectedText();mainApp.showEditDistanceDialog(selectedText);}@FXMLprivate void handleMarkovText() {// get MTG objecttextgen.MarkovTextGenerator mtg = launch.getMTG();Task<textgen.MarkovTextGenerator> task = new Task<textgen.MarkovTextGenerator>() {@Overridepublic textgen.MarkovTextGenerator call() {// process long-running computation, data retrieval, etc...mtg.retrain(textBox.getText());return mtg;}};// stage for load dialogfinal Stage loadStage = new Stage();// consume close request until task is finishedloadStage.setOnCloseRequest( e -> {if(!task.isDone()) {e.consume();}});// show loading dialog when task is runningtask.setOnRunning( e -> {mainApp.showLoadStage(loadStage, "Training MTG...");});// MTG trained, close loading dialog, show MTG dialogtask.setOnSucceeded(e -> {loadStage.close();textgen.MarkovTextGenerator result = task.getValue();mainApp.showMarkovDialog(result);});Thread thread = new Thread(task);thread.start();}@FXMLprivate void handleAutoComplete() {if(autocompleteBox.isSelected()) {textBox.setAutoComplete(true);}else {textBox.setAutoComplete(false);}}@FXMLprivate void handleSpelling() {if(spellingBox.isSelected()) {textBox.setSpelling(true);}else {textBox.setSpelling(false);}}@FXMLprivate void handleClear() {textBox.clear();}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。