diff --git a/src/org/ntlab/animations/MagnetRONAnimation.java b/src/org/ntlab/animations/MagnetRONAnimation.java index 42379dd..f73128c 100644 --- a/src/org/ntlab/animations/MagnetRONAnimation.java +++ b/src/org/ntlab/animations/MagnetRONAnimation.java @@ -179,7 +179,7 @@ STOPPED } -// private static int animationCount = 0; + private static int animationCount = 0; /** * The constructor of {@code MagnetRONAnimation}. @@ -364,16 +364,16 @@ updateCurrentCycle(getCurrentCycleCount()); jumpTo(getCurrentCycleCount()); } else if(Math.abs(getCurrentCycleCount()) >= Math.abs(getTotalCycleCount())){ -// animationCount = 0; -// System.out.println(TAG + ": animationCount=" + animationCount); + animationCount = 0; + System.out.println(TAG + ": animationCount=" + animationCount); onFinished(); } } }, getInitialDelay(), getDelay(), TimeUnit.MILLISECONDS); setScheduledFuture(scheduledFuture); setCurrentStatus(Status.RUNNING); -// animationCount = 1; -// System.out.println(TAG + ": animationCount=" + animationCount); + animationCount = 1; + System.out.println(TAG + ": animationCount=" + animationCount); }; break; case PAUSED: @@ -388,22 +388,28 @@ }; } -// public static void waitAnimationEnd() { -// while (animationCount > 0) { -// try { -// Thread.sleep(1L); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// } -// // Buffer for another waiting animation. -// try { -// Thread.sleep(30L); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// } + /** + * Sleep main thread and wait for {@link MagnetRONAnimation#play()} to finish running. + */ + public static void waitAnimationEnd() { + while (animationCount > 0) { + try { + Thread.sleep(1L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + // Buffer for another waiting animation. + try { + Thread.sleep(30L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + /** + * Play animation in sync with main thread. + */ public void syncPlay() { if (getCurrentStatus() == Status.STOPPED) { try { diff --git a/src/org/ntlab/deltaViewer/MagnetRONViewer.java b/src/org/ntlab/deltaViewer/MagnetRONViewer.java index a30c423..4a1dad6 100644 --- a/src/org/ntlab/deltaViewer/MagnetRONViewer.java +++ b/src/org/ntlab/deltaViewer/MagnetRONViewer.java @@ -67,7 +67,7 @@ protected static Dimension DEFAULT_METHOD_EXECUTION_VERTEX_SIZE = new Dimension(55, 20); protected static long DEFAULT_THREAD_SLEEP_MILLIS = 1100L; - protected static long POSTPONE_ANIMATION_MILLIS = 400L; + protected static long POSTPONE_ANIMATION_MILLIS = 250L; protected IAliasCollector aliasCollector; @@ -177,7 +177,6 @@ createObjectVertexOnConstractor(alias); createMethodExecutionVertex(alias.getObjectId(), ((MethodInvocation)alias.getOccurrencePoint().getStatement()).getCallerSideMethodName(), ((MethodInvocation)alias.getOccurrencePoint().getStatement()).getCalledMethodExecution()); update(); -// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); removeMethodExecutionVertex(alias); update(); break; @@ -241,6 +240,7 @@ fieldName = methodInv.getCallerSideMethodName(); } mxICell ovCell; + MagnetRONAnimation.waitAnimationEnd(); mxgraph.getModel().beginUpdate(); synchronized (mxgraph.getModel()) { try { @@ -447,6 +447,7 @@ ObjectVertex srcObjVertex = objectToVertexMap.get(alias.getObjectId()); if (alias.getMethodExecution().isStatic() && !methodExecToVertexMap.containsKey(alias.getMethodExecution())) { createMethodExecutionVertex(alias.getObjectId(), alias.getMethodExecution().getSignature(), alias.getMethodExecution()); + sleepMainThread(POSTPONE_ANIMATION_MILLIS); } // destination {@code ObjectVertex} MethodExecutionVertex dstMethodExecVertex = methodExecToVertexMap.get(alias.getMethodExecution()); @@ -475,7 +476,8 @@ } } if (alias.getAliasType().equals(AliasType.RETURN_VALUE)) { - sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation.waitAnimationEnd(); } moveLocalObjectVertex(methodExec, sourceObjectVertex, destinationMethodExecutionVertex); } else if (alias.getAliasType().equals(AliasType.FORMAL_PARAMETER)) { @@ -663,9 +665,9 @@ double overlapWidth = srcCellWidth - (srcCellWidth * Math.sqrt(2) * 0.1); double overlapHeight = srcCellHeight - (srcCellHeight * Math.sqrt(2) * 0.1); - // deltaAnimation.setVertexAnimation(srcCell, new mxPoint(dstCell.getGeometry().getX() - overlapWidth, dstCell.getGeometry().getY() - overlapHeight + (srcCellHeight * time))); - // deltaAnimation.startVertexAnimation(); - // deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); +// deltaAnimation.setVertexAnimation(srcCell, new mxPoint(dstCell.getGeometry().getX() - overlapWidth, dstCell.getGeometry().getY() - overlapHeight + (srcCellHeight * time))); +// deltaAnimation.startVertexAnimation(); +// deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); vertexAnim.setTotalCycleCount(10); vertexAnim.setDelay(100); @@ -674,7 +676,7 @@ threadPoolExecutor); // vertexAnim.play(); // sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); -// sleepMainThread(POSTPONE_ANIMATION_MILLIS); + sleepMainThread(POSTPONE_ANIMATION_MILLIS); vertexAnim.syncPlay(); // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. @@ -879,6 +881,7 @@ */ protected void updateObjectVertices() { Map mxICellToTranslateAnimMap = new HashMap<>(); + MagnetRONAnimation.waitAnimationEnd(); for (ObjectVertex ov: objectToVertexMap.values()) { mxICell ovCell = (mxICell) ov.getCell(); // if (ovCell == null || mxICellToTranslateAnimMap.get(ovCell) != null) continue; @@ -962,7 +965,8 @@ childVertexAnim.init(childCell, childDstPt.getX(), childDstPt.getY(), threadPoolExecutor); childVertexAnim.play(); } - sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation.waitAnimationEnd(); } } // sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); @@ -978,10 +982,6 @@ * @param methodExec: called or this {@code MethodExecution} */ protected void createMethodExecutionVertex(String objectId, String methodSignature, MethodExecution methodExecution) { - mxICell parentCell = (mxICell) objectToVertexMap.get(objectId).getCell(); - -// if (cell == null) return; - if (methodSignature == null) { methodSignature = methodExecution.getSignature(); } @@ -996,6 +996,7 @@ objectId = methodExecution.getCallerMethodExecution().getThisObjId(); } + mxICell parentCell = (mxICell) objectToVertexMap.get(objectId).getCell(); double coordX = DEFAULT_OBJECT_VERTEX_SIZE.getWidth() * 0.1; double coordY = DEFAULT_OBJECT_VERTEX_SIZE.getHeight() * 0.5; double stdX = coordX; @@ -1034,7 +1035,7 @@ } } if(methodExecToVertexMap.size() > 1) { - createEdgeToMethodExecution(); + createEdgesToMethodExecutions(); } objectToVertexMap.get(objectId).addMethodExecution(methodExecVertex); // setCellsStyle(); @@ -1173,7 +1174,7 @@ protected void removeCalledMethodExecutionVertex(ObjectVertex sourceObjectVertex, MethodExecution methodExecution, MethodExecution calledMethodExecution) { // Test code (will be deleted) outputLog(); -// MagnetRONAnimation.waitAnimationEnd(); + MagnetRONAnimation.waitAnimationEnd(); // Remove ObjectVertex other than sourceObjectVertex from locals and arguments of called MethodExecutionVertex. if (methodExecToVertexMap.containsKey(calledMethodExecution)) { MethodExecutionVertex calledMethodExecVertex = methodExecToVertexMap.get(calledMethodExecution); @@ -1367,7 +1368,7 @@ /** * Create an edge between method execution While animating the edge to stretch. */ - private void createEdgeToMethodExecution() { + private void createEdgesToMethodExecutions() { List methodExecList = new ArrayList<>(methodExecToVertexMap.keySet()); // TODO: Fix a bug where an edge orientation is reversed. @@ -1382,6 +1383,7 @@ Point2D srcMethodExecVertexCellAbsPt = getAbsolutePointforCell(srcMethodExecVertexCell); Point2D dstMethodExecVertexCellAbsPt = getAbsolutePointforCell(dstMethodExecVertexCell); + MagnetRONAnimation.waitAnimationEnd(); try { final mxICell[] clonedstMethodExecVertexCell = new mxICell[1]; @@ -1437,7 +1439,6 @@ } } }); -// MagnetRONAnimation.waitAnimationEnd(); edgeAnim.play(); // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); @@ -1452,26 +1453,26 @@ e.printStackTrace(); } } - sleepMainThread(POSTPONE_ANIMATION_MILLIS); +// sleepMainThread(POSTPONE_ANIMATION_MILLIS); } } /** - * - * @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;"); -// } - } + * + * @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. @@ -1560,10 +1561,6 @@ mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, methodExecEdge.toArray(new Object[methodExecEdge.size()])); } - private void setWindowSize(int width, int height) { - DEFAULT_WINDOW_SIZE.setSize(width, height); - } - protected Point2D getAbsolutePointforCell(mxICell cell) { Point2D p1 = new Point2D.Double(cell.getGeometry().getX(), cell.getGeometry().getY());; // if(cell.getParent().getValue() == null || cell == cell.getParent()) { @@ -1664,6 +1661,10 @@ return sb.toString(); } + private void setWindowSize(int width, int height) { + DEFAULT_WINDOW_SIZE.setSize(width, height); + } + /** * Test code (will be deleted) */