Проверка входных данных (GUI)
This commit is contained in:
@@ -1,16 +1,21 @@
|
|||||||
package ru.dmitriymx.corrector1s.gui;
|
package ru.dmitriymx.corrector1s.gui;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import ru.dmitriymx.corrector1s.Corrector1S;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class MainController {
|
public class MainController {
|
||||||
private Stage stage;
|
private Stage stage;
|
||||||
@FXML
|
@FXML
|
||||||
@@ -54,6 +59,28 @@ public class MainController {
|
|||||||
return fileChooser;
|
return fileChooser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Alert buildErrorDialog(String title, String text, Exception e) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.setTitle(title);
|
||||||
|
alert.setHeaderText(text);
|
||||||
|
|
||||||
|
VBox dialogPaneContent = new VBox();
|
||||||
|
Label label = new Label("Stack Trace:");
|
||||||
|
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
e.printStackTrace(pw);
|
||||||
|
String stackTrace = sw.toString();
|
||||||
|
|
||||||
|
TextArea textArea = new TextArea();
|
||||||
|
textArea.setText(stackTrace);
|
||||||
|
|
||||||
|
dialogPaneContent.getChildren().addAll(label, textArea);
|
||||||
|
alert.getDialogPane().setContent(dialogPaneContent);
|
||||||
|
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
gonorar.setValueFactory(gonorarValueFactory);
|
gonorar.setValueFactory(gonorarValueFactory);
|
||||||
@@ -83,21 +110,31 @@ public class MainController {
|
|||||||
progressBar.setProgress(0d);
|
progressBar.setProgress(0d);
|
||||||
|
|
||||||
Runnable runnable = () -> {
|
Runnable runnable = () -> {
|
||||||
do {
|
Corrector1S corrector = new Corrector1S();
|
||||||
try {
|
corrector.setSourceFile(new File(sourceFilePath.getText()));
|
||||||
Thread.sleep(500);
|
if (saveAsCheckBox.isSelected()) {
|
||||||
} catch (InterruptedException e) {
|
corrector.setTargetFile(new File(saveAsFilePath.getText()));
|
||||||
break;
|
} else {
|
||||||
}
|
corrector.setTargetFile(new File(sourceFilePath.getText()));
|
||||||
progressBar.setProgress(progressBar.getProgress() + 0.1d);
|
}
|
||||||
} while (progressBar.getProgress() <= 1.0d);
|
corrector.setHonorarium(gonorar.getValue());
|
||||||
|
|
||||||
|
progressBar.setProgress(0.3d);
|
||||||
|
|
||||||
|
try {
|
||||||
|
corrector.check();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Analize input data", e);
|
||||||
|
Alert alert = buildErrorDialog("Ошибка", "Ошибка при анализе входных данных", e);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
waitPane.setVisible(false);
|
waitPane.setVisible(false);
|
||||||
mainPane.setOpacity(1.0d);
|
mainPane.setOpacity(1.0d);
|
||||||
mainPane.setDisable(false);
|
mainPane.setDisable(false);
|
||||||
};
|
};
|
||||||
Thread thread = new Thread(runnable);
|
|
||||||
thread.start();
|
Platform.runLater(runnable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user