package org.simantics.debug.graphical;
-import gnu.trove.list.array.TDoubleArrayList;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import org.simantics.debug.graphical.model.Node;
import org.simantics.debug.graphical.model.NodeData;
import org.simantics.layer0.Layer0;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function;
import org.simantics.ui.dnd.LocalObjectTransfer;
import org.simantics.ui.dnd.LocalObjectTransferable;
import org.simantics.ui.selection.AnyResource;
import org.simantics.ui.selection.WorkbenchSelectionElement;
+import gnu.trove.list.array.TDoubleArrayList;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TObjectIntHashMap;
+
public class DebuggerCanvas extends JPanel {
private static final long serialVersionUID = -718678297301786379L;
double canvasZoom = 1.0;
boolean extensionMode = false;
Random random = new Random();
-
+ public Function statementFilter;
+
LabelingPreferences labelingPreferences =
new LabelingPreferences();
+ public void setStatementFilter(Function statementFilter) {
+ this.statementFilter = statementFilter;
+ }
+
+ public void removeStatementFilter() {
+ this.statementFilter = null;
+ }
+
@Override
public void paint(Graphics _g) {
Graphics2D g = (Graphics2D)_g;
nodes.add(a);
return a;
}
+
+ public void addResource(Resource resource) {
+ double x, y;
+ if(nodes.isEmpty()) {
+ x = 0.0;
+ y = 0.0;
+ }
+ else {
+ double xMin=Double.POSITIVE_INFINITY, yMin=Double.POSITIVE_INFINITY;
+ double xMax=Double.NEGATIVE_INFINITY, yMax=Double.NEGATIVE_INFINITY;
+ for(Node node : nodes) {
+ xMin = Math.min(node.getMinX(), xMin);
+ yMin = Math.min(node.getMinY(), yMin);
+ xMax = Math.max(node.getMaxX(), xMax);
+ yMax = Math.max(node.getMaxY(), yMax);
+ }
+ x = xMin + (xMax - xMin) * random.nextDouble();
+ y = yMin + (yMax - yMin) * random.nextDouble();
+ }
+
+ addResource(x, y, resource);
+ repaint();
+ }
private void scheduleUpdate() {
Simantics.getSession().asyncRequest(new ReadRequest() {
Simantics.getSession().syncRequest(new ReadRequest() {
@Override
public void run(ReadGraph graph) throws DatabaseException {
- THashMap<Resource, Node> oldExtensionNodeMap = DebuggerCanvas.this.extensionNodeMap;
- THashMap<Resource, Node> extensionNodeMap = new THashMap<Resource, Node>();
- for(Node node : nodes) {
- for(Statement stat : node.getData().getStatements()) {
- Resource object = stat.getObject();
- Node node2 = extensionNodeMap.get(object);
- if(node2 == null) {
- node2 = oldExtensionNodeMap.get(object);
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.put("graph", graph);
+ try {
+ THashMap<Resource, Node> oldExtensionNodeMap = DebuggerCanvas.this.extensionNodeMap;
+ THashMap<Resource, Node> extensionNodeMap = new THashMap<Resource, Node>();
+ for(Node node : nodes) {
+ for(Statement stat : node.getData().getStatements()) {
+ Resource object = stat.getObject();
+ Node node2 = extensionNodeMap.get(object);
if(node2 == null) {
- node2 = new Node(new NodeData(object));
- double angle = random.nextDouble() * Math.PI * 2.0;
- double dx = Math.cos(angle);
- double dy = Math.sin(angle);
- double len = 150.0;
- node2.setPos(node.getX() + dx*len, node.getY() + dy*len);
+ if(statementFilter != null && Boolean.FALSE.equals(statementFilter.apply(stat)))
+ continue;
+ node2 = oldExtensionNodeMap.get(object);
+ if(node2 == null) {
+ node2 = new Node(new NodeData(object));
+ double angle = random.nextDouble() * Math.PI * 2.0;
+ double dx = Math.cos(angle);
+ double dy = Math.sin(angle);
+ double len = 150.0;
+ node2.setPos(node.getX() + dx*len, node.getY() + dy*len);
+ }
+ node2.getData().updateData(graph, labelingPreferences);
+ node2.setContent(new LabelContent(node2.getData().getLabels()));
+ extensionNodeMap.put(object, node2);
+ extensionNodes.add(node2);
}
- node2.getData().updateData(graph, labelingPreferences);
- node2.setContent(new LabelContent(node2.getData().getLabels()));
- extensionNodeMap.put(object, node2);
- extensionNodes.add(node2);
+ extensionEdges.add(createEdge(graph, stat, node, node2));
}
- extensionEdges.add(createEdge(graph, stat, node, node2));
}
+ } catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
+ throw new DatabaseException(t);
+ } finally {
+ sclContext.put("graph", oldGraph);
}
DebuggerCanvas.this.extensionNodeMap = extensionNodeMap;
layoutExtension();