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; ...@@ -4,13 +4,12 @@ import de.uka.ilkd.key.proof.Node;
import de.uka.ilkd.key.proof.Proof; import de.uka.ilkd.key.proof.Proof;
import de.uka.ilkd.key.proof.ProofTreeEvent; import de.uka.ilkd.key.proof.ProofTreeEvent;
import de.uka.ilkd.key.proof.ProofTreeListener; import de.uka.ilkd.key.proof.ProofTreeListener;
import javafx.beans.InvalidationListener; import javafx.application.Platform;
import javafx.beans.property.MapProperty; import javafx.beans.property.MapProperty;
import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleMapProperty; import javafx.beans.property.SimpleMapProperty;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.TreeCell; import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem; import javafx.scene.control.TreeItem;
...@@ -18,23 +17,28 @@ import javafx.scene.control.TreeView; ...@@ -18,23 +17,28 @@ import javafx.scene.control.TreeView;
import javafx.scene.control.cell.TextFieldTreeCell; import javafx.scene.control.cell.TextFieldTreeCell;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.util.StringConverter; import javafx.util.StringConverter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.val;
import java.util.stream.Collectors;
/** /**
* KeY Proof Tree * KeY Proof Tree
*/ */
public class ProofTree extends BorderPane { public class ProofTree extends BorderPane {
private ObjectProperty<Proof> proof = new SimpleObjectProperty<>(); private ObjectProperty<Proof> proof = new SimpleObjectProperty<>();
private ObjectProperty<Node> root = new SimpleObjectProperty<>(); private ObjectProperty<Node> root = new SimpleObjectProperty<>();
private MapProperty colorOfNodes = new SimpleMapProperty<>(FXCollections.observableHashMap()); private MapProperty colorOfNodes = new SimpleMapProperty<>(FXCollections.observableHashMap());
@FXML @FXML
private TreeView<Node> treeProof; private TreeView<TreeNode> treeProof;
private ProofTreeListener proofTreeListener = new ProofTreeListener() { private ProofTreeListener proofTreeListener = new ProofTreeListener() {
@Override @Override
public void proofExpanded(ProofTreeEvent proofTreeEvent) { public void proofExpanded(ProofTreeEvent proofTreeEvent) {
treeProof.refresh(); Platform.runLater(() -> init());
} }
@Override @Override
...@@ -44,32 +48,32 @@ public class ProofTree extends BorderPane { ...@@ -44,32 +48,32 @@ public class ProofTree extends BorderPane {
@Override @Override
public void proofPruned(ProofTreeEvent proofTreeEvent) { public void proofPruned(ProofTreeEvent proofTreeEvent) {
treeProof.refresh(); Platform.runLater(() -> init());
} }
@Override @Override
public void proofStructureChanged(ProofTreeEvent proofTreeEvent) { public void proofStructureChanged(ProofTreeEvent proofTreeEvent) {
treeProof.refresh(); Platform.runLater(() -> init());
} }
@Override @Override
public void proofClosed(ProofTreeEvent proofTreeEvent) { public void proofClosed(ProofTreeEvent proofTreeEvent) {
treeProof.refresh(); Platform.runLater(() -> init());
} }
@Override @Override
public void proofGoalRemoved(ProofTreeEvent proofTreeEvent) { public void proofGoalRemoved(ProofTreeEvent proofTreeEvent) {
treeProof.refresh(); Platform.runLater(() -> init());
} }
@Override @Override
public void proofGoalsAdded(ProofTreeEvent proofTreeEvent) { public void proofGoalsAdded(ProofTreeEvent proofTreeEvent) {
treeProof.refresh(); Platform.runLater(() -> init());
} }
@Override @Override
public void proofGoalsChanged(ProofTreeEvent proofTreeEvent) { public void proofGoalsChanged(ProofTreeEvent proofTreeEvent) {
treeProof.refresh(); Platform.runLater(() -> init());
} }
@Override @Override
...@@ -91,59 +95,106 @@ public class ProofTree extends BorderPane { ...@@ -91,59 +95,106 @@ public class ProofTree extends BorderPane {
if (old != null) { if (old != null) {
old.removeProofTreeListener(proofTreeListener); old.removeProofTreeListener(proofTreeListener);
} }
n.addProofTreeListener(proofTreeListener); if (n != null)
n.addProofTreeListener(proofTreeListener);
}); });
init(); 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() { private void init() {
if (root.get() != null) if (root.get() != null) {
treeProof.setRoot(new TreeItemNode(root.get())); TreeItem<TreeNode> item = populate("Proof", root.get());
treeProof.setRoot(item);
}
treeProof.refresh(); treeProof.refresh();
} }
private TreeCell<Node> cellFactory(TreeView<Node> nodeTreeView) { private TreeItem<TreeNode> populate(String label, Node n) {
TextFieldTreeCell<Node> tftc = new TextFieldTreeCell<>(); val treeNode = new TreeNode(label, n);
tftc.setConverter(new StringConverter<Node>() { 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 @Override
public String toString(Node object) { public String toString(TreeNode object) {
/* if (object.getAppliedRuleApp() != null) { return object.getLabel();
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();
} }
@Override @Override
public Node fromString(String string) { public TreeNode fromString(String string) {
return null; return null;
} }
}); };
tftc.itemProperty().addListener((p, o, n) -> repaint(tftc)); tftc.setConverter(stringConverter);
colorOfNodes.addListener((InvalidationListener) o -> repaint(tftc));
//tftc.itemProperty().addListener((p, o, n) -> repaint(tftc));
//colorOfNodes.addListener((InvalidationListener) o -> repaint(tftc));
return tftc; return tftc;
} }
private void repaint(TextFieldTreeCell<Node> tftc) { /*private void repaint(TextFieldTreeCell<TreeNode> tftc) {
Node n = tftc.getItem(); Node n = tftc.getItem().node;
tftc.setStyle(""); tftc.setStyle("");
if (n != null) { if (n != null) {
if (n.isClosed()) { if (n.isClosed()) {
tftc.setStyle("-fx-background-color: greenyellow"); colorOfNodes.putIfAbsent(n, "green");
//tftc.setStyle("-fx-background-color: greenyellow");
} }
if (colorOfNodes.containsKey(n)) { if (colorOfNodes.containsKey(n)) {
tftc.setStyle("-fx-background-color: " + colorOfNodes.get(n) + ";"); tftc.setStyle("-fx-background-color: " + colorOfNodes.get(n) + ";");
} }
} }
} expandRootToItem(tftc.getTreeItem());
}*/
public Object getColorOfNodes() { public Object getColorOfNodes() {
return colorOfNodes.get(); return colorOfNodes.get();
...@@ -180,23 +231,13 @@ public class ProofTree extends BorderPane { ...@@ -180,23 +231,13 @@ public class ProofTree extends BorderPane {
public ObjectProperty<Proof> proofProperty() { public ObjectProperty<Proof> proofProperty() {
return proof; return proof;
} }
}
class TreeItemNode extends TreeItem<Node> {
public TreeItemNode(Node value) {
super(value);
}
@Override @AllArgsConstructor
public boolean isLeaf() { @Data
return getValue().leaf(); private static class TreeNode {
} String label;
@Override Node node;
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();
} }
} }
\ 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