diff --git a/src/org/ntlab/deltaViewer/DeltaGraphAdapter.java b/src/org/ntlab/deltaViewer/DeltaGraphAdapter.java index f19a666..17c9faf 100644 --- a/src/org/ntlab/deltaViewer/DeltaGraphAdapter.java +++ b/src/org/ntlab/deltaViewer/DeltaGraphAdapter.java @@ -131,7 +131,7 @@ mxICell cell = addJGraphTVertex(value); cell.setId(id); - ((mxCell) parent).insert(cell); + ((mxCell) parent).insert(cell); cell.setParent((mxICell) parent); getCellGeometry(cell).setX(x); diff --git a/src/org/ntlab/deltaViewer/DeltaViewer.java b/src/org/ntlab/deltaViewer/DeltaViewer.java index a9f1c3d..53a3ed9 100644 --- a/src/org/ntlab/deltaViewer/DeltaViewer.java +++ b/src/org/ntlab/deltaViewer/DeltaViewer.java @@ -13,6 +13,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import javax.swing.JFrame; @@ -52,7 +53,7 @@ //BUG: finally field reference. O //BUG: edge drawing order. -> parent //BUG: methodExecution drawing order. -> parent -//BUG: ObjectVertex position when Resize ObjectVertex. +//BUG: ObjectVertex position when Resize ObjectVertex. O public class DeltaViewer { private static Dimension DEFAULT_SIZE = new Dimension(700, 700); private static String WINDOW_TITLE = "Delta Viewer"; @@ -129,7 +130,7 @@ /** Update graph on JFrame and set Cell style. */ public void update() { - setStyleOfCells(); + setCellsStyle(); mxgraphComponent.refresh(); try { Thread.sleep(1000); @@ -156,8 +157,9 @@ } /** Set style of All cells. */ - private void setStyleOfCells() { + private void setCellsStyle() { List vertexObject = new ArrayList<>(); + List staticVertexObject = new ArrayList<>(); List alignMiddleVertex = new ArrayList<>(); List alignTopVertex = new ArrayList<>(); List edgeObject = new ArrayList<>(); @@ -165,12 +167,18 @@ List edgeMethodExec = new ArrayList<>(); List roundEdge = new ArrayList<>(); - for (ObjectVertex vertex: objectToVertexMap.values()) { - vertexObject.add(vertex.getCell()); - if(vertex.getVertexMethodExecutions().size() == 0) { - alignMiddleVertex.add(vertex.getCell()); + for (Entry objectToVertexEntry: objectToVertexMap.entrySet()) { + String key = objectToVertexEntry.getKey(); + ObjectVertex objectVertex = objectToVertexEntry.getValue(); + if (key.matches("0")) { + staticVertexObject.add(objectVertex.getCell()); } else { - alignTopVertex.add(vertex.getCell()); + vertexObject.add(objectVertex.getCell()); + } + if(objectVertex.getVertexMethodExecutions().size() == 0) { + alignMiddleVertex.add(objectVertex.getCell()); + } else { + alignTopVertex.add(objectVertex.getCell()); } } @@ -338,7 +346,7 @@ update(); break; case THIS: - if (curFrame == 0) { + if (curFrame == 0 || alias.getObjectId().matches("0")) { createMethodExecutionVertex(alias); update(); } @@ -378,7 +386,7 @@ createObjectRefrence(fieldUpdateStatement, fieldName); removeCalledMethodExecutionVertex(objectToVertexMap.get(sourceObjectId), alias.getMethodExecution().getCallerMethodExecution(), alias.getMethodExecution()); - updateObjectVerticesSize(); + updateObjectVertices(); } } @@ -409,7 +417,7 @@ deltaAnimation.startVertexAnimation(); } removeCalledMethodExecutionVertex(sourceVertexObject, methodExec.getCallerMethodExecution(), methodExec); - updateObjectVerticesSize(); + updateObjectVertices(); // removeVertexMethodExecution(sourceVertexObject, methodExec); // update(); break; @@ -443,7 +451,7 @@ methodExecToVertexMap.get(methodExec).getLocals().remove(vo); } } - updateObjectVerticesSize(); + updateObjectVertices(); } } } finally { @@ -472,9 +480,9 @@ int srcSideSize = delta.getSrcSide().size(); for (int i = srcSideSize - 1; i >= 0; i--) { Reference ref = delta.getSrcSide().get(i); - // System.out.println("srcSide: " + ref.getSrcClassName() + ", " + ref.isCreation()); + System.out.println("srcSide: " + ref.getSrcClassName() + ", " + ref.isCreation()); if (!ref.isCreation() && !ref.getSrcObjectId().equals(ref.getDstObjectId())) { - if(!objectToVertexMap.containsKey(ref.getSrcObjectId())) { + if (!objectToVertexMap.containsKey(ref.getSrcObjectId())) { String srcClassName = ref.getSrcClassName(); if (srcClassName.contains("[L")) { srcClassName = formatArrayName(srcClassName); @@ -482,8 +490,8 @@ Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getSrcClassName(), srcClassName, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)), VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. objectToVertexMap.put(ref.getSrcObjectId(), new ObjectVertex(ref.getSrcClassName(), vertex, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)))); } - if(!objectToVertexMap.containsKey(ref.getDstObjectId())) { - // System.out.println(ref.getDstClassName() + ", " + ref.isCreation()); + if (!objectToVertexMap.containsKey(ref.getDstObjectId())) { + System.out.println(ref.getDstClassName() + ", " + ref.isCreation()); String dstClassName = ref.getDstClassName(); if (dstClassName.contains("[L")) { dstClassName = formatArrayName(dstClassName); @@ -491,23 +499,37 @@ Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getDstClassName(), dstClassName, xCor + (time * (srcSideSize - i)), yCor + (time * (srcSideSize - i)), VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. objectToVertexMap.put(ref.getDstObjectId(), new ObjectVertex(ref.getDstClassName(), vertex, xCor + (time * (srcSideSize - i)), yCor + (time * (srcSideSize - i)))); } + } else { + objectToVertexMap.put(ref.getSrcObjectId(), new ObjectVertex(ref.getSrcClassName(), null, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)))); } } // dstSide int dstSideSize = delta.getDstSide().size(); + int cnt = 0; for (int i = dstSideSize - 1; i >= 0; i--) { Reference ref = delta.getDstSide().get(i); - // System.out.println("dstSide: " + ref.getDstClassName() + ", " + ref.isCreation()); + System.out.println("dstSide: " + ref.getSrcClassName() + ", " + ref.getDstClassName() + ", " + ref.isCreation()); if (!ref.isCreation() && !ref.getSrcObjectId().equals(ref.getDstObjectId())) { - String dstClassName = ref.getDstClassName(); - if (dstClassName.contains("[L")) { - dstClassName = formatArrayName(dstClassName); + if (!objectToVertexMap.containsKey(ref.getSrcObjectId())) { + String srcClassName = ref.getSrcClassName(); + if (srcClassName.contains("[L")) { + srcClassName = formatArrayName(srcClassName); + } + Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getSrcClassName(), srcClassName, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)), VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + objectToVertexMap.put(ref.getSrcObjectId(), new ObjectVertex(ref.getSrcClassName(), vertex, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)))); + cnt++; } - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getDstClassName(), dstClassName, xCor - (time * (dstSideSize - i)), yCor + (time * (dstSideSize - i)), VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(ref.getDstObjectId(), new ObjectVertex(ref.getDstClassName(), vertex, xCor - (time * (dstSideSize - i)), yCor + (time * (dstSideSize - i)))); + if (!objectToVertexMap.containsKey(ref.getDstObjectId())) { + String dstClassName = ref.getDstClassName(); + if (dstClassName.contains("[L")) { + dstClassName = formatArrayName(dstClassName); + } + Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getDstClassName(), dstClassName, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)), VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + objectToVertexMap.put(ref.getDstObjectId(), new ObjectVertex(ref.getDstClassName(), vertex, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)))); + } } else { - objectToVertexMap.put(ref.getDstObjectId(), new ObjectVertex(ref.getDstClassName(), null, xCor - (time * (dstSideSize - i)), yCor + (time * (dstSideSize - i)))); + objectToVertexMap.put(ref.getDstObjectId(), new ObjectVertex(ref.getDstClassName(), null, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)))); } } } finally { @@ -542,7 +564,7 @@ ((mxCell)edge).setStyle("exitX=0;exitY=1;exitPerimeter=1;entryX=1;entryY=0;entryPerimeter=1;"); } edgeMap.put(alias.getMethodExecution().getThisClassName() + "." + fieldName, new Edge(fieldName, TypeName.Create, edge)); - setStyleOfCells(); + setCellsStyle(); deltaAnimation.setVertexAnimation((mxICell)vertex, new mxPoint(vertexObj.getInitialX(), vertexObj.getInitialY())); deltaAnimation.startVertexAnimation(); } finally { @@ -582,7 +604,7 @@ MethodExecutionVertex targetMethodExecVertex = methodExecToVertexMap.get(alias.getMethodExecution()); moveObjectVertex(alias, sourceObjectVertex, targetMethodExecVertex); - updateObjectVerticesSize(); + updateObjectVertices(); } /** @@ -839,33 +861,42 @@ // } // } // } - - /** Update ObjectVertices size. */ - private void updateObjectVerticesSize() { + + /** Update ObjectVertices size and position. */ + private void updateObjectVertices() { // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology mxgraph.getModel().beginUpdate(); try { - for (ObjectVertex vertexObject: objectToVertexMap.values()) { - mxCell vertexObjectCell = ((mxCell) vertexObject.getCell()); - int time = vertexObjectCell.getChildCount(); + for (ObjectVertex objectVertex: objectToVertexMap.values()) { + mxCell objectVertexCell = ((mxCell) objectVertex.getCell()); + int time = objectVertexCell.getChildCount(); if (time == 0) { time = 1; } - // System.out.println("updateVertexObjectSize: " + vertexObjectCell.getGeometry().getWidth() + "->" + VERTEX_OBJECT_SIZE.getWidth() * time+ ", " + vertexObjectCell.getId()); - if(vertexObjectCell.getGeometry().getWidth() != VERTEX_OBJECT_SIZE.getWidth() * time) { - System.out.println("updateVertexObjectSize: " + vertexObjectCell.getGeometry().getWidth() + "->" + VERTEX_OBJECT_SIZE.getWidth() * time+ ", " + vertexObjectCell.getId()); + if(objectVertexCell.getGeometry().getWidth() != VERTEX_OBJECT_SIZE.getWidth() * time) { + System.out.println("updateVertexObjectSize: " + objectVertexCell.getGeometry().getWidth() + "->" + VERTEX_OBJECT_SIZE.getWidth() * time+ ", " + objectVertexCell.getId()); Dimension targetDimension = new Dimension(); targetDimension.setSize(VERTEX_OBJECT_SIZE.getWidth() * time, VERTEX_OBJECT_SIZE.getHeight() * time); - // if (vertexObjectCell.getParent() != mxDefaultParent && vertexObjectCell.getChildCount() != 0) { - // mxPoint targetPoint = new mxPoint(vertexObjectCell.getGeometry().getX() - (targetDimension.getWidth() - vertexObjectCell.getGeometry().getWidth()) / 2, vertexObjectCell.getGeometry().getY() + (targetDimension.getHeight() - vertexObjectCell.getGeometry().getHeight()) / 2); - // deltaAnimation.setVertexAnimation(vertexObjectCell, targetPoint); - // deltaAnimation.startVertexAnimation(); - // } - deltaAnimation.setResizeVertexAnimation(vertexObjectCell, targetDimension); + if (objectVertexCell.getParent() != mxDefaultParent && (objectVertexCell.getChildCount() != 0 || objectVertexCell.getGeometry().getWidth() > VERTEX_OBJECT_SIZE.getWidth() * time)) { + double overlapX = (targetDimension.getWidth() - objectVertexCell.getGeometry().getWidth()) / 2 / Math.sqrt(2); + double overlapY = (targetDimension.getHeight() - objectVertexCell.getGeometry().getHeight()) / 2 / Math.sqrt(2); + System.out.println("updateVertexObjectPosition: " + objectVertexCell.getGeometry().getX() + " - " + overlapX); + mxPoint targetPoint = new mxPoint(objectVertexCell.getGeometry().getX() - overlapX, objectVertexCell.getGeometry().getY() + overlapY); + for (MethodExecutionVertex methodExecVertex: methodExecToVertexMap.values()) { + List arguments = methodExecVertex.getArguments(); + if (arguments != null && arguments.contains(objectVertex)) { + targetPoint.setY(objectVertexCell.getGeometry().getY() - overlapY); + break; + } + } + deltaAnimation.setVertexAnimation(objectVertexCell, targetPoint); + deltaAnimation.startVertexAnimation(); + } + deltaAnimation.setResizeVertexAnimation(objectVertexCell, targetDimension); deltaAnimation.startResizeVertexAnimation(); } } - }finally { + } finally { mxgraph.getModel().endUpdate(); } } @@ -901,7 +932,11 @@ * @param alias */ private void createMethodExecutionVertex(Alias alias) { - createMethodExecutionVertex(alias, alias.getMethodSignature(), alias.getMethodExecution()); + if (curFrame == 0) { + createMethodExecutionVertex(alias, alias.getMethodSignature(), alias.getMethodExecution()); + } else if (alias.getObjectId().matches("0")) { + createMethodExecutionVertex(alias, alias.getMethodExecution().getSignature(), alias.getMethodExecution()); + } } /** @@ -943,7 +978,7 @@ } finally { mxgraph.getModel().endUpdate(); } - setStyleOfCells(); + setCellsStyle(); } /** @@ -980,7 +1015,7 @@ objectToVertexMap.get(methodExec.getThisObjId()).getVertexMethodExecutions().remove(methodExecToVertexMap.get(methodExec)); methodExecToVertexMap.remove(methodExec); edgeMap.remove(methodExec.getSignature()); - updateObjectVerticesSize(); + updateObjectVertices(); } } diff --git a/src/org/ntlab/deltaViewer/DeltaViewerSample.java b/src/org/ntlab/deltaViewer/DeltaViewerSample.java index ad803b4..4fcf9a1 100644 --- a/src/org/ntlab/deltaViewer/DeltaViewerSample.java +++ b/src/org/ntlab/deltaViewer/DeltaViewerSample.java @@ -46,8 +46,8 @@ // TraceJSON trace = new TraceJSON("traces/_worstCase.txt"); // TraceJSON trace = new TraceJSON("traces/sample1.trace"); // TraceJSON trace = new TraceJSON("traces/sampleArray.trace"); -// TraceJSON trace = new TraceJSON("traces/sampleCollection.trace"); - TraceJSON trace = new TraceJSON("traces/sampleCreate.trace"); + TraceJSON trace = new TraceJSON("traces/sampleCollection.trace"); +// TraceJSON trace = new TraceJSON("traces/sampleCreate.trace"); // TraceJSON trace = new TraceJSON("traces/sampleStatic.trace"); // Error display MagnetRON. @@ -64,8 +64,8 @@ // ExtractedStructure e = s.extract(new Reference(null, null, "worstCase.P", "worstCase.M"), tp, dac); // ExtractedStructure e = s.extract(new Reference(null, null, "sample1.D", "sample1.C"), tp, dac); // ExtractedStructure e = s.extract(new Reference(null, null, "sampleArray.D", "sampleArray.C"), tp, dac); -// ExtractedStructure e = s.extract(new Reference(null, null, "sampleCollection.D", "sampleCollection.C"), tp, dac); - ExtractedStructure e = s.extract(new Reference(null, null, "sampleCreate.D", "sampleCreate.C"), tp, dac); + ExtractedStructure e = s.extract(new Reference(null, null, "sampleCollection.D", "sampleCollection.C"), tp, dac); +// ExtractedStructure e = s.extract(new Reference(null, null, "sampleCreate.D", "sampleCreate.C"), tp, dac); // ExtractedStructure e = s.extract(new Reference(null, null, "sampleStatic.D", "sampleStatic.C"), tp, dac); // HashSet marked = trace.getMarkedMethodSignatures(1255991806833871L, 1255991808597322L);