Commit fe351689 authored by Alexander Weigl's avatar Alexander Weigl

ProofTree changes

parent e6361f70
package edu.kit.iti.formal.psdbg.interpreter.dbg;
import edu.kit.iti.formal.psdbg.parser.Facade;
import edu.kit.iti.formal.psdbg.parser.ast.Expression;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(of = {"sourceName", "lineNumber"})
public class Breakpoint {
private String sourceName;
private int lineNumber;
private boolean enabled;
private String condition;
private Expression conditionAst;
public Breakpoint(String file, int lineNumber) {
sourceName = file;
this.lineNumber = lineNumber;
}
public boolean isConditional() {
return condition != null;
}
public void setCondition(String condition) {
this.condition = condition;
if (condition != null)
this.conditionAst = Facade.parseExpression(condition);
}
}
\ No newline at end of file
......@@ -4,13 +4,12 @@ import de.uka.ilkd.key.proof.Node;
import de.uka.ilkd.key.proof.Proof;
import de.uka.ilkd.key.proof.ProofTreeEvent;
import de.uka.ilkd.key.proof.ProofTreeListener;
import javafx.beans.InvalidationListener;
import javafx.application.Platform;
import javafx.beans.property.MapProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleMapProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
......@@ -18,23 +17,28 @@ import javafx.scene.control.TreeView;
import javafx.scene.control.cell.TextFieldTreeCell;
import javafx.scene.layout.BorderPane;
import javafx.util.StringConverter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.val;
import java.util.stream.Collectors;
/**
* KeY Proof Tree
*/
public class ProofTree extends BorderPane {
private ObjectProperty<Proof> proof = new SimpleObjectProperty<>();
private ObjectProperty<Node> root = new SimpleObjectProperty<>();
private MapProperty colorOfNodes = new SimpleMapProperty<>(FXCollections.observableHashMap());
@FXML
private TreeView<Node> treeProof;
private TreeView<TreeNode> treeProof;
private ProofTreeListener proofTreeListener = new ProofTreeListener() {
@Override
public void proofExpanded(ProofTreeEvent proofTreeEvent) {
treeProof.refresh();
Platform.runLater(() -> init());
}
@Override
......@@ -44,32 +48,32 @@ public class ProofTree extends BorderPane {
@Override
public void proofPruned(ProofTreeEvent proofTreeEvent) {
treeProof.refresh();
Platform.runLater(() -> init());
}
@Override
public void proofStructureChanged(ProofTreeEvent proofTreeEvent) {
treeProof.refresh();
Platform.runLater(() -> init());
}
@Override
public void proofClosed(ProofTreeEvent proofTreeEvent) {
treeProof.refresh();
Platform.runLater(() -> init());
}
@Override
public void proofGoalRemoved(ProofTreeEvent proofTreeEvent) {
treeProof.refresh();
Platform.runLater(() -> init());
}
@Override
public void proofGoalsAdded(ProofTreeEvent proofTreeEvent) {
treeProof.refresh();
Platform.runLater(() -> init());
}
@Override
public void proofGoalsChanged(ProofTreeEvent proofTreeEvent) {
treeProof.refresh();
Platform.runLater(() -> init());
}
@Override
......@@ -91,59 +95,106 @@ public class ProofTree extends BorderPane {
if (old != null) {
old.removeProofTreeListener(proofTreeListener);
}
n.addProofTreeListener(proofTreeListener);
if (n != null)
n.addProofTreeListener(proofTreeListener);
});
init();
}
/**
* From https://www.programcreek.com/java-api-examples/index.php?api=javafx.scene.control.TreeItem
*
* @param candidate
*/
private static void expandRootToItem(TreeItem candidate) {
if (candidate != null) {
expandRootToItem(candidate.getParent());
if (!candidate.isLeaf()) {
candidate.setExpanded(true);
}
}
}
public static String toString(Node object) {
if (object.getAppliedRuleApp() != null) {
return object.getAppliedRuleApp().rule().name().toString();
} else {
return object.isClosed() ? "CLOSED GOAL" : "OPEN GOAL";
}
}
private void init() {
if (root.get() != null)
treeProof.setRoot(new TreeItemNode(root.get()));
if (root.get() != null) {
TreeItem<TreeNode> item = populate("Proof", root.get());
treeProof.setRoot(item);
}
treeProof.refresh();
}
private TreeCell<Node> cellFactory(TreeView<Node> nodeTreeView) {
TextFieldTreeCell<Node> tftc = new TextFieldTreeCell<>();
tftc.setConverter(new StringConverter<Node>() {
private TreeItem<TreeNode> populate(String label, Node n) {
val treeNode = new TreeNode(label, n);
TreeItem<TreeNode> ti = new TreeItem<>(treeNode);
if (n.childrenCount() == 0) {
ti.getChildren().add(new TreeItem<>(new TreeNode(
n.isClosed() ? "CLOSED GOAL" : "OPEN GOAL", null)));
return ti;
}
Node node = n.child(0);
if (n.childrenCount() == 1) {
ti.getChildren().add(new TreeItem<>(new TreeNode(toString(node), node)));
while (node.childrenCount() == 1) {
node = node.child(0);
ti.getChildren().add(new TreeItem<>(new TreeNode(toString(node), node)));
}
}
if (node.childrenCount() == 0) {
} else { // children count > 1
node.children().forEach(child ->
ti.getChildren().add(populate(child.getNodeInfo().getBranchLabel(), child)));
}
return ti;
}
private TreeCell<TreeNode> cellFactory(TreeView<TreeNode> nodeTreeView) {
TextFieldTreeCell<TreeNode> tftc = new TextFieldTreeCell<>();
StringConverter<TreeNode> stringConverter = new StringConverter<TreeNode>() {
@Override
public String toString(Node object) {
/* if (object.getAppliedRuleApp() != null) {
return object.getAppliedRuleApp().rule().displayName();
} else {
return object.name();
}*/
String nodeLabel;
if (object.getAppliedRuleApp() != null) {
nodeLabel = object.getAppliedRuleApp().rule().displayName();
} else {
nodeLabel = object.isClosed() ? "Closed Goal" : "Open Goal";
}
return nodeLabel;
// return object.sequent().toString();
public String toString(TreeNode object) {
return object.getLabel();
}
@Override
public Node fromString(String string) {
public TreeNode fromString(String string) {
return null;
}
});
tftc.itemProperty().addListener((p, o, n) -> repaint(tftc));
colorOfNodes.addListener((InvalidationListener) o -> repaint(tftc));
};
tftc.setConverter(stringConverter);
//tftc.itemProperty().addListener((p, o, n) -> repaint(tftc));
//colorOfNodes.addListener((InvalidationListener) o -> repaint(tftc));
return tftc;
}
private void repaint(TextFieldTreeCell<Node> tftc) {
Node n = tftc.getItem();
/*private void repaint(TextFieldTreeCell<TreeNode> tftc) {
Node n = tftc.getItem().node;
tftc.setStyle("");
if (n != null) {
if (n.isClosed()) {
tftc.setStyle("-fx-background-color: greenyellow");
colorOfNodes.putIfAbsent(n, "green");
//tftc.setStyle("-fx-background-color: greenyellow");
}
if (colorOfNodes.containsKey(n)) {
tftc.setStyle("-fx-background-color: " + colorOfNodes.get(n) + ";");
}
}
}
expandRootToItem(tftc.getTreeItem());
}*/
public Object getColorOfNodes() {
return colorOfNodes.get();
......@@ -180,23 +231,13 @@ public class ProofTree extends BorderPane {
public ObjectProperty<Proof> proofProperty() {
return proof;
}
}
class TreeItemNode extends TreeItem<Node> {
public TreeItemNode(Node value) {
super(value);
}
@Override
public boolean isLeaf() {
return getValue().leaf();
}
@AllArgsConstructor
@Data
private static class TreeNode {
String label;
@Override
public ObservableList<TreeItem<Node>> getChildren() {
if (super.getChildren().size() != getValue().children().size())
super.getChildren().setAll(
getValue().children().stream().map(TreeItemNode::new).collect(Collectors.toList()));
return super.getChildren();
Node node;
}
}
\ No newline at end of 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