diff --git a/res/strings/en.properties b/res/strings/en.properties index 3344738..9dbbdd3 100644 --- a/res/strings/en.properties +++ b/res/strings/en.properties @@ -9,4 +9,5 @@ extract_feature=Extract Feature anim_settings=Animation Settings normal=Normal +auto_tracking=Auto Tracking view=View \ No newline at end of file diff --git a/res/strings/ja.properties b/res/strings/ja.properties index eda5566..c2499a2 100644 --- a/res/strings/ja.properties +++ b/res/strings/ja.properties @@ -9,5 +9,6 @@ extract_feature=\u6A5F\u80FD\u62BD\u51FA anim_settings=\u30A2\u30CB\u30E1\u30FC\u30B7\u30E7\u30F3\u8A2D\u5B9A normal=\u901A\u5E38 +auto_tracking=\u81EA\u52D5\u8FFD\u8DE1 view=\u8868\u793A diff --git a/src/org/ntlab/deltaViewer/CollaborationViewer.java b/src/org/ntlab/deltaViewer/CollaborationViewer.java index 4a4c64d..4188f52 100644 --- a/src/org/ntlab/deltaViewer/CollaborationViewer.java +++ b/src/org/ntlab/deltaViewer/CollaborationViewer.java @@ -1,5 +1,6 @@ package org.ntlab.deltaViewer; +import java.awt.Dimension; import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Collections; @@ -22,6 +23,7 @@ import org.ntlab.trace.TracePoint; import com.mxgraph.model.mxICell; +import com.mxgraph.util.mxRectangle; import com.mxgraph.view.mxGraphView; public class CollaborationViewer extends MagnetRONViewer { @@ -33,7 +35,8 @@ private IObjectCallGraph objectCallGraph; - private double scale = 1.0; + private Dimension graphMaxSize; + private double viwerScale = 1.0; public CollaborationViewer() { super(); @@ -60,13 +63,26 @@ // reflectCoordinates(mxgraph); // objectVertex��mxGraph�̍��W�𔽉f������(���[�U���w�肵�����W�ʒu�𔽉f) // Fit graph size in visible JFrame. - mxGraphView view = mxgraphComponent.getGraph().getView(); - int componentWidth = mxgraphComponent.getWidth() - 25; - double viewWidth = (double) view.getGraphBounds().getWidth(); -// scale = (double)componentWidth/viewWidth; - view.setScale(scale); + mxGraphView mxGraphView = getGraphComponent().getGraph().getView(); +// int componentWidth = getGraphComponent().getWidth() - 25; +// double viewWidth = (double) mxGraphView.getGraphBounds().getWidth(); +// scale = (double) componentWidth/viewWidth; + mxGraphView.setScale(viwerScale); update(); + + graphMaxSize = new Dimension(); + for (ObjectVertex objVx: objectToVertexMap.values()) { + double objVxInitMaxX = objVx.getInitialX() + DEFAULT_OBJECT_VERTEX_SIZE.getWidth(); + double objVxInitMaxY = objVx.getInitialY() + DEFAULT_OBJECT_VERTEX_SIZE.getHeight(); + if (objVxInitMaxX > graphMaxSize.getWidth()) { + graphMaxSize.setSize(objVxInitMaxX, graphMaxSize.getHeight()); + } + if (objVxInitMaxY > graphMaxSize.getHeight()) { + graphMaxSize.setSize(graphMaxSize.getWidth(), objVxInitMaxY); + } + } + mxgraph.setMinimumGraphSize(new mxRectangle(0, 0, graphMaxSize.getWidth(), graphMaxSize.getHeight())); } /** @@ -124,7 +140,7 @@ private void doLastAnimation(int numFrame, TracePoint relatedPoint) { // TODO: Implement doLastAnimation() to support multiple delta. - curFrame = numFrame; + setCurrentFrame(numFrame); List aliasList = aliasCollector.getAliasList(); Alias prevAlias = aliasList.get(numFrame - 1); Alias nextAlias = (numFrame < aliasList.size()) ? aliasList.get(numFrame) : null; @@ -140,17 +156,21 @@ String srcClassName = calledMethodExec.getThisClassName(); String srcObjId = calledMethodExec.getThisObjId(); String tgtObjId = prevAlias.getObjectId(); - ObjectVertex tgtObjectVertex = objectToVertexMap.get(tgtObjId); - + ObjectVertex tgtObjVx = objectToVertexMap.get(tgtObjId); + createObjectRefrence(srcClassName, srcObjId, tgtObjId); + if (methodExecToVertexMap.containsKey(prevMethodExec)) { - if (methodExecToVertexMap.get(prevMethodExec).getLocals().contains(tgtObjectVertex)) { - methodExecToVertexMap.get(prevMethodExec).getLocals().remove(tgtObjectVertex); - } else if (methodExecToVertexMap.get(prevMethodExec).getArguments().contains(tgtObjectVertex)) { - methodExecToVertexMap.get(prevMethodExec).getArguments().remove(tgtObjectVertex); + MethodExecutionVertex prevMethodExecVx = methodExecToVertexMap.get(prevMethodExec); + if (prevMethodExecVx.getLocals().contains(tgtObjVx)) { + prevMethodExecVx.getLocals().remove(tgtObjVx); + } else if (prevMethodExecVx.getArguments().contains(tgtObjVx)) { + prevMethodExecVx.getArguments().remove(tgtObjVx); } } - if (nextAlias == null || (nextAlias != null && !calledMethodExec.getSignature().equals(nextAlias.getMethodSignature()))) { + + if (nextAlias == null + || (nextAlias != null && !calledMethodExec.getSignature().equals(nextAlias.getMethodSignature()))) { removeCalledMethodExecutionVertex(objectToVertexMap.get(srcObjId), prevMethodExec, calledMethodExec); updateObjectVertices(); } @@ -168,22 +188,24 @@ } else { fieldName = ""; } - String sourceObjectId = fieldUpdateStatement.getContainerObjId(); - + String srcObjId = fieldUpdateStatement.getContainerObjId(); + createObjectRefrence(fieldUpdateStatement, fieldName); - String targetObjectId = fieldUpdateStatement.getValueObjId(); - ObjectVertex targetObjectVertex = objectToVertexMap.get(targetObjectId); + String tgtObjId = fieldUpdateStatement.getValueObjId(); + ObjectVertex tgtObjVx = objectToVertexMap.get(tgtObjId); if (methodExecToVertexMap.containsKey(prevMethodExec)) { - if (methodExecToVertexMap.get(prevMethodExec).getLocals().contains(targetObjectVertex)) { - methodExecToVertexMap.get(prevMethodExec).getLocals().remove(targetObjectVertex); - } else if (methodExecToVertexMap.get(prevMethodExec).getArguments().contains(targetObjectVertex)) { - methodExecToVertexMap.get(prevMethodExec).getArguments().remove(targetObjectVertex); + MethodExecutionVertex prevMethodExecVx = methodExecToVertexMap.get(prevMethodExec); + if (prevMethodExecVx.getLocals().contains(tgtObjVx)) { + prevMethodExecVx.getLocals().remove(tgtObjVx); + } else if (prevMethodExecVx.getArguments().contains(tgtObjVx)) { + prevMethodExecVx.getArguments().remove(tgtObjVx); } } + if (nextAlias == null || (nextAlias != null && !prevMethodExec.getSignature().equals(nextAlias.getMethodSignature()))) { - removeCalledMethodExecutionVertex(objectToVertexMap.get(sourceObjectId), prevMethodExec.getCallerMethodExecution(), prevMethodExec); + removeCalledMethodExecutionVertex(objectToVertexMap.get(srcObjId), prevMethodExec.getCallerMethodExecution(), prevMethodExec); updateObjectVertices(); } } @@ -209,25 +231,28 @@ srcClassName = calledMethodExec.getThisClassName(); srcObjId = calledMethodExec.getThisObjId(); tgtObjId = calledMethodExec.getArguments().get(0).getId(); - ObjectVertex tgtObjectVertex = objectToVertexMap.get(tgtObjId); + ObjectVertex tgtObjVx = objectToVertexMap.get(tgtObjId); if (!methodExecToVertexMap.containsKey(calledMethodExec)) { createMethodExecutionVertex(calledMethodExec.getThisObjId(), methodInvStatement.getCallerSideMethodName(), calledMethodExec); update(); - moveArgumentObjectVertex(calledMethodExec, tgtObjectVertex, methodExecToVertexMap.get(calledMethodExec)); + moveArgumentObjectVertex(calledMethodExec, tgtObjVx, methodExecToVertexMap.get(calledMethodExec)); update(); createObjectRefrence(srcClassName, srcObjId, tgtObjId); removeCalledMethodExecutionVertex(null, prevMethodExec, calledMethodExec); } else { createObjectRefrence(srcClassName, srcObjId, tgtObjId); } + if (methodExecToVertexMap.containsKey(prevMethodExec)) { - if (methodExecToVertexMap.get(prevMethodExec).getLocals().contains(tgtObjectVertex)) { - methodExecToVertexMap.get(prevMethodExec).getLocals().remove(tgtObjectVertex); - } else if (methodExecToVertexMap.get(prevMethodExec).getArguments().contains(tgtObjectVertex)) { - methodExecToVertexMap.get(prevMethodExec).getArguments().remove(tgtObjectVertex); + MethodExecutionVertex prevMethodExecVx = methodExecToVertexMap.get(prevMethodExec); + if (prevMethodExecVx.getLocals().contains(tgtObjVx)) { + prevMethodExecVx.getLocals().remove(tgtObjVx); + } else if (prevMethodExecVx.getArguments().contains(tgtObjVx)) { + prevMethodExecVx.getArguments().remove(tgtObjVx); } } + List methodExecList = new ArrayList<>(methodExecToVertexMap.keySet()); if (nextAlias == null || (nextAlias != null && !prevMethodExec.getSignature().equals(nextAlias.getMethodSignature()))) { if (methodExecList.size() > 1) { @@ -242,16 +267,19 @@ srcClassName = methodInvStatement.getThisClassName(); srcObjId = methodInvStatement.getThisObjId(); tgtObjId = calledMethodExec.getReturnValue().getId(); - ObjectVertex tgtObjectVertex = objectToVertexMap.get(tgtObjId); - + ObjectVertex tgtObjVx = objectToVertexMap.get(tgtObjId); + createObjectRefrence(srcClassName, srcObjId, tgtObjId); + if (methodExecToVertexMap.containsKey(prevMethodExec)) { - if (methodExecToVertexMap.get(prevMethodExec).getLocals().contains(tgtObjectVertex)) { - methodExecToVertexMap.get(prevMethodExec).getLocals().remove(tgtObjectVertex); - } else if (methodExecToVertexMap.get(prevMethodExec).getArguments().contains(tgtObjectVertex)) { - methodExecToVertexMap.get(prevMethodExec).getArguments().remove(tgtObjectVertex); + MethodExecutionVertex prevMethodExecVx = methodExecToVertexMap.get(prevMethodExec); + if (prevMethodExecVx.getLocals().contains(tgtObjVx)) { + prevMethodExecVx.getLocals().remove(tgtObjVx); + } else if (prevMethodExecVx.getArguments().contains(tgtObjVx)) { + prevMethodExecVx.getArguments().remove(tgtObjVx); } } + if (nextAlias == null || (nextAlias != null && !calledMethodExec.getSignature().equals(nextAlias.getMethodSignature()))) { removeCalledMethodExecutionVertex(objectToVertexMap.get(srcObjId), prevMethodExec, calledMethodExec); updateObjectVertices(); @@ -265,77 +293,81 @@ List methodExecList = new ArrayList<>(methodExecToVertexMap.keySet()); Collections.reverse(methodExecList); for(int i = 0; i < methodExecList.size(); i++) { - String objectId = methodExecList.get(i).getThisObjId(); - ObjectVertex srcObjectVertex = objectToVertexMap.get(objectId); // sourceVertex + String objId = methodExecList.get(i).getThisObjId(); + ObjectVertex srcObjVx = objectToVertexMap.get(objId); // sourceVertex MethodExecution methodExec = methodExecList.get(i); + if (nextAlias != null && methodExec.getSignature().equals(nextAlias.getMethodSignature())) break; - if (i != methodExecList.size()-1) { + + if (i != methodExecList.size() - 1) { for(Statement st: methodExec.getStatements()) { if(st instanceof MethodInvocation) { MethodExecution calledMethodExec = ((MethodInvocation) st).getCalledMethodExecution(); String calledObjId = calledMethodExec.getThisObjId(); if(objectToVertexMap.containsKey(calledObjId)) { - removeCalledMethodExecutionVertex(srcObjectVertex, methodExec.getCallerMethodExecution(), methodExec); + removeCalledMethodExecutionVertex(srcObjVx, methodExec.getCallerMethodExecution(), methodExec); updateObjectVertices(); break; } } } } else { + scrollCellToVisible((mxICell) srcObjVx.getCell(), true); + List arguments = new ArrayList<>(methodExecToVertexMap.get(methodExec).getArguments()); List locals = new ArrayList<>(methodExecToVertexMap.get(methodExec).getLocals()); if (arguments.size() != 0) { - for (ObjectVertex vo: arguments) { - mxICell cell = (mxICell)vo.getCell(); - Point2D absolutePointCell = getAbsolutePointforCell(cell); + for (ObjectVertex objVx: arguments) { + mxICell objVxCell = (mxICell) objVx.getCell(); + Point2D objVxCellAbsPt = getAbsolutePointforCell(objVxCell); // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - if (!cell.getParent().equals(getMxDefaultParent())) { + if (!objVxCell.getParent().equals(getMxDefaultParent())) { // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. - cell.getParent().remove(cell); - cell.setParent(getMxDefaultParent()); + objVxCell.getParent().remove(objVxCell); + objVxCell.setParent(getMxDefaultParent()); } - cell.getGeometry().setX(absolutePointCell.getX()); - cell.getGeometry().setY(absolutePointCell.getY()); + objVxCell.getGeometry().setX(objVxCellAbsPt.getX()); + objVxCell.getGeometry().setY(objVxCellAbsPt.getY()); } finally { mxgraph.getModel().endUpdate(); } } - MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - vertexAnim.setTotalCycleCount(10); - vertexAnim.setDelay(100); - vertexAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); - vertexAnim.syncPlay(); - methodExecToVertexMap.get(methodExec).getArguments().remove(vo); + MagnetRONAnimation pbjVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + pbjVxCellAnim.setTotalCycleCount(10); + pbjVxCellAnim.setDelay(100); + pbjVxCellAnim.init(objVxCell, objVx.getInitialX(), objVx.getInitialY(), threadPoolExecutor); + pbjVxCellAnim.syncPlay(); + methodExecToVertexMap.get(methodExec).getArguments().remove(objVx); } - }else if (locals.size() != 0) { - for (ObjectVertex vo: locals) { - mxICell cell = (mxICell)vo.getCell(); - Point2D absolutePointCell = getAbsolutePointforCell(cell); + } else if (locals.size() != 0) { + for (ObjectVertex objVx: locals) { + mxICell objVxCell = (mxICell) objVx.getCell(); + Point2D objVxCellAbsPt = getAbsolutePointforCell(objVxCell); // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - if (!cell.getParent().equals(getMxDefaultParent())) { + if (!objVxCell.getParent().equals(getMxDefaultParent())) { // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. - cell.getParent().remove(cell); - cell.setParent(getMxDefaultParent()); + objVxCell.getParent().remove(objVxCell); + objVxCell.setParent(getMxDefaultParent()); } - cell.getGeometry().setX(absolutePointCell.getX()); - cell.getGeometry().setY(absolutePointCell.getY()); + objVxCell.getGeometry().setX(objVxCellAbsPt.getX()); + objVxCell.getGeometry().setY(objVxCellAbsPt.getY()); } finally { mxgraph.getModel().endUpdate(); } } - MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - vertexAnim.setTotalCycleCount(10); - vertexAnim.setDelay(100); - vertexAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); - vertexAnim.syncPlay(); - methodExecToVertexMap.get(methodExec).getLocals().remove(vo); + MagnetRONAnimation objVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + objVxCellAnim.setTotalCycleCount(10); + objVxCellAnim.setDelay(100); + objVxCellAnim.init(objVxCell, objVx.getInitialX(), objVx.getInitialY(), threadPoolExecutor); + objVxCellAnim.syncPlay(); + methodExecToVertexMap.get(methodExec).getLocals().remove(objVx); } } updateObjectVertices(); @@ -356,15 +388,15 @@ try { // Create vertices(mxGraph) and OvjectVerticies. List refList = objectCallGraph.getReferences(); - double objecVertexWidth = DEFAULT_OBJECT_VERTEX_SIZE.getWidth(); - double ObjectVertexHeight = DEFAULT_OBJECT_VERTEX_SIZE.getHeight(); + double objVxWid = DEFAULT_OBJECT_VERTEX_SIZE.getWidth(); + double ObjVxHt = DEFAULT_OBJECT_VERTEX_SIZE.getHeight(); { MethodExecution coordinator = objectCallGraph.getStartPoints().get(0); String coordinatorObjId = coordinator.getThisObjId(); String coordinatorClassName = coordinator.getThisClassName(); - mxICell vertex = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), coordinatorObjId, coordinatorClassName, 0, 0, DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(coordinatorObjId, new ObjectVertex(coordinatorClassName, vertex, 0, 0)); + mxICell coordinatorObjVxCell = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), coordinatorObjId, coordinatorClassName, 0, 0, DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + objectToVertexMap.put(coordinatorObjId, new ObjectVertex(coordinatorClassName, coordinatorObjVxCell, 0, 0)); } for (int i = 0; i < refList.size(); i++) { @@ -378,8 +410,8 @@ if (srcClassName.contains("[L")) { srcClassName = formatArrayName(srcClassName); } - mxICell vertex = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), srcObjId, srcClassName, 0, 0, objecVertexWidth, ObjectVertexHeight, "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(srcObjId, new ObjectVertex(ref.getSrcClassName(), vertex, 0, 0)); + mxICell srcObjVxCell = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), srcObjId, srcClassName, 0, 0, objVxWid, ObjVxHt, "fillColor=white"); //creates a white vertex. + objectToVertexMap.put(srcObjId, new ObjectVertex(ref.getSrcClassName(), srcObjVxCell, 0, 0)); } // dstSide if (!objectToVertexMap.containsKey(ref.getDstObjectId())) { @@ -389,8 +421,8 @@ if (dstClassName.contains("[L")) { dstClassName = formatArrayName(dstClassName); } - mxICell vertex = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), dstObjId, dstClassName, 0, 0, objecVertexWidth, ObjectVertexHeight, "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(dstObjId, new ObjectVertex(ref.getDstClassName(), vertex, 0, 0)); + mxICell dstObjVxCell = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), dstObjId, dstClassName, 0, 0, objVxWid, ObjVxHt, "fillColor=white"); //creates a white vertex. + objectToVertexMap.put(dstObjId, new ObjectVertex(ref.getDstClassName(), dstObjVxCell, 0, 0)); } } else { if (!objectToVertexMap.containsKey(ref.getSrcObjectId())) { @@ -399,8 +431,8 @@ if (srcClassName.contains("[L")) { srcClassName = formatArrayName(srcClassName); } - mxICell vertex = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), srcObjId, srcClassName, 0, 0, objecVertexWidth, ObjectVertexHeight, "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(srcObjId, new ObjectVertex(ref.getSrcClassName(), vertex, 0, 0)); + mxICell srcObjVxCell = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), srcObjId, srcClassName, 0, 0, objVxWid, ObjVxHt, "fillColor=white"); //creates a white vertex. + objectToVertexMap.put(srcObjId, new ObjectVertex(ref.getSrcClassName(), srcObjVxCell, 0, 0)); } String dstObjId = ref.getDstObjectId(); if (!objectToVertexMap.containsKey(dstObjId)) { @@ -418,8 +450,8 @@ // When both of the calling and called method are static. String thisObjId = alias.getObjectId(); String thisClassName = alias.getMethodExecution().getThisClassName(); - mxICell vertex = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), thisObjId, thisClassName, 0, 0, objecVertexWidth, ObjectVertexHeight, "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(thisObjId, new ObjectVertex(thisClassName, vertex, 0, 0)); + mxICell thisObjVxCell = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), thisObjId, thisClassName, 0, 0, objVxWid, ObjVxHt, "fillColor=white"); //creates a white vertex. + objectToVertexMap.put(thisObjId, new ObjectVertex(thisClassName, thisObjVxCell, 0, 0)); } } } @@ -442,7 +474,10 @@ if (curFrame == 0) { MethodExecution callerMethodExec = methodExec.getCallerMethodExecution(); - if (callerMethodExec != null && methodExecSignature != callerMethodExec.getSignature() && objectToVertexMap.containsKey(callerMethodExec.getThisObjId()) && objectCallGraph.getStartPoints().get(0) == callerMethodExec) { + if (callerMethodExec != null + && methodExecSignature != callerMethodExec.getSignature() + && objectToVertexMap.containsKey(callerMethodExec.getThisObjId()) + && objectCallGraph.getStartPoints().get(0) == callerMethodExec) { createMethodExecutionVertex(callerMethodExec.getThisObjId(), callerMethodExec.getSignature(), callerMethodExec); } createMethodExecutionVertex(objId, methodExecSignature, methodExec); @@ -544,21 +579,18 @@ // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); try { - Object srcCell = objectToVertexMap.get(curAliasObjId).getCell(); - Object dstCell = objectToVertexMap.get(nextAliasObjId).getCell(); - if (srcCell != null && dstCell != null) { // isCreation() + Object srcObjVxCell = objectToVertexMap.get(curAliasObjId).getCell(); + Object dstObjVxCell = objectToVertexMap.get(nextAliasObjId).getCell(); + if (srcObjVxCell != null && dstObjVxCell != null) { // isCreation() System.out.println(TAG + ": Create Edge. srcClassName=" + srcClassName + "(curObjectId=" + curAliasObjId + ") -- fieldName=" + fieldName + " --> " + "(nextObjectId" + nextAliasObjId + ")"); // TODO: Fix bug of NullPointerException. - mxICell edge = null; + mxICell edgeCell = null; if (fieldName.equals(nextAliasObjId)) { // If fieldName is objectId. - edge = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), "", "", srcCell, dstCell); + edgeCell = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), "", "", srcObjVxCell, dstObjVxCell); } else { - edge = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), fieldName, fieldName, srcCell, dstCell); + edgeCell = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), fieldName, fieldName, srcObjVxCell, dstObjVxCell); } - Point2D absPtSrcCell = getAbsolutePointforCell((mxICell)srcCell); - Point2D absPtDstCell = getAbsolutePointforCell((mxICell)dstCell); - setEdgePoint((mxICell)edge, absPtSrcCell, absPtDstCell); - edgeMap.put(srcClassName + "." + fieldName, new Edge(fieldName, TypeName.Reference, edge)); + edgeMap.put(srcClassName + "." + fieldName, new Edge(fieldName, TypeName.Reference, edgeCell)); } } finally { mxgraph.getModel().endUpdate(); diff --git a/src/org/ntlab/deltaViewer/DeltaViewer.java b/src/org/ntlab/deltaViewer/DeltaViewer.java index 7a96622..487c974 100644 --- a/src/org/ntlab/deltaViewer/DeltaViewer.java +++ b/src/org/ntlab/deltaViewer/DeltaViewer.java @@ -597,7 +597,6 @@ Object edge = mxgraph.insertDeltaEdge(getMxDefaultParent(), fieldName, fieldName, srcCell, dstCell); Point2D absPtSrcCell = getAbsolutePointforCell((mxICell)srcCell); Point2D absPtDstCell = getAbsolutePointforCell((mxICell)dstCell); - setEdgePoint((mxICell)edge, absPtSrcCell, absPtDstCell); edgeMap.put(srcClassName + "." + fieldName, new Edge(fieldName, TypeName.Reference, edge)); } } finally { diff --git a/src/org/ntlab/deltaViewer/MagnetRONMenuBar.java b/src/org/ntlab/deltaViewer/MagnetRONMenuBar.java index a1a4dc3..0f0dc34 100644 --- a/src/org/ntlab/deltaViewer/MagnetRONMenuBar.java +++ b/src/org/ntlab/deltaViewer/MagnetRONMenuBar.java @@ -5,6 +5,7 @@ import java.util.Locale; import java.util.Properties; +import javax.swing.ButtonGroup; import javax.swing.JCheckBox; import javax.swing.JMenu; import javax.swing.JMenuBar; @@ -64,10 +65,13 @@ JMenu animationSettingMenu = add(new JMenu(properties.getProperty("anim_settings"))); JCheckBox defaultCheck = new JCheckBox(properties.getProperty("normal"), true); defaultCheck.addActionListener(new ZoomActualAction(magnetRON.getViewer())); - defaultCheck.setEnabled(false); - animationSettingMenu.add(defaultCheck); JCheckBox autoTrackingCheck = new JCheckBox(properties.getProperty("auto_tracking"), false); autoTrackingCheck.addChangeListener(new AutoTrackingAction(magnetRON.getViewer())); + + ButtonGroup checkBoxGroup = new ButtonGroup(); + checkBoxGroup.add(defaultCheck); + checkBoxGroup.add(autoTrackingCheck); + animationSettingMenu.add(defaultCheck); animationSettingMenu.add(autoTrackingCheck); JMenu viewMenu = add(new JMenu(properties.getProperty("view"))); diff --git a/src/org/ntlab/deltaViewer/MagnetRONViewer.java b/src/org/ntlab/deltaViewer/MagnetRONViewer.java index 3c62966..24fd78e 100644 --- a/src/org/ntlab/deltaViewer/MagnetRONViewer.java +++ b/src/org/ntlab/deltaViewer/MagnetRONViewer.java @@ -36,7 +36,6 @@ import org.ntlab.trace.ObjectReference; import org.ntlab.trace.Reference; import org.ntlab.trace.Statement; -import org.ntlab.trace.Trace; import org.ntlab.trace.TracePoint; import com.mxgraph.canvas.mxGraphics2DCanvas; @@ -85,7 +84,7 @@ protected ThreadPoolExecutor threadPoolExecutor; protected int curFrame = 0; - private boolean autoTracking = false; + private boolean fAutoTracking = false; public MagnetRONViewer() { mxgraph = new DeltaGraphAdapter(new DirectedWeightedPseudograph(DefaultEdge.class)); @@ -226,13 +225,14 @@ } /** - * Create a {@code mxIcell} of {@code ObjectVertex} while animating {@code TranslateAnimation} when {@link Alias#getAliasType()} is CONSTRACTOR_INVOCATION. + * Create a {@code mxIcell} of {@code ObjectVertex} while animating {@code TranslateAnimation} + * when {@link Alias#getAliasType()} is CONSTRACTOR_INVOCATION. * * @param alias */ protected void createObjectVertexOnConstractor(Alias alias) { - ObjectVertex objectVertex = objectToVertexMap.get(alias.getObjectId()); - mxICell ovCell = null; + ObjectVertex objVx = objectToVertexMap.get(alias.getObjectId()); + mxICell objVxCell = null; // Position of srcCell is start point for ovCell to TranslateAnimation. MethodExecution methodExec = alias.getMethodExecution(); @@ -240,46 +240,46 @@ if (srcObjId.matches("0")) { srcObjId += ":" + alias.getMethodExecution().getThisClassName(); } - mxICell srcCell = (mxICell)objectToVertexMap.get(srcObjId).getCell(); - double srcWidth = srcCell.getGeometry().getWidth(); - double srcHeight = srcCell.getGeometry().getHeight(); - double overlapWidth = srcWidth * Math.sqrt(2) * 0.1; - double overlapHeight = srcHeight - (srcHeight * Math.sqrt(2) * 0.1); - Point2D srcCellAbsPt = getAbsolutePointforCell(srcCell); + mxICell srcObjVxCell = (mxICell) objectToVertexMap.get(srcObjId).getCell(); + double srcObjVxCellWid = srcObjVxCell.getGeometry().getWidth(); + double srcObjVxCellHt = srcObjVxCell.getGeometry().getHeight(); + double overlapWid = srcObjVxCellWid * Math.sqrt(2) * 0.1; + double overlapHt = srcObjVxCellHt - (srcObjVxCellHt * Math.sqrt(2) * 0.1); + Point2D srcObjVxCellAbsPt = getAbsolutePointforCell(srcObjVxCell); MethodInvocation methodInv; String fieldName = null; if (!methodExec.isCollectionType() && alias.getOccurrencePoint().getStatement() != null) { - methodInv = (MethodInvocation)alias.getOccurrencePoint().getStatement(); + methodInv = (MethodInvocation) alias.getOccurrencePoint().getStatement(); fieldName = methodInv.getCallerSideMethodName(); } MagnetRONAnimation.waitAnimationEnd(); - scrollPointsToVisible(srcCellAbsPt, objectVertex.getInitialPoint(), true); + scrollCellAndPointToVisible(srcObjVxCell, objVx.getInitialPoint(), 2); mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { // Creates a white mxICell of ObjectVertex. - ovCell = - (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), alias.getObjectId(), objectVertex.getLabel(), - srcCellAbsPt.getX() + overlapWidth, srcCellAbsPt.getY() + overlapHeight, + objVxCell = + (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), alias.getObjectId(), objVx.getLabel(), + srcObjVxCellAbsPt.getX() + overlapWid, srcObjVxCellAbsPt.getY() + overlapHt, DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); - objectVertex.setCell(ovCell); - mxICell edge = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), fieldName, null, srcCell, ovCell); - edgeMap.put(methodExec.getThisClassName() + "." + fieldName, new Edge(fieldName, TypeName.Create, edge)); + objVx.setCell(objVxCell); + mxICell edgeCell = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), fieldName, null, srcObjVxCell, objVxCell); + edgeMap.put(methodExec.getThisClassName() + "." + fieldName, new Edge(fieldName, TypeName.Create, edgeCell)); update(); } finally { mxgraph.getModel().endUpdate(); } } - MagnetRONAnimation ovCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - ovCellAnim.setTotalCycleCount(10); - ovCellAnim.setDelay(100); - ovCellAnim.init(ovCell, objectVertex.getInitialX(), objectVertex.getInitialY(), threadPoolExecutor); - ovCellAnim.syncPlay(); + MagnetRONAnimation objVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + objVxCellAnim.setTotalCycleCount(10); + objVxCellAnim.setDelay(100); + objVxCellAnim.init(objVxCell, objVx.getInitialX(), objVx.getInitialY(), threadPoolExecutor); + objVxCellAnim.syncPlay(); } /** @@ -288,20 +288,20 @@ * @param alias */ protected void createObjectVertexOnConstractorByFormalParameter(Alias alias) { - ObjectVertex objectVertex = objectToVertexMap.get(alias.getObjectId()); // Create mxICell of this ObjectVertex. + ObjectVertex objVx = objectToVertexMap.get(alias.getObjectId()); // Create mxICell of this ObjectVertex. MethodExecution methodExec = alias.getMethodExecution(); - mxICell ovCell = null; + mxICell objVxCell = null; // Position of srcCell is start point for ovCell to TranslateAnimation. String srcObjId = methodExec.getArguments().get(0).getId(); - mxICell srcCell = (mxICell)objectToVertexMap.get(srcObjId).getCell(); - double srcWidth = srcCell.getGeometry().getWidth(); - double srcHeight = srcCell.getGeometry().getHeight(); - double overlapWidth = srcWidth * Math.sqrt(2) * 0.1; - double overlapHeight = srcHeight - (srcHeight * Math.sqrt(2) * 0.1); - Point2D srcCellAbsPt = getAbsolutePointforCell(srcCell); + mxICell srcObjVxCell = (mxICell) objectToVertexMap.get(srcObjId).getCell(); + double srcObjVxCellWid = srcObjVxCell.getGeometry().getWidth(); + double srcObjVxCellHt = srcObjVxCell.getGeometry().getHeight(); + double overlapWidth = srcObjVxCellWid * Math.sqrt(2) * 0.1; + double overlapHeight = srcObjVxCellHt - (srcObjVxCellHt * Math.sqrt(2) * 0.1); + Point2D srcObjVxCellAbsPt = getAbsolutePointforCell(srcObjVxCell); - scrollPointsToVisible(srcCellAbsPt, objectVertex.getInitialPoint(), true); + scrollCellAndPointToVisible(srcObjVxCell, objVx.getInitialPoint(), 2); MethodInvocation methodInv; String fieldName = null; @@ -314,24 +314,24 @@ synchronized (mxgraph.getModel()) { try { // Creates a white mxIcell of ObjectVertex. - ovCell = - (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), objectVertex.getLabel(), objectVertex.getLabel(), - srcCellAbsPt.getX() + overlapWidth, srcCellAbsPt.getY() + overlapHeight, + objVxCell = + (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), objVx.getLabel(), objVx.getLabel(), + srcObjVxCellAbsPt.getX() + overlapWidth, srcObjVxCellAbsPt.getY() + overlapHeight, DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); - objectVertex.setCell(ovCell); - mxICell edge = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), fieldName, null, srcCell, ovCell); - edgeMap.put(methodExec.getThisClassName() + "." + fieldName, new Edge(fieldName, TypeName.Create, edge)); + objVx.setCell(objVxCell); + mxICell edgeCell = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), fieldName, null, srcObjVxCell, objVxCell); + edgeMap.put(methodExec.getThisClassName() + "." + fieldName, new Edge(fieldName, TypeName.Create, edgeCell)); update(); } finally { mxgraph.getModel().endUpdate(); } } - MagnetRONAnimation ovCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - ovCellAnim.setTotalCycleCount(10); - ovCellAnim.setDelay(100); - ovCellAnim.init(ovCell, objectVertex.getInitialX(), objectVertex.getInitialY(), threadPoolExecutor); - ovCellAnim.syncPlay(); + MagnetRONAnimation objVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + objVxCellAnim.setTotalCycleCount(10); + objVxCellAnim.setDelay(100); + objVxCellAnim.init(objVxCell, objVx.getInitialX(), objVx.getInitialY(), threadPoolExecutor); + objVxCellAnim.syncPlay(); } /** @@ -341,50 +341,49 @@ * @param fieldName */ protected void createObjectRefrence(FieldUpdate fieldUpdateStatement, String fieldName) { - // Create edge between srcCell and dstCell. + // Create edge between source ObjectVertex mxICell and destination ObjectVertex mxICell. String srcObjId = fieldUpdateStatement.getContainerObjId(); - mxICell srcCell = (mxICell)objectToVertexMap.get(srcObjId).getCell(); - Point2D srcCellAbsPt = getAbsolutePointforCell(srcCell); + mxICell srcObjVxCell = (mxICell) objectToVertexMap.get(srcObjId).getCell(); String dstObjId = fieldUpdateStatement.getValueObjId(); - ObjectVertex dstObjectVertex = objectToVertexMap.get(dstObjId); - mxICell dstCell = (mxICell)dstObjectVertex.getCell(); - Point2D dstCellAbsPt = getAbsolutePointforCell(dstCell); + ObjectVertex dstObjVx = objectToVertexMap.get(dstObjId); + mxICell dstObjVxCell = (mxICell) dstObjVx.getCell(); + Point2D dstObjVxCellAbsPt = getAbsolutePointforCell(dstObjVxCell); - scrollPointsToVisible(srcCellAbsPt, dstObjectVertex.getInitialPoint(), true); + scrollCellAndPointToVisible(srcObjVxCell, dstObjVx.getInitialPoint(), 2); mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - if (!dstCell.getParent().equals(getMxDefaultParent())) { + if (!dstObjVxCell.getParent().equals(getMxDefaultParent())) { // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. - dstCell.getParent().remove(dstCell); - dstCell.setParent(getMxDefaultParent()); + dstObjVxCell.getParent().remove(dstObjVxCell); + dstObjVxCell.setParent(getMxDefaultParent()); } - dstCell.getGeometry().setX(dstCellAbsPt.getX()); - dstCell.getGeometry().setY(dstCellAbsPt.getY()); - mxICell edge = + dstObjVxCell.getGeometry().setX(dstObjVxCellAbsPt.getX()); + dstObjVxCell.getGeometry().setY(dstObjVxCellAbsPt.getY()); + mxICell edgeCell = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), fieldUpdateStatement.getFieldName(), fieldName, - srcCell, dstCell); - edge.setStyle("strokeColor=red;"); + srcObjVxCell, dstObjVxCell); + edgeCell.setStyle("strokeColor=red;"); // mxgraph.orderCells(true, new Object[] {edge}); - edgeMap.put(fieldUpdateStatement.getFieldName(), new Edge(fieldName, TypeName.Reference, edge)); + edgeMap.put(fieldUpdateStatement.getFieldName(), new Edge(fieldName, TypeName.Reference, edgeCell)); } finally { mxgraph.getModel().endUpdate(); } } - MagnetRONAnimation dstCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - dstCellAnim.setTotalCycleCount(10); - dstCellAnim.setDelay(100); - dstCellAnim.init(dstCell, dstObjectVertex.getInitialX(), dstObjectVertex.getInitialY(), threadPoolExecutor); - dstCellAnim.syncPlay(); + MagnetRONAnimation dstObjVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + dstObjVxCellAnim.setTotalCycleCount(10); + dstObjVxCellAnim.setDelay(100); + dstObjVxCellAnim.init(dstObjVxCell, dstObjVx.getInitialX(), dstObjVx.getInitialY(), threadPoolExecutor); + dstObjVxCellAnim.syncPlay(); // If the animation didn't work to the end. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - dstCell.getGeometry().setX(dstObjectVertex.getInitialX()); - dstCell.getGeometry().setY(dstObjectVertex.getInitialY()); + dstObjVxCell.getGeometry().setX(dstObjVx.getInitialX()); + dstObjVxCell.getGeometry().setY(dstObjVx.getInitialY()); } finally { mxgraph.getModel().endUpdate(); } @@ -399,49 +398,48 @@ * @param destinationObjectId */ protected void createObjectRefrence(String sourceClassName, String sourceObjectId, String destinationObjectId) { - // Create edge between srcCell and dstCell. - mxICell srcCell = (mxICell)objectToVertexMap.get(sourceObjectId).getCell(); - Point2D srcCellAbsPt = getAbsolutePointforCell(srcCell); + // Create edge between source ObjectVertex mxICell and destination ObjectVertex mxICell. + mxICell srcObjVxCell = (mxICell)objectToVertexMap.get(sourceObjectId).getCell(); - ObjectVertex dstObjectVertex = objectToVertexMap.get(destinationObjectId); - mxICell dstCell = (mxICell) dstObjectVertex.getCell(); - Point2D dstCellAbsPt = getAbsolutePointforCell(dstCell); + ObjectVertex dstObjVx = objectToVertexMap.get(destinationObjectId); + mxICell dstObjVxCell = (mxICell) dstObjVx.getCell(); + Point2D dstObjVxCellAbsPt = getAbsolutePointforCell(dstObjVxCell); - scrollPointsToVisible(srcCellAbsPt, dstObjectVertex.getInitialPoint(), true); + scrollCellAndPointToVisible(srcObjVxCell, dstObjVx.getInitialPoint(), 2); // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - if (!dstCell.getParent().equals(getMxDefaultParent())) { + if (!dstObjVxCell.getParent().equals(getMxDefaultParent())) { // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. - dstCell.getParent().remove(dstCell); - dstCell.setParent(getMxDefaultParent()); + dstObjVxCell.getParent().remove(dstObjVxCell); + dstObjVxCell.setParent(getMxDefaultParent()); } - dstCell.getGeometry().setX(dstCellAbsPt.getX()); - dstCell.getGeometry().setY(dstCellAbsPt.getY()); - mxICell edge = + dstObjVxCell.getGeometry().setX(dstObjVxCellAbsPt.getX()); + dstObjVxCell.getGeometry().setY(dstObjVxCellAbsPt.getY()); + mxICell edgeCell = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), destinationObjectId, null, - srcCell, dstCell); - edge.setStyle("strokeColor=red;"); - edgeMap.put(destinationObjectId, new Edge(null, TypeName.Reference, edge)); + srcObjVxCell, dstObjVxCell); + edgeCell.setStyle("strokeColor=red;"); + edgeMap.put(destinationObjectId, new Edge(null, TypeName.Reference, edgeCell)); } finally { mxgraph.getModel().endUpdate(); } } - MagnetRONAnimation dstCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - dstCellAnim.setTotalCycleCount(10); - dstCellAnim.setDelay(100); - dstCellAnim.init(dstCell, dstObjectVertex.getInitialX(), dstObjectVertex.getInitialY(), threadPoolExecutor); - dstCellAnim.syncPlay(); + MagnetRONAnimation dstObjVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + dstObjVxCellAnim.setTotalCycleCount(10); + dstObjVxCellAnim.setDelay(100); + dstObjVxCellAnim.init(dstObjVxCell, dstObjVx.getInitialX(), dstObjVx.getInitialY(), threadPoolExecutor); + dstObjVxCellAnim.syncPlay(); // If the animation didn't work to the end. // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - dstCell.getGeometry().setX(dstObjectVertex.getInitialX()); - dstCell.getGeometry().setY(dstObjectVertex.getInitialY()); + dstObjVxCell.getGeometry().setX(dstObjVx.getInitialX()); + dstObjVxCell.getGeometry().setY(dstObjVx.getInitialY()); } finally { mxgraph.getModel().endUpdate(); } @@ -454,17 +452,17 @@ * @param alias */ protected void moveObjectVertex(Alias alias) { - // source {@code ObjectVertex} + // source ObjectVertex String objId = alias.getObjectId(); - ObjectVertex srcObjectVertex = objectToVertexMap.get(objId); + ObjectVertex srcObjVx = objectToVertexMap.get(objId); MethodExecution methodExec = alias.getMethodExecution(); if (!methodExecToVertexMap.containsKey(methodExec) && methodExec.isStatic()) { createMethodExecutionVertex(objId, methodExec.getSignature(), methodExec); sleepMainThread(POSTPONE_ANIMATION_MILLIS); } - // destination {@code ObjectVertex} - MethodExecutionVertex dstMethodExecVertex = methodExecToVertexMap.get(methodExec); - moveObjectVertex(alias, srcObjectVertex, dstMethodExecVertex); + // destination ObjectVertex + MethodExecutionVertex dstMethodExecVx = methodExecToVertexMap.get(methodExec); + moveObjectVertex(alias, srcObjVx, dstMethodExecVx); updateObjectVertices(); } @@ -505,23 +503,23 @@ * @param destinationMethodExecutionVertex */ private void moveLocalObjectVertex(MethodExecution callerMethodExecution, ObjectVertex sourceObjectVertex, MethodExecutionVertex destinationMethodExecutionVertex) { - mxICell srcObjectVertexCell = (mxICell)sourceObjectVertex.getCell(); - mxICell dstMethodExecVertexCell = (mxICell) destinationMethodExecutionVertex.getCell(); + mxICell srcObjVxCell = (mxICell)sourceObjectVertex.getCell(); + mxICell dstMethodExecVxCell = (mxICell) destinationMethodExecutionVertex.getCell(); - if (srcObjectVertexCell.equals(dstMethodExecVertexCell.getParent())) { + if (srcObjVxCell.equals(dstMethodExecVxCell.getParent())) { return; } - scrollCellsToVisible(srcObjectVertexCell, dstMethodExecVertexCell); + scrollCellsToVisible(dstMethodExecVxCell.getParent(), srcObjVxCell); // Remove source ObjectVertex from Locals and Arguments of caller MethodExecutionVertex. if (methodExecToVertexMap.containsKey(callerMethodExecution)) { - MethodExecutionVertex callerMethodExecVertex = methodExecToVertexMap.get(callerMethodExecution); - if (callerMethodExecVertex.getLocals().contains(sourceObjectVertex)) { - callerMethodExecVertex.getLocals().remove(sourceObjectVertex); + MethodExecutionVertex callerMethodExecVx = methodExecToVertexMap.get(callerMethodExecution); + if (callerMethodExecVx.getLocals().contains(sourceObjectVertex)) { + callerMethodExecVx.getLocals().remove(sourceObjectVertex); } - if (callerMethodExecVertex.getArguments().contains(sourceObjectVertex)) { - callerMethodExecVertex.getArguments().remove(sourceObjectVertex); + if (callerMethodExecVx.getArguments().contains(sourceObjectVertex)) { + callerMethodExecVx.getArguments().remove(sourceObjectVertex); } } @@ -529,61 +527,61 @@ mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - double srcCellCoordX = srcObjectVertexCell.getGeometry().getX(); - double srcCellCoordY = srcObjectVertexCell.getGeometry().getY(); + double srcObjVxCellX = srcObjVxCell.getGeometry().getX(); + double srcObjVxCellY = srcObjVxCell.getGeometry().getY(); // TODO: Confirm why not .equals(getMxDefaultParent()). - if(srcObjectVertexCell.getParent().getValue() != null) { - Point2D absolutePointSourceCell = getAbsolutePointforCell(srcObjectVertexCell); - srcCellCoordX = absolutePointSourceCell.getX(); - srcCellCoordY = absolutePointSourceCell.getY(); - srcObjectVertexCell.getParent().remove(srcObjectVertexCell); + if(srcObjVxCell.getParent().getValue() != null) { + Point2D srcObjVxCellAbsPt = getAbsolutePointforCell(srcObjVxCell); + srcObjVxCellX = srcObjVxCellAbsPt.getX(); + srcObjVxCellY = srcObjVxCellAbsPt.getY(); + srcObjVxCell.getParent().remove(srcObjVxCell); } - mxgraph.orderCells(true, new Object[] {srcObjectVertexCell}); - if (srcObjectVertexCell.getParent() == null || !srcObjectVertexCell.getParent().equals(dstMethodExecVertexCell.getParent())) { + mxgraph.orderCells(true, new Object[] {srcObjVxCell}); + if (srcObjVxCell.getParent() == null || !srcObjVxCell.getParent().equals(dstMethodExecVxCell.getParent())) { // TODO: Confirm why not need following comment out. // if (srcCell.getParent() != null) srcCell.getParent().remove(srcCell); - srcObjectVertexCell.setParent(dstMethodExecVertexCell.getParent()); - dstMethodExecVertexCell.getParent().insert(srcObjectVertexCell); + srcObjVxCell.setParent(dstMethodExecVxCell.getParent()); + dstMethodExecVxCell.getParent().insert(srcObjVxCell); } - Point2D dstCellAbsPt = getAbsolutePointforCell(srcObjectVertexCell.getParent()); - srcObjectVertexCell.getGeometry().setX(srcCellCoordX - dstCellAbsPt.getX()); - srcObjectVertexCell.getGeometry().setY(srcCellCoordY - dstCellAbsPt.getY()); + Point2D dstObjVxCellAbsPt = getAbsolutePointforCell(srcObjVxCell.getParent()); + srcObjVxCell.getGeometry().setX(srcObjVxCellX - dstObjVxCellAbsPt.getX()); + srcObjVxCell.getGeometry().setY(srcObjVxCellY - dstObjVxCellAbsPt.getY()); } finally { mxgraph.getModel().endUpdate(); } } - int sizeScale = destinationMethodExecutionVertex.getLocals().size(); - double srcCellWidth = srcObjectVertexCell.getGeometry().getWidth(); - double dstCellHeight = dstMethodExecVertexCell.getGeometry().getHeight(); - double srcCellDstX = dstMethodExecVertexCell.getGeometry().getX() - (srcCellWidth / Math.sqrt(2.5)) + (srcCellWidth * sizeScale); - double srcCellDstY = dstMethodExecVertexCell.getGeometry().getY() + dstCellHeight; + int dstMethodExecVxLocalsSize = destinationMethodExecutionVertex.getLocals().size(); + double srcObjVxCellWid = srcObjVxCell.getGeometry().getWidth(); + double dstMethodExecVxCellHt = dstMethodExecVxCell.getGeometry().getHeight(); + double srcObjVxCellDstX = dstMethodExecVxCell.getGeometry().getX() - (srcObjVxCellWid / Math.sqrt(2.5)) + (srcObjVxCellWid * dstMethodExecVxLocalsSize); + double srcObjVxCellDstY = dstMethodExecVxCell.getGeometry().getY() + dstMethodExecVxCellHt; - MagnetRONAnimation srcCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - srcCellAnim.setTotalCycleCount(10); - srcCellAnim.setDelay(100); - srcCellAnim.init(srcObjectVertexCell, srcCellDstX, srcCellDstY, threadPoolExecutor); - srcCellAnim.syncPlay(); + MagnetRONAnimation srcObjVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + srcObjVxCellAnim.setTotalCycleCount(10); + srcObjVxCellAnim.setDelay(100); + srcObjVxCellAnim.init(srcObjVxCell, srcObjVxCellDstX, srcObjVxCellDstY, threadPoolExecutor); + srcObjVxCellAnim.syncPlay(); // If the animation didn't work to the end. // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { -// if (!srcObjectVertexCell.getParent().equals(dstMethodExecVertexCell.getParent())) { -// srcObjectVertexCell.getParent().remove(srcObjectVertexCell); -// srcObjectVertexCell.setParent(dstMethodExecVertexCell.getParent()); -// dstMethodExecVertexCell.getParent().insert(srcObjectVertexCell); -// } - srcObjectVertexCell.getGeometry().setX(dstMethodExecVertexCell.getGeometry().getX() - (srcCellWidth / Math.sqrt(2.5)) + (srcCellWidth * sizeScale)); - srcObjectVertexCell.getGeometry().setY(dstMethodExecVertexCell.getGeometry().getY() + dstCellHeight); - destinationMethodExecutionVertex.getLocals().add(sourceObjectVertex); + if (!srcObjVxCell.getParent().equals(dstMethodExecVxCell.getParent())) { + srcObjVxCell.getParent().remove(srcObjVxCell); + srcObjVxCell.setParent(dstMethodExecVxCell.getParent()); + dstMethodExecVxCell.getParent().insert(srcObjVxCell); + } + srcObjVxCell.getGeometry().setX(srcObjVxCellDstX); + srcObjVxCell.getGeometry().setY(srcObjVxCellDstY); } finally { mxgraph.getModel().endUpdate(); } } + destinationMethodExecutionVertex.getLocals().add(sourceObjectVertex); } /** @@ -594,142 +592,149 @@ * @param destinationMethodExecutionVertex */ protected void moveArgumentObjectVertex(MethodExecution methodExecution, ObjectVertex sourceObjectVertex, MethodExecutionVertex destinationMethodExecutionVertex) { - mxICell srcCell = (mxICell)sourceObjectVertex.getCell(); - mxICell dstCell = (mxICell) destinationMethodExecutionVertex.getCell(); + mxICell srcObjVxCell = (mxICell)sourceObjectVertex.getCell(); + mxICell dstMethodExecVxCell = (mxICell) destinationMethodExecutionVertex.getCell(); - // Remove source {@code VertexObject} from Locals and Arguments of {@code MethodExecution}'s Vertex. + // Remove source VertexObject from Locals and Arguments of MethodExecutionVertex. MethodExecution callerMethodExec = methodExecution.getCallerMethodExecution(); - if (methodExecToVertexMap.containsKey(callerMethodExec) && methodExecToVertexMap.get(callerMethodExec).getLocals().contains(sourceObjectVertex)) { - methodExecToVertexMap.get(callerMethodExec).getLocals().remove(sourceObjectVertex); + if (methodExecToVertexMap.containsKey(callerMethodExec)) { + MethodExecutionVertex callerMethodExecVx = methodExecToVertexMap.get(callerMethodExec); + mxICell callerMethodExecVxCell = (mxICell) callerMethodExecVx.getCell(); + scrollCellsToVisible(callerMethodExecVxCell.getParent(), dstMethodExecVxCell.getParent(), 2); + if (callerMethodExecVx.getLocals().contains(sourceObjectVertex)) { + callerMethodExecVx.getLocals().remove(sourceObjectVertex); + } + if (callerMethodExecVx.getArguments().contains(sourceObjectVertex)) { + callerMethodExecVx.getArguments().remove(sourceObjectVertex); + } + } else { + scrollCellsToVisible(srcObjVxCell, dstMethodExecVxCell.getParent(), 2); } - if (methodExecToVertexMap.containsKey(callerMethodExec) && methodExecToVertexMap.get(callerMethodExec).getArguments().contains(sourceObjectVertex)) { - methodExecToVertexMap.get(callerMethodExec).getArguments().remove(sourceObjectVertex); - } - - int time = destinationMethodExecutionVertex.getArguments().size(); - double srcCoordX = srcCell.getGeometry().getX(); - double srcCoordY = srcCell.getGeometry().getY(); + int dstMethodExecVxArgumentsSize = destinationMethodExecutionVertex.getArguments().size(); + double srcObjVxCellX = srcObjVxCell.getGeometry().getX(); + double srcObjVxCellY = srcObjVxCell.getGeometry().getY(); // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - if(srcCell.getParent().getValue() != null) { - Point2D srcCellAbsPt = getAbsolutePointforCell(srcCell); - srcCoordX = srcCellAbsPt.getX(); - srcCoordY = srcCellAbsPt.getY(); - srcCell.getParent().remove(srcCell); + if(srcObjVxCell.getParent().getValue() != null) { + Point2D srcObjVxCellAbsPt = getAbsolutePointforCell(srcObjVxCell); + srcObjVxCellX = srcObjVxCellAbsPt.getX(); + srcObjVxCellY = srcObjVxCellAbsPt.getY(); + srcObjVxCell.getParent().remove(srcObjVxCell); } } finally { mxgraph.getModel().endUpdate(); } } - if (!isParent(dstCell, srcCell)) { + if (!isParent(dstMethodExecVxCell, srcObjVxCell)) { // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - mxgraph.orderCells(true, new Object[] {srcCell}); - if (srcCell.getParent() == null || !srcCell.getParent().equals(dstCell.getParent())) { + mxgraph.orderCells(true, new Object[] {srcObjVxCell}); + if (srcObjVxCell.getParent() == null || !srcObjVxCell.getParent().equals(dstMethodExecVxCell.getParent())) { // TODO: Confirm why not need following comment out. // if (srcCell.getParent() != null) srcCell.getParent().remove(srcCell); - srcCell.setParent(dstCell.getParent()); - dstCell.getParent().insert(srcCell); + srcObjVxCell.setParent(dstMethodExecVxCell.getParent()); + dstMethodExecVxCell.getParent().insert(srcObjVxCell); } - Point2D srcParentCellAbsPt = getAbsolutePointforCell(srcCell.getParent()); - srcCell.getGeometry().setX(srcCoordX - srcParentCellAbsPt.getX()); - srcCell.getGeometry().setY(srcCoordY - srcParentCellAbsPt.getY()); + Point2D srcObjVxCellParentAbsPt = getAbsolutePointforCell(srcObjVxCell.getParent()); + srcObjVxCell.getGeometry().setX(srcObjVxCellX - srcObjVxCellParentAbsPt.getX()); + srcObjVxCell.getGeometry().setY(srcObjVxCellY - srcObjVxCellParentAbsPt.getY()); } finally { mxgraph.getModel().endUpdate(); } } - double srcCellWidth = srcCell.getGeometry().getWidth(); - double srcCellHeight = srcCell.getGeometry().getHeight(); - double overlapWidth = srcCellWidth - (srcCellWidth * Math.sqrt(2) * 0.1); - double overlapHeight = srcCellHeight - (srcCellHeight * Math.sqrt(2) * 0.1); - - MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - vertexAnim.setTotalCycleCount(10); - vertexAnim.setDelay(100); - vertexAnim.init(srcCell, - dstCell.getGeometry().getX() - overlapWidth, dstCell.getGeometry().getY() - overlapHeight + (srcCellHeight * time), - threadPoolExecutor); + double srcObjVxCellWid = srcObjVxCell.getGeometry().getWidth(); + double srcObjVxCellHt = srcObjVxCell.getGeometry().getHeight(); + double overlapWid = srcObjVxCellWid - (srcObjVxCellWid * Math.sqrt(2) * 0.1); + double overlapHt = srcObjVxCellHt - (srcObjVxCellHt * Math.sqrt(2) * 0.1); + Point2D srcObjVxCellDstPt = + new Point2D.Double(dstMethodExecVxCell.getGeometry().getX() - overlapWid, + dstMethodExecVxCell.getGeometry().getY() - overlapHt + (srcObjVxCellHt * dstMethodExecVxArgumentsSize)); + + MagnetRONAnimation srcObjVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + srcObjVxCellAnim.setTotalCycleCount(10); + srcObjVxCellAnim.setDelay(100); + srcObjVxCellAnim.init(srcObjVxCell, srcObjVxCellDstPt.getX(), srcObjVxCellDstPt.getY(), threadPoolExecutor); sleepMainThread(POSTPONE_ANIMATION_MILLIS); - vertexAnim.syncPlay(); + srcObjVxCellAnim.syncPlay(); + // If the animation didn't work to the end. // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - srcCell.getGeometry().setX(dstCell.getGeometry().getX() - overlapWidth); - srcCell.getGeometry().setY(dstCell.getGeometry().getY() - overlapHeight + (srcCellHeight * time)); + srcObjVxCell.getGeometry().setX(srcObjVxCellDstPt.getX()); + srcObjVxCell.getGeometry().setY(srcObjVxCellDstPt.getY()); } finally { mxgraph.getModel().endUpdate(); } } - destinationMethodExecutionVertex.getArguments().add(sourceObjectVertex); } else { // TODO: �d�l��̃o�O�A���[�v������ // ���� ObjectVertex - Point2D srcCellAbsPt = getAbsolutePointforCell(srcCell); - Point2D dstParentCellAbsPt = getAbsolutePointforCell(dstCell.getParent()); + Point2D srcObjVxCellAbsPt = getAbsolutePointforCell(srcObjVxCell); + mxICell dstMethodExecVxParentCell = dstMethodExecVxCell.getParent(); + Point2D dstMethodExecVxParentCellAbsPt = getAbsolutePointforCell(dstMethodExecVxParentCell); // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - if (dstCell.getParent() != null - || dstCell.getParent().getParent() != null - || srcCell.getParent() != null - || !dstCell.getParent().getParent().equals(getMxDefaultParent()) - || !srcCell.getParent().equals(dstCell.getParent())) { - srcCell.remove(dstCell.getParent()); - dstCell.getParent().setParent(getMxDefaultParent()); + if ((dstMethodExecVxParentCell != null && dstMethodExecVxParentCell.getParent() != null) + || srcObjVxCell.getParent() != null + || !dstMethodExecVxParentCell.getParent().equals(getMxDefaultParent()) + || !srcObjVxCell.getParent().equals(dstMethodExecVxParentCell)) { + srcObjVxCell.remove(dstMethodExecVxParentCell); + dstMethodExecVxParentCell.setParent(getMxDefaultParent()); // TODO: Confirm why not need following comment out. // dstCell.getParent().remove(dstCell); // TODO: Confirm why not need following comment out. // srcCell.getParent().remove(srcCell); - srcCell.setParent(dstCell.getParent()); - dstCell.getParent().insert(srcCell); + srcObjVxCell.setParent(dstMethodExecVxParentCell); + dstMethodExecVxParentCell.insert(srcObjVxCell); } - dstCell.getParent().getGeometry().setX(dstParentCellAbsPt.getX()); - dstCell.getParent().getGeometry().setY(dstParentCellAbsPt.getY()); - srcCell.getGeometry().setX(srcCellAbsPt.getX() - dstParentCellAbsPt.getX()); - srcCell.getGeometry().setY(srcCellAbsPt.getY() - dstParentCellAbsPt.getY()); - srcCell.setStyle("opacity=50;shape=ellipse"); + dstMethodExecVxParentCell.getGeometry().setX(dstMethodExecVxParentCellAbsPt.getX()); + dstMethodExecVxParentCell.getGeometry().setY(dstMethodExecVxParentCellAbsPt.getY()); + srcObjVxCell.getGeometry().setX(srcObjVxCellAbsPt.getX() - dstMethodExecVxParentCellAbsPt.getX()); + srcObjVxCell.getGeometry().setY(srcObjVxCellAbsPt.getY() - dstMethodExecVxParentCellAbsPt.getY()); + srcObjVxCell.setStyle("opacity=50;shape=ellipse"); } finally { mxgraph.getModel().endUpdate(); } } - double srcCellWidth = srcCell.getGeometry().getWidth(); - double srcCellHeight = srcCell.getGeometry().getHeight(); - double overlapWidth = srcCellWidth - (srcCellWidth * Math.sqrt(2) * 0.1); - double overlapHeight = srcCellHeight - (srcCellHeight * Math.sqrt(2) * 0.1); + double srcObjVxCellWid = srcObjVxCell.getGeometry().getWidth(); + double srcObjVxCellHt = srcObjVxCell.getGeometry().getHeight(); + double overlapWid = srcObjVxCellWid - (srcObjVxCellWid * Math.sqrt(2) * 0.1); + double overlapHt = srcObjVxCellHt - (srcObjVxCellHt * Math.sqrt(2) * 0.1); + double srcObjVxCellDstX = dstMethodExecVxCell.getGeometry().getX() - overlapWid + (srcObjVxCellWid * dstMethodExecVxArgumentsSize); + double srcObjVxCellDstY = dstMethodExecVxCell.getGeometry().getY() - overlapHt + (srcObjVxCellHt * dstMethodExecVxArgumentsSize); + + MagnetRONAnimation srcObjVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + srcObjVxCellAnim.setTotalCycleCount(10); + srcObjVxCellAnim.setDelay(100); + srcObjVxCellAnim.init(srcObjVxCell, srcObjVxCellDstX, srcObjVxCellDstY, threadPoolExecutor); + srcObjVxCellAnim.syncPlay(); - MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - vertexAnim.setTotalCycleCount(10); - vertexAnim.setDelay(100); - vertexAnim.init(srcCell, - dstCell.getGeometry().getX() - overlapWidth + (srcCellWidth * time), dstCell.getGeometry().getY() - overlapHeight + (srcCellHeight * time), - threadPoolExecutor); - vertexAnim.syncPlay(); - + // If the animation didn't work to the end. // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - srcCell.getGeometry().setX(dstCell.getGeometry().getX() - overlapWidth + (srcCellWidth * time)); - srcCell.getGeometry().setY(dstCell.getGeometry().getY() - overlapHeight + (srcCellHeight * time)); + srcObjVxCell.getGeometry().setX(srcObjVxCellDstX); + srcObjVxCell.getGeometry().setY(srcObjVxCellDstY); } finally { mxgraph.getModel().endUpdate(); } } - destinationMethodExecutionVertex.getArguments().add(sourceObjectVertex); } } @@ -749,70 +754,74 @@ * @param destinationMethodExecutionVertex */ private void moveActualArgumentObjectVertex(MethodExecution methodExecution, ObjectVertex sourceObjectVertex, MethodExecutionVertex destinationMethodExecutionVertex) { - mxICell srcCell = (mxICell)sourceObjectVertex.getCell(); - mxICell dstCell = (mxICell) destinationMethodExecutionVertex.getCell(); + mxICell srcObjVxCell = (mxICell)sourceObjectVertex.getCell(); + mxICell dstMethodExecVxCell = (mxICell) destinationMethodExecutionVertex.getCell(); - if (srcCell.equals(dstCell.getParent())) { - System.out.println("Nothing to moveActualArgumentObjectVertex()."); + if (srcObjVxCell.equals(dstMethodExecVxCell.getParent())) { return; } - // Remove sourceVertex from Locals and Arguments of MethodExecution's Vertex. - if (methodExecToVertexMap.containsKey(methodExecution) && methodExecToVertexMap.get(methodExecution).getLocals().contains(sourceObjectVertex)) { - methodExecToVertexMap.get(methodExecution).getLocals().remove(sourceObjectVertex); + // Remove source ObjectVertex from Locals and Arguments of MethodExecutionVertex. + if (methodExecToVertexMap.containsKey(methodExecution)) { + if (methodExecToVertexMap.get(methodExecution).getLocals().contains(sourceObjectVertex)) { + methodExecToVertexMap.get(methodExecution).getLocals().remove(sourceObjectVertex); + } + if (methodExecToVertexMap.get(methodExecution).getArguments().contains(sourceObjectVertex)) { + methodExecToVertexMap.get(methodExecution).getArguments().remove(sourceObjectVertex); + } } - - if (methodExecToVertexMap.containsKey(methodExecution) && methodExecToVertexMap.get(methodExecution).getArguments().contains(sourceObjectVertex)) { - methodExecToVertexMap.get(methodExecution).getArguments().remove(sourceObjectVertex); - } - - int time = destinationMethodExecutionVertex.getLocals().size(); - double srcCellCoordX = srcCell.getGeometry().getX(); - double srcCellCoordY = srcCell.getGeometry().getY(); + + int dstMethodExecVxLocalsSize = destinationMethodExecutionVertex.getLocals().size(); + double srcObjVxCellX = srcObjVxCell.getGeometry().getX(); + double srcObjVxCellY = srcObjVxCell.getGeometry().getY(); MagnetRONAnimation.waitAnimationEnd(); + scrollCellsToVisible(srcObjVxCell, dstMethodExecVxCell.getParent(), 2); // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - if(srcCell.getParent().getValue() != null) { - Point2D srcCellAbsPt = getAbsolutePointforCell(srcCell); - srcCellCoordX = srcCellAbsPt.getX(); - srcCellCoordY = srcCellAbsPt.getY(); - srcCell.getParent().remove(srcCell); + if(srcObjVxCell.getParent().getValue() != null) { + Point2D srcObjVxCellAbsPt = getAbsolutePointforCell(srcObjVxCell); + srcObjVxCellX = srcObjVxCellAbsPt.getX(); + srcObjVxCellY = srcObjVxCellAbsPt.getY(); + srcObjVxCell.getParent().remove(srcObjVxCell); } - if (srcCell.getParent() == null || !srcCell.getParent().equals(dstCell.getParent())) { + if (srcObjVxCell.getParent() == null + || !srcObjVxCell.getParent().equals(dstMethodExecVxCell.getParent())) { // TODO: Confirm why not need following comment out. // if (srcCell.getParent() != null) srcCell.getParent().remove(srcCell); - srcCell.setParent(dstCell.getParent()); - dstCell.getParent().insert(srcCell); + srcObjVxCell.setParent(dstMethodExecVxCell.getParent()); + dstMethodExecVxCell.getParent().insert(srcObjVxCell); } - Point2D srcParentCellAbsPt = getAbsolutePointforCell(srcCell.getParent()); - srcCell.getGeometry().setX(srcCellCoordX - srcParentCellAbsPt.getX()); - srcCell.getGeometry().setY(srcCellCoordY - srcParentCellAbsPt.getY()); + Point2D srcObjVxCellParentAbsPt = getAbsolutePointforCell(srcObjVxCell.getParent()); + srcObjVxCell.getGeometry().setX(srcObjVxCellX - srcObjVxCellParentAbsPt.getX()); + srcObjVxCell.getGeometry().setY(srcObjVxCellY - srcObjVxCellParentAbsPt.getY()); } finally { mxgraph.getModel().endUpdate(); } } - double srcCellWidth = srcCell.getGeometry().getWidth(); - double dstCellHeight = dstCell.getGeometry().getHeight(); - Point2D srcCellDstPoint = new Point2D.Double(dstCell.getGeometry().getX() - (srcCellWidth / Math.sqrt(3)) + (srcCellWidth * time), - dstCell.getGeometry().getY() + dstCellHeight); - MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - vertexAnim.setTotalCycleCount(10); - vertexAnim.setDelay(100); - vertexAnim.init(srcCell, srcCellDstPoint.getX(), srcCellDstPoint.getY(), threadPoolExecutor); - vertexAnim.syncPlay(); + double srcObjVxCellWid = srcObjVxCell.getGeometry().getWidth(); + double dstMethodExecVxCellHt = dstMethodExecVxCell.getGeometry().getHeight(); + Point2D srcObjVxCellDstPt = new Point2D.Double(dstMethodExecVxCell.getGeometry().getX() - (srcObjVxCellWid / Math.sqrt(3)) + (srcObjVxCellWid * dstMethodExecVxLocalsSize), + dstMethodExecVxCell.getGeometry().getY() + dstMethodExecVxCellHt); + + MagnetRONAnimation srcObjVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + srcObjVxCellAnim.setTotalCycleCount(10); + srcObjVxCellAnim.setDelay(100); + srcObjVxCellAnim.init(srcObjVxCell, srcObjVxCellDstPt.getX(), srcObjVxCellDstPt.getY(), threadPoolExecutor); + srcObjVxCellAnim.syncPlay(); + // If the animation didn't work to the end. // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - srcCell.getGeometry().setX(srcCellDstPoint.getX()); - srcCell.getGeometry().setY(srcCellDstPoint.getY()); + srcObjVxCell.getGeometry().setX(srcObjVxCellDstPt.getX()); + srcObjVxCell.getGeometry().setY(srcObjVxCellDstPt.getY()); } finally { mxgraph.getModel().endUpdate(); } @@ -826,71 +835,71 @@ */ protected void updateObjectVertices() { MagnetRONAnimation.waitAnimationEnd(); - for (ObjectVertex ov: objectToVertexMap.values()) { - mxICell ovCell = (mxICell) ov.getCell(); - if (ovCell == null) continue; - Dimension2D curDim = new Dimension((int) ovCell.getGeometry().getWidth(), (int) ovCell.getGeometry().getHeight()); + for (ObjectVertex objVx: objectToVertexMap.values()) { + mxICell objVxCell = (mxICell) objVx.getCell(); + if (objVxCell == null) continue; + Dimension2D curDim = new Dimension((int) objVxCell.getGeometry().getWidth(), (int) objVxCell.getGeometry().getHeight()); int sizeScale = 0; - for (int i = 0; i < ovCell.getChildCount(); i++) { - if (!ovCell.getChildAt(i).getId().contains("clone")) sizeScale++; + for (int i = 0; i < objVxCell.getChildCount(); i++) { + if (!objVxCell.getChildAt(i).getId().contains("clone")) sizeScale++; } if (sizeScale == 0) sizeScale = 1; Dimension2D dstDim = new Dimension((int) DEFAULT_OBJECT_VERTEX_SIZE.getWidth() * sizeScale, (int) DEFAULT_OBJECT_VERTEX_SIZE.getHeight() * sizeScale); - Point2D dstPt = new Point2D.Double(ovCell.getGeometry().getX(), ovCell.getGeometry().getY()); + Point2D dstPt = new Point2D.Double(objVxCell.getGeometry().getX(), objVxCell.getGeometry().getY()); if(!curDim.equals(dstDim)) { // Test code (will be deleted) - System.out.println(TAG + ": Update size of ObjectVertex " + ovCell.getId() + ". " + curDim.getWidth() + "->" + dstDim.getWidth()); - if (!ovCell.getParent().equals(getMxDefaultParent()) - && (ovCell.getChildCount() != 0 || (curDim.getWidth() > dstDim.getWidth() && curDim.getHeight() > dstDim.getHeight()))) { + System.out.println(TAG + ": Update size of ObjectVertex " + objVxCell.getId() + ". " + curDim.getWidth() + "->" + dstDim.getWidth()); + if (!objVxCell.getParent().equals(getMxDefaultParent()) + && (objVxCell.getChildCount() != 0 || (curDim.getWidth() > dstDim.getWidth() && curDim.getHeight() > dstDim.getHeight()))) { double overlapX = (dstDim.getWidth() - curDim.getWidth()) / 2 / Math.sqrt(2); double overlapY = (dstDim.getHeight() - curDim.getHeight()) / 2 / Math.sqrt(2); - dstPt.setLocation(ovCell.getGeometry().getX() - overlapX, ovCell.getGeometry().getY() + overlapY); + dstPt.setLocation(objVxCell.getGeometry().getX() - overlapX, objVxCell.getGeometry().getY() + overlapY); // If two and over ObjectVertex are arranged side by side as an argument or local, shift the Y coordinate of ObjectVertex slightly. for (MethodExecutionVertex methodExecVertex: methodExecToVertexMap.values()) { List locals = methodExecVertex.getLocals(); - if (locals != null && locals.contains(ov) && locals.indexOf(ov) >= 1) { - overlapY = (dstDim.getHeight() - ovCell.getGeometry().getHeight()) / 2; - dstPt.setLocation(dstPt.getX(), ovCell.getGeometry().getY() + overlapY); + if (locals != null && locals.contains(objVx) && locals.indexOf(objVx) >= 1) { + overlapY = (dstDim.getHeight() - objVxCell.getGeometry().getHeight()) / 2; + dstPt.setLocation(dstPt.getX(), objVxCell.getGeometry().getY() + overlapY); break; } List arguments = methodExecVertex.getArguments(); - if (arguments != null && arguments.contains(ov)) { - dstPt.setLocation(dstPt.getX(), ovCell.getGeometry().getY() - overlapY); + if (arguments != null && arguments.contains(objVx)) { + dstPt.setLocation(dstPt.getX(), objVxCell.getGeometry().getY() - overlapY); break; } } } dstPt.setLocation(dstPt.getX() - (dstDim.getWidth() - curDim.getWidth()) / 2, dstPt.getY() - (dstDim.getHeight() - curDim.getHeight()) / 2); // Test code (will be deleted) - System.out.println(TAG + ": Translate " + ovCell.getId() + ". Current point=" + ovCell.getGeometry().getPoint() + ", Destination Point=" + dstPt); - MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - vertexAnim.setTotalCycleCount(10); - vertexAnim.setDelay(100); - vertexAnim.init(ovCell, dstPt.getX(), dstPt.getY(), threadPoolExecutor); - vertexAnim.play(); - MagnetRONAnimation vertexResizeAnim = new VertexResizeAnimation(mxgraph, getGraphComponent()); - vertexResizeAnim.setTotalCycleCount(10); - vertexResizeAnim.setDelay(100); - vertexResizeAnim.init(ovCell, dstDim.getWidth(), dstDim.getHeight(), threadPoolExecutor); - vertexResizeAnim.play(); - for (int i = 0; i < ovCell.getChildCount(); i++) { - mxICell childCell = ovCell.getChildAt(i); - double childCellCurX = childCell.getGeometry().getX(); - double childCellCurY = childCell.getGeometry().getY(); + System.out.println(TAG + ": Translate " + objVxCell.getId() + ". Current point=" + objVxCell.getGeometry().getPoint() + ", Destination Point=" + dstPt); + MagnetRONAnimation objVxCellTransAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + objVxCellTransAnim.setTotalCycleCount(10); + objVxCellTransAnim.setDelay(100); + objVxCellTransAnim.init(objVxCell, dstPt.getX(), dstPt.getY(), threadPoolExecutor); + objVxCellTransAnim.play(); + MagnetRONAnimation objVxCellResizeAnim = new VertexResizeAnimation(mxgraph, getGraphComponent()); + objVxCellResizeAnim.setTotalCycleCount(10); + objVxCellResizeAnim.setDelay(100); + objVxCellResizeAnim.init(objVxCell, dstDim.getWidth(), dstDim.getHeight(), threadPoolExecutor); + objVxCellResizeAnim.play(); + for (int i = 0; i < objVxCell.getChildCount(); i++) { + mxICell objVxCellChild = objVxCell.getChildAt(i); + double childCellCurX = objVxCellChild.getGeometry().getX(); + double childCellCurY = objVxCellChild.getGeometry().getY(); Point2D childDstPt = new Point2D.Double(childCellCurX + (dstDim.getWidth() - curDim.getWidth()) / 2, childCellCurY + (dstDim.getHeight() - curDim.getHeight()) / 2); // Test code (will be deleted) - System.out.println(TAG + ": Translate " + childCell.getId() + " of " + ovCell.getId() + ". Current point=" + childCell.getGeometry().getPoint() + ", Destination Point=" + childDstPt); - MagnetRONAnimation childVertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - childVertexAnim.setTotalCycleCount(10); - childVertexAnim.setDelay(100); - childVertexAnim.init(childCell, childDstPt.getX(), childDstPt.getY(), threadPoolExecutor); - childVertexAnim.play(); + System.out.println(TAG + ": Translate " + objVxCellChild.getId() + " of " + objVxCell.getId() + ". Current point=" + objVxCellChild.getGeometry().getPoint() + ", Destination Point=" + childDstPt); + MagnetRONAnimation childCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + childCellAnim.setTotalCycleCount(10); + childCellAnim.setDelay(100); + childCellAnim.init(objVxCellChild, childDstPt.getX(), childDstPt.getY(), threadPoolExecutor); + childCellAnim.play(); } MagnetRONAnimation.waitAnimationEnd(); } @@ -915,7 +924,7 @@ methodSignature = formatMethodSignature(methodSignature, methodExecution.getThisClassName()); } - // Why is the following code needed? + // TODO: Confirm why is the following code needed? if (methodExecution.isStatic() && !objectId.startsWith("0")) { objectId = methodExecution.getCallerMethodExecution().getThisObjId(); if (objectId.matches("0")) { @@ -923,36 +932,36 @@ } } - ObjectVertex parentObjectVertex = objectToVertexMap.get(objectId); - mxICell parentCell = (mxICell) parentObjectVertex.getCell(); + ObjectVertex parentObjVx = objectToVertexMap.get(objectId); + mxICell parentObjVxCell = (mxICell) parentObjVx.getCell(); double coordX = DEFAULT_OBJECT_VERTEX_SIZE.getWidth() * 0.1; double coordY = DEFAULT_OBJECT_VERTEX_SIZE.getHeight() * 0.5; double stdX = coordX; double stdY = 0; - int time = parentObjectVertex.getMethodExecutionVertices().size(); - if (time >= 1) { - mxICell stdCell = (mxICell) parentObjectVertex.getMethodExecutionVertices().get(0).getCell(); + int methodExecVxSize = parentObjVx.getMethodExecutionVertices().size(); + if (methodExecVxSize >= 1) { + mxICell stdCell = (mxICell) parentObjVx.getMethodExecutionVertices().get(0).getCell(); stdX = stdCell.getGeometry().getX(); stdY = stdCell.getGeometry().getY(); - time -= 1; + methodExecVxSize -= 1; } - mxICell cell = null; - MethodExecutionVertex methodExecVertex = null; + mxICell methodExecVxCell = null; + MethodExecutionVertex methodExecVx = null; // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { // Creates a white cell of MethodExecutionVertex. - cell = (mxICell) mxgraph.insertDeltaVertex(parentCell, methodSignature, methodSignature, "fillColor=white"); - mxgraph.orderCells(false, new Object[] {cell}); - methodExecVertex = - new MethodExecutionVertex(methodSignature, cell, stdX, coordY * (time + 1) + stdY, + methodExecVxCell = (mxICell) mxgraph.insertDeltaVertex(parentObjVxCell, methodSignature, methodSignature, "fillColor=white"); + mxgraph.orderCells(false, new Object[] {methodExecVxCell}); + methodExecVx = + new MethodExecutionVertex(methodSignature, methodExecVxCell, stdX, coordY * (methodExecVxSize + 1) + stdY, DEFAULT_METHOD_EXECUTION_VERTEX_SIZE.getWidth(), DEFAULT_METHOD_EXECUTION_VERTEX_SIZE.getHeight()); - methodExecToVertexMap.put(methodExecution, methodExecVertex); + methodExecToVertexMap.put(methodExecution, methodExecVx); if(methodExecToVertexMap.size() > 1) { // Caution: If synchronized block is split here, {@code cell} is visible instantly until cell#setVisible(false) is executed. - cell.setVisible(false); + methodExecVxCell.setVisible(false); } } finally { mxgraph.getModel().endUpdate(); @@ -962,7 +971,7 @@ if(methodExecToVertexMap.size() > 1) { createEdgesToMethodExecutions(); } - parentObjectVertex.addMethodExecutionVertex(methodExecVertex); + parentObjVx.addMethodExecutionVertex(methodExecVx); update(); } @@ -973,7 +982,7 @@ */ private void removeMethodExecutionVertex(Alias alias) { // source ObjectVertex - ObjectVertex srcObjectVertex = objectToVertexMap.get(alias.getObjectId()); + ObjectVertex srcObjVx = objectToVertexMap.get(alias.getObjectId()); MethodExecution methodExec = alias.getMethodExecution(); AliasType aliasType = alias.getAliasType(); @@ -982,71 +991,70 @@ List arguments = new ArrayList<>(methodExecToVertexMap.get(calledMethodExec).getArguments()); List locals = new ArrayList<>(methodExecToVertexMap.get(calledMethodExec).getLocals()); if (arguments.size() != 0) { - for (ObjectVertex vo: arguments) { + for (ObjectVertex objVx: arguments) { // TODO: Implement equals(). - if (vo != srcObjectVertex) { - mxICell cell = (mxICell)vo.getCell(); - if (!cell.getParent().equals(getMxDefaultParent())) { + if (objVx != srcObjVx) { + mxICell objVxcell = (mxICell)objVx.getCell(); + if (!objVxcell.getParent().equals(getMxDefaultParent())) { // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - Point2D cellAbsPt = getAbsolutePointforCell(cell); - cell.getParent().remove(cell); - cell.setParent(getMxDefaultParent()); - cell.getGeometry().setX(cellAbsPt.getX()); - cell.getGeometry().setY(cellAbsPt.getY()); + Point2D objVxCellAbsPt = getAbsolutePointforCell(objVxcell); + objVxcell.getParent().remove(objVxcell); + objVxcell.setParent(getMxDefaultParent()); + objVxcell.getGeometry().setX(objVxCellAbsPt.getX()); + objVxcell.getGeometry().setY(objVxCellAbsPt.getY()); } finally { mxgraph.getModel().endUpdate(); } } - MagnetRONAnimation cellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - cellAnim.setTotalCycleCount(10); - cellAnim.setDelay(100); - cellAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); - cellAnim.play(); - methodExecToVertexMap.get(calledMethodExec).getArguments().remove(vo); + MagnetRONAnimation objVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + objVxCellAnim.setTotalCycleCount(10); + objVxCellAnim.setDelay(100); + objVxCellAnim.init(objVxcell, objVx.getInitialX(), objVx.getInitialY(), threadPoolExecutor); + objVxCellAnim.play(); + methodExecToVertexMap.get(calledMethodExec).getArguments().remove(objVx); } } } if (locals.size() != 0) { - for (ObjectVertex vo: locals) { - if (vo != srcObjectVertex) { - mxICell cell = (mxICell) vo.getCell(); + for (ObjectVertex objVx: locals) { + if (objVx != srcObjVx) { + mxICell objVxCell = (mxICell) objVx.getCell(); // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - Point2D cellAbsPt = getAbsolutePointforCell(cell); - if (!cell.getParent().equals(getMxDefaultParent())) { + Point2D objVxCellAbsPt = getAbsolutePointforCell(objVxCell); + if (!objVxCell.getParent().equals(getMxDefaultParent())) { // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. - cell.getParent().remove(cell); - cell.setParent(getMxDefaultParent()); + objVxCell.getParent().remove(objVxCell); + objVxCell.setParent(getMxDefaultParent()); } - cell.getGeometry().setX(cellAbsPt.getX()); - cell.getGeometry().setY(cellAbsPt.getY()); + objVxCell.getGeometry().setX(objVxCellAbsPt.getX()); + objVxCell.getGeometry().setY(objVxCellAbsPt.getY()); } finally { mxgraph.getModel().endUpdate(); } } - MagnetRONAnimation cellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - cellAnim.setTotalCycleCount(10); - cellAnim.setDelay(100); - cellAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); - cellAnim.play(); + MagnetRONAnimation objVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + objVxCellAnim.setTotalCycleCount(10); + objVxCellAnim.setDelay(100); + objVxCellAnim.init(objVxCell, objVx.getInitialX(), objVx.getInitialY(), threadPoolExecutor); + objVxCellAnim.play(); } } } } - MagnetRONAnimation.waitAnimationEnd(); if (aliasType.equals(AliasType.CONSTRACTOR_INVOCATION)) { sleepMainThread(500L); } - removeCalledMethodExecutionVertex(srcObjectVertex, methodExec, calledMethodExec); + removeCalledMethodExecutionVertex(srcObjVx, methodExec, calledMethodExec); } else { - removeMethodExecutionVertex(srcObjectVertex, methodExec); + removeMethodExecutionVertex(srcObjVx, methodExec); } } @@ -1062,13 +1070,13 @@ try { // Remove source {@code ObjectVertex} from Locals and Arguments of called {@code MethodExecution}'s Vertex. if (methodExecToVertexMap.containsKey(methodExecution)) { - mxCell dstMethodExecVertexCell = (mxCell)methodExecToVertexMap.get(methodExecution).getCell(); - if (!dstMethodExecVertexCell.getParent().equals(getMxDefaultParent())) { + mxCell dstMethodExecVxCell = (mxCell)methodExecToVertexMap.get(methodExecution).getCell(); + if (!dstMethodExecVxCell.getParent().equals(getMxDefaultParent())) { // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. - dstMethodExecVertexCell.getParent().remove(dstMethodExecVertexCell); - dstMethodExecVertexCell.setParent(getMxDefaultParent()); + dstMethodExecVxCell.getParent().remove(dstMethodExecVxCell); + dstMethodExecVxCell.setParent(getMxDefaultParent()); } - mxgraph.removeCells(new Object[] {dstMethodExecVertexCell}); + mxgraph.removeCells(new Object[] {dstMethodExecVxCell}); objectToVertexMap.get(methodExecution.getThisObjId()).getMethodExecutionVertices().remove(methodExecToVertexMap.get(methodExecution)); methodExecToVertexMap.remove(methodExecution); edgeMap.remove(methodExecution.getSignature()); @@ -1092,87 +1100,87 @@ // Remove ObjectVertex other than source ObjectVertex from locals and arguments of called MethodExecutionVertex. if (methodExecToVertexMap.containsKey(calledMethodExecution)) { - MethodExecutionVertex calledMethodExecVertex = methodExecToVertexMap.get(calledMethodExecution); + MethodExecutionVertex calledMethodExecVx = methodExecToVertexMap.get(calledMethodExecution); // TODO: Confirm bug. - List arguments = new ArrayList<>(calledMethodExecVertex.getArguments()); + List arguments = new ArrayList<>(calledMethodExecVx.getArguments()); if (arguments.size() != 0) { - for (ObjectVertex vo: arguments) { - if (vo != sourceObjectVertex) { - mxICell cell = (mxICell)vo.getCell(); - Point2D cellAbsPt = getAbsolutePointforCell(cell); + for (ObjectVertex objVx: arguments) { + if (objVx != sourceObjectVertex) { + mxICell objVxCell = (mxICell)objVx.getCell(); + Point2D objVxCellAbsPt = getAbsolutePointforCell(objVxCell); // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - if (!cell.getParent().equals(getMxDefaultParent())) { + if (!objVxCell.getParent().equals(getMxDefaultParent())) { // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. - cell.getParent().remove(cell); - cell.setParent(getMxDefaultParent()); + objVxCell.getParent().remove(objVxCell); + objVxCell.setParent(getMxDefaultParent()); } } finally { mxgraph.getModel().endUpdate(); } } - if (!cellAbsPt.equals(vo.getInitialPoint())) { + if (!objVxCellAbsPt.equals(objVx.getInitialPoint())) { // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - cell.getGeometry().setX(cellAbsPt.getX()); - cell.getGeometry().setY(cellAbsPt.getY()); + objVxCell.getGeometry().setX(objVxCellAbsPt.getX()); + objVxCell.getGeometry().setY(objVxCellAbsPt.getY()); } finally { mxgraph.getModel().endUpdate(); } } - MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - vertexAnim.setTotalCycleCount(10); - vertexAnim.setDelay(100); - vertexAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); - vertexAnim.syncPlay(); + MagnetRONAnimation objVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + objVxCellAnim.setTotalCycleCount(10); + objVxCellAnim.setDelay(100); + objVxCellAnim.init(objVxCell, objVx.getInitialX(), objVx.getInitialY(), threadPoolExecutor); + objVxCellAnim.syncPlay(); } - methodExecToVertexMap.get(calledMethodExecution).getArguments().remove(vo); + methodExecToVertexMap.get(calledMethodExecution).getArguments().remove(objVx); } } } - List locals = new ArrayList<>(calledMethodExecVertex.getLocals()); + List locals = new ArrayList<>(calledMethodExecVx.getLocals()); if (locals.size() != 0) { - for (ObjectVertex vo: locals) { - if (vo != sourceObjectVertex) { - mxICell cell = (mxICell)vo.getCell(); - Point2D cellAbsPt = getAbsolutePointforCell(cell); + for (ObjectVertex objVx: locals) { + if (objVx != sourceObjectVertex) { + mxICell objVxCell = (mxICell)objVx.getCell(); + Point2D objVxCellAbsPt = getAbsolutePointforCell(objVxCell); // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - if (!cell.getParent().equals(getMxDefaultParent())) { + if (!objVxCell.getParent().equals(getMxDefaultParent())) { // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. - cell.getParent().remove(cell); - cell.setParent(getMxDefaultParent()); + objVxCell.getParent().remove(objVxCell); + objVxCell.setParent(getMxDefaultParent()); } } finally { mxgraph.getModel().endUpdate(); } } - if (!cellAbsPt.equals(vo.getInitialPoint())) { + if (!objVxCellAbsPt.equals(objVx.getInitialPoint())) { // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - cell.getGeometry().setX(cellAbsPt.getX()); - cell.getGeometry().setY(cellAbsPt.getY()); + objVxCell.getGeometry().setX(objVxCellAbsPt.getX()); + objVxCell.getGeometry().setY(objVxCellAbsPt.getY()); } finally { mxgraph.getModel().endUpdate(); } } - MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - vertexAnim.setTotalCycleCount(10); - vertexAnim.setDelay(100); - vertexAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); - vertexAnim.syncPlay(); + MagnetRONAnimation objVxCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + objVxCellAnim.setTotalCycleCount(10); + objVxCellAnim.setDelay(100); + objVxCellAnim.init(objVxCell, objVx.getInitialX(), objVx.getInitialY(), threadPoolExecutor); + objVxCellAnim.syncPlay(); } - methodExecToVertexMap.get(calledMethodExecution).getLocals().remove(vo); + methodExecToVertexMap.get(calledMethodExecution).getLocals().remove(objVx); } } } @@ -1181,39 +1189,40 @@ return; } - mxICell srcMethodExecVertexCell = (mxICell)methodExecToVertexMap.get(methodExecution).getCell(); - mxICell dstMethodExecVertexCell = (mxICell)calledMethodExecVertex.getCell(); - scrollCellsToVisible(srcMethodExecVertexCell.getParent(), dstMethodExecVertexCell.getParent()); + mxICell srcMethodExecVxCell = (mxICell)methodExecToVertexMap.get(methodExecution).getCell(); + mxICell dstMethodExecVxCell = (mxICell)calledMethodExecVx.getCell(); + + scrollCellsToVisible(srcMethodExecVxCell.getParent(), dstMethodExecVxCell.getParent()); try { - Point2D srcMethodExecVertexCellAbsPt = null; - Point2D dstMethodExecVertexCellAbsPt = null; - final mxICell[] clonedstMethodExecVertexCell = new mxICell[1]; + Point2D srcMethodExecVxCellAbsPt = null; + Point2D dstMethodExecVxCellAbsPt = null; + final mxICell[] cloneDstMethodExecVxCell = new mxICell[1]; // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - mxgraph.removeCells(mxgraph.getEdgesBetween(srcMethodExecVertexCell, dstMethodExecVertexCell)); - srcMethodExecVertexCellAbsPt = getAbsolutePointforCell(srcMethodExecVertexCell); - dstMethodExecVertexCellAbsPt = getAbsolutePointforCell(dstMethodExecVertexCell); - clonedstMethodExecVertexCell[0] = (mxICell) mxgraph.addCell(dstMethodExecVertexCell.clone()); - clonedstMethodExecVertexCell[0].getGeometry().setX(dstMethodExecVertexCellAbsPt.getX()); - clonedstMethodExecVertexCell[0].getGeometry().setY(dstMethodExecVertexCellAbsPt.getY()); - clonedstMethodExecVertexCell[0].setStyle("fillColor=none;strokeColor=none;fontColor=#008000;"); - clonedstMethodExecVertexCell[0].setValue(null); - mxICell tmpEdge = (mxICell) mxgraph.insertEdge(getMxDefaultParent(), null, null, srcMethodExecVertexCell, clonedstMethodExecVertexCell[0]); - tmpEdge.setStyle("dashed=1;strokeColor=#008000;exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;endArrow=none"); + mxgraph.removeCells(mxgraph.getEdgesBetween(srcMethodExecVxCell, dstMethodExecVxCell)); + srcMethodExecVxCellAbsPt = getAbsolutePointforCell(srcMethodExecVxCell); + dstMethodExecVxCellAbsPt = getAbsolutePointforCell(dstMethodExecVxCell); + cloneDstMethodExecVxCell[0] = (mxICell) mxgraph.addCell(dstMethodExecVxCell.clone()); + cloneDstMethodExecVxCell[0].getGeometry().setX(dstMethodExecVxCellAbsPt.getX()); + cloneDstMethodExecVxCell[0].getGeometry().setY(dstMethodExecVxCellAbsPt.getY()); + cloneDstMethodExecVxCell[0].setStyle("fillColor=none;strokeColor=none;fontColor=#008000;"); + cloneDstMethodExecVxCell[0].setValue(null); + mxICell tmpEdgeCell = (mxICell) mxgraph.insertEdge(getMxDefaultParent(), null, null, srcMethodExecVxCell, cloneDstMethodExecVxCell[0]); + tmpEdgeCell.setStyle("dashed=1;strokeColor=#008000;exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;endArrow=none"); } finally { mxgraph.getModel().endUpdate(); } } // Animate an edge to shrink. - MagnetRONAnimation edgeAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - edgeAnim.setTotalCycleCount(10); - edgeAnim.setDelay(100); - edgeAnim.init(clonedstMethodExecVertexCell[0], srcMethodExecVertexCellAbsPt.getX(), srcMethodExecVertexCellAbsPt.getY() + srcMethodExecVertexCell.getGeometry().getHeight(), threadPoolExecutor); - edgeAnim.setOnFinished(new ActionListener() { + MagnetRONAnimation edgeCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + edgeCellAnim.setTotalCycleCount(10); + edgeCellAnim.setDelay(100); + edgeCellAnim.init(cloneDstMethodExecVxCell[0], srcMethodExecVxCellAbsPt.getX(), srcMethodExecVxCellAbsPt.getY() + srcMethodExecVxCell.getGeometry().getHeight(), threadPoolExecutor); + edgeCellAnim.setOnFinished(new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. @@ -1222,15 +1231,15 @@ try { // Test code (will be deleted) System.out.println(TAG + ": Shrink edge animation action performed."); - mxgraph.removeCells(new Object[]{clonedstMethodExecVertexCell[0]}); + mxgraph.removeCells(new Object[]{cloneDstMethodExecVxCell[0]}); // TODO: Confirm execution order. - if (!dstMethodExecVertexCell.getParent().equals(getMxDefaultParent())) { + if (!dstMethodExecVxCell.getParent().equals(getMxDefaultParent())) { // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. - dstMethodExecVertexCell.getParent().remove(dstMethodExecVertexCell); - dstMethodExecVertexCell.setParent(getMxDefaultParent()); + dstMethodExecVxCell.getParent().remove(dstMethodExecVxCell); + dstMethodExecVxCell.setParent(getMxDefaultParent()); } - mxgraph.removeCells(new Object[] {dstMethodExecVertexCell}); + mxgraph.removeCells(new Object[] {dstMethodExecVxCell}); update(); } finally { mxgraph.getModel().endUpdate(); @@ -1238,12 +1247,12 @@ } } }); - edgeAnim.play(); + edgeCellAnim.play(); if (!calledMethodExecution.isStatic()) { objectToVertexMap.get(calledMethodExecution.getThisObjId()).getMethodExecutionVertices().remove(methodExecToVertexMap.get(calledMethodExecution)); } else { - // Why is this object id of the caller method used? + // TODO: Confirm why is this object id of the caller method used? String objId = calledMethodExecution.getCallerMethodExecution().getThisObjId(); if (objId.matches("0")) { objId += ":" + calledMethodExecution.getCallerMethodExecution().getThisClassName(); @@ -1274,29 +1283,29 @@ if (!edgeMap.containsKey(methodSig)) { // Draw an edge from sourceVertexCell to destinationVertexCell. - mxICell srcMethodExecVertexCell = (mxICell)methodExecToVertexMap.get(srcMethodExec).getCell(); - mxICell dstMethodExecVertexCell = (mxICell)methodExecToVertexMap.get(dstMethodExec).getCell(); - Point2D srcMethodExecVertexCellAbsPt = getAbsolutePointforCell(srcMethodExecVertexCell); - Point2D dstMethodExecVertexCellAbsPt = getAbsolutePointforCell(dstMethodExecVertexCell); + mxICell srcMethodExecVxCell = (mxICell)methodExecToVertexMap.get(srcMethodExec).getCell(); + mxICell dstMethodExecVxCell = (mxICell)methodExecToVertexMap.get(dstMethodExec).getCell(); + Point2D srcMethodExecVxCellAbsPt = getAbsolutePointforCell(srcMethodExecVxCell); + Point2D dstMethodExecVxCellAbsPt = getAbsolutePointforCell(dstMethodExecVxCell); MagnetRONAnimation.waitAnimationEnd(); - scrollCellsToVisible(srcMethodExecVertexCell.getParent(), dstMethodExecVertexCell.getParent()); + scrollCellsToVisible(srcMethodExecVxCell.getParent(), dstMethodExecVxCell.getParent(), 2); try { - final mxICell[] clonedstMethodExecVertexCell = new mxICell[1]; + final mxICell[] cloneDstMethodExecVxCell = new mxICell[1]; // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { - clonedstMethodExecVertexCell[0] = (mxICell) mxgraph.addCell(dstMethodExecVertexCell.clone()); - clonedstMethodExecVertexCell[0].getGeometry().setX(srcMethodExecVertexCellAbsPt.getX()); - clonedstMethodExecVertexCell[0].getGeometry().setY(srcMethodExecVertexCellAbsPt.getY() + dstMethodExecVertexCell.getGeometry().getHeight()); - clonedstMethodExecVertexCell[0].setStyle("fillColor=none;strokeColor=none;fontColor=#008000;"); - clonedstMethodExecVertexCell[0].setValue(null); - clonedstMethodExecVertexCell[0].setVisible(true); - mxICell tmpEdge = (mxICell) mxgraph.insertEdge(getMxDefaultParent(), null, null, srcMethodExecVertexCell, clonedstMethodExecVertexCell[0]); - tmpEdge.setStyle("dashed=1;strokeColor=#008000;exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;endArrow=none"); - dstMethodExecVertexCell.setVisible(true); + cloneDstMethodExecVxCell[0] = (mxICell) mxgraph.addCell(dstMethodExecVxCell.clone()); + cloneDstMethodExecVxCell[0].getGeometry().setX(srcMethodExecVxCellAbsPt.getX()); + cloneDstMethodExecVxCell[0].getGeometry().setY(srcMethodExecVxCellAbsPt.getY() + dstMethodExecVxCell.getGeometry().getHeight()); + cloneDstMethodExecVxCell[0].setStyle("fillColor=none;strokeColor=none;fontColor=#008000;"); + cloneDstMethodExecVxCell[0].setValue(null); + cloneDstMethodExecVxCell[0].setVisible(true); + mxICell tmpEdgeCell = (mxICell) mxgraph.insertEdge(getMxDefaultParent(), null, null, srcMethodExecVxCell, cloneDstMethodExecVxCell[0]); + tmpEdgeCell.setStyle("dashed=1;strokeColor=#008000;exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;endArrow=none"); + dstMethodExecVxCell.setVisible(true); update(); } finally { mxgraph.getModel().endUpdate(); @@ -1304,11 +1313,11 @@ } // Animate an edge to stretch. - MagnetRONAnimation edgeAnim = new TranslateAnimation(mxgraph, getGraphComponent()); - edgeAnim.setTotalCycleCount(10); - edgeAnim.setDelay(100); - edgeAnim.init(clonedstMethodExecVertexCell[0], dstMethodExecVertexCellAbsPt.getX(), dstMethodExecVertexCellAbsPt.getY(), threadPoolExecutor); - edgeAnim.setOnFinished(new ActionListener() { + MagnetRONAnimation edgeCellAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + edgeCellAnim.setTotalCycleCount(10); + edgeCellAnim.setDelay(100); + edgeCellAnim.init(cloneDstMethodExecVxCell[0], dstMethodExecVxCellAbsPt.getX(), dstMethodExecVxCellAbsPt.getY(), threadPoolExecutor); + edgeCellAnim.setOnFinished(new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. @@ -1317,16 +1326,16 @@ try { // Test code (will be deleted) System.out.println(TAG + ": Stretch edge animation action performed. "); - mxICell edge = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), methodSig, null, srcMethodExecVertexCell, dstMethodExecVertexCell); - if (!edge.getParent().equals(getMxDefaultParent())) { + mxICell edgeCell = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), methodSig, null, srcMethodExecVxCell, dstMethodExecVxCell); + if (!edgeCell.getParent().equals(getMxDefaultParent())) { // If parent of Edge cell isn't mxDefaltParent, reset parent. - edge.getParent().remove(edge); - edge.setParent(getMxDefaultParent()); + edgeCell.getParent().remove(edgeCell); + edgeCell.setParent(getMxDefaultParent()); } - mxgraph.orderCells(false, new Object[] {edge}); - edge.setStyle("exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;"); - edgeMap.put(methodSig, new Edge(methodSig, TypeName.Call, edge)); - mxgraph.removeCells(new Object[]{clonedstMethodExecVertexCell[0]}); + mxgraph.orderCells(false, new Object[] {edgeCell}); + edgeCell.setStyle("exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;"); + edgeMap.put(methodSig, new Edge(methodSig, TypeName.Call, edgeCell)); + mxgraph.removeCells(new Object[]{cloneDstMethodExecVxCell[0]}); update(); } finally { mxgraph.getModel().endUpdate(); @@ -1334,17 +1343,7 @@ } } }); - edgeAnim.play(); - -// // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. -// mxgraph.getModel().beginUpdate(); -// synchronized (mxgraph.getModel()) { -// try { -// update(); -// } finally { -// mxgraph.getModel().endUpdate(); -// } -// } + edgeCellAnim.play(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } @@ -1352,87 +1351,65 @@ } } - /** - * - * @param edge - * @param srcCellAbsPt - * @param dstCellAbsPt - */ - protected void setEdgePoint(mxICell edge, Point2D srcCellAbsPt, Point2D dstCellAbsPt) { -// mxgraph.orderCells(true, new Object[] {edge}); -// if(srcCellAbsPt.getX() <= dstCellAbsPt.getX()) { -// // �E�����獶��փG�b�W������ -// edge.setStyle("exitX=0.5;exitY=0.5;exitPerimeter=1;entryX=0;entryY=0.5;entryPerimeter=1;"); -// } else { -// // ��������E��փG�b�W������ -// edge.setStyle("exitX=0.5;exitY=0.5;exitPerimeter=1;entryX=1;entryY=0.5;entryPerimeter=1;"); -// } - } - /** * Styles all cells on the graph. */ protected void setCellsStyle() { - List objectVertex = new ArrayList<>(); - List staticObjectVertex = new ArrayList<>(); - List alignMidObjectVertex = new ArrayList<>(); - List alignTopObjectVertex = new ArrayList<>(); - List refEdge = new ArrayList<>(); - List refCreateEdge = new ArrayList<>(); - List methodExecEdge = new ArrayList<>(); - List roundEdge = new ArrayList<>(); + List objVxs = new ArrayList<>(); + List staticObjVxs = new ArrayList<>(); + List alignMidObjVxs = new ArrayList<>(); + List alignTopObjVxs = new ArrayList<>(); + List refEdges = new ArrayList<>(); + List refCreateEdges = new ArrayList<>(); + List methodExecEdges = new ArrayList<>(); + List roundEdges = new ArrayList<>(); for (Entry objectToVertexEntry: objectToVertexMap.entrySet()) { - String key = objectToVertexEntry.getKey(); - ObjectVertex ov = objectToVertexEntry.getValue(); - if (key.startsWith("0:")) { - staticObjectVertex.add(ov.getCell()); + String objId = objectToVertexEntry.getKey(); + ObjectVertex objVx = objectToVertexEntry.getValue(); + if (objId.startsWith("0:")) { + staticObjVxs.add(objVx.getCell()); } else { - objectVertex.add(ov.getCell()); + objVxs.add(objVx.getCell()); } - if(ov.getMethodExecutionVertices().size() == 0) { - alignMidObjectVertex.add(ov.getCell()); + if(objVx.getMethodExecutionVertices().size() == 0) { + alignMidObjVxs.add(objVx.getCell()); } else { - alignTopObjectVertex.add(ov.getCell()); + alignTopObjVxs.add(objVx.getCell()); } } - List methodExecVertexList = new ArrayList<>(methodExecToVertexMap.values()); - Collections.reverse(methodExecVertexList); - for (int i = 0; i < methodExecVertexList.size(); i++) { - switch(i) { - case 0: - ((mxICell)methodExecVertexList.get(i).getCell()).setStyle("fillColor=#ff7fbf"); - break; - case 1: - ((mxICell)methodExecVertexList.get(i).getCell()).setStyle("fillColor=#ff99cc"); - break; - case 2: - ((mxICell)methodExecVertexList.get(i).getCell()).setStyle("fillColor=#ffb2d8"); - break; - case 3: - ((mxICell)methodExecVertexList.get(i).getCell()).setStyle("fillColor=#ffcce5"); - break; - case 4: - ((mxICell)methodExecVertexList.get(i).getCell()).setStyle("fillColor=#ffe0ef"); - break; - default: - break; + List methodExecVxList = new ArrayList<>(methodExecToVertexMap.values()); + Collections.reverse(methodExecVxList); + for (int i = 0; i < methodExecVxList.size(); i++) { + mxICell methodExecVxCell = (mxICell) methodExecVxList.get(i).getCell(); + if (i == 0) { + methodExecVxCell.setStyle("fillColor=#ff7fbf"); + } else if (i == 1) { + methodExecVxCell.setStyle("fillColor=#ff99cc"); + } else if (i == 2) { + methodExecVxCell.setStyle("fillColor=#ffb2d8"); + } else if (i == 3) { + methodExecVxCell.setStyle("fillColor=#ffcce5"); + } else if (i == 4) { + methodExecVxCell.setStyle("fillColor=#ffe0ef"); + } else { + break; } } for (Edge edge: edgeMap.values()) { - roundEdge.add(edge.getCell()); + roundEdges.add(edge.getCell()); switch(edge.getTypeName()) { case Reference: - refEdge.add(edge.getCell()); + refEdges.add(edge.getCell()); break; case Create: - refEdge.add(edge.getCell()); - refCreateEdge.add(edge.getCell()); + refEdges.add(edge.getCell()); + refCreateEdges.add(edge.getCell()); break; case Call: - methodExecEdge.add(edge.getCell()); + methodExecEdges.add(edge.getCell()); break; default: break; @@ -1440,20 +1417,20 @@ } // Styles ObjectVertex. - mxgraph.setCellStyles(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE, objectVertex.toArray(new Object[objectVertex.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_PERIMETER, mxConstants.PERIMETER_ELLIPSE, objectVertex.toArray(new Object[objectVertex.size()])); - mxgraph.setCellStyleFlags(mxConstants.STYLE_FONTSTYLE, mxConstants.FONT_UNDERLINE, true, objectVertex.toArray(new Object[objectVertex.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE, alignMidObjectVertex.toArray(new Object[alignMidObjectVertex.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, alignTopObjectVertex.toArray(new Object[alignTopObjectVertex.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE, objVxs.toArray(new Object[objVxs.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_PERIMETER, mxConstants.PERIMETER_ELLIPSE, objVxs.toArray(new Object[objVxs.size()])); + mxgraph.setCellStyleFlags(mxConstants.STYLE_FONTSTYLE, mxConstants.FONT_UNDERLINE, true, objVxs.toArray(new Object[objVxs.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE, alignMidObjVxs.toArray(new Object[alignMidObjVxs.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, alignTopObjVxs.toArray(new Object[alignTopObjVxs.size()])); // Styles Edge. - mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_TOPTOBOTTOM, refEdge.toArray(new Object[refEdge.size()])); - mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, refCreateEdge.toArray(new Object[refCreateEdge.size()])); - mxgraph.setCellStyleFlags(mxConstants.STYLE_ROUNDED, 1, true, roundEdge.toArray(new Object[roundEdge.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, roundEdge.toArray(new Object[roundEdge.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_BOTTOM, roundEdge.toArray(new Object[roundEdge.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_TOPTOBOTTOM, refEdges.toArray(new Object[refEdges.size()])); + mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, refCreateEdges.toArray(new Object[refCreateEdges.size()])); + mxgraph.setCellStyleFlags(mxConstants.STYLE_ROUNDED, 1, true, roundEdges.toArray(new Object[roundEdges.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, roundEdges.toArray(new Object[roundEdges.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_BOTTOM, roundEdges.toArray(new Object[roundEdges.size()])); // Styles MethodExecutionVertex. - mxgraph.setCellStyles(mxConstants.STYLE_STROKECOLOR, "#008000", methodExecEdge.toArray(new Object[methodExecEdge.size()])); - mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, methodExecEdge.toArray(new Object[methodExecEdge.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_STROKECOLOR, "#008000", methodExecEdges.toArray(new Object[methodExecEdges.size()])); + mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, methodExecEdges.toArray(new Object[methodExecEdges.size()])); } protected Point2D getAbsolutePointforCell(mxICell cell) { @@ -1478,39 +1455,86 @@ getGraphComponent().refresh(); } - private void scrollCellsToVisible(mxICell cell1, mxICell cell2) { + protected void scrollCellToVisible(mxICell cell, boolean center) { if (isAutoTracking()) { - Rectangle rec = new Rectangle(); - Point2D cell1AbsPt = getAbsolutePointforCell(cell1); - Point2D cell2AbsPt = getAbsolutePointforCell(cell2); - int cell1X = (int) cell1AbsPt.getX(), cell1Y = (int) cell1AbsPt.getY(); - int cell2X = (int) cell2AbsPt.getX(), cell2Y = (int) cell2AbsPt.getY(); - if (cell1X <= cell2X) { - if (cell1Y <= cell2Y) { - cell2X += cell2.getGeometry().getWidth(); - cell2Y += cell2.getGeometry().getHeight(); - rec.setBounds(cell1X, cell1Y, cell2X - cell1X, cell2Y - cell1Y); + getGraphComponent().scrollCellToVisible(cell, center); + } + } + + private void scrollCellsToVisible(mxICell cell1, mxICell cell2) { + scrollCellsToVisible(cell1, cell2, 1); + } + + private void scrollCellsToVisible(mxICell cell1, mxICell cell2, int priorityArgumentsIndex) { + if (isAutoTracking()) { + Point2D p1 = getAbsolutePointforCell(cell1); + Point2D p2 = getAbsolutePointforCell(cell2); + if (p1.getX() <= p2.getX()) { + if (p1.getY() <= p2.getY()) { + double p2X = p2.getX() + cell2.getGeometry().getWidth(); + double p2Y = p2.getY() + cell2.getGeometry().getHeight(); + p2.setLocation(p2X, p2Y); } else { - cell2X += cell2.getGeometry().getWidth(); - cell1Y += cell1.getGeometry().getHeight(); - rec.setBounds(cell1X, cell2Y, cell2X - cell1X, cell1Y - cell2Y); + double p1Y = p1.getY() + cell1.getGeometry().getHeight(); + double p2X = p2.getX() + cell2.getGeometry().getWidth(); + p1.setLocation(p1.getX(), p1Y); + p2.setLocation(p2X, p2.getY()); } } else { - if (cell1Y <= cell2Y) { - cell1X += cell1.getGeometry().getWidth(); - cell2Y += cell2.getGeometry().getHeight(); - rec.setBounds(cell2X, cell1Y, cell1X - cell2X, cell2Y - cell1Y); + if (p1.getY() <= p2.getY()) { + double p1X = p1.getX() + cell1.getGeometry().getWidth(); + double p2Y = p2.getY() + cell2.getGeometry().getHeight(); + p1.setLocation(p1X, p1.getY()); + p2.setLocation(p2.getX(), p2Y); } else { - cell1X += cell1.getGeometry().getWidth(); - cell1Y += cell1.getGeometry().getHeight(); - rec.setBounds(cell2X, cell2Y, cell1X - cell2X, cell1Y - cell2Y); + double p1X = p1.getX() + cell1.getGeometry().getWidth(); + double p1Y = p1.getY() + cell1.getGeometry().getHeight(); + p1.setLocation(p1X, p1Y); } } - scrollRectToVisible(rec); + scrollPointsToVisible(p1, p2, false, priorityArgumentsIndex); + } + } + + private void scrollCellAndPointToVisible(mxICell cell1, Point2D p2, int priorityArgumentsIndex) { + if (isAutoTracking()) { + Point2D p1 = getAbsolutePointforCell(cell1); + if (p1.getX() <= p2.getX()) { + if (p1.getY() <= p2.getY()) { + double p2X = p2.getX() + DEFAULT_OBJECT_VERTEX_SIZE.getWidth(); + double p2Y = p2.getY() + DEFAULT_OBJECT_VERTEX_SIZE.getHeight(); + p2.setLocation(p2X, p2Y); + } else { + double p1Y = p1.getY() + cell1.getGeometry().getHeight(); + double p2X = p2.getX() + DEFAULT_OBJECT_VERTEX_SIZE.getWidth(); + p1.setLocation(p1.getX(), p1Y); + p2.setLocation(p2X, p2.getY()); + } + } else { + if (p1.getY() <= p2.getY()) { + double p1X = p1.getX() + cell1.getGeometry().getWidth(); + double p2Y = p2.getY() + DEFAULT_OBJECT_VERTEX_SIZE.getHeight(); + p1.setLocation(p1X, p1.getY()); + p2.setLocation(p2.getX(), p2Y); + } else { + double p1X = p1.getX() + cell1.getGeometry().getWidth(); + double p1Y = p1.getY() + cell1.getGeometry().getHeight(); + p1.setLocation(p1X, p1Y); + } + } + scrollPointsToVisible(p1, p2, false, priorityArgumentsIndex); } } - private void scrollPointsToVisible(Point2D p1, Point2D p2, boolean center) { + /** + * + * + * @param p1 + * @param p2 + * @param center + * @param priorityArgumentsIndex: 1 is the default value, indicating that 1st argument(p1) of this method should be preferred. + */ + private void scrollPointsToVisible(Point2D p1, Point2D p2, boolean center, int priorityArgumentsIndex) { if (isAutoTracking()) { Rectangle rec = new Rectangle(); int p1X = (int) p1.getX(), p1Y = (int) p1.getY(); @@ -1518,22 +1542,73 @@ if (p1X <= p2X) { if (p1Y <= p2Y) { rec.setBounds(p1X, p1Y, p2X - p1X, p2Y - p1Y); + if (rec.getWidth() > super.getWidth() || rec.getHeight() > super.getHeight()) { + switch(priorityArgumentsIndex) { + case 1: + break; + case 2: + int x = (int) (rec.getX() + (rec.getWidth() - super.getWidth())); + int y = (int) (rec.getY() + (rec.getHeight() - super.getHeight())); + rec.setLocation(x, y); + break; + } + rec.setSize(super.getWidth(), super.getHeight()); + } } else { - rec.setBounds(p1X, p2Y, p2X - p1X, p1Y - p2Y); + rec.setBounds(p1X, p2Y, p2X - p1X, p1Y - p2Y); + if (rec.getWidth() > super.getWidth() || rec.getHeight() > super.getHeight()) { + switch(priorityArgumentsIndex) { + case 1: + int y = (int) (rec.getY() + (rec.getHeight() - super.getHeight())); + rec.setLocation((int) rec.getX(), y); + break; + case 2: + int x = (int) (rec.getX() + (rec.getWidth() - super.getWidth())); + rec.setLocation(x, (int) rec.getY()); + break; + } + rec.setSize(super.getWidth(), super.getHeight()); + } } } else { if (p1Y <= p2Y) { rec.setBounds(p2X, p1Y, p1X - p2X, p2Y - p1Y); + if (rec.getWidth() > super.getWidth() || rec.getHeight() > super.getHeight()) { + switch(priorityArgumentsIndex) { + case 1: + int x = (int) (rec.getX() + (rec.getWidth() - super.getWidth())); + rec.setLocation(x, (int) rec.getY()); + break; + case 2: + int y = (int) (rec.getY() + (rec.getHeight() - super.getHeight())); + rec.setLocation((int) rec.getX(), y); + break; + } + rec.setSize(super.getWidth(), super.getHeight()); + } } else { - rec.setBounds(p2X, p2Y, p1X - p2X, p1Y - p2Y); + rec.setBounds(p2X, p2Y, p1X - p2X, p1Y - p2Y); + if (rec.getWidth() > super.getWidth() || rec.getHeight() > super.getHeight()) { + switch(priorityArgumentsIndex) { + case 1: + int x = (int) (rec.getX() + (rec.getWidth() - super.getWidth())); + int y = (int) (rec.getY() + (rec.getHeight() - super.getHeight())); + rec.setLocation(x, y); + break; + case 2: + break; + } + rec.setSize(super.getWidth(), super.getHeight()); + } } } if (center) { - int x = (int) (rec.getCenterX() - getWidth() / 2); - int y = (int) (rec.getCenterY() - getHeight() / 2); - rec.setBounds(x, y, getWidth(), getHeight()); + int x = (int) (rec.getCenterX() - super.getWidth() / 2); + int y = (int) (rec.getCenterY() - super.getHeight() / 2); + rec.setBounds(x, y, super.getWidth(), super.getHeight()); } + scrollRectToVisible(rec); } } @@ -1541,27 +1616,25 @@ @Override public void scrollRectToVisible(Rectangle rec) { Rectangle visibleRec = getGraphComponent().getGraphControl().getVisibleRect(); - if (isAutoTracking() && !visibleRec.contains(rec)) { + if (isAutoTracking() && !rec.contains(visibleRec)) { System.out.println(TAG + ": Before scroll visibleRect=" + getGraphComponent().getGraphControl().getVisibleRect()); getGraphComponent().getGraphControl().scrollRectToVisible(rec); System.out.println(TAG + ": After scroll visibleRect=" + getGraphComponent().getGraphControl().getVisibleRect()); } } - private int countChildVertex(ObjectVertex objectVertex) { - int time = objectVertex.getMethodExecutionVertices().size(); - if(time == 0) { - return 1; + private boolean isAutoTracking() { + return this.fAutoTracking; + } + + public void setAutoTracking(boolean fAutoTracking) { + if (fAutoTracking != isAutoTracking()) { + this.fAutoTracking = fAutoTracking; } - for(MethodExecutionVertex mev: objectVertex.getMethodExecutionVertices()) { - for(ObjectVertex ov: mev.getLocals()) { - time += countChildVertex(ov); - } - for(ObjectVertex ov: mev.getArguments()) { - return countChildVertex(ov); - } - } - return time; + } + + protected void setCurrentFrame(int numberFrame) { + this.curFrame = numberFrame; } protected static String[] formatFieldName(String fieldName) { @@ -1660,7 +1733,7 @@ } /** - * Whether sourceCell parents contain destinationCell. + * Whether parents of source mxICell contain destination mxICell. * * @param sourceCell * @param destinationCell @@ -1760,16 +1833,6 @@ return new AbstractMap.SimpleEntry<>(new Reference(rpSrcObjId, rpDstObjId, rpSrcClassName, rpDstClassName), rpFieldName); } - private boolean isAutoTracking() { - return this.autoTracking; - } - - public void setAutoTracking(boolean autoTracking) { - if (autoTracking != isAutoTracking()) { - this.autoTracking = autoTracking; - } - } - public void sleepMainThread(long millis) { try { // Test code (will be deleted)