package application;import java.util.List;import javafx.concurrent.Task;import javafx.fxml.FXML;import javafx.scene.control.Button;import javafx.scene.control.TextField;import javafx.stage.Stage;public class EditDistanceDialogController {private Stage dialogStage;private MainApp mainApp;@FXMLprivate TextField word1;@FXMLprivate TextField word2;@FXMLprivate Button okButton;@FXMLprivate void initialize() {okButton.setDefaultButton(true);}/*** Sets the stage of this dialog.* @param dialogStage*/public void setDialogStage(Stage dialogStage) {this.dialogStage = dialogStage;}public void setField(String text) {word1.setText(text);}/*** Called when the user clicks ok.*/@FXMLprivate void handleOk() {if(isInputValid()) {Task<List<String>> task = new Task<List<String>>() {@Overridepublic List<String> call() {// get word pathLaunchClass launch = new LaunchClass();spelling.WordPath wp = launch.getWordPath();List<String> path = wp.findPath(word1.getText(), word2.getText());return path;}};// 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 -> {dialogStage.close();mainApp.showLoadStage(loadStage, "Finding word path...");});// findPath done executing, close loading dialog, show resultstask.setOnSucceeded(e -> {loadStage.close();mainApp.showEDResult(task.getValue());});Thread thread = new Thread(task);thread.start();}else {// display error pop-upmainApp.showInputErrorDialog("You must input two words for Edit Distance.");}}/*** Is called by the main application to give a reference back to itself.*** @param mainApp*/public void setMainApp(MainApp mainApp) {this.mainApp = mainApp;}@FXMLprivate void handleCancel() {dialogStage.close();}private boolean isInputValid() {return !(word1.getText().equals("") || word2.getText().equals(""));}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。