diff --git a/src/org/ntlab/deltaViewer/DeltaAnimation.java b/src/org/ntlab/deltaViewer/DeltaAnimation.java index c2494ce..b4c4fc9 100644 --- a/src/org/ntlab/deltaViewer/DeltaAnimation.java +++ b/src/org/ntlab/deltaViewer/DeltaAnimation.java @@ -29,13 +29,13 @@ private DeltaGraphAdapter mxgraph; private mxGraphComponent mxgraphComponent; - + private Graphics2D graphics2D; private Timer timer; private static int FINAL_STEP_COUNT = 10; private mxICell sourceCell; - + GeneralPath p = new GeneralPath(); // X, Y @@ -43,14 +43,14 @@ private mxPoint targetPoint; private mxPoint curPoint; private mxPoint updatePoint = new mxPoint(); - + // Width, Height private Dimension targetDimension; private Dimension curDimension = new Dimension(); private Dimension updateDimension = new Dimension(); private double scale = 1; - + /** * @param mxgraph * @param mxgraphComponent @@ -82,26 +82,19 @@ // System.out.println("targetPoint : " + targetPoint); calculateResizeLineModel(); } - + /** * Set stretch(expand) animation of edge from sourcePoint to targetPoint. * - * @param sourcePoint Edge sourcePoint. + * @param cloneTargetVertexCell Edge sourcePoint. * @param targetPoint Edge targetPoint. */ - public void setExpandEdgeAnimation(mxPoint sourcePoint, mxPoint targetPoint) { - this.sourcePoint = new mxPoint(sourcePoint.getX() * scale + 1, sourcePoint.getY() * scale + 1); - this.targetPoint = new mxPoint(targetPoint.getX() * scale, targetPoint.getY() * scale); - curPoint = this.sourcePoint; -// System.out.println("sourcePoint : " + sourcePoint); -// System.out.println("targetPoint : " + targetPoint); - - graphics2D = (Graphics2D)mxgraphComponent.getGraphics(); - graphics2D.setColor(Color.decode("#008000")); - - float width = (float) (1 * scale); - Stroke dashed = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[]{(float) (3.0f * scale * width), (float) (3.0f * scale * width)}, 0.0f); - graphics2D.setStroke(dashed); + public void setExpandEdgeAnimation(mxICell sourceCell, mxPoint targetPoint) { + this.sourceCell = sourceCell; + this.targetPoint = targetPoint; + curPoint = new mxPoint(sourceCell.getGeometry().getX(), sourceCell.getGeometry().getY()); + System.out.println("sourcePoint : " + sourceCell.getGeometry().getPoint()); + System.out.println("targetPoint : " + targetPoint); calculateResizeLineModel(); } @@ -139,11 +132,12 @@ public void calculateResizeLineModel() { mxPoint distancePoint = new mxPoint(); distancePoint.setX(targetPoint.getX() - curPoint.getX()); - distancePoint.setY(targetPoint.getY() - curPoint.getY()); + distancePoint.setY(targetPoint.getY() - curPoint.getY()); updatePoint.setX(distancePoint.getX() / FINAL_STEP_COUNT); updatePoint.setY(distancePoint.getY() / FINAL_STEP_COUNT); + System.out.println(updatePoint); } - + /** * Calculate updateDimension every second from curPoint and targetPoint. */ @@ -160,7 +154,7 @@ timer = new Timer(); timer.schedule(new TimerTask() { int stepCount = 0; - + @Override public void run() { if(stepCount < FINAL_STEP_COUNT) { @@ -178,20 +172,21 @@ e.printStackTrace(); } } - + /** * Start stretch(expand) animation of edge from sourcePoint to targetPoint for 10 sec. - */ + */ public void startExpandEdgeAnimation() { timer = new Timer(); timer.schedule(new TimerTask() { int stepCount = 0; - + @Override public void run() { if(stepCount < FINAL_STEP_COUNT) { updateExpandEdgeAnimation(); - stepCount++; + System.out.println(stepCount + ": " + curPoint.getX()); + stepCount++; if(stepCount >= FINAL_STEP_COUNT){ timer.cancel(); } @@ -229,22 +224,22 @@ // } catch (InterruptedException e) { // e.printStackTrace(); // } - ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); - scheduledThreadPoolExecutor.scheduleWithFixedDelay(new TimerTask() { - int stepCount = 0; - - @Override - public void run() { - if(stepCount < FINAL_STEP_COUNT) { + ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); + scheduledThreadPoolExecutor.scheduleWithFixedDelay(new TimerTask() { + int stepCount = 0; + + @Override + public void run() { + if(stepCount < FINAL_STEP_COUNT) { updateReductionEdgeAnimation(); - System.out.println(stepCount + ": " + curPoint.getX()); - stepCount++; - if(stepCount >= FINAL_STEP_COUNT){ - timer.cancel(); - } - } - } - }, 0, 100, TimeUnit.MILLISECONDS); + System.out.println(stepCount + ": " + curPoint.getX()); + stepCount++; + if(stepCount >= FINAL_STEP_COUNT){ + timer.cancel(); + } + } + } + }, 0, 100, TimeUnit.MILLISECONDS); try { System.out.println("Thread.sleep()"); Thread.sleep(1001); @@ -253,7 +248,7 @@ e.printStackTrace(); } } - + /** * Start animation resize vertex for 10 sec. */ @@ -278,23 +273,23 @@ // } catch (InterruptedException e) { // e.printStackTrace(); // } - - ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); - scheduledThreadPoolExecutor.scheduleWithFixedDelay(new TimerTask() { - int stepCount = 0; - - @Override - public void run() { - if(stepCount < FINAL_STEP_COUNT) { - updateResizeVertexAnimation(); - System.out.println(stepCount + ": " + curDimension.width); - stepCount++; - if(stepCount >= FINAL_STEP_COUNT){ - timer.cancel(); - } - } - } - }, 0, 100, TimeUnit.MILLISECONDS); + + ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); + scheduledThreadPoolExecutor.scheduleWithFixedDelay(new TimerTask() { + int stepCount = 0; + + @Override + public void run() { + if(stepCount < FINAL_STEP_COUNT) { + updateResizeVertexAnimation(); + System.out.println(stepCount + ": " + curDimension.width); + stepCount++; + if(stepCount >= FINAL_STEP_COUNT){ + timer.cancel(); + } + } + } + }, 0, 100, TimeUnit.MILLISECONDS); try { System.out.println("Thread.sleep()"); Thread.sleep(1001); @@ -317,52 +312,46 @@ sourceCell.getGeometry().setY(curPoint.getY() + updatePoint.getY()); // System.out.println(sourceCell.getGeometry().getPoint()); } finally { - mxgraph.getModel().endUpdate(); + mxgraph.getModel().endUpdate(); } - mxgraphComponent.refresh(); + mxgraphComponent.refresh(); } /** * Update stretch(expand) animation of edge length updatePoint every second. */ private void updateExpandEdgeAnimation() { - Runnable r = new Runnable() { - public void run() { - p.reset(); - p.moveTo((float)curPoint.getX(), (float)curPoint.getY()); - curPoint.setX(curPoint.getX() + updatePoint.getX()); - curPoint.setY(curPoint.getY() + updatePoint.getY()); -// System.out.println("curPoint : " + curPoint); - p.lineTo((float)curPoint.getX(), (float)curPoint.getY()); - graphics2D.draw(p); - } - }; - - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - if (!SwingUtilities.isEventDispatchThread()) { - SwingUtilities.invokeLater(r); - } else { - r.run(); - } + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. + mxgraph.getModel().beginUpdate(); + try { + curPoint.setX(sourceCell.getGeometry().getX()); + curPoint.setY(sourceCell.getGeometry().getY()); + sourceCell.getGeometry().setX(curPoint.getX() + updatePoint.getX()); + sourceCell.getGeometry().setY(curPoint.getY() + updatePoint.getY()); +// System.out.println(sourceCell.getGeometry().getPoint()); + } finally { + mxgraph.getModel().endUpdate(); + } + mxgraphComponent.refresh(); } - + /** * Update move animation sourcell vertex clone to targetPoint, reduce edge length updatePoint every second. */ private void updateReductionEdgeAnimation() { - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - mxgraph.getModel().beginUpdate(); - try { - curPoint.setX(sourceCell.getGeometry().getX()); - curPoint.setY(sourceCell.getGeometry().getY()); - sourceCell.getGeometry().setX(curPoint.getX() + updatePoint.getX()); - sourceCell.getGeometry().setY(curPoint.getY() + updatePoint.getY()); - // System.out.println(sourceCell.getGeometry().getPoint()); - } finally { - mxgraph.getModel().endUpdate(); - } - mxgraphComponent.refresh(); + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. + mxgraph.getModel().beginUpdate(); + try { + curPoint.setX(sourceCell.getGeometry().getX()); + curPoint.setY(sourceCell.getGeometry().getY()); + sourceCell.getGeometry().setX(curPoint.getX() + updatePoint.getX()); + sourceCell.getGeometry().setY(curPoint.getY() + updatePoint.getY()); +// System.out.println(sourceCell.getGeometry().getPoint()); + } finally { + mxgraph.getModel().endUpdate(); } + mxgraphComponent.refresh(); + } /** * Update animation resize vertex every second. @@ -372,33 +361,33 @@ mxgraph.getModel().beginUpdate(); try { double preCenterX = sourceCell.getGeometry().getCenterX(); - double preCenterY = sourceCell.getGeometry().getCenterY(); + double preCenterY = sourceCell.getGeometry().getCenterY(); curDimension.setSize(sourceCell.getGeometry().getWidth(), sourceCell.getGeometry().getHeight()); sourceCell.getGeometry().setWidth(curDimension.getWidth() + updateDimension.getWidth()); sourceCell.getGeometry().setHeight(curDimension.getHeight() + updateDimension.getHeight()); - double curCenterX = sourceCell.getGeometry().getCenterX(); - double curCenterY = sourceCell.getGeometry().getCenterY(); - double distanceX = (curCenterX - preCenterX); - double distanceY = (curCenterY - preCenterY); - double curX = sourceCell.getGeometry().getX(); - double curY = sourceCell.getGeometry().getY(); - - sourceCell.getGeometry().setX(curX - distanceX); - sourceCell.getGeometry().setY(curY - distanceY); + double curCenterX = sourceCell.getGeometry().getCenterX(); + double curCenterY = sourceCell.getGeometry().getCenterY(); + double distanceX = (curCenterX - preCenterX); + double distanceY = (curCenterY - preCenterY); + double curX = sourceCell.getGeometry().getX(); + double curY = sourceCell.getGeometry().getY(); - for (int i = 0; i < sourceCell.getChildCount(); i++) { - mxICell childCell = sourceCell.getChildAt(i); + sourceCell.getGeometry().setX(curX - distanceX); + sourceCell.getGeometry().setY(curY - distanceY); + + for (int i = 0; i < sourceCell.getChildCount(); i++) { + mxICell childCell = sourceCell.getChildAt(i); // System.out.println("child" + childCell); - curX = childCell.getGeometry().getX(); - curY = childCell.getGeometry().getY(); - childCell.getGeometry().setX(curX + distanceX); - childCell.getGeometry().setY(curY + distanceY); - } + curX = childCell.getGeometry().getX(); + curY = childCell.getGeometry().getY(); + childCell.getGeometry().setX(curX + distanceX); + childCell.getGeometry().setY(curY + distanceY); + } } finally { - mxgraph.getModel().endUpdate(); + mxgraph.getModel().endUpdate(); } - mxgraphComponent.refresh(); + mxgraphComponent.refresh(); } } diff --git a/src/org/ntlab/deltaViewer/DeltaViewer.java b/src/org/ntlab/deltaViewer/DeltaViewer.java index c2decd4..edcf69a 100644 --- a/src/org/ntlab/deltaViewer/DeltaViewer.java +++ b/src/org/ntlab/deltaViewer/DeltaViewer.java @@ -26,6 +26,7 @@ import org.ntlab.deltaViewer.Edge.TypeName; import org.ntlab.deltaExtractor.Alias.AliasType; import org.ntlab.trace.ArrayAccess; +import org.ntlab.trace.ArrayUpdate; import org.ntlab.trace.FieldAccess; import org.ntlab.trace.FieldUpdate; import org.ntlab.trace.MethodExecution; @@ -114,8 +115,16 @@ // Fit graph size in visible JFrame. mxGraphView view = mxgraphComponent.getGraph().getView(); - int componentWidth = mxgraphComponent.getWidth(); + int componentWidth = mxgraphComponent.getWidth() - 25; double viewWidth = (double) view.getGraphBounds().getWidth(); + +// Object component = mxgraph.insertDeltaVertex(mxDefaultParent, "component", "component", "fillColor=white"); //creates a white vertex. +// ((mxICell)component).getGeometry().setX(mxgraphComponent.getWidth() - 30); +// ((mxICell)component).getGeometry().setY(10); +// Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, "view", "view", "fillColor=white"); //creates a white vertex. +// ((mxICell)vertex).getGeometry().setX(view.getGraphBounds().getWidth()); +// ((mxICell)vertex).getGeometry().setY(10); + System.out.print("Scale " + componentWidth + ", " + viewWidth + ", " + coordinatorPoint.getX()); if (viewWidth < coordinatorPoint.getX()) { viewWidth += coordinatorPoint.getX(); @@ -274,7 +283,7 @@ private Point getAbsolutePointforCell(mxICell cell) { Point p1 = cell.getGeometry().getPoint(); - if(cell.getParent().getValue() == null || cell.equals(cell.getParent())) { + if(cell.getParent().getValue() == null || cell == cell.getParent()) { return p1; } System.out.println(cell.getId() + ", " + cell.getParent().getId()); @@ -321,7 +330,8 @@ for (int i = fromFrame; i <= toFrame; i++) { List aliasList = new ArrayList<>(deltaAliasCollector.getAliasList()); Alias alias = aliasList.get(i); - System.out.println("\r\n" + i + ": " + alias.getObjectId() + ", " + alias.getMethodSignature() + " l." + alias.getLineNo() + " : " + alias.getAliasType().toString()); + System.out.println("\r\n" + i + ": " + alias.getAliasType().toString()); + System.out.println(alias.getObjectId() + ", " + alias.getMethodSignature() + " l." + alias.getLineNo()); switch(alias.getAliasType()) { case RETURN_VALUE: moveObjectVertex(alias); @@ -390,13 +400,51 @@ removeCalledMethodExecutionVertex(objectToVertexMap.get(sourceObjectId), alias.getMethodExecution().getCallerMethodExecution(), alias.getMethodExecution()); updateObjectVertices(); } + + if(statement instanceof MethodInvocation) { + MethodInvocation methodInvocationStatement = (MethodInvocation) statement; + + MethodExecution methodExec = methodInvocationStatement.getCalledMethodExecution(); + //Array��List�̂Ƃ��������x����t����i�m���ɕ������Ă�����̂Ƃ�)getSignature->contains("List.get(") || "Map.get(") <�z���C�g���X�g> + if (methodExec.getSignature().contains("List.add(") || + methodExec.getSignature().contains("Map.put(")) { + String sourceObjectId = methodExec.getThisObjId(); + + createObjectRefrence(methodExec); + removeCalledMethodExecutionVertex(objectToVertexMap.get(sourceObjectId), alias.getMethodExecution().getCallerMethodExecution(), alias.getMethodExecution()); + updateObjectVertices(); + } + } } +// MethodExecution tempMethodExec = alias.getMethodExecution(); +// //Array��List�̂Ƃ��������x����t����i�m���ɕ������Ă�����̂Ƃ�)getSignature->contains("List.get(") || "Map.get(") <�z���C�g���X�g> +// if (tempMethodExec.getSignature().contains("List.add(") || +// tempMethodExec.getSignature().contains("Map.put(")) { +// String srcClassName = tempMethodExec.getThisClassName(); +// String fieldName = tempMethodExec.getArguments().get(0).getId(); +// System.out.println("rTHIS " + srcClassName + ", " + fieldName); +// } + +// Statement tempStatement = alias.getOccurrencePoint().getStatement(); -> MethodInvocation +// if(tempStatement instanceof FieldAccess) { +// FieldAccess fieldAccessStatement = (FieldAccess) tempStatement; +// String fieldNames[] = formatFieldName(fieldAccessStatement.getFieldName()); +// String srcClassName = fieldNames[0]; +// String fieldName = fieldNames[1]; +// String sourceObjectId = fieldAccessStatement.getContainerObjId(); +// System.out.println(fieldName); +// createObjectRefrence(fieldAccessStatement, fieldName); +// removeCalledMethodExecutionVertex(objectToVertexMap.get(sourceObjectId), alias.getMethodExecution().getCallerMethodExecution(), alias.getMethodExecution()); +// updateObjectVertices(); +// } + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); try { List methodExecList = new ArrayList<>(methodExecToVertexMap.keySet()); Collections.reverse(methodExecList); + System.out.println(methodExecList.size()); for(int i = 0; i < methodExecList.size(); i++) { String objectId = methodExecList.get(i).getThisObjId(); ObjectVertex sourceVertexObject = objectToVertexMap.get(objectId); // sourceVertex @@ -406,26 +454,30 @@ if(statement instanceof MethodInvocation) { MethodExecution calledMethodExec = ((MethodInvocation) statement).getCalledMethodExecution(); String calledObjectId = calledMethodExec.getThisObjId(); - mxICell calledCell = (mxICell)objectToVertexMap.get(calledObjectId).getCell(); - Point absolutePointCalledCell = getAbsolutePointforCell(calledCell); - System.out.println(objectId + ", " + methodExec.getSignature()); - // objectToVertexMap.get(calledObjectId).resetCellPosition(); - if (methodExecToVertexMap.get(methodExec).getArguments().contains(objectToVertexMap.get(calledObjectId)) || methodExecToVertexMap.get(methodExec).getLocals().contains(objectToVertexMap.get(calledObjectId))) { - calledCell.getParent().remove(calledCell); - calledCell.setParent(mxDefaultParent); - calledCell.getGeometry().setX(absolutePointCalledCell.getX()); - calledCell.getGeometry().setY(absolutePointCalledCell.getY()); - deltaAnimation.setVertexAnimation(calledCell, new mxPoint(objectToVertexMap.get(calledObjectId).getInitialX(), objectToVertexMap.get(calledObjectId).getInitialY())); - deltaAnimation.startVertexAnimation(); + System.out.println(calledObjectId); + if(objectToVertexMap.containsKey(calledObjectId)) { + mxICell calledCell = (mxICell)objectToVertexMap.get(calledObjectId).getCell(); + Point absolutePointCalledCell = getAbsolutePointforCell(calledCell); + System.out.println(objectId + ", " + methodExec.getSignature()); + // objectToVertexMap.get(calledObjectId).resetCellPosition(); + if (methodExecToVertexMap.get(methodExec).getArguments().contains(objectToVertexMap.get(calledObjectId)) || methodExecToVertexMap.get(methodExec).getLocals().contains(objectToVertexMap.get(calledObjectId))) { + calledCell.getParent().remove(calledCell); + calledCell.setParent(mxDefaultParent); + calledCell.getGeometry().setX(absolutePointCalledCell.getX()); + calledCell.getGeometry().setY(absolutePointCalledCell.getY()); + deltaAnimation.setVertexAnimation(calledCell, new mxPoint(objectToVertexMap.get(calledObjectId).getInitialX(), objectToVertexMap.get(calledObjectId).getInitialY())); + deltaAnimation.startVertexAnimation(); + } + removeCalledMethodExecutionVertex(sourceVertexObject, methodExec.getCallerMethodExecution(), methodExec); + updateObjectVertices(); + // removeVertexMethodExecution(sourceVertexObject, methodExec); + // update(); + break; } - removeCalledMethodExecutionVertex(sourceVertexObject, methodExec.getCallerMethodExecution(), methodExec); - updateObjectVertices(); - // removeVertexMethodExecution(sourceVertexObject, methodExec); - // update(); - break; } } } else { + outputLog(); List arguments = new ArrayList<>(methodExecToVertexMap.get(methodExec).getArguments()); List locals = new ArrayList<>(methodExecToVertexMap.get(methodExec).getLocals()); if (arguments.size() != 0) { @@ -559,9 +611,10 @@ aliasPair = aliasPairListByAlias.get(0); } boolean isSrcSideChanged = aliasPair.getIsSrcSideChanged(); + Point absolutePointSourceCell = getAbsolutePointforCell(sourceCell); mxgraph.getModel().beginUpdate(); try { - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, vertexObj.getLabel(), vertexObj.getLabel(), sourceCell.getGeometry().getX() + overlapWidth, sourceCell.getGeometry().getY() + overlapHeight, VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, vertexObj.getLabel(), vertexObj.getLabel(), absolutePointSourceCell.getX() + overlapWidth, absolutePointSourceCell.getY() + overlapHeight, VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. vertexObj.setCell(vertex); Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, fieldName, null, sourceCell, vertex); if(isSrcSideChanged) { @@ -598,6 +651,30 @@ targetCell.getGeometry().setY(objectToVertexMap.get(targetObjectId).getInitialY()); } + private void createObjectRefrence(MethodExecution methodExec) { + String sourceObjectId = methodExec.getThisObjId(); + String srcClassName = methodExec.getThisClassName(); + String targetObjectId = methodExec.getArguments().get(0).getId(); + mxICell targetCell = (mxICell)objectToVertexMap.get(targetObjectId).getCell(); + Point absolutePointTargetCell = getAbsolutePointforCell(targetCell); + + targetCell.getParent().remove(targetCell); + targetCell.setParent(mxDefaultParent); + targetCell.getGeometry().setX(absolutePointTargetCell.getX()); + targetCell.getGeometry().setY(absolutePointTargetCell.getY()); + Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, targetObjectId, null, objectToVertexMap.get(sourceObjectId).getCell(), objectToVertexMap.get(targetObjectId).getCell()); + ((mxCell)edge).setStyle("exitX=0;exitY=0.5;exitPerimeter=1;entryX=1;entryY=0.5;entryPerimeter=1;"); + edgeMap.put(targetObjectId, new Edge(null, TypeName.Reference, edge)); + // System.out.println("last" + objectToVertexMap.get(targetObjectId).getInitialX() + ", " + objectToVertexMap.get(targetObjectId).getInitialY()); + deltaAnimation.setVertexAnimation(targetCell, new mxPoint(objectToVertexMap.get(targetObjectId).getInitialX(), objectToVertexMap.get(targetObjectId).getInitialY())); + deltaAnimation.startVertexAnimation(); + targetCell.getGeometry().setX(objectToVertexMap.get(targetObjectId).getInitialX()); + targetCell.getGeometry().setY(objectToVertexMap.get(targetObjectId).getInitialY()); + + + System.out.println("rTHIS " + srcClassName + ", " + targetObjectId); + } + /** * SourceVertex move targetVertex. * @@ -606,9 +683,13 @@ private void moveObjectVertex(Alias alias) { // sourceVertex ObjectVertex sourceObjectVertex = objectToVertexMap.get(alias.getObjectId()); + if (alias.getMethodExecution().isStatic() && !methodExecToVertexMap.containsKey(alias.getMethodExecution())) { + createMethodExecutionVertex(alias, alias.getMethodExecution().getSignature(), alias.getMethodExecution()); + } // targetVertex MethodExecutionVertex targetMethodExecVertex = methodExecToVertexMap.get(alias.getMethodExecution()); - + System.out.println("moveObjectVertex: " + targetMethodExecVertex); + System.out.println("moveObjectVertex: " + alias.getMethodExecution().isStatic()); moveObjectVertex(alias, sourceObjectVertex, targetMethodExecVertex); updateObjectVertices(); } @@ -641,20 +722,25 @@ private void moveLocalObjectVertex(MethodExecution callerMethodExec, ObjectVertex sourceVertexObject, MethodExecutionVertex targetVertexMethodExec) { mxICell sourceCell = (mxICell)sourceVertexObject.getCell(); mxICell targetCell = (mxICell) targetVertexMethodExec.getCell(); - // mxICell parentTargetMethodExecCell = targetMethodExecCell.getParent(); +// mxICell parentTargetMethodExecCell = targetMethodExecCell.getParent(); + + if (sourceCell == targetCell.getParent()) { + System.out.println("nothing."); + return; + } // Remove sourceVertex from Locals and Arguments Vertex of MethodExecution's Vertex. - // MethodExecution callercallerMethodExec = callerMethodExec.getCallerMethodExecution(); - // System.out.println(callerMethodExec.getSignature()); - // if (methodExecToVertexMap.containsKey(callercallerMethodExec) && methodExecToVertexMap.get(callercallerMethodExec).getLocals().contains(sourceVertexObject)) { - // methodExecToVertexMap.get(callercallerMethodExec).getLocals().remove(sourceVertexObject); - // System.out.println(methodExecToVertexMap.get(callercallerMethodExec).getLabel() + " :removeLocal: " + sourceVertexObject.getLabel()); - // } - // - // if (methodExecToVertexMap.containsKey(callercallerMethodExec) && methodExecToVertexMap.get(callercallerMethodExec).getArguments().contains(sourceVertexObject)) { - // methodExecToVertexMap.get(callercallerMethodExec).getArguments().remove(sourceVertexObject); - // System.out.println(methodExecToVertexMap.get(callercallerMethodExec).getLabel() + " :removeArgument: " + sourceVertexObject.getLabel()); - // } +// MethodExecution callercallerMethodExec = callerMethodExec.getCallerMethodExecution(); +// System.out.println(callerMethodExec.getSignature()); +// if (methodExecToVertexMap.containsKey(callercallerMethodExec) && methodExecToVertexMap.get(callercallerMethodExec).getLocals().contains(sourceVertexObject)) { +// methodExecToVertexMap.get(callercallerMethodExec).getLocals().remove(sourceVertexObject); +// System.out.println(methodExecToVertexMap.get(callercallerMethodExec).getLabel() + " :removeLocal: " + sourceVertexObject.getLabel()); +// } +// +// if (methodExecToVertexMap.containsKey(callercallerMethodExec) && methodExecToVertexMap.get(callercallerMethodExec).getArguments().contains(sourceVertexObject)) { +// methodExecToVertexMap.get(callercallerMethodExec).getArguments().remove(sourceVertexObject); +// System.out.println(methodExecToVertexMap.get(callercallerMethodExec).getLabel() + " :removeArgument: " + sourceVertexObject.getLabel()); +// } if (methodExecToVertexMap.containsKey(callerMethodExec) && methodExecToVertexMap.get(callerMethodExec).getLocals().contains(sourceVertexObject)) { methodExecToVertexMap.get(callerMethodExec).getLocals().remove(sourceVertexObject); System.out.println(methodExecToVertexMap.get(callerMethodExec).getLabel() + " :removeLocal: " + sourceVertexObject.getLabel()); @@ -683,8 +769,8 @@ sourceCell.setParent(targetCell.getParent()); targetCell.getParent().insert(sourceCell); - System.out.println("moveLocalObjectVertex: " + sourceCell.getId() + ", " + sourceCell.getParent().getId()); - System.out.println(" " + targetCell.getId() + ", " + targetCell.getParent().getId()); + System.out.println("moveLocalObjectVertex: " + sourceCell.getId() + " (" + sourceCell.hashCode() + ")" + ", " + sourceCell.getParent().getId() + " (" + sourceCell.getParent().hashCode() + ")"); + System.out.println(" " + targetCell.getId() + " (" + targetCell.hashCode() + ")" + ", " + targetCell.getParent().getId() + " (" + targetCell.getParent().hashCode() + ")"); Point absolutePointTargetCell = getAbsolutePointforCell(sourceCell.getParent()); sourceCell.getGeometry().setX(sourceX - absolutePointTargetCell.getX()); @@ -751,8 +837,9 @@ sourceCell.setParent(targetCell.getParent()); targetCell.getParent().insert(sourceCell); - sourceCell.getGeometry().setX(sourceX - sourceCell.getParent().getGeometry().getX()); - sourceCell.getGeometry().setY(sourceY - sourceCell.getParent().getGeometry().getY()); + Point absolutePointSourceParentCell = getAbsolutePointforCell(sourceCell.getParent()); + sourceCell.getGeometry().setX(sourceX - absolutePointSourceParentCell.getX()); + sourceCell.getGeometry().setY(sourceY - absolutePointSourceParentCell.getY()); double sourceWidth = sourceCell.getGeometry().getWidth(); double sourceHeight = sourceCell.getGeometry().getHeight(); @@ -828,8 +915,9 @@ sourceCell.setParent(targetCell.getParent()); targetCell.getParent().insert(sourceCell); - sourceCell.getGeometry().setX(sourceX - sourceCell.getParent().getGeometry().getX()); - sourceCell.getGeometry().setY(sourceY - sourceCell.getParent().getGeometry().getY()); + Point absolutePointSourceParentCell = getAbsolutePointforCell(sourceCell.getParent()); + sourceCell.getGeometry().setX(sourceX - absolutePointSourceParentCell.getX()); + sourceCell.getGeometry().setY(sourceY - absolutePointSourceParentCell.getY()); double sourceWidth = sourceCell.getGeometry().getWidth(); double sourceHeight = sourceCell.getGeometry().getHeight(); @@ -943,7 +1031,7 @@ */ private void createMethodExecutionVertex(Alias alias) { if (curFrame == 0) { - createMethodExecutionVertex(alias, alias.getMethodSignature(), alias.getMethodExecution()); + createMethodExecutionVertex(alias, alias.getMethodExecution().getSignature(), alias.getMethodExecution()); } else if (alias.getObjectId().matches("0")) { createMethodExecutionVertex(alias, alias.getMethodExecution().getSignature(), alias.getMethodExecution()); } @@ -967,15 +1055,27 @@ mxgraph.getModel().beginUpdate(); try { String objectId = alias.getObjectId(); + if (methodExec.isStatic()) { + objectId = alias.getMethodExecution().getCallerMethodExecution().getThisObjId(); + } Object object = objectToVertexMap.get(objectId).getCell(); double xCor = VERTEX_OBJECT_SIZE.getWidth() * 0.1; double yCor = VERTEX_OBJECT_SIZE.getHeight() * 0.5; + double standardX = xCor; + double standardY = 0; int time = objectToVertexMap.get(objectId).getVertexMethodExecutions().size(); + System.out.println(time); + if (time >= 1) { + mxICell standardCell = (mxICell) objectToVertexMap.get(objectId).getVertexMethodExecutions().get(0).getCell(); + standardX = standardCell.getGeometry().getX(); + standardY = standardCell.getGeometry().getY(); + time-=1; + } Object vertex = mxgraph.insertDeltaVertex(object, methodSignature, methodSignature, "fillColor=white"); //creates a white vertex. - System.out.println("makeVertexMethodExecution: " + ((mxICell)vertex).getId() + " (" + xCor * (time + 1) + ", " + yCor * (time + 1) + ")"); + System.out.println("makeVertexMethodExecution: " + ((mxICell)vertex).getId() + " in " + objectId + " (" + standardX + ", " + yCor * (time + 1) + standardY + ")"); - MethodExecutionVertex vertexMethodExecution = new MethodExecutionVertex(methodSignature, vertex, xCor , yCor * (time + 1), VERTEX_METHOD_EXECUTION_SIZE.getWidth(), VERTEX_METHOD_EXECUTION_SIZE.getHeight()); + MethodExecutionVertex vertexMethodExecution = new MethodExecutionVertex(methodSignature, vertex, standardX , yCor * (time + 1) + standardY, VERTEX_METHOD_EXECUTION_SIZE.getWidth(), VERTEX_METHOD_EXECUTION_SIZE.getHeight()); // Object vertex = mxgraph.insertVertex(object, methodSignature, methodSignature, 0, 0, 0, 0, "fillColor=white", true); //creates a white vertex. // Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, methodSignature, methodSignature, "fillColor=white"); //creates a white vertex. // VertexMethodExecution vertexMethodExecution = new VertexMethodExecution(methodSignature, vertex, getXForCell(objectId) + (xCor * (time + 1)), getYForCell(objectId) + (yCor * (time + 1)), VERTEX_METHOD_EXECUTION_SIZE.getWidth(), VERTEX_METHOD_EXECUTION_SIZE.getHeight()); @@ -1043,40 +1143,79 @@ mxICell sourceVertexCell = (mxICell)methodExecToVertexMap.get(methodExec).getCell(); mxCell targetVertexCell = (mxCell)methodExecToVertexMap.get(calledMethodExec).getCell(); Point absolutPointSourceVertexCell = getAbsolutePointforCell(sourceVertexCell); - - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - mxgraph.getModel().beginUpdate(); - try { - mxgraph.removeCells(mxgraph.getEdgesBetween(sourceVertexCell, targetVertexCell)); + if(!calledMethodExec.isStatic()) { + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. + mxgraph.getModel().beginUpdate(); try { - mxICell cloneTargetVertexCell = (mxICell) mxgraph.addCell(targetVertexCell.clone()); - Point absolutPointTargetVertexCell = getAbsolutePointforCell(targetVertexCell); - cloneTargetVertexCell.getGeometry().setX(absolutPointTargetVertexCell.getX()); - cloneTargetVertexCell.getGeometry().setY(absolutPointTargetVertexCell.getY()); - cloneTargetVertexCell.setStyle("fillColor=none;strokeColor=none;fontColor=#008000;"); - cloneTargetVertexCell.setValue(null); - Object tempEdge = mxgraph.insertEdge(mxDefaultParent, null, null, sourceVertexCell, cloneTargetVertexCell); - ((mxCell)tempEdge).setStyle("dashed=1;strokeColor=#008000;exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;endArrow=none"); - deltaAnimation.setReductionEdgeAnimation(cloneTargetVertexCell, new mxPoint(absolutPointSourceVertexCell.getX(), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight())); - deltaAnimation.startReductionEdgeAnimation(); - // deltaAnimation.setReductionEdgeAnimation(new mxPoint(absolutPointSourceVertexCell.getX() + (sourceVertexCell.getGeometry().getWidth() / 2), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight()), new mxPoint(absolutPointTargetVertexCell.getX() + (targetVertexCell.getGeometry().getWidth() / 2), absolutPointTargetVertexCell.getY())); - // deltaAnimation.startReductionEdgeAnimation(); - mxgraph.removeCells(new Object[]{cloneTargetVertexCell}); - } catch (CloneNotSupportedException e) { - e.printStackTrace(); + mxgraph.removeCells(mxgraph.getEdgesBetween(sourceVertexCell, targetVertexCell)); + try { + mxICell cloneTargetVertexCell = (mxICell) mxgraph.addCell(targetVertexCell.clone()); + Point absolutPointTargetVertexCell = getAbsolutePointforCell(targetVertexCell); + + // +// List arguments = new ArrayList<>(methodExecToVertexMap.get(calledMethodExec).getArguments()); +// List locals = new ArrayList<>(methodExecToVertexMap.get(calledMethodExec).getLocals()); +// if (arguments.size() != 0) { +// for (ObjectVertex vo: arguments) { +// mxICell cell = (mxICell)vo.getCell(); +// Point absolutePointCell = getAbsolutePointforCell(cell); +// cell.getParent().remove(cell); +// cell.setParent(mxDefaultParent); +// cell.getGeometry().setX(absolutePointCell.getX()); +// cell.getGeometry().setY(absolutePointCell.getY()); +// deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); +// deltaAnimation.startVertexAnimation(); +// methodExecToVertexMap.get(calledMethodExec).getArguments().remove(vo); +// } +// }else if (locals.size() != 0) { +// for (ObjectVertex vo: locals) { +// mxICell cell = (mxICell)vo.getCell(); +// Point absolutePointCell = getAbsolutePointforCell(cell); +// cell.getParent().remove(cell); +// cell.setParent(mxDefaultParent); +// cell.getGeometry().setX(absolutePointCell.getX()); +// cell.getGeometry().setY(absolutePointCell.getY()); +// deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); +// deltaAnimation.startVertexAnimation(); +// methodExecToVertexMap.get(calledMethodExec).getLocals().remove(vo); +// } +// } + // + + cloneTargetVertexCell.getGeometry().setX(absolutPointTargetVertexCell.getX()); + cloneTargetVertexCell.getGeometry().setY(absolutPointTargetVertexCell.getY()); + cloneTargetVertexCell.setStyle("fillColor=none;strokeColor=none;fontColor=#008000;"); + cloneTargetVertexCell.setValue(null); + Object tempEdge = mxgraph.insertEdge(mxDefaultParent, null, null, sourceVertexCell, cloneTargetVertexCell); + ((mxCell)tempEdge).setStyle("dashed=1;strokeColor=#008000;exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;endArrow=none"); + deltaAnimation.setReductionEdgeAnimation(cloneTargetVertexCell, new mxPoint(absolutPointSourceVertexCell.getX(), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight())); + deltaAnimation.startReductionEdgeAnimation(); +// deltaAnimation.setReductionEdgeAnimation(new mxPoint(absolutPointSourceVertexCell.getX() + (sourceVertexCell.getGeometry().getWidth() / 2), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight()), new mxPoint(absolutPointTargetVertexCell.getX() + (targetVertexCell.getGeometry().getWidth() / 2), absolutPointTargetVertexCell.getY())); +// deltaAnimation.startReductionEdgeAnimation(); + mxgraph.removeCells(new Object[]{cloneTargetVertexCell}); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + } finally { + mxgraph.getModel().endUpdate(); } - } finally { - mxgraph.getModel().endUpdate(); + ((mxCell)targetVertexCell.getParent()).remove(targetVertexCell); + targetVertexCell.setParent(mxDefaultParent); + mxgraph.removeCells(new Object[] {targetVertexCell}); + objectToVertexMap.get(calledMethodExec.getThisObjId()).getVertexMethodExecutions().remove(methodExecToVertexMap.get(calledMethodExec)); + methodExecToVertexMap.get(calledMethodExec).getLocals().remove(sourceVertexObject); + methodExecToVertexMap.remove(calledMethodExec); + edgeMap.remove(methodExec.getSignature()); +// moveInitialVertexObject(methodExec); +// updateObjectVerticesSize(); + } else { + ((mxCell)targetVertexCell.getParent()).remove(targetVertexCell); + targetVertexCell.setParent(mxDefaultParent); + mxgraph.removeCells(new Object[] {targetVertexCell}); + objectToVertexMap.get(calledMethodExec.getCallerMethodExecution().getThisObjId()).getVertexMethodExecutions().remove(methodExecToVertexMap.get(calledMethodExec)); + methodExecToVertexMap.get(calledMethodExec).getLocals().remove(sourceVertexObject); + methodExecToVertexMap.remove(calledMethodExec); } - ((mxCell)targetVertexCell.getParent()).remove(targetVertexCell); - targetVertexCell.setParent(mxDefaultParent); - mxgraph.removeCells(new Object[] {targetVertexCell}); - objectToVertexMap.get(calledMethodExec.getThisObjId()).getVertexMethodExecutions().remove(methodExecToVertexMap.get(calledMethodExec)); - methodExecToVertexMap.get(calledMethodExec).getLocals().remove(sourceVertexObject); - methodExecToVertexMap.remove(calledMethodExec); - edgeMap.remove(methodExec.getSignature()); - // moveInitialVertexObject(methodExec); - // updateObjectVerticesSize(); } } @@ -1178,32 +1317,50 @@ private void createEdgeToMethodExecution() { List methodExecList = new ArrayList<>(methodExecToVertexMap.keySet()); - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology - mxgraph.getModel().beginUpdate(); - try { - // BUG : Edge Orientation Reverse. - for (int i = 0; i < methodExecList.size() - 1; i++) { - MethodExecution sourceMethodExec = methodExecList.get(i); - MethodExecution targetMethodExec = methodExecList.get(i + 1); - String methodSignature = sourceMethodExec.getSignature(); - if (!edgeMap.containsKey(methodSignature)) { - mxICell sourceVertexCell = (mxICell)methodExecToVertexMap.get(sourceMethodExec).getCell(); - mxICell targetVertexCell = (mxICell)methodExecToVertexMap.get(targetMethodExec).getCell(); + // BUG : Edge Orientation Reverse. + for (int i = 0; i < methodExecList.size() - 1; i++) { + MethodExecution sourceMethodExec = methodExecList.get(i); + MethodExecution targetMethodExec = methodExecList.get(i + 1); + String methodSignature = sourceMethodExec.getSignature(); + if (!edgeMap.containsKey(methodSignature)) { + mxICell sourceVertexCell = (mxICell)methodExecToVertexMap.get(sourceMethodExec).getCell(); + mxICell targetVertexCell = (mxICell)methodExecToVertexMap.get(targetMethodExec).getCell(); + if (!targetMethodExec.isStatic()) { Point absolutPointSourceVertexCell = getAbsolutePointforCell(sourceVertexCell); Point absolutPointTargetVertexCell = getAbsolutePointforCell(targetVertexCell); + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology + mxgraph.getModel().beginUpdate(); + try { - // System.out.println("start : " + sourceVertexCell.getGeometry().getCenterX() + ", " + (sourceVertexCell.getGeometry().getY() + sourceVertexCell.getGeometry().getHeight()) + ", " + targetVertexCell.getGeometry().getCenterX() + ", " + targetVertexCell.getGeometry().getY()); - // deltaAnimation.setEdgeAnimation(new mxPoint(sourceVertexCell.getGeometry().getCenterX(), sourceVertexCell.getGeometry().getY() + sourceVertexCell.getGeometry().getHeight()), new mxPoint(targetVertexCell.getGeometry().getCenterX(), targetVertexCell.getGeometry().getY())); - deltaAnimation.setExpandEdgeAnimation(new mxPoint(absolutPointSourceVertexCell.getX() + (sourceVertexCell.getGeometry().getWidth() / 2), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight()), new mxPoint(absolutPointTargetVertexCell.getX() + (targetVertexCell.getGeometry().getWidth() / 2), absolutPointTargetVertexCell.getY())); - deltaAnimation.startExpandEdgeAnimation(); + try { + mxICell cloneTargetVertexCell = (mxICell) mxgraph.addCell(targetVertexCell.clone()); + cloneTargetVertexCell.getGeometry().setX(absolutPointSourceVertexCell.getX()); + cloneTargetVertexCell.getGeometry().setY(absolutPointSourceVertexCell.getY() + targetVertexCell.getGeometry().getHeight()); + cloneTargetVertexCell.setStyle("fillColor=none;strokeColor=none;fontColor=#008000;"); + cloneTargetVertexCell.setValue(null); + cloneTargetVertexCell.setVisible(true); + Object tempEdge = mxgraph.insertEdge(mxDefaultParent, null, null, sourceVertexCell, cloneTargetVertexCell); + ((mxCell)tempEdge).setStyle("dashed=1;strokeColor=#008000;exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;endArrow=none"); + deltaAnimation.setExpandEdgeAnimation(cloneTargetVertexCell, new mxPoint(absolutPointTargetVertexCell.getX(), absolutPointTargetVertexCell.getY())); + deltaAnimation.startExpandEdgeAnimation(); + targetVertexCell.setVisible(true); +// deltaAnimation.setExpandEdgeAnimation(new mxPoint(absolutPointSourceVertexCell.getX() + (sourceVertexCell.getGeometry().getWidth() / 2), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight()), new mxPoint(absolutPointTargetVertexCell.getX() + (targetVertexCell.getGeometry().getWidth() / 2), absolutPointTargetVertexCell.getY())); +// deltaAnimation.startExpandEdgeAnimation(); + Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, methodSignature, null, sourceVertexCell, targetVertexCell); + ((mxCell)edge).setStyle("exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;"); + mxgraph.removeCells(new Object[]{cloneTargetVertexCell}); + edgeMap.put(methodSignature, new Edge(methodSignature, TypeName.Call, edge)); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + } finally { + mxgraph.getModel().endUpdate(); + } + } else { targetVertexCell.setVisible(true); - Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, methodSignature, null, sourceVertexCell, targetVertexCell); - ((mxCell)edge).setStyle("exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;"); - edgeMap.put(methodSignature, new Edge(methodSignature, TypeName.Call, edge)); } + } - } finally { - mxgraph.getModel().endUpdate(); } } diff --git a/src/org/ntlab/deltaViewer/DeltaViewerSample.java b/src/org/ntlab/deltaViewer/DeltaViewerSample.java index 4e5370b..3ed3ae3 100644 --- a/src/org/ntlab/deltaViewer/DeltaViewerSample.java +++ b/src/org/ntlab/deltaViewer/DeltaViewerSample.java @@ -145,6 +145,7 @@ setArgmentsForDeltaExtract(argsMap); // String argsKey = "ArgoUMLPlace1_1"; //���o�������f���^�̈������i�[����Map��key String argsKey = "ArgoUMLSelect0_1"; //���o�������f���^�̈������i�[����Map��key +// String argsKey = "ArgoUMLSelect1_2"; //���o�������f���^�̈������i�[����Map��key // String argsKey = "sampleStatic"; //���o�������f���^�̈������i�[����Map��key // String argsKey = "worstCase"; //���o�������f���^�̈������i�[����Map��key // String argsKey = "sample1"; //���o�������f���^�̈������i�[����Map��key @@ -166,7 +167,7 @@ if (e != null) { eList.add(e); dacList.add(dac); - System.out.println("add" + eList.size()); + System.out.println("add" + eList.size() + ", " + dacList.size()); } System.out.println("---------------------------"); } @@ -481,7 +482,6 @@ // // s.extractArg(e.getCoodinator(), 123456789); // // s.getCallHistory(e.getCoodinator()); - startDeltaViewer(eList.get(0), dacList.get(0)); }