| |
---|
| | import java.util.HashSet; |
---|
| | import java.util.LinkedHashMap; |
---|
| | import java.util.List; |
---|
| | import java.util.Map; |
---|
| | import java.util.Map.Entry; |
---|
| | |
---|
| | import javax.swing.JFrame; |
---|
| | |
---|
| | import org.jgrapht.graph.DefaultEdge; |
---|
| |
---|
| | //BUG: Resize ObjectVertex sometimes. O |
---|
| | //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"; |
---|
| | |
---|
| |
---|
| | } |
---|
| | |
---|
| | /** Update graph on JFrame and set Cell style. */ |
---|
| | public void update() { |
---|
| | setStyleOfCells(); |
---|
| | setCellsStyle(); |
---|
| | mxgraphComponent.refresh(); |
---|
| | try { |
---|
| | Thread.sleep(1000); |
---|
| | } catch (InterruptedException e) { |
---|
| |
---|
| | coordinatorPoint.setY(y); |
---|
| | } |
---|
| | |
---|
| | /** Set style of All cells. */ |
---|
| | private void setStyleOfCells() { |
---|
| | private void setCellsStyle() { |
---|
| | List<Object> vertexObject = new ArrayList<>(); |
---|
| | List<Object> staticVertexObject = new ArrayList<>(); |
---|
| | List<Object> alignMiddleVertex = new ArrayList<>(); |
---|
| | List<Object> alignTopVertex = new ArrayList<>(); |
---|
| | List<Object> edgeObject = new ArrayList<>(); |
---|
| | List<Object> edgeObjectCreate = new ArrayList<>(); |
---|
| | List<Object> edgeMethodExec = new ArrayList<>(); |
---|
| | List<Object> roundEdge = new ArrayList<>(); |
---|
| | |
---|
| | for (ObjectVertex vertex: objectToVertexMap.values()) { |
---|
| | vertexObject.add(vertex.getCell()); |
---|
| | if(vertex.getVertexMethodExecutions().size() == 0) { |
---|
| | alignMiddleVertex.add(vertex.getCell()); |
---|
| | for (Entry<String, ObjectVertex> 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()); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | List<MethodExecutionVertex> vertexMethodExecList = new ArrayList<>(methodExecToVertexMap.values()); |
---|
| |
---|
| | moveObjectVertex(alias); |
---|
| | update(); |
---|
| | break; |
---|
| | case THIS: |
---|
| | if (curFrame == 0) { |
---|
| | if (curFrame == 0 || alias.getObjectId().matches("0")) { |
---|
| | createMethodExecutionVertex(alias); |
---|
| | update(); |
---|
| | } |
---|
| | break; |
---|
| |
---|
| | String sourceObjectId = fieldUpdateStatement.getContainerObjId(); |
---|
| | |
---|
| | createObjectRefrence(fieldUpdateStatement, fieldName); |
---|
| | removeCalledMethodExecutionVertex(objectToVertexMap.get(sourceObjectId), alias.getMethodExecution().getCallerMethodExecution(), alias.getMethodExecution()); |
---|
| | updateObjectVerticesSize(); |
---|
| | updateObjectVertices(); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. |
---|
| |
---|
| | deltaAnimation.setVertexAnimation(calledCell, new mxPoint(objectToVertexMap.get(calledObjectId).getInitialX(), objectToVertexMap.get(calledObjectId).getInitialY())); |
---|
| | deltaAnimation.startVertexAnimation(); |
---|
| | } |
---|
| | removeCalledMethodExecutionVertex(sourceVertexObject, methodExec.getCallerMethodExecution(), methodExec); |
---|
| | updateObjectVerticesSize(); |
---|
| | updateObjectVertices(); |
---|
| | // removeVertexMethodExecution(sourceVertexObject, methodExec); |
---|
| | // update(); |
---|
| | break; |
---|
| | } |
---|
| |
---|
| | deltaAnimation.startVertexAnimation(); |
---|
| | methodExecToVertexMap.get(methodExec).getLocals().remove(vo); |
---|
| | } |
---|
| | } |
---|
| | updateObjectVerticesSize(); |
---|
| | updateObjectVertices(); |
---|
| | } |
---|
| | } |
---|
| | } finally { |
---|
| | mxgraph.getModel().endUpdate(); |
---|
| |
---|
| | Delta delta = eStructure.getDelta(); |
---|
| | 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); |
---|
| | } |
---|
| | 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); |
---|
| | } |
---|
| | 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 { |
---|
| | mxgraph.getModel().endUpdate(); |
---|
| |
---|
| | } else { |
---|
| | ((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 { |
---|
| | mxgraph.getModel().endUpdate(); |
---|
| |
---|
| | // targetVertex |
---|
| | MethodExecutionVertex targetMethodExecVertex = methodExecToVertexMap.get(alias.getMethodExecution()); |
---|
| | |
---|
| | moveObjectVertex(alias, sourceObjectVertex, targetMethodExecVertex); |
---|
| | updateObjectVerticesSize(); |
---|
| | updateObjectVertices(); |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * Parent : Source VertexObject move target VertexMethodExecution. |
---|
| |
---|
| | // } |
---|
| | // } |
---|
| | // } |
---|
| | // } |
---|
| | |
---|
| | /** 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<ObjectVertex> 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(); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| |
---|
| | * |
---|
| | * @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()); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * Parent : Create MethodExecutionVertex. |
---|
| |
---|
| | objectToVertexMap.get(objectId).addMethodExecution(vertexMethodExecution); |
---|
| | } finally { |
---|
| | mxgraph.getModel().endUpdate(); |
---|
| | } |
---|
| | setStyleOfCells(); |
---|
| | setCellsStyle(); |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * Remove VertexMethodExecution on AliasType is MethodInvocation of alias. |
---|
| |
---|
| | mxgraph.removeCells(new Object[] {targetVertexCell}); |
---|
| | objectToVertexMap.get(methodExec.getThisObjId()).getVertexMethodExecutions().remove(methodExecToVertexMap.get(methodExec)); |
---|
| | methodExecToVertexMap.remove(methodExec); |
---|
| | edgeMap.remove(methodExec.getSignature()); |
---|
| | updateObjectVerticesSize(); |
---|
| | updateObjectVertices(); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| |
---|
| | |