1 Star 0 Fork 0

Lu Ning/Course2TextEditor

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
EditDistanceDialogController.java 2.64 KB
一键复制 编辑 原始数据 按行查看 历史
Lu Ning 提交于 2016-04-17 16:18 +08:00 . initial commit
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;
@FXML
private TextField word1;
@FXML
private TextField word2;
@FXML
private Button okButton;
@FXML
private 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.
*/
@FXML
private void handleOk() {
if(isInputValid()) {
Task<List<String>> task = new Task<List<String>>() {
@Override
public List<String> call() {
// get word path
LaunchClass launch = new LaunchClass();
spelling.WordPath wp = launch.getWordPath();
List<String> path = wp.findPath(word1.getText(), word2.getText());
return path;
}
};
// stage for load dialog
final Stage loadStage = new Stage();
// consume close request until task is finished
loadStage.setOnCloseRequest( e -> {
if(!task.isDone()) {
e.consume();
}
});
// show loading dialog when task is running
task.setOnRunning( e -> {
dialogStage.close();
mainApp.showLoadStage(loadStage, "Finding word path...");
});
// findPath done executing, close loading dialog, show results
task.setOnSucceeded(e -> {
loadStage.close();
mainApp.showEDResult(task.getValue());
});
Thread thread = new Thread(task);
thread.start();
}
else {
// display error pop-up
mainApp.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;
}
@FXML
private void handleCancel() {
dialogStage.close();
}
private boolean isInputValid() {
return !(word1.getText().equals("") || word2.getText().equals(""));
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/luning/Course2TextEditor.git
git@gitee.com:luning/Course2TextEditor.git
luning
Course2TextEditor
Course2TextEditor
master

搜索帮助