Commit 2d44879d authored by Alexander Weigl's avatar Alexander Weigl

add apache commons-io and showExceptionDialog

parent 670967de
Pipeline #10933 passed with stage
in 1 minute and 53 seconds
......@@ -235,6 +235,18 @@
<version>8.40.12</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
......
package edu.kit.formal.gui;
import java.io.*;
/**
* Created by sarah on 5/29/17.
*/
public class FileUtils {
public static BufferedReader readFile(File file) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(file));
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return br;
}
}
package edu.kit.formal.gui.controller;
import de.uka.ilkd.key.speclang.Contract;
import edu.kit.formal.gui.FileUtils;
import edu.kit.formal.gui.model.RootModel;
import edu.kit.formal.interpreter.KeYProofFacade;
import edu.kit.formal.interpreter.data.GoalNode;
......@@ -14,14 +13,21 @@ import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import lombok.Setter;
import org.apache.commons.io.FileUtils;
import org.controlsfx.dialog.Wizard;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.List;
import java.util.ResourceBundle;
import java.util.concurrent.ExecutorService;
......@@ -120,11 +126,47 @@ public class DebuggerMainWindowController implements Initializable {
protected void openScript() {
File scriptFile = openFileChooserDialog("Select Script File", "Proof Script File", "kps");
if (scriptFile != null) {
model.setScriptFile(scriptFile);
this.model.currentScriptProperty().set(FileUtils.readFile(scriptFile).toString());
try {
String code = FileUtils.readFileToString(scriptFile, Charset.defaultCharset());
model.currentScriptProperty().set(code);
model.setScriptFile(scriptFile);
} catch (IOException e) {
showExceptionDialog("Exception occured", "",
"Could not load file " + scriptFile, e);
}
}
}
public void showExceptionDialog(String title, String headerText, String contentText, Exception ex) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(title);
alert.setHeaderText(headerText);
alert.setContentText(contentText);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
String exceptionText = sw.toString();
Label label = new Label("The exception stacktrace was:");
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(label, 0, 0);
expContent.add(textArea, 0, 1);
alert.getDialogPane().setExpandableContent(expContent);
alert.showAndWait();
}
@FXML
protected void loadKeYFile() {
File keyFile = openFileChooserDialog("Select KeY File", "KeY Files", "key", "script");
......@@ -248,7 +290,8 @@ public class DebuggerMainWindowController implements Initializable {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(title);
fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(description, fileEndings));
fileChooser.setInitialDirectory(new File(testFile1));
File value = new File(testFile1);
fileChooser.setInitialDirectory(value.exists() ? value : new File("."));
File file = fileChooser.showOpenDialog(this.stage);
return file;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment