diff --git a/src/org/ntlab/animations/EdgeAnimation.java b/src/org/ntlab/animations/EdgeAnimation.java deleted file mode 100644 index cdd0a87..0000000 --- a/src/org/ntlab/animations/EdgeAnimation.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.ntlab.animations; - -import java.awt.Point; -import java.awt.geom.Point2D; -import java.util.concurrent.ThreadPoolExecutor; - -import org.ntlab.deltaViewer.DeltaGraphAdapter; - -import com.mxgraph.model.mxICell; -import com.mxgraph.swing.mxGraphComponent; -import com.mxgraph.util.mxPoint; - -/** - * Animation of edge stretching and shrinking. - * - * @author Nitta Lab. - */ -public class EdgeAnimation extends MagnetRONAnimation { - - /** - * The constructor of {@code EdgeAnimation}. - * - * @param mxgraph - * @param mxgraphComponent - */ - public EdgeAnimation(DeltaGraphAdapter mxgraph, mxGraphComponent mxgraphComponent) { - super(mxgraph, mxgraphComponent); - } - - /** - * See {@code MagnetRONAnimation#init(mxICell, Point2D, ThreadPoolExecutor)} - * - * @param sourceCell - * @param targetPoint - */ - @Override - public void init(mxICell sourceCell, Point2D targetPoint, ThreadPoolExecutor threadPoolExecutor) { - super.init(sourceCell, targetPoint, threadPoolExecutor); - - Point2D curPoint = new Point(sourceCell.getGeometry().getPoint()); - System.out.println("sourcePoint: " + sourceCell.getGeometry().getPoint()); - System.out.println("targetPoint: " + targetPoint); - - // Calculate resize line model - mxPoint distancePoint = new mxPoint(); - distancePoint.setX(targetPoint.getX() - curPoint.getX()); - distancePoint.setY(targetPoint.getY() - curPoint.getY()); - Point2D updatePoint = new Point2D.Double(); - updatePoint.setLocation(distancePoint.getX() / getTotalCycleCount(), distancePoint.getY() / getTotalCycleCount()); - setVelocity(updatePoint); - System.out.println("updatePoint: " + getVelocity()); - } - - protected void jumpTo(int curCycleCount) { - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - mxgraph.getModel().beginUpdate(); - try { - getSourceCell().getGeometry().setX(getSourceInitalPoint().getX() + getVelocity().getX() * curCycleCount); - getSourceCell().getGeometry().setY(getSourceInitalPoint().getY() + getVelocity().getY() * curCycleCount); - } finally { - mxgraph.getModel().endUpdate(); - } - mxgraphComponent.refresh(); - } - -} diff --git a/src/org/ntlab/animations/MagnetRONAnimation.java b/src/org/ntlab/animations/MagnetRONAnimation.java index 0bc6537..151fea1 100644 --- a/src/org/ntlab/animations/MagnetRONAnimation.java +++ b/src/org/ntlab/animations/MagnetRONAnimation.java @@ -1,7 +1,9 @@ package org.ntlab.animations; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.geom.Dimension2D; import java.awt.geom.Point2D; import java.util.TimerTask; import java.util.concurrent.ScheduledFuture; @@ -21,6 +23,9 @@ */ public abstract class MagnetRONAnimation { + // Test code (will be deleted) + private static final String TAG = MagnetRONAnimation.class.getSimpleName(); + protected DeltaGraphAdapter mxgraph; protected mxGraphComponent mxgraphComponent; @@ -150,14 +155,11 @@ * The initial point of sourceCell. */ private Point2D sourceInitPoint; + /** - * The target point where the sourceCell animates. + * The initial size of sourceCell. */ - private Point2D destinationPoint; - /** - * The point to update for each cycle count. - */ - private Point2D velocity; + private Dimension2D sourceInitDimension; /** * The possible state for MagnetRONAnimation. @@ -236,14 +238,18 @@ this.sourceInitPoint = sourceInitPoint; } - protected void setDestinationPoint(Point2D destinationPoint) { - this.destinationPoint = destinationPoint; + protected void setSourceInitialDimension(Dimension2D sourceInitDimension) { + this.sourceInitDimension = sourceInitDimension; } - protected void setVelocity(Point2D velocity) { - this.velocity = velocity; + protected void setScheduledFuture(ScheduledFuture scheduledFuture) { + this.scheduledFuture = scheduledFuture; } + protected abstract void setDestination(double x, double y); + + protected abstract void setVelocity(double x, double y); + protected ThreadPoolExecutor getThreadPoolExecutor() { return threadPoolExecutor; } @@ -295,16 +301,16 @@ return sourceCell; } - protected Point2D getSourceInitalPoint() { + protected Point2D getSourceInitialPoint() { return sourceInitPoint; } - protected Point2D getDestinationPoint() { - return destinationPoint; + protected Dimension2D getSourceInitialDimension() { + return sourceInitDimension; } - protected Point2D getVelocity() { - return velocity; + protected ScheduledFuture getScheduledFuture() { + return scheduledFuture; } /** @@ -314,18 +320,20 @@ * @param sourceCell: edge object * @param destinationPoint */ - protected void init(mxICell sourceCell, Point2D destinationPoint, ThreadPoolExecutor threadPoolExecutor) { + public void init(mxICell sourceCell, double destinationX, double destinationY, ThreadPoolExecutor threadPoolExecutor) { setSourceCell(sourceCell); - setDestinationPoint(destinationPoint); + setDestination(destinationX, destinationY); setThreadPoolExecutor(threadPoolExecutor); setSourceInitialPoint(getSourceCell().getGeometry().getPoint()); + setSourceInitialDimension( + new Dimension((int) getSourceCell().getGeometry().getWidth(), + (int) getSourceCell().getGeometry().getHeight())); setCurrentCycleCount(0); } - public void stepCurrentCycle(int currentCycleCount) { + public void updateCurrentCycle(int currentCycleCount) { if (!getReverse()) { // Animation direction is forward. setCurrentCycleCount((int) (currentCycleCount + Math.signum(getTotalCycleCount()))); - System.out.println("curCycleCount: " + getCurrentCycleCount()); } else { setCurrentCycleCount((int) (currentCycleCount - Math.signum(getTotalCycleCount()))); } @@ -344,18 +352,21 @@ case STOPPED: if (getThreadPoolExecutor() != null & getThreadPoolExecutor() instanceof ScheduledThreadPoolExecutor) { ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = (ScheduledThreadPoolExecutor) getThreadPoolExecutor(); - this.scheduledFuture = scheduledThreadPoolExecutor.scheduleWithFixedDelay(new TimerTask() { + setThreadPoolExecutor(scheduledThreadPoolExecutor); + ScheduledFuture scheduledFuture = scheduledThreadPoolExecutor.scheduleWithFixedDelay(new TimerTask() { @Override public void run() { if(Math.abs(getCurrentCycleCount()) < Math.abs(getTotalCycleCount())) { + // Test code (will be deleted) + System.out.println(TAG + ": Run task " + getSourceCell().getId() + " " + MagnetRONAnimation.this.getClass().getSimpleName() + "-" + getCurrentCycleCount() + ". ThreadId=" + Thread.currentThread().getId()); + updateCurrentCycle(getCurrentCycleCount()); jumpTo(getCurrentCycleCount()); - stepCurrentCycle(getCurrentCycleCount()); } else if(Math.abs(getCurrentCycleCount()) >= Math.abs(getTotalCycleCount())){ - scheduledFuture.cancel(true); onFinished(); } } - }, getInitialDelay(), getDelay(), TimeUnit.MILLISECONDS); + }, getInitialDelay(), getDelay(), TimeUnit.MILLISECONDS); + setScheduledFuture(scheduledFuture); setCurrentStatus(Status.RUNNING); }; break; @@ -370,6 +381,31 @@ break; }; } + + public void syncPlay() { + if (getCurrentStatus() == Status.STOPPED) { + try { + Thread.sleep(getInitialDelay()); + while (true) { + while (getCurrentStatus() == Status.PAUSED) { + Thread.sleep(1L); + } + if(Math.abs(getCurrentCycleCount()) < Math.abs(getTotalCycleCount())) { + // Test code (will be deleted) + System.out.println(TAG + ": Run task " + getSourceCell().getId() + " " + MagnetRONAnimation.this.getClass().getSimpleName() + "-" + getCurrentCycleCount() + ". ThreadId=" + Thread.currentThread().getId()); + updateCurrentCycle(getCurrentCycleCount()); + jumpTo(getCurrentCycleCount()); + } else if(Math.abs(getCurrentCycleCount()) >= Math.abs(getTotalCycleCount())){ + onFinished(); + break; + } + Thread.sleep(getDelay()); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } public void playFormStart() { @@ -377,6 +413,7 @@ public void stop() { if (getCurrentStatus() == Status.RUNNING) { + getScheduledFuture().cancel(true); } setCurrentStatus(Status.STOPPED); setCurrentRate(0.0); @@ -406,12 +443,4 @@ } protected abstract void jumpTo(int currentCycleCount); - - public void sleepThread(long millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } } diff --git a/src/org/ntlab/animations/TranslateAnimation.java b/src/org/ntlab/animations/TranslateAnimation.java new file mode 100644 index 0000000..0fa1e29 --- /dev/null +++ b/src/org/ntlab/animations/TranslateAnimation.java @@ -0,0 +1,113 @@ +package org.ntlab.animations; + +import java.awt.Point; +import java.awt.geom.Point2D; +import java.util.concurrent.ThreadPoolExecutor; + +import org.ntlab.deltaViewer.DeltaGraphAdapter; + +import com.mxgraph.model.mxICell; +import com.mxgraph.swing.mxGraphComponent; + +/** + * Animation of edge stretching and shrinking, vertex translating. + * + * @author Nitta Lab. + */ +public class TranslateAnimation extends MagnetRONAnimation { + + // Test code (will be deleted) + private static final String TAG = TranslateAnimation.class.getSimpleName(); + + /** + * The destination point where the sourceCell animates. + */ + private Point2D destinationPoint; + /** + * The point to update for each cycle count. + */ + private Point2D velocity; + + /** + * The constructor of {@code TranslateAnimation}. + * + * @param mxgraph + * @param mxgraphComponent + */ + public TranslateAnimation(DeltaGraphAdapter mxgraph, mxGraphComponent mxgraphComponent) { + super(mxgraph, mxgraphComponent); + } + + @Override + protected void setDestination(double x, double y) { + setDestinationPoint(new Point2D.Double(x, y)); + } + + private void setDestinationPoint(Point2D destinationPoint) { + this.destinationPoint = destinationPoint; + } + + @Override + protected void setVelocity(double x, double y) { + setVelocity(new Point2D.Double(x, y)); + } + + private void setVelocity(Point2D velocity) { + this.velocity = velocity; + } + + private Point2D getDestinationPoint() { + return destinationPoint; + } + + private Point2D getVelocity() { + return velocity; + } + + public void init(mxICell sourceCell, Point2D destinationPoint, ThreadPoolExecutor threadPoolExecutor) { + init(sourceCell, destinationPoint.getX(), destinationPoint.getY(), threadPoolExecutor); + } + + /** + * See {@code MagnetRONAnimation#init(mxICell, double, double, ThreadPoolExecutor)} + * + * @param sourceCell + * @param destinationPoint + * @param threadPoolExecutor + */ + @Override + public void init(mxICell sourceCell, double x, double y, ThreadPoolExecutor threadPoolExecutor) { + super.init(sourceCell, x, y, threadPoolExecutor); + + Point2D curPt = new Point(sourceCell.getGeometry().getPoint()); + + // Calculate resize line model + Point2D distancePoint = new Point(); + distancePoint.setLocation(destinationPoint.getX() - curPt.getX(), + destinationPoint.getY() - curPt.getY()); + Point2D velocity = new Point2D.Double(); + velocity.setLocation(distancePoint.getX() / getTotalCycleCount(), distancePoint.getY() / getTotalCycleCount()); + setVelocity(velocity); + + // Test code (will be deleted) +// System.out.println(TAG + ": Translate " + getSourceCell().getId() + ". Current point=" + getSourceCell().getGeometry().getPoint() + ", Velocity=" + getVelocity() + ", Destination Point=" + getDestinationPoint()); + } + + @Override + protected void jumpTo(int currentCycleCount) { + // 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 { + getSourceCell().getGeometry().setX(getSourceInitialPoint().getX() + getVelocity().getX() * currentCycleCount); + getSourceCell().getGeometry().setY(getSourceInitialPoint().getY() + getVelocity().getY() * currentCycleCount); + // Test code (will be deleted) + System.out.println(TAG + ": Translate " + getSourceCell().getId() + ". Current point=" + getSourceCell().getGeometry().getPoint() + ", Velocity=" + getVelocity() + "-" + currentCycleCount); + } finally { + mxgraph.getModel().endUpdate(); + } + mxgraphComponent.refresh(); + } + } + +} diff --git a/src/org/ntlab/animations/VertexResizeAnimation.java b/src/org/ntlab/animations/VertexResizeAnimation.java new file mode 100644 index 0000000..00db2bf --- /dev/null +++ b/src/org/ntlab/animations/VertexResizeAnimation.java @@ -0,0 +1,114 @@ +package org.ntlab.animations; + +import java.awt.Dimension; +import java.awt.geom.Dimension2D; +import java.util.concurrent.ThreadPoolExecutor; + +import org.ntlab.deltaViewer.DeltaGraphAdapter; + +import com.mxgraph.model.mxICell; +import com.mxgraph.swing.mxGraphComponent; + +/** + * Animation to resize vertex. + * + * @author Nitta Lab. + */ +public class VertexResizeAnimation extends MagnetRONAnimation { + + // Test code (will be deleted) + private static final String TAG = VertexResizeAnimation.class.getSimpleName(); + + /** + * The destination dimension where the sourceCell animates. + */ + private Dimension2D destinationDimension; + /** + * The dimension to update for each cycle count. + */ + private Dimension2D velocity; + + /** + * The constructor of {@code VertexResizeAnimation}. + * + * @param mxgraph + * @param mxgraphComponent + */ + public VertexResizeAnimation(DeltaGraphAdapter mxgraph, mxGraphComponent mxgraphComponent) { + super(mxgraph, mxgraphComponent); + } + + @Override + protected void setDestination(double x, double y) { + setDestinationDimension(new Dimension((int) x, (int) y)); + } + + private void setDestinationDimension(Dimension2D destinationDimension) { + this.destinationDimension = destinationDimension; + } + + @Override + protected void setVelocity(double x, double y) { + setVelocity(new Dimension((int) x, (int) y)); + } + + private void setVelocity(Dimension2D velocity) { + this.velocity = velocity; + } + + private Dimension2D getDestinationDimension() { + return destinationDimension; + } + + private Dimension2D getVelocity() { + return velocity; + } + + public void init(mxICell sourceCell, Dimension2D destinationDimension, ThreadPoolExecutor threadPoolExecutor) { + init(sourceCell, destinationDimension.getWidth(), destinationDimension.getHeight(), threadPoolExecutor); + } + + /** + * See {@code MagnetRONAnimation#init(mxICell, double, double, ThreadPoolExecutor)} + * + * @param sourceCell + * @param destinationDimension + * @param threadPoolExecutor + */ + @Override + public void init(mxICell sourceCell, double width, double height, ThreadPoolExecutor threadPoolExecutor) { + super.init(sourceCell, width, height, threadPoolExecutor); + + Dimension2D curDim = new Dimension(); + curDim.setSize(sourceCell.getGeometry().getWidth(), sourceCell.getGeometry().getHeight()); + + // Calculate resize dimension model + Dimension2D distanceDimension = new Dimension(); + distanceDimension.setSize(destinationDimension.getWidth() - curDim.getWidth(), + destinationDimension.getHeight() - curDim.getHeight()); + Dimension2D velocity = new Dimension(); + velocity.setSize(distanceDimension.getWidth() / getTotalCycleCount(), distanceDimension.getHeight() / getTotalCycleCount()); + setVelocity(velocity); + + // Test code (will be deleted) +// System.out.println(TAG + ": Resize " + getSourceCell().getId() + ". Current Dimension=(" + getSourceCell().getGeometry().getWidth() + ", " + getSourceCell().getGeometry().getHeight() + "), Velocity=" + getVelocity() + ", Destination dimension=" + getDestinationDimension()); + } + + @Override + protected void jumpTo(int currentCycleCount) { + // 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 { + getSourceCell().getGeometry().setWidth(getSourceInitialDimension().getWidth() + getVelocity().getWidth() * currentCycleCount); + getSourceCell().getGeometry().setHeight(getSourceInitialDimension().getHeight() + getVelocity().getHeight() * currentCycleCount); + // Test code (will be deleted) +// System.out.println(TAG + ": Resize " + getSourceCell().getId() + ". Current Dimension=(" + getSourceCell().getGeometry().getWidth() + ", " + getSourceCell().getGeometry().getHeight() + "), Velocity=" + getVelocity() + "-" + currentCycleCount); + } finally { + mxgraph.getModel().endUpdate(); + } + mxgraphComponent.refresh(); + } + } + +} diff --git a/src/org/ntlab/deltaViewer/CollaborationViewer.java b/src/org/ntlab/deltaViewer/CollaborationViewer.java index 7f1583f..633639d 100644 --- a/src/org/ntlab/deltaViewer/CollaborationViewer.java +++ b/src/org/ntlab/deltaViewer/CollaborationViewer.java @@ -1,13 +1,13 @@ package org.ntlab.deltaViewer; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.Point; +import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; +import org.ntlab.animations.MagnetRONAnimation; +import org.ntlab.animations.TranslateAnimation; import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.IAliasCollector; import org.ntlab.deltaExtractor.Alias.AliasType; @@ -22,7 +22,6 @@ import org.ntlab.trace.TracePoint; import com.mxgraph.model.mxICell; -import com.mxgraph.util.mxPoint; import com.mxgraph.view.mxGraphView; public class CollaborationViewer extends MagnetRONViewer { @@ -69,7 +68,7 @@ System.out.println(", " + scale); // scale = 1.5; view.setScale(scale); - deltaAnimation.setScale(scale); +// deltaAnimation.setScale(scale); update(); } @@ -280,7 +279,7 @@ System.out.println(calledObjectId); if(objectToVertexMap.containsKey(calledObjectId)) { mxICell calledCell = (mxICell)objectToVertexMap.get(calledObjectId).getCell(); - Point absolutePointCalledCell = getAbsolutePointforCell(calledCell); + Point2D absolutePointCalledCell = getAbsolutePointforCell(calledCell); System.out.println(objectId + ", " + me.getSignature()); // objectToVertexMap.get(calledObjectId).resetCellPosition(); // if (methodExecToVertexMap.get(methodExec).getArguments().contains(objectToVertexMap.get(calledObjectId)) || methodExecToVertexMap.get(methodExec).getLocals().contains(objectToVertexMap.get(calledObjectId))) { @@ -308,27 +307,49 @@ if (arguments.size() != 0) { for (ObjectVertex vo: arguments) { mxICell cell = (mxICell)vo.getCell(); - Point absolutePointCell = getAbsolutePointforCell(cell); - cell.getParent().remove(cell); - cell.setParent(mxDefaultParent); + Point2D absolutePointCell = getAbsolutePointforCell(cell); +// cell.getParent().remove(cell); +// cell.setParent(mxDefaultParent); + if (!cell.getParent().equals(getMxDefaultParent())) { + // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. + cell.getParent().remove(cell); + cell.setParent(getMxDefaultParent()); + } cell.getGeometry().setX(absolutePointCell.getX()); cell.getGeometry().setY(absolutePointCell.getY()); - deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); - deltaAnimation.startVertexAnimation(); - deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); +// deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); +// deltaAnimation.startVertexAnimation(); +// deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); + vertexAnim.play(); + sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); methodExecToVertexMap.get(me).getArguments().remove(vo); } }else if (locals.size() != 0) { for (ObjectVertex vo: locals) { mxICell cell = (mxICell)vo.getCell(); - Point absolutePointCell = getAbsolutePointforCell(cell); - cell.getParent().remove(cell); - cell.setParent(mxDefaultParent); + Point2D absolutePointCell = getAbsolutePointforCell(cell); +// cell.getParent().remove(cell); +// cell.setParent(mxDefaultParent); + if (!cell.getParent().equals(getMxDefaultParent())) { + // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. + cell.getParent().remove(cell); + cell.setParent(getMxDefaultParent()); + } cell.getGeometry().setX(absolutePointCell.getX()); cell.getGeometry().setY(absolutePointCell.getY()); - deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); - deltaAnimation.startVertexAnimation(); - deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); +// deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); +// deltaAnimation.startVertexAnimation(); +// deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); + vertexAnim.play(); + sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); methodExecToVertexMap.get(me).getLocals().remove(vo); } } @@ -359,7 +380,7 @@ MethodExecution coordinator = objectCallGraph.getStartPoints().get(0); String coordinatorObjId = coordinator.getThisObjId(); String coordinatorClassName = coordinator.getThisClassName(); - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, coordinatorObjId, coordinatorClassName, 0, 0, DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + Object vertex = 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)); } @@ -373,7 +394,7 @@ if (srcClassName.contains("[L")) { srcClassName = formatArrayName(srcClassName); } - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getSrcObjectId(), srcClassName, 0, 0, vertexObjWidth, vertexObjHeight, "fillColor=white"); //creates a white vertex. + Object vertex = mxgraph.insertDeltaVertex(getMxDefaultParent(), ref.getSrcObjectId(), srcClassName, 0, 0, vertexObjWidth, vertexObjHeight, "fillColor=white"); //creates a white vertex. objectToVertexMap.put(ref.getSrcObjectId(), new ObjectVertex(ref.getSrcClassName(), vertex, 0, 0)); } // dstSide @@ -383,7 +404,7 @@ if (dstClassName.contains("[L")) { dstClassName = formatArrayName(dstClassName); } - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getDstObjectId(), dstClassName, 0, 0, vertexObjWidth, vertexObjHeight, "fillColor=white"); //creates a white vertex. + Object vertex = mxgraph.insertDeltaVertex(getMxDefaultParent(), ref.getDstObjectId(), dstClassName, 0, 0, vertexObjWidth, vertexObjHeight, "fillColor=white"); //creates a white vertex. objectToVertexMap.put(ref.getDstObjectId(), new ObjectVertex(ref.getDstClassName(), vertex, 0, 0)); } } else { @@ -392,7 +413,7 @@ if (srcClassName.contains("[L")) { srcClassName = formatArrayName(srcClassName); } - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getSrcObjectId(), srcClassName, 0, 0, vertexObjWidth, vertexObjHeight, "fillColor=white"); //creates a white vertex. + Object vertex = mxgraph.insertDeltaVertex(getMxDefaultParent(), ref.getSrcObjectId(), srcClassName, 0, 0, vertexObjWidth, vertexObjHeight, "fillColor=white"); //creates a white vertex. objectToVertexMap.put(ref.getSrcObjectId(), new ObjectVertex(ref.getSrcClassName(), vertex, 0, 0)); } if (!objectToVertexMap.containsKey(ref.getDstObjectId())) { @@ -500,9 +521,9 @@ if (srcCell != null && dstCell != null) { // isCreation() System.out.println("makeEdgeObject: " + fieldName + ", " + srcClassName + " (" + srcCell.hashCode() + "), " + " (" + dstCell.hashCode() + ")"/* + ", " + dstClassName*/); // BUG:NullPointerException - Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, fieldName, fieldName, srcCell, dstCell); - Point absPtSrcCell = getAbsolutePointforCell((mxICell)srcCell); - Point absPtDstCell = getAbsolutePointforCell((mxICell)dstCell); + 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)); } diff --git a/src/org/ntlab/deltaViewer/DeltaGraphAdapter.java b/src/org/ntlab/deltaViewer/DeltaGraphAdapter.java index 86046c3..ae7841d 100644 --- a/src/org/ntlab/deltaViewer/DeltaGraphAdapter.java +++ b/src/org/ntlab/deltaViewer/DeltaGraphAdapter.java @@ -1,17 +1,14 @@ package org.ntlab.deltaViewer; -import java.util.AbstractMap.SimpleEntry; -import java.util.HashMap; -import java.util.Map.Entry; import org.jgrapht.Graph; import org.jgrapht.ext.JGraphXAdapter; -import org.jgrapht.graph.DefaultEdge; import org.jgrapht.graph.DirectedWeightedPseudograph; import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGeometry; import com.mxgraph.model.mxICell; +import com.mxgraph.model.mxIGraphModel; import com.mxgraph.util.mxConstants; /** @@ -21,10 +18,14 @@ */ public class DeltaGraphAdapter extends JGraphXAdapter { protected Graph graphT; - + private DeltaGraphModel deltaGraphModel; + +// private long refreshedTime = 0L; + public DeltaGraphAdapter(DirectedWeightedPseudograph graphT) { super(graphT); this.graphT = graphT; + this.deltaGraphModel = new DeltaGraphModel(super.getModel()); } /** @@ -161,8 +162,209 @@ } return cell; } + + @Override + public void refresh() { +// long curTime = System.currentTimeMillis(); +// if (curTime - refreshedTime > 5L) { +// super.refresh(); +// refreshedTime = curTime; +// } +// if (((DeltaGraphModel) getModel()).getCount() <= 1) { +// view.reload(); +// repaint(); +// } + super.refresh(); + } public Graph getGraph() { return graphT; } + + @Override + public mxIGraphModel getModel() { + if (deltaGraphModel == null) return super.getModel(); + return deltaGraphModel; + } + + public class DeltaGraphModel implements mxIGraphModel { + + private mxIGraphModel model; + private int count = 0; + + public DeltaGraphModel(mxIGraphModel model) { + this.model = model; + } + + public int getCount() { + return count; + } + + @Override + public Object getRoot() { + return model.getRoot(); + } + + @Override + public Object setRoot(Object root) { + return model.setRoot(root); + } + + @Override + public Object[] cloneCells(Object[] cells, boolean includeChildren) { + return model.cloneCells(cells, includeChildren); + } + + @Override + public boolean isAncestor(Object parent, Object child) { + return model.isAncestor(parent, child); + } + + @Override + public boolean contains(Object cell) { + return model.contains(cell); + } + + @Override + public Object getParent(Object child) { + return model.getParent(child); + } + + @Override + public Object add(Object parent, Object child, int index) { + return model.add(parent, child, index); + } + + @Override + public Object remove(Object cell) { + return model.remove(cell); + } + + @Override + public int getChildCount(Object cell) { + return model.getChildCount(cell); + } + + @Override + public Object getChildAt(Object parent, int index) { + return model.getChildAt(parent, index); + } + + @Override + public Object getTerminal(Object edge, boolean isSource) { + return model.getTerminal(edge, isSource); + } + + @Override + public Object setTerminal(Object edge, Object terminal, boolean isSource) { + return model.setTerminal(edge, terminal, isSource); + } + + @Override + public int getEdgeCount(Object cell) { + return model.getEdgeCount(cell); + } + + @Override + public Object getEdgeAt(Object cell, int index) { + return model.getEdgeAt(cell, index); + } + + @Override + public boolean isVertex(Object cell) { + return model.isVertex(cell); + } + + @Override + public boolean isEdge(Object cell) { + return model.isEdge(cell); + } + + @Override + public boolean isConnectable(Object cell) { + return model.isConnectable(cell); + } + + @Override + public Object getValue(Object cell) { + return model.getValue(cell); + } + + @Override + public Object setValue(Object cell, Object value) { + return model.setValue(cell, value); + } + + @Override + public mxGeometry getGeometry(Object cell) { + return model.getGeometry(cell); + } + + @Override + public mxGeometry setGeometry(Object cell, mxGeometry geometry) { + return model.setGeometry(cell, geometry); + } + + @Override + public String getStyle(Object cell) { + return model.getStyle(cell); + } + + @Override + public String setStyle(Object cell, String style) { + return model.setStyle(cell, style); + } + + @Override + public boolean isCollapsed(Object cell) { + return model.isCollapsed(cell); + } + + @Override + public boolean setCollapsed(Object cell, boolean collapsed) { + return model.setCollapsed(cell, collapsed); + } + + @Override + public boolean isVisible(Object cell) { + return model.isVisible(cell); + } + + @Override + public boolean setVisible(Object cell, boolean visible) { + return model.setVisible(cell, visible); + } + + @Override + public void beginUpdate() { + if (count == 0) { + model.beginUpdate(); + } + count++; + } + + @Override + public void endUpdate() { + count--; + if (count == 0) { + model.endUpdate(); + } + } + + @Override + public void addListener(String eventName, mxIEventListener listener) { + model.addListener(eventName, listener); + } + + @Override + public void removeListener(mxIEventListener listener) { + model.removeListener(listener); + } + + @Override + public void removeListener(mxIEventListener listener, String eventName) { + model.removeListener(listener, eventName); + } + + } } diff --git a/src/org/ntlab/deltaViewer/DeltaViewer.java b/src/org/ntlab/deltaViewer/DeltaViewer.java index 5004659..6bbc6de 100644 --- a/src/org/ntlab/deltaViewer/DeltaViewer.java +++ b/src/org/ntlab/deltaViewer/DeltaViewer.java @@ -1,12 +1,12 @@ package org.ntlab.deltaViewer; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.Point; +import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.ntlab.animations.MagnetRONAnimation; +import org.ntlab.animations.TranslateAnimation; import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.Delta; import org.ntlab.deltaExtractor.ExtractedStructure; @@ -79,7 +79,7 @@ System.out.println(", " + scale); // scale = 1.5; view.setScale(scale); - deltaAnimation.setScale(scale); +// deltaAnimation.setScale(scale); update(); } @@ -259,7 +259,7 @@ System.out.println(calledObjectId); if(objectToVertexMap.containsKey(calledObjectId)) { mxICell calledCell = (mxICell)objectToVertexMap.get(calledObjectId).getCell(); - Point absolutePointCalledCell = getAbsolutePointforCell(calledCell); + Point2D absolutePointCalledCell = getAbsolutePointforCell(calledCell); System.out.println(objectId + ", " + methodExec.getSignature()); // objectToVertexMap.get(calledObjectId).resetCellPosition(); // if (methodExecToVertexMap.get(methodExec).getArguments().contains(objectToVertexMap.get(calledObjectId)) || methodExecToVertexMap.get(methodExec).getLocals().contains(objectToVertexMap.get(calledObjectId))) { @@ -287,25 +287,35 @@ if (arguments.size() != 0) { for (ObjectVertex vo: arguments) { mxICell cell = (mxICell)vo.getCell(); - Point absolutePointCell = getAbsolutePointforCell(cell); + Point2D absolutePointCell = getAbsolutePointforCell(cell); cell.getParent().remove(cell); - cell.setParent(mxDefaultParent); + cell.setParent(getMxDefaultParent()); cell.getGeometry().setX(absolutePointCell.getX()); cell.getGeometry().setY(absolutePointCell.getY()); - deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); - deltaAnimation.startVertexAnimation(); +// deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); +// deltaAnimation.startVertexAnimation(); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); + vertexAnim.play(); methodExecToVertexMap.get(methodExec).getArguments().remove(vo); } }else if (locals.size() != 0) { for (ObjectVertex vo: locals) { mxICell cell = (mxICell)vo.getCell(); - Point absolutePointCell = getAbsolutePointforCell(cell); + Point2D absolutePointCell = getAbsolutePointforCell(cell); cell.getParent().remove(cell); - cell.setParent(mxDefaultParent); + cell.setParent(getMxDefaultParent()); cell.getGeometry().setX(absolutePointCell.getX()); cell.getGeometry().setY(absolutePointCell.getY()); - deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); - deltaAnimation.startVertexAnimation(); +// deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); +// deltaAnimation.startVertexAnimation(); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); + vertexAnim.play(); methodExecToVertexMap.get(methodExec).getLocals().remove(vo); } } @@ -347,7 +357,7 @@ System.out.println("coordinator: " + coordinatorClassName + ", " + coordinatorObjId); coordinatorPoint.setX(coordinatorPoint.getX() + time * 2); xCor += time * 2; - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, coordinatorObjId, coordinatorClassName, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + Object vertex = mxgraph.insertDeltaVertex(getMxDefaultParent(), coordinatorObjId, coordinatorClassName, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. objectToVertexMap.put(coordinatorObjId, new ObjectVertex(coordinatorClassName, vertex, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)))); srcSideSize++; } @@ -358,7 +368,7 @@ if (srcClassName.contains("[L")) { srcClassName = formatArrayName(srcClassName); } - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getSrcObjectId(), srcClassName, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + Object vertex = mxgraph.insertDeltaVertex(getMxDefaultParent(), ref.getSrcObjectId(), srcClassName, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. objectToVertexMap.put(ref.getSrcObjectId(), new ObjectVertex(ref.getSrcClassName(), vertex, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)))); } if (!objectToVertexMap.containsKey(ref.getDstObjectId())) { @@ -367,7 +377,7 @@ if (dstClassName.contains("[L")) { dstClassName = formatArrayName(dstClassName); } - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getDstObjectId(), dstClassName, xCor + (time * (srcSideSize - i)), yCor + (time * (srcSideSize - i)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + Object vertex = mxgraph.insertDeltaVertex(getMxDefaultParent(), ref.getDstObjectId(), dstClassName, xCor + (time * (srcSideSize - i)), yCor + (time * (srcSideSize - i)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. objectToVertexMap.put(ref.getDstObjectId(), new ObjectVertex(ref.getDstClassName(), vertex, xCor + (time * (srcSideSize - i)), yCor + (time * (srcSideSize - i)))); } } else { @@ -375,7 +385,7 @@ if (srcClassName.contains("[L")) { srcClassName = formatArrayName(srcClassName); } - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getSrcObjectId(), srcClassName, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + Object vertex = mxgraph.insertDeltaVertex(getMxDefaultParent(), ref.getSrcObjectId(), srcClassName, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. objectToVertexMap.put(ref.getSrcObjectId(), new ObjectVertex(ref.getSrcClassName(), vertex, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)))); objectToVertexMap.put(ref.getDstObjectId(), new ObjectVertex(ref.getDstClassName(), null, xCor + (time * (srcSideSize - i)), yCor + (time * (srcSideSize - i)))); } @@ -391,7 +401,7 @@ coordinatorPoint.setX(coordinatorPoint.getX() + time * 2); xCor += time * 2; System.out.println(coordinatorPoint.getX() + ", " + xCor); - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, coordinatorObjId, coordinatorClassName, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + Object vertex = mxgraph.insertDeltaVertex(getMxDefaultParent(), coordinatorObjId, coordinatorClassName, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. objectToVertexMap.put(coordinatorObjId, new ObjectVertex(coordinatorClassName, vertex, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)))); dstSideSize++; } @@ -402,7 +412,7 @@ if (srcClassName.contains("[L")) { srcClassName = formatArrayName(srcClassName); } - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getSrcObjectId(), srcClassName, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + Object vertex = mxgraph.insertDeltaVertex(getMxDefaultParent(), ref.getSrcObjectId(), srcClassName, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. objectToVertexMap.put(ref.getSrcObjectId(), new ObjectVertex(ref.getSrcClassName(), vertex, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)))); cnt++; } @@ -411,7 +421,7 @@ if (dstClassName.contains("[L")) { dstClassName = formatArrayName(dstClassName); } - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getDstObjectId(), dstClassName, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + Object vertex = mxgraph.insertDeltaVertex(getMxDefaultParent(), ref.getDstObjectId(), dstClassName, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)), DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. objectToVertexMap.put(ref.getDstObjectId(), new ObjectVertex(ref.getDstClassName(), vertex, xCor - (time * (dstSideSize - i + cnt)), yCor + (time * (dstSideSize - i + cnt)))); } } else { @@ -567,9 +577,9 @@ if (srcCell != null && dstCell != null) { // isCreation() System.out.println("makeEdgeObject: " + fieldName + ", " + srcClassName + " (" + srcCell.hashCode() + "), " + " (" + dstCell.hashCode() + ")"/* + ", " + dstClassName*/); // BUG:NullPointerException - Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, fieldName, fieldName, srcCell, dstCell); - Point absPtSrcCell = getAbsolutePointforCell((mxICell)srcCell); - Point absPtDstCell = getAbsolutePointforCell((mxICell)dstCell); + 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)); } diff --git a/src/org/ntlab/deltaViewer/MagnetRONScheduledThreadPoolExecutor.java b/src/org/ntlab/deltaViewer/MagnetRONScheduledThreadPoolExecutor.java index 2b53e83..9768f62 100644 --- a/src/org/ntlab/deltaViewer/MagnetRONScheduledThreadPoolExecutor.java +++ b/src/org/ntlab/deltaViewer/MagnetRONScheduledThreadPoolExecutor.java @@ -32,6 +32,7 @@ } public void stop() { + super.shutdown(); } public void pause() { diff --git a/src/org/ntlab/deltaViewer/MagnetRONViewer.java b/src/org/ntlab/deltaViewer/MagnetRONViewer.java index a022c18..27d31cd 100644 --- a/src/org/ntlab/deltaViewer/MagnetRONViewer.java +++ b/src/org/ntlab/deltaViewer/MagnetRONViewer.java @@ -3,8 +3,8 @@ import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Graphics2D; -import java.awt.Point; import java.awt.event.ActionListener; +import java.awt.geom.Dimension2D; import java.awt.geom.Path2D; import java.awt.geom.Point2D; import java.util.AbstractMap; @@ -21,7 +21,9 @@ import org.jgrapht.graph.DefaultEdge; import org.jgrapht.graph.DirectedWeightedPseudograph; -import org.ntlab.animations.EdgeAnimation; +import org.ntlab.animations.MagnetRONAnimation; +import org.ntlab.animations.TranslateAnimation; +import org.ntlab.animations.VertexResizeAnimation; import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.IAliasCollector; import org.ntlab.deltaExtractor.Alias.AliasType; @@ -46,10 +48,6 @@ import com.mxgraph.util.mxUtils; import com.mxgraph.view.mxCellState; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; -import javafx.util.Duration; - /** * @@ -59,13 +57,16 @@ private static final long serialVersionUID = -6828987937804142956L; + // Test code (will be deleted) + private static final String TAG = MagnetRONViewer.class.getSimpleName(); + protected static Dimension DEFAULT_WINDOW_SIZE = new Dimension(1300, 700); protected static String WINDOW_TITLE = "Delta Viewer"; protected static Dimension DEFAULT_OBJECT_VERTEX_SIZE = new Dimension(70, 70); protected static Dimension DEFAULT_METHOD_EXECUTION_VERTEX_SIZE = new Dimension(55, 20); - protected static long DEFAULT_THREAD_SLEEP_MILLIS = 1001; + protected static long DEFAULT_THREAD_SLEEP_MILLIS = 1100; protected IAliasCollector aliasCollector; @@ -80,7 +81,6 @@ protected ThreadPoolExecutor threadPoolExecutor; protected DeltaAnimation deltaAnimation; - protected EdgeAnimation edgeAnimation; protected int curFrame = 0; public MagnetRONViewer() { @@ -93,36 +93,38 @@ }; deltaAnimation = new DeltaAnimation(mxgraph, getGraphComponent()); - edgeAnimation = new EdgeAnimation(mxgraph, getGraphComponent()); - edgeAnimation.setTotalCycleCount(10); - edgeAnimation.setDelay(100); threadPoolExecutor = new MagnetRONScheduledThreadPoolExecutor(2); - getGraphComponent().setPreferredSize(DEFAULT_WINDOW_SIZE); setLayout(new BorderLayout()); add(getGraphComponent(), BorderLayout.CENTER); } + public mxICell getMxDefaultParent() { + return mxDefaultParent; + } + public mxGraphComponent getGraphComponent() { return mxgraphComponent; } public void clear() { mxgraph.getModel().beginUpdate(); - try { - for (ObjectVertex ov: objectToVertexMap.values()) { - mxICell ovCell = (mxICell)ov.getCell(); - if (ovCell != null) { - if (!ovCell.getParent().equals(mxDefaultParent)) { - // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. - ovCell.getParent().remove(ovCell); - ovCell.setParent(mxDefaultParent); + synchronized (mxgraph.getModel()) { + try { + for (ObjectVertex ov: objectToVertexMap.values()) { + mxICell ovCell = (mxICell)ov.getCell(); + if (ovCell != null) { + if (!ovCell.getParent().equals(getMxDefaultParent())) { + // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. + ovCell.getParent().remove(ovCell); + ovCell.setParent(getMxDefaultParent()); + } } } + mxgraph.removeCells(mxgraph.getChildVertices(getMxDefaultParent())); + } finally { + mxgraph.getModel().endUpdate(); } - mxgraph.removeCells(mxgraph.getChildVertices(mxDefaultParent)); - } finally { - mxgraph.getModel().endUpdate(); } curFrame = 0; objectToVertexMap.clear(); @@ -228,7 +230,7 @@ double srcHeight = srcCell.getGeometry().getHeight(); double overlapWidth = srcWidth * Math.sqrt(2) * 0.1; double overlapHeight = srcHeight - (srcHeight * Math.sqrt(2) * 0.1); - Point srcCellAbsPt = getAbsolutePointforCell(srcCell); + Point2D srcCellAbsPt = getAbsolutePointforCell(srcCell); MethodInvocation methodInv; String fieldName = null; if (!methodExec.isCollectionType() @@ -236,26 +238,36 @@ methodInv = (MethodInvocation)alias.getOccurrencePoint().getStatement(); fieldName = methodInv.getCallerSideMethodName(); } + mxICell ovCell; mxgraph.getModel().beginUpdate(); - try { - // Creates a white cell of {@code ObjectVertex}. - mxICell ovCell = - (mxICell) mxgraph.insertDeltaVertex(mxDefaultParent, alias.getObjectId(), objectVertex.getLabel(), - srcCellAbsPt.getX() + overlapWidth, srcCellAbsPt.getY() + overlapHeight, - DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), - "fillColor=white"); - objectVertex.setCell(ovCell); - mxICell edge = (mxICell) mxgraph.insertDeltaEdge(mxDefaultParent, fieldName, null, srcCell, ovCell); -// setEdgePoint((mxCell)edge, srcCellAbsPt, objectVertex.getInitialPoint()); - edgeMap.put(methodExec.getThisClassName() + "." + fieldName, new Edge(fieldName, TypeName.Create, edge)); -// setCellsStyle(); - update(); - deltaAnimation.setVertexAnimation(ovCell, new mxPoint(objectVertex.getInitialX(), objectVertex.getInitialY())); - deltaAnimation.startVertexAnimation(); - deltaAnimation.sleepThread(1001); - } finally { - mxgraph.getModel().endUpdate(); + synchronized (mxgraph.getModel()) { + try { + // Creates a white cell of {@code ObjectVertex}. + ovCell = + (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), alias.getObjectId(), objectVertex.getLabel(), + srcCellAbsPt.getX() + overlapWidth, srcCellAbsPt.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); + // setEdgePoint((mxCell)edge, srcCellAbsPt, objectVertex.getInitialPoint()); + edgeMap.put(methodExec.getThisClassName() + "." + fieldName, new Edge(fieldName, TypeName.Create, edge)); + // setCellsStyle(); + update(); + } finally { + mxgraph.getModel().endUpdate(); + } } + // deltaAnimation.setVertexAnimation(ovCell, new mxPoint(objectVertex.getInitialX(), objectVertex.getInitialY())); + // deltaAnimation.startVertexAnimation(); + // deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(ovCell, objectVertex.getX(), objectVertex.getY(), threadPoolExecutor); +// vertexAnim.play(); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + vertexAnim.syncPlay(); } /** @@ -272,33 +284,43 @@ double srcHeight = srcCell.getGeometry().getHeight(); double overlapWidth = srcWidth * Math.sqrt(2) * 0.1; double overlapHeight = srcHeight - (srcHeight * Math.sqrt(2) * 0.1); - Point srcCellAbsPt = getAbsolutePointforCell(srcCell); + Point2D srcCellAbsPt = getAbsolutePointforCell(srcCell); MethodInvocation methodInv; String fieldName = null; if (!methodExec.isCollectionType() && alias.getOccurrencePoint().getStatement() != null) { methodInv = (MethodInvocation)alias.getOccurrencePoint().getStatement(); fieldName = methodInv.getCallerSideMethodName(); } + mxICell ovCell; mxgraph.getModel().beginUpdate(); - try { - // Creates a white cell of {@code ObjectVertex}. - mxICell ovCell = - (mxICell) mxgraph.insertDeltaVertex(mxDefaultParent, objectVertex.getLabel(), objectVertex.getLabel(), - srcCellAbsPt.getX() + overlapWidth, srcCellAbsPt.getY() + overlapHeight, - DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), - "fillColor=white"); - objectVertex.setCell(ovCell); - mxICell edge = (mxICell) mxgraph.insertDeltaEdge(mxDefaultParent, fieldName, null, srcCell, ovCell); - setEdgePoint(edge, srcCellAbsPt, objectVertex.getInitialPoint()); - edgeMap.put(methodExec.getThisClassName() + "." + fieldName, new Edge(fieldName, TypeName.Create, edge)); -// setCellsStyle(); - update(); - deltaAnimation.setVertexAnimation(ovCell, new mxPoint(objectVertex.getInitialX(), objectVertex.getInitialY())); - deltaAnimation.startVertexAnimation(); - deltaAnimation.sleepThread(1001); - } finally { - mxgraph.getModel().endUpdate(); - } + synchronized (mxgraph.getModel()) { + try { + // Creates a white cell of {@code ObjectVertex}. + ovCell = + (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), objectVertex.getLabel(), objectVertex.getLabel(), + srcCellAbsPt.getX() + overlapWidth, srcCellAbsPt.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); + setEdgePoint(edge, srcCellAbsPt, objectVertex.getInitialPoint()); + edgeMap.put(methodExec.getThisClassName() + "." + fieldName, new Edge(fieldName, TypeName.Create, edge)); + // setCellsStyle(); + update(); + } finally { + mxgraph.getModel().endUpdate(); + } + } + // deltaAnimation.setVertexAnimation(ovCell, new mxPoint(objectVertex.getInitialX(), objectVertex.getInitialY())); + // deltaAnimation.startVertexAnimation(); + // deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(ovCell, objectVertex.getInitialX(), objectVertex.getInitialY(), threadPoolExecutor); +// vertexAnim.play(); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + vertexAnim.syncPlay(); } /** @@ -309,29 +331,51 @@ protected void createObjectRefrence(FieldUpdate fieldUpdateStatement, String fieldName) { String srcObjId = fieldUpdateStatement.getContainerObjId(); String dstObjId = fieldUpdateStatement.getValueObjId(); - mxICell dstCell = (mxICell)objectToVertexMap.get(dstObjId).getCell(); - Point dstCellAbsPt = getAbsolutePointforCell(dstCell); + ObjectVertex dstObjVertex = objectToVertexMap.get(dstObjId); + mxICell dstCell = (mxICell)dstObjVertex.getCell(); + Point2D dstCellAbsPt = getAbsolutePointforCell(dstCell); mxgraph.getModel().beginUpdate(); - try { - dstCell.getParent().remove(dstCell); - dstCell.setParent(mxDefaultParent); - dstCell.getGeometry().setX(dstCellAbsPt.getX()); - dstCell.getGeometry().setY(dstCellAbsPt.getY()); - mxICell edge = - (mxICell) mxgraph.insertDeltaEdge(mxDefaultParent, fieldUpdateStatement.getFieldName(), fieldName, - objectToVertexMap.get(srcObjId).getCell(), objectToVertexMap.get(dstObjId).getCell()); - edge.setStyle("strokeColor=red;"); - // mxgraph.orderCells(true, new Object[] {edge}); - edgeMap.put(fieldUpdateStatement.getFieldName(), new Edge(fieldName, TypeName.Reference, edge)); - deltaAnimation.setVertexAnimation(dstCell, new mxPoint(objectToVertexMap.get(dstObjId).getInitialX(), objectToVertexMap.get(dstObjId).getInitialY())); - deltaAnimation.startVertexAnimation(); - deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); - dstCell.getGeometry().setX(objectToVertexMap.get(dstObjId).getInitialX()); - dstCell.getGeometry().setY(objectToVertexMap.get(dstObjId).getInitialY()); - } finally { - mxgraph.getModel().endUpdate(); - } + synchronized (mxgraph.getModel()) { + try { + // dstCell.getParent().remove(dstCell); + // dstCell.setParent(mxDefaultParent); + if (!dstCell.getParent().equals(getMxDefaultParent())) { + // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. + dstCell.getParent().remove(dstCell); + dstCell.setParent(getMxDefaultParent()); + } + dstCell.getGeometry().setX(dstCellAbsPt.getX()); + dstCell.getGeometry().setY(dstCellAbsPt.getY()); + mxICell edge = + (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), fieldUpdateStatement.getFieldName(), fieldName, + objectToVertexMap.get(srcObjId).getCell(), objectToVertexMap.get(dstObjId).getCell()); + edge.setStyle("strokeColor=red;"); + // mxgraph.orderCells(true, new Object[] {edge}); + edgeMap.put(fieldUpdateStatement.getFieldName(), new Edge(fieldName, TypeName.Reference, edge)); + } finally { + mxgraph.getModel().endUpdate(); + } + } + // deltaAnimation.setVertexAnimation(dstCell, new mxPoint(objectToVertexMap.get(dstObjId).getInitialX(), objectToVertexMap.get(dstObjId).getInitialY())); + // deltaAnimation.startVertexAnimation(); + // deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(dstCell, dstObjVertex.getInitialX(), dstObjVertex.getInitialY(), threadPoolExecutor); +// vertexAnim.play(); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + vertexAnim.syncPlay(); + mxgraph.getModel().beginUpdate(); + synchronized (mxgraph.getModel()) { + try { + dstCell.getGeometry().setX(dstObjVertex.getInitialX()); + dstCell.getGeometry().setY(dstObjVertex.getInitialY()); + } finally { + mxgraph.getModel().endUpdate(); + } + } } /** @@ -341,31 +385,54 @@ * @param destinationObjectId */ protected void createObjectRefrence(String sourceClassName, String sourceObjectId, String destinationObjectId) { - mxICell dstCell = (mxICell)objectToVertexMap.get(destinationObjectId).getCell(); - Point dstCellAbsPt = getAbsolutePointforCell(dstCell); + ObjectVertex dstObjVertex = objectToVertexMap.get(destinationObjectId); + mxICell dstCell = (mxICell)dstObjVertex.getCell(); + Point2D dstCellAbsPt = getAbsolutePointforCell(dstCell); // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); - try { - dstCell.getParent().remove(dstCell); - dstCell.setParent(mxDefaultParent); - dstCell.getGeometry().setX(dstCellAbsPt.getX()); - dstCell.getGeometry().setY(dstCellAbsPt.getY()); - mxICell edge = - (mxICell) mxgraph.insertDeltaEdge(mxDefaultParent, destinationObjectId, null, - objectToVertexMap.get(sourceObjectId).getCell(), objectToVertexMap.get(destinationObjectId).getCell()); - ((mxCell)edge).setStyle("strokeColor=red;"); - edgeMap.put(destinationObjectId, new Edge(null, TypeName.Reference, edge)); - deltaAnimation.setVertexAnimation(dstCell, new mxPoint(objectToVertexMap.get(destinationObjectId).getInitialX(), objectToVertexMap.get(destinationObjectId).getInitialY())); - deltaAnimation.startVertexAnimation(); - deltaAnimation.sleepThread(1001); - dstCell.getGeometry().setX(objectToVertexMap.get(destinationObjectId).getInitialX()); - dstCell.getGeometry().setY(objectToVertexMap.get(destinationObjectId).getInitialY()); - } finally { - mxgraph.getModel().endUpdate(); + synchronized (mxgraph.getModel()) { + try { + // dstCell.getParent().remove(dstCell); + // dstCell.setParent(mxDefaultParent); + if (!dstCell.getParent().equals(getMxDefaultParent())) { + // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. + dstCell.getParent().remove(dstCell); + dstCell.setParent(getMxDefaultParent()); + } + dstCell.getGeometry().setX(dstCellAbsPt.getX()); + dstCell.getGeometry().setY(dstCellAbsPt.getY()); + mxICell edge = + (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), destinationObjectId, null, + objectToVertexMap.get(sourceObjectId).getCell(), objectToVertexMap.get(destinationObjectId).getCell()); + edge.setStyle("strokeColor=red;"); + edgeMap.put(destinationObjectId, new Edge(null, TypeName.Reference, edge)); + } finally { + mxgraph.getModel().endUpdate(); + } } - // Test code (will be deleted) - System.out.println("rTHIS " + sourceClassName + ", " + destinationObjectId); + // deltaAnimation.setVertexAnimation(dstCell, new mxPoint(objectToVertexMap.get(destinationObjectId).getInitialX(), objectToVertexMap.get(destinationObjectId).getInitialY())); + // deltaAnimation.startVertexAnimation(); + // deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(dstCell, dstObjVertex.getInitialX(), dstObjVertex.getInitialY(), threadPoolExecutor); +// vertexAnim.play(); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + vertexAnim.syncPlay(); + // 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(dstObjVertex.getInitialX()); + dstCell.getGeometry().setY(dstObjVertex.getInitialY()); + // Test code (will be deleted) + System.out.println("rTHIS " + sourceClassName + ", " + destinationObjectId); + } finally { + mxgraph.getModel().endUpdate(); + } + } } /** @@ -406,7 +473,7 @@ } } if (alias.getAliasType().equals(AliasType.RETURN_VALUE)) { - deltaAnimation.sleepThread(1001); + sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); } moveLocalObjectVertex(methodExec, sourceObjectVertex, destinationMethodExecutionVertex); } else if (alias.getAliasType().equals(AliasType.FORMAL_PARAMETER)) { @@ -424,10 +491,11 @@ * @param destinationMethodExecutionVertex */ private void moveLocalObjectVertex(MethodExecution callerMethodExecution, ObjectVertex sourceObjectVertex, MethodExecutionVertex destinationMethodExecutionVertex) { - mxICell sourceCell = (mxICell)sourceObjectVertex.getCell(); - mxICell destinationCell = (mxICell) destinationMethodExecutionVertex.getCell(); + mxICell srcCell = (mxICell)sourceObjectVertex.getCell(); + mxICell dstCell = (mxICell) destinationMethodExecutionVertex.getCell(); - if (sourceCell == destinationCell.getParent()) { +// if (srcCell == dstCell.getParent()) { + if (srcCell.equals(dstCell.getParent())) { // Test code (will be deleted) System.out.println("Nothing to moveLocalObjectVertex()."); return; @@ -446,47 +514,78 @@ System.out.println(methodExecToVertexMap.get(callerMethodExecution).getLabel() + " :removeArgument: " + sourceObjectVertex.getLabel()); } + int time = destinationMethodExecutionVertex.getLocals().size(); + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); - try { - int time = destinationMethodExecutionVertex.getLocals().size(); - double srcCellCoordX = sourceCell.getGeometry().getX(); - double srcCellCoordY = sourceCell.getGeometry().getY(); + synchronized (mxgraph.getModel()) { + try { + double srcCellCoordX = srcCell.getGeometry().getX(); + double srcCellCoordY = srcCell.getGeometry().getY(); - if(sourceCell.getParent().getValue() != null) { - Point absolutePointSourceCell = getAbsolutePointforCell(sourceCell); - srcCellCoordX = absolutePointSourceCell.getX(); - srcCellCoordY = absolutePointSourceCell.getY(); - sourceCell.getParent().remove(sourceCell); + if(srcCell.getParent().getValue() != null) { + Point2D absolutePointSourceCell = getAbsolutePointforCell(srcCell); + srcCellCoordX = absolutePointSourceCell.getX(); + srcCellCoordY = absolutePointSourceCell.getY(); + srcCell.getParent().remove(srcCell); + } + + mxgraph.orderCells(true, new Object[] {srcCell}); + // srcCell.setParent(dstCell.getParent()); + // dstCell.getParent().insert(srcCell); + if (srcCell.getParent() == null || !srcCell.getParent().equals(dstCell.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); + } + // Test code (will be deleted) + System.out.println("moveLocalObjectVertex: " + srcCell.getId() + " (" + srcCell.hashCode() + ")" + ", " + srcCell.getParent().getId() + " (" + srcCell.getParent().hashCode() + ")"); + System.out.println(" " + dstCell.getId() + " (" + dstCell.hashCode() + ")" + ", " + dstCell.getParent().getId() + " (" + dstCell.getParent().hashCode() + ")"); + + Point2D dstCellAbsPt = getAbsolutePointforCell(srcCell.getParent()); + srcCell.getGeometry().setX(srcCellCoordX - dstCellAbsPt.getX()); + srcCell.getGeometry().setY(srcCellCoordY - dstCellAbsPt.getY()); + } finally { + mxgraph.getModel().endUpdate(); } + } - mxgraph.orderCells(true, new Object[] {sourceCell}); - sourceCell.setParent(destinationCell.getParent()); - destinationCell.getParent().insert(sourceCell); - // Test code (will be deleted) - System.out.println("moveLocalObjectVertex: " + sourceCell.getId() + " (" + sourceCell.hashCode() + ")" + ", " + sourceCell.getParent().getId() + " (" + sourceCell.getParent().hashCode() + ")"); - System.out.println(" " + destinationCell.getId() + " (" + destinationCell.hashCode() + ")" + ", " + destinationCell.getParent().getId() + " (" + destinationCell.getParent().hashCode() + ")"); + double srcCellWidth = srcCell.getGeometry().getWidth(); + double dstCellHeight = dstCell.getGeometry().getHeight(); - Point dstCellAbsPt = getAbsolutePointforCell(sourceCell.getParent()); - sourceCell.getGeometry().setX(srcCellCoordX - dstCellAbsPt.getX()); - sourceCell.getGeometry().setY(srcCellCoordY - dstCellAbsPt.getY()); - - double srcCellWidth = sourceCell.getGeometry().getWidth(); - double dstCellHeight = destinationCell.getGeometry().getHeight(); - - deltaAnimation.setVertexAnimation(sourceCell, new mxPoint(destinationCell.getGeometry().getX() - (srcCellWidth / Math.sqrt(2.5)) + (srcCellWidth * time), destinationCell.getGeometry().getY() + dstCellHeight)); - deltaAnimation.startVertexAnimation(); - deltaAnimation.sleepThread(1001); - - sourceCell.setParent(destinationCell.getParent()); - destinationCell.getParent().insert(sourceCell); - sourceCell.getGeometry().setX(destinationCell.getGeometry().getX() - (srcCellWidth / Math.sqrt(2.5)) + (srcCellWidth * time)); - sourceCell.getGeometry().setY(destinationCell.getGeometry().getY() + dstCellHeight); - destinationMethodExecutionVertex.getLocals().add(sourceObjectVertex); - // Test code (will be deleted) - System.out.println("moveLocalObjectVertex: " + destinationMethodExecutionVertex.getLabel() + " :Local: " + sourceObjectVertex.getLabel()); - } finally { - mxgraph.getModel().endUpdate(); + // deltaAnimation.setVertexAnimation(srcCell, new mxPoint(dstCell.getGeometry().getX() - (srcCellWidth / Math.sqrt(2.5)) + (srcCellWidth * time), dstCell.getGeometry().getY() + dstCellHeight)); + // deltaAnimation.startVertexAnimation(); + // deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(srcCell, + dstCell.getGeometry().getX() - (srcCellWidth / Math.sqrt(2.5)) + (srcCellWidth * time), dstCell.getGeometry().getY() + dstCellHeight, + threadPoolExecutor); + // vertexAnim.play(); + // sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + vertexAnim.syncPlay(); + + // 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.setParent(dstCell.getParent()); + // dstCell.getParent().insert(srcCell); + if (!srcCell.getParent().equals(dstCell.getParent())) { + srcCell.getParent().remove(srcCell); + srcCell.setParent(dstCell.getParent()); + dstCell.getParent().insert(srcCell); + } + srcCell.getGeometry().setX(dstCell.getGeometry().getX() - (srcCellWidth / Math.sqrt(2.5)) + (srcCellWidth * time)); + srcCell.getGeometry().setY(dstCell.getGeometry().getY() + dstCellHeight); + destinationMethodExecutionVertex.getLocals().add(sourceObjectVertex); + // Test code (will be deleted) + System.out.println("moveLocalObjectVertex: " + destinationMethodExecutionVertex.getLabel() + " :Local: " + sourceObjectVertex.getLabel()); + } finally { + mxgraph.getModel().endUpdate(); + } } } @@ -515,78 +614,147 @@ System.out.println(methodExecToVertexMap.get(callerMethodExec).getLabel() + " :removeArgument: " + sourceObjectVertex.getLabel()); } + int time = destinationMethodExecutionVertex.getArguments().size(); + double srcCoordX = srcCell.getGeometry().getX(); + double srcCoordY = srcCell.getGeometry().getY(); + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); - try { - int time = destinationMethodExecutionVertex.getArguments().size(); - double srcCoordX = srcCell.getGeometry().getX(); - double srcCoordY = srcCell.getGeometry().getY(); + synchronized (mxgraph.getModel()) { + try { + if(srcCell.getParent().getValue() != null) { + Point2D srcCellAbsPt = getAbsolutePointforCell(srcCell); + srcCoordX = srcCellAbsPt.getX(); + srcCoordY = srcCellAbsPt.getY(); + srcCell.getParent().remove(srcCell); + } + } finally { + mxgraph.getModel().endUpdate(); + } + } - if(srcCell.getParent().getValue() != null) { - Point srcCellAbsPt = getAbsolutePointforCell(srcCell); - srcCoordX = srcCellAbsPt.getX(); - srcCoordY = srcCellAbsPt.getY(); - srcCell.getParent().remove(srcCell); + if (!isParent(dstCell, srcCell)) { + // 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}); + // srcCell.setParent(dstCell.getParent()); + // dstCell.getParent().insert(srcCell); + if (srcCell.getParent() == null || !srcCell.getParent().equals(dstCell.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); + } + Point2D srcParentCellAbsPt = getAbsolutePointforCell(srcCell.getParent()); + srcCell.getGeometry().setX(srcCoordX - srcParentCellAbsPt.getX()); + srcCell.getGeometry().setY(srcCoordY - srcParentCellAbsPt.getY()); + } finally { + mxgraph.getModel().endUpdate(); + } } - if (!isParent(dstCell, srcCell)) { - mxgraph.orderCells(true, new Object[] {srcCell}); - srcCell.setParent(dstCell.getParent()); - dstCell.getParent().insert(srcCell); - Point srcParentCellAbsPt = getAbsolutePointforCell(srcCell.getParent()); - srcCell.getGeometry().setX(srcCoordX - srcParentCellAbsPt.getX()); - srcCell.getGeometry().setY(srcCoordY - srcParentCellAbsPt.getY()); + 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 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); + // 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); + vertexAnim.init(srcCell, + dstCell.getGeometry().getX() - overlapWidth, dstCell.getGeometry().getY() - overlapHeight + (srcCellHeight * time), + threadPoolExecutor); +// vertexAnim.play(); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + vertexAnim.syncPlay(); - deltaAnimation.setVertexAnimation(srcCell, new mxPoint(dstCell.getGeometry().getX() - overlapWidth, dstCell.getGeometry().getY() - overlapHeight + (srcCellHeight * time))); - deltaAnimation.startVertexAnimation(); - deltaAnimation.sleepThread(1001); - - srcCell.getGeometry().setX(dstCell.getGeometry().getX() - overlapWidth); - srcCell.getGeometry().setY(dstCell.getGeometry().getY() - overlapHeight + (srcCellHeight * time)); - destinationMethodExecutionVertex.getArguments().add(sourceObjectVertex); - // Test code (will be deleted) - System.out.println("moveArgumentObejctVertex" + destinationMethodExecutionVertex.getLabel() + " :Argument: " + sourceObjectVertex.getLabel()); - } else { // TODO: �d�l��̃o�O�A���[�v������ - // Test code (will be deleted) - outputLog(); - - // ����{@code ObjectVertex} - Point srcCellAbsPt = getAbsolutePointforCell(srcCell); - Point dstParentCellAbsPt = getAbsolutePointforCell(dstCell.getParent()); - - srcCell.remove(dstCell.getParent()); - dstCell.getParent().setParent(mxDefaultParent); - srcCell.setParent(dstCell.getParent()); - dstCell.getParent().insert(srcCell); - - 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"); - - 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); - - deltaAnimation.setVertexAnimation(srcCell, new mxPoint(dstCell.getGeometry().getX() - overlapWidth + (srcCellWidth * time), dstCell.getGeometry().getY() - overlapHeight + (srcCellHeight * time))); - deltaAnimation.startVertexAnimation(); - deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); - // Test code (will be deleted) - outputLog(); - srcCell.getGeometry().setX(dstCell.getGeometry().getX() - overlapWidth + (srcCellWidth * time)); - srcCell.getGeometry().setY(dstCell.getGeometry().getY() - overlapHeight + (srcCellHeight * time)); - - destinationMethodExecutionVertex.getArguments().add(sourceObjectVertex); + // 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)); + } finally { + mxgraph.getModel().endUpdate(); + } } - } finally { - mxgraph.getModel().endUpdate(); + + destinationMethodExecutionVertex.getArguments().add(sourceObjectVertex); + // Test code (will be deleted) + System.out.println("moveArgumentObejctVertex" + destinationMethodExecutionVertex.getLabel() + " :Argument: " + sourceObjectVertex.getLabel()); + } else { // TODO: �d�l��̃o�O�A���[�v������ + // Test code (will be deleted) + outputLog(); + + // ���� ObjectVertex + Point2D srcCellAbsPt = getAbsolutePointforCell(srcCell); + Point2D dstParentCellAbsPt = getAbsolutePointforCell(dstCell.getParent()); + + // 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.remove(dstCell.getParent()); + // dstCell.getParent().setParent(mxDefaultParent); + // srcCell.setParent(dstCell.getParent()); + // dstCell.getParent().insert(srcCell); + if (!dstCell.getParent().getParent().equals(getMxDefaultParent()) + || !srcCell.getParent().equals(dstCell.getParent())) { + srcCell.remove(dstCell.getParent()); + dstCell.getParent().remove(dstCell); + dstCell.getParent().setParent(getMxDefaultParent()); + srcCell.getParent().remove(srcCell); + srcCell.setParent(dstCell.getParent()); + dstCell.getParent().insert(srcCell); + } + + 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"); + } 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); + + // deltaAnimation.setVertexAnimation(srcCell, new mxPoint(dstCell.getGeometry().getX() - overlapWidth + (srcCellWidth * time), 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); + vertexAnim.init(srcCell, + dstCell.getGeometry().getX() - overlapWidth + (srcCellWidth * time), dstCell.getGeometry().getY() - overlapHeight + (srcCellHeight * time), + threadPoolExecutor); +// vertexAnim.play(); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + vertexAnim.syncPlay(); + + // Test code (will be deleted) + outputLog(); + // 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)); + } finally { + mxgraph.getModel().endUpdate(); + } + } + + destinationMethodExecutionVertex.getArguments().add(sourceObjectVertex); } } @@ -608,7 +776,8 @@ mxICell srcCell = (mxICell)sourceObjectVertex.getCell(); mxICell dstCell = (mxICell) destinationMethodExecutionVertex.getCell(); - if (srcCell == dstCell.getParent()) { +// if (srcCell == dstCell.getParent()) { + if (srcCell.equals(dstCell.getParent())) { System.out.println("Nothing to moveActualArgumentObjectVertex()."); return; } @@ -629,101 +798,164 @@ System.out.println(methodExecToVertexMap.get(methodExecution).getLabel() + " :removeArgument: " + sourceObjectVertex.getLabel()); } + int time = destinationMethodExecutionVertex.getLocals().size(); + double srcCellCoordX = srcCell.getGeometry().getX(); + double srcCellCoordY = srcCell.getGeometry().getY(); + + // Test code (will be deleted) + System.out.println(time + ", " + destinationMethodExecutionVertex.getLocals().size()); + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); - try { - int time = destinationMethodExecutionVertex.getLocals().size(); - double srcCellCoordX = srcCell.getGeometry().getX(); - double srcCellCoordY = srcCell.getGeometry().getY(); + synchronized (mxgraph.getModel()) { + try { + if(srcCell.getParent().getValue() != null) { + Point2D srcCellAbsPt = getAbsolutePointforCell(srcCell); + srcCellCoordX = srcCellAbsPt.getX(); + srcCellCoordY = srcCellAbsPt.getY(); + srcCell.getParent().remove(srcCell); + } - // Test code (will be deleted) - System.out.println(time + ", " + destinationMethodExecutionVertex.getLocals().size()); - - if(srcCell.getParent().getValue() != null) { - Point srcCellAbsPt = getAbsolutePointforCell(srcCell); - srcCellCoordX = srcCellAbsPt.getX(); - srcCellCoordY = srcCellAbsPt.getY(); - srcCell.getParent().remove(srcCell); + // srcCell.setParent(dstCell.getParent()); + // dstCell.getParent().insert(srcCell); + if (srcCell.getParent() == null || !srcCell.getParent().equals(dstCell.getParent())) { + if (srcCell.getParent() != null) srcCell.getParent().remove(srcCell); + srcCell.setParent(dstCell.getParent()); + dstCell.getParent().insert(srcCell); + } + Point2D srcParentCellAbsPt = getAbsolutePointforCell(srcCell.getParent()); + srcCell.getGeometry().setX(srcCellCoordX - srcParentCellAbsPt.getX()); + srcCell.getGeometry().setY(srcCellCoordY - srcParentCellAbsPt.getY()); + } finally { + mxgraph.getModel().endUpdate(); } - - srcCell.setParent(dstCell.getParent()); - dstCell.getParent().insert(srcCell); - Point srcParentCellAbsPt = getAbsolutePointforCell(srcCell.getParent()); - srcCell.getGeometry().setX(srcCellCoordX - srcParentCellAbsPt.getX()); - srcCell.getGeometry().setY(srcCellCoordY - srcParentCellAbsPt.getY()); - - double srcCellWidth = srcCell.getGeometry().getWidth(); - double dstCellHeight = dstCell.getGeometry().getHeight(); - - deltaAnimation.setVertexAnimation(srcCell, - new mxPoint(dstCell.getGeometry().getX() - (srcCellWidth / Math.sqrt(3)) + (srcCellWidth * time), dstCell.getGeometry().getY() + dstCellHeight)); - deltaAnimation.startVertexAnimation(); - deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); - srcCell.getGeometry().setX(dstCell.getGeometry().getX() - (srcCellWidth / Math.sqrt(3)) + (srcCellWidth * time)); - srcCell.getGeometry().setY(dstCell.getGeometry().getY() + dstCellHeight); - - destinationMethodExecutionVertex.getArguments().add(sourceObjectVertex); - // Test code (will be deleted) - System.out.println("moveActualArgumentObjectVertex: " + destinationMethodExecutionVertex.getLabel() + " :Argument: " + sourceObjectVertex.getLabel()); - } finally { - mxgraph.getModel().endUpdate(); } + + double srcCellWidth = srcCell.getGeometry().getWidth(); + double dstCellHeight = dstCell.getGeometry().getHeight(); + + // deltaAnimation.setVertexAnimation(srcCell, + // new mxPoint(dstCell.getGeometry().getX() - (srcCellWidth / Math.sqrt(3)) + (srcCellWidth * time), dstCell.getGeometry().getY() + dstCellHeight)); + // deltaAnimation.startVertexAnimation(); + // deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(srcCell, + dstCell.getGeometry().getX() - (srcCellWidth / Math.sqrt(3)) + (srcCellWidth * time), dstCell.getGeometry().getY() + dstCellHeight, + threadPoolExecutor); +// vertexAnim.play(); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + vertexAnim.syncPlay(); + + // 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() - (srcCellWidth / Math.sqrt(3)) + (srcCellWidth * time)); + srcCell.getGeometry().setY(dstCell.getGeometry().getY() + dstCellHeight); + } finally { + mxgraph.getModel().endUpdate(); + } + } + + destinationMethodExecutionVertex.getArguments().add(sourceObjectVertex); + // Test code (will be deleted) + System.out.println("moveActualArgumentObjectVertex: " + destinationMethodExecutionVertex.getLabel() + " :Argument: " + sourceObjectVertex.getLabel()); } /** * Update size and position of all {@code ObjectVertex}. */ protected void updateObjectVertices() { - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology - mxgraph.getModel().beginUpdate(); - try { - for (ObjectVertex ov: objectToVertexMap.values()) { - mxCell ovCell = (mxCell) ov.getCell(); - if (ovCell != null) { - int time = 0; - for (int i = 0; i < ovCell.getChildCount(); i++) { - if (!(ovCell.getChildAt(i).getId()).contains("clone")) { - time++; - } + Map mxICellToTranslateAnimMap = new HashMap<>(); + for (ObjectVertex ov: objectToVertexMap.values()) { + mxICell ovCell = (mxICell) ov.getCell(); +// if (ovCell == null || mxICellToTranslateAnimMap.get(ovCell) != null) continue; + if (ovCell == null) continue; + Dimension2D curDim = new Dimension((int) ovCell.getGeometry().getWidth(), (int) ovCell.getGeometry().getHeight()); + int sizeScale = 0; + for (int i = 0; i < ovCell.getChildCount(); i++) { + if (!ovCell.getChildAt(i).getId().contains("clone")) sizeScale++; + } + if (sizeScale == 0) sizeScale = 1; +// Dimension dstDim = +// new Dimension((int) DEFAULT_OBJECT_VERTEX_SIZE.getWidth() * sizeScale, +// (int) DEFAULT_OBJECT_VERTEX_SIZE.getHeight() * sizeScale); + 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()); +// mxPoint dstPt = new mxPoint(ovCell.getGeometry().getX(), ovCell.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() != mxDefaultParent && (ovCell.getChildCount() != 0 || ovCell.getGeometry().getWidth() > DEFAULT_OBJECT_VERTEX_SIZE.getWidth() * time)) { + if (!ovCell.getParent().equals(getMxDefaultParent()) + && (ovCell.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 = new mxPoint(ovCell.getGeometry().getX() - overlapX, ovCell.getGeometry().getY() + overlapY); + dstPt.setLocation(ovCell.getGeometry().getX() - overlapX, ovCell.getGeometry().getY() + overlapY); + + int idxFromParent = ovCell.getParent().getIndex(ovCell); + if (idxFromParent >= 2) { + overlapY = (dstDim.getHeight() - ovCell.getGeometry().getHeight()) / 2; +// dstPt.setY(ovCell.getGeometry().getY() + overlapY); + dstPt.setLocation(dstPt.getX(), ovCell.getGeometry().getY() + overlapY); } - if (time == 0) { - time = 1; - } - if(ovCell.getGeometry().getWidth() != DEFAULT_OBJECT_VERTEX_SIZE.getWidth() * time) { - // Test code (will be deleted) - System.out.println("updateVertexObjectSize: " + ovCell.getGeometry().getWidth() + "->" + DEFAULT_OBJECT_VERTEX_SIZE.getWidth() * time+ ", " + ovCell.getId()); - Dimension dstSize = new Dimension(); - dstSize.setSize(DEFAULT_OBJECT_VERTEX_SIZE.getWidth() * time, DEFAULT_OBJECT_VERTEX_SIZE.getHeight() * time); - if (ovCell.getParent() != mxDefaultParent && (ovCell.getChildCount() != 0 || ovCell.getGeometry().getWidth() > DEFAULT_OBJECT_VERTEX_SIZE.getWidth() * time)) { - double overlapX = (dstSize.getWidth() - ovCell.getGeometry().getWidth()) / 2 / Math.sqrt(2); - double overlapY = (dstSize.getHeight() - ovCell.getGeometry().getHeight()) / 2 / Math.sqrt(2); - // Test code (will be deleted) - System.out.println("updateVertexObjectPosition: " + ovCell.getGeometry().getX() + " - " + overlapX); - mxPoint dstPt = new mxPoint(ovCell.getGeometry().getX() - overlapX, ovCell.getGeometry().getY() + overlapY); - int idxFromParent = ovCell.getParent().getIndex(ovCell); - if (idxFromParent >= 2) { - overlapY = (dstSize.getHeight() - ovCell.getGeometry().getHeight()) / 2; - dstPt.setY(ovCell.getGeometry().getY() + overlapY); - } - for (MethodExecutionVertex methodExecVertex: methodExecToVertexMap.values()) { - List arguments = methodExecVertex.getArguments(); - if (arguments != null && arguments.contains(ov)) { - dstPt.setY(ovCell.getGeometry().getY() - overlapY); - break; - } - } - deltaAnimation.setVertexAnimation(ovCell, dstPt); - deltaAnimation.startVertexAnimation(); + for (MethodExecutionVertex methodExecVertex: methodExecToVertexMap.values()) { + List arguments = methodExecVertex.getArguments(); + if (arguments != null && arguments.contains(ov)) { +// dstPt.setY(ovCell.getGeometry().getY() - overlapY); + dstPt.setLocation(dstPt.getX(), ovCell.getGeometry().getY() - overlapY); + break; } - deltaAnimation.setResizeVertexAnimation(ovCell, dstSize); - deltaAnimation.startResizeVertexAnimation(); - deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); } } + 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); +// deltaAnimation.setVertexAnimation(ovCell, dstPt); +// deltaAnimation.startVertexAnimation(); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + mxICellToTranslateAnimMap.put(ovCell, vertexAnim); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(ovCell, dstPt.getX(), dstPt.getY(), threadPoolExecutor); + vertexAnim.play(); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); +// deltaAnimation.setResizeVertexAnimation(ovCell, dstDim); +// deltaAnimation.startResizeVertexAnimation(); +// deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation vertexResizeAnim = new VertexResizeAnimation(mxgraph, getGraphComponent()); + vertexResizeAnim.setTotalCycleCount(10); + vertexResizeAnim.setDelay(100); + vertexResizeAnim.init(ovCell, dstDim.getWidth(), dstDim.getHeight(), threadPoolExecutor); + vertexResizeAnim.play(); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + for (int i = 0; i < ovCell.getChildCount(); i++) { + mxICell childCell = ovCell.getChildAt(i); +// if (mxICellToTranslateAnimMap.get(childCell) != null) continue; + double childCellCurX = childCell.getGeometry().getX(); + double childCellCurY = childCell.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()); + mxICellToTranslateAnimMap.put(childCell, childVertexAnim); + childVertexAnim.setTotalCycleCount(10); + childVertexAnim.setDelay(100); + childVertexAnim.init(childCell, childDstPt.getX(), childDstPt.getY(), threadPoolExecutor); + childVertexAnim.play(); + } + sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); } - } finally { - mxgraph.getModel().endUpdate(); } +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); } abstract protected void createMethodExecutionVertex(Alias alias); @@ -755,7 +987,7 @@ } double coordX = DEFAULT_OBJECT_VERTEX_SIZE.getWidth() * 0.1; - double coordY = DEFAULT_OBJECT_VERTEX_SIZE.getHeight() * 0.5; + double coordY = DEFAULT_OBJECT_VERTEX_SIZE.getHeight() * 0.5; double stdX = coordX; double stdY = 0; int time = objectToVertexMap.get(objectId).getVertexMethodExecutions().size(); @@ -770,27 +1002,29 @@ // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); - try { - // Creates a white cell of {@code ObjectVertex}. - mxICell cell = (mxICell) mxgraph.insertDeltaVertex(parentCell, methodSignature, methodSignature, "fillColor=white"); - mxgraph.orderCells(false, new Object[] {cell}); - // Test code (will be deleted) - System.out.println("makeVertexMethodExecution: " + cell.getId() + " in " + objectId + " (" + stdX + ", " + coordY * (time + 1) + stdY + ")"); - - MethodExecutionVertex methodExecVertex = - new MethodExecutionVertex(methodSignature, cell, stdX, coordY * (time + 1) + stdY, - DEFAULT_METHOD_EXECUTION_VERTEX_SIZE.getWidth(), DEFAULT_METHOD_EXECUTION_VERTEX_SIZE.getHeight()); - methodExecToVertexMap.put(methodExecution, methodExecVertex); - if(methodExecToVertexMap.size() > 1) { - cell.setVisible(false); - createEdgeToMethodExecution(); + synchronized (mxgraph.getModel()) { + try { + // Creates a white cell of {@code ObjectVertex}. + mxICell cell = (mxICell) mxgraph.insertDeltaVertex(parentCell, methodSignature, methodSignature, "fillColor=white"); + mxgraph.orderCells(false, new Object[] {cell}); + // Test code (will be deleted) + System.out.println("makeVertexMethodExecution: " + cell.getId() + " in " + objectId + " (" + stdX + ", " + coordY * (time + 1) + stdY + ")"); + + MethodExecutionVertex methodExecVertex = + new MethodExecutionVertex(methodSignature, cell, stdX, coordY * (time + 1) + stdY, + DEFAULT_METHOD_EXECUTION_VERTEX_SIZE.getWidth(), DEFAULT_METHOD_EXECUTION_VERTEX_SIZE.getHeight()); + methodExecToVertexMap.put(methodExecution, methodExecVertex); + if(methodExecToVertexMap.size() > 1) { + cell.setVisible(false); + createEdgeToMethodExecution(); + } + objectToVertexMap.get(objectId).addMethodExecution(methodExecVertex); + } finally { + mxgraph.getModel().endUpdate(); } - objectToVertexMap.get(objectId).addMethodExecution(methodExecVertex); - } finally { - mxgraph.getModel().endUpdate(); +// setCellsStyle(); + update(); } -// setCellsStyle(); - update(); } /** @@ -805,26 +1039,37 @@ if(alias.getAliasType().equals(AliasType.METHOD_INVOCATION) || alias.getAliasType().equals(AliasType.CONSTRACTOR_INVOCATION)) { MethodExecution calledMethodExec = ((MethodInvocation) alias.getOccurrencePoint().getStatement()).getCalledMethodExecution(); - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - mxgraph.getModel().beginUpdate(); - try { - List arguments = new ArrayList<>(methodExecToVertexMap.get(calledMethodExec).getArguments()); - List locals = new ArrayList<>(methodExecToVertexMap.get(calledMethodExec).getLocals()); - if (arguments.size() != 0) { - for (ObjectVertex vo: arguments) { - if (vo != srcObjVertex) { - // Test code (will be deleted) - System.out.println("argumentRemove"); - mxICell cell = (mxICell)vo.getCell(); - if (!cell.getParent().equals(mxDefaultParent)) { - Point cellAbsPt = getAbsolutePointforCell(cell); - cell.getParent().remove(cell); - cell.setParent(mxDefaultParent); - cell.getGeometry().setX(cellAbsPt.getX()); - cell.getGeometry().setY(cellAbsPt.getY()); - deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); - deltaAnimation.startVertexAnimation(); + List arguments = new ArrayList<>(methodExecToVertexMap.get(calledMethodExec).getArguments()); + List locals = new ArrayList<>(methodExecToVertexMap.get(calledMethodExec).getLocals()); + if (arguments.size() != 0) { + for (ObjectVertex vo: arguments) { + if (vo != srcObjVertex) { + // Test code (will be deleted) + System.out.println("argumentRemove"); + mxICell cell = (mxICell)vo.getCell(); + if (!cell.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()); + } finally { + mxgraph.getModel().endUpdate(); + } } + +// deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); +// deltaAnimation.startVertexAnimation(); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); + vertexAnim.play(); methodExecToVertexMap.get(calledMethodExec).getArguments().remove(vo); } } @@ -835,19 +1080,35 @@ // Test code (will be deleted) System.out.println("localRemove"); mxICell cell = (mxICell)vo.getCell(); - Point cellAbsPt = getAbsolutePointforCell(cell); - cell.getParent().remove(cell); - cell.setParent(mxDefaultParent); - cell.getGeometry().setX(cellAbsPt.getX()); - cell.getGeometry().setY(cellAbsPt.getY()); - deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); - deltaAnimation.startVertexAnimation(); - methodExecToVertexMap.get(calledMethodExec).getLocals().remove(vo); + // 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(mxDefaultParent); + if (!cell.getParent().equals(getMxDefaultParent())) { + // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. + cell.getParent().remove(cell); + cell.setParent(getMxDefaultParent()); + } + cell.getGeometry().setX(cellAbsPt.getX()); + cell.getGeometry().setY(cellAbsPt.getY()); + } finally { + mxgraph.getModel().endUpdate(); + } + } +// deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); +// deltaAnimation.startVertexAnimation(); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); + vertexAnim.play(); +// methodExecToVertexMap.get(calledMethodExec).getLocals().remove(vo); } } } - } finally { - mxgraph.getModel().endUpdate(); } removeCalledMethodExecutionVertex(srcObjVertex, methodExec, calledMethodExec); @@ -864,20 +1125,27 @@ */ private void removeMethodExecutionVertex(ObjectVertex sourceObjectVertex, MethodExecution methodExecution) { mxgraph.getModel().beginUpdate(); - 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(); - dstMethodExecVertexCell.getParent().remove(dstMethodExecVertexCell); - dstMethodExecVertexCell.setParent(mxDefaultParent); - mxgraph.removeCells(new Object[] {dstMethodExecVertexCell}); - objectToVertexMap.get(methodExecution.getThisObjId()).getVertexMethodExecutions().remove(methodExecToVertexMap.get(methodExecution)); - methodExecToVertexMap.remove(methodExecution); - edgeMap.remove(methodExecution.getSignature()); - updateObjectVertices(); + synchronized (mxgraph.getModel()) { + 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(); + // dstMethodExecVertexCell.getParent().remove(dstMethodExecVertexCell); + // dstMethodExecVertexCell.setParent(mxDefaultParent); + if (!dstMethodExecVertexCell.getParent().equals(getMxDefaultParent())) { + // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. + dstMethodExecVertexCell.getParent().remove(dstMethodExecVertexCell); + dstMethodExecVertexCell.setParent(getMxDefaultParent()); + } + mxgraph.removeCells(new Object[] {dstMethodExecVertexCell}); + objectToVertexMap.get(methodExecution.getThisObjId()).getVertexMethodExecutions().remove(methodExecToVertexMap.get(methodExecution)); + methodExecToVertexMap.remove(methodExecution); + edgeMap.remove(methodExecution.getSignature()); + updateObjectVertices(); + } + } finally { + mxgraph.getModel().endUpdate(); } - } finally { - mxgraph.getModel().endUpdate(); } } @@ -896,31 +1164,52 @@ if (methodExecToVertexMap.containsKey(calledMethodExecution)) { MethodExecutionVertex calledMethodExecVertex = methodExecToVertexMap.get(calledMethodExecution); - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - mxgraph.getModel().beginUpdate(); - try { // TODO: Confirm bug. List arguments = new ArrayList<>(calledMethodExecVertex.getArguments()); if (arguments.size() != 0) { for (ObjectVertex vo: arguments) { if (vo != sourceObjectVertex) { mxICell cell = (mxICell)vo.getCell(); - Point cellAbsPt = getAbsolutePointforCell(cell); + Point2D cellAbsPt = getAbsolutePointforCell(cell); // Test code (will be deleted) System.out.println(cell); System.out.println(vo.getInitialX() + ", " + vo.getInitialY()); System.out.println(cell.getGeometry().getX() + ", " + cell.getGeometry().getY()); System.out.println(cellAbsPt); - if (cell.getParent() != mxDefaultParent) { - cell.getParent().remove(cell); - cell.setParent(mxDefaultParent); + // 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 parent of ObjectVertex cell isn't mxDefaltParent, reset parent. + cell.getParent().remove(cell); + cell.setParent(getMxDefaultParent()); + } + } finally { + mxgraph.getModel().endUpdate(); + } } if (!cellAbsPt.equals(vo.getInitialPoint())) { - cell.getGeometry().setX(cellAbsPt.getX()); - cell.getGeometry().setY(cellAbsPt.getY()); - deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); - deltaAnimation.startVertexAnimation(); - deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + // 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()); + } finally { + mxgraph.getModel().endUpdate(); + } + } +// deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); +// deltaAnimation.startVertexAnimation(); +// deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); +// vertexAnim.play(); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + vertexAnim.syncPlay(); } methodExecToVertexMap.get(calledMethodExecution).getArguments().remove(vo); } @@ -932,30 +1221,51 @@ for (ObjectVertex vo: locals) { if (vo != sourceObjectVertex) { mxICell cell = (mxICell)vo.getCell(); - Point cellAbsPt = getAbsolutePointforCell(cell); + Point2D cellAbsPt = getAbsolutePointforCell(cell); // Test code (will be deleted) System.out.println(cell); System.out.println(vo.getInitialX() + ", " + vo.getInitialY()); System.out.println(cell.getGeometry().getX() + ", " + cell.getGeometry().getY()); System.out.println(cellAbsPt); - if (cell.getParent() != mxDefaultParent) { - cell.getParent().remove(cell); - cell.setParent(mxDefaultParent); + // 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 parent of ObjectVertex cell isn't mxDefaltParent, reset parent. + cell.getParent().remove(cell); + cell.setParent(getMxDefaultParent()); + } + } finally { + mxgraph.getModel().endUpdate(); + } } if (!cellAbsPt.equals(vo.getInitialPoint())) { - cell.getGeometry().setX(cellAbsPt.getX()); - cell.getGeometry().setY(cellAbsPt.getY()); - deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); - deltaAnimation.startVertexAnimation(); - deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + // 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()); + } finally { + mxgraph.getModel().endUpdate(); + } + } +// deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); +// deltaAnimation.startVertexAnimation(); +// deltaAnimation.sleepThread(DEFAULT_THREAD_SLEEP_MILLIS); + MagnetRONAnimation vertexAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + vertexAnim.setTotalCycleCount(10); + vertexAnim.setDelay(100); + vertexAnim.init(cell, vo.getInitialX(), vo.getInitialY(), threadPoolExecutor); +// vertexAnim.play(); +// sleepMainThread(DEFAULT_THREAD_SLEEP_MILLIS); + vertexAnim.syncPlay(); } methodExecToVertexMap.get(calledMethodExecution).getLocals().remove(vo); } } } - } finally { - mxgraph.getModel().endUpdate(); - } if (methodExecution == null) { return; @@ -964,38 +1274,62 @@ mxICell srcMethodExecVertexCell = (mxICell)methodExecToVertexMap.get(methodExecution).getCell(); mxICell dstMethodExecVertexCell = (mxICell)calledMethodExecVertex.getCell(); - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - mxgraph.getModel().beginUpdate(); try { - mxgraph.removeCells(mxgraph.getEdgesBetween(srcMethodExecVertexCell, dstMethodExecVertexCell)); - Point srcMethodExecVertexCellAbsPt = getAbsolutePointforCell(srcMethodExecVertexCell); - Point dstMethodExecVertexCellAbsPt = getAbsolutePointforCell(dstMethodExecVertexCell); - mxICell clonedstMethodExecVertexCell = (mxICell) mxgraph.addCell(dstMethodExecVertexCell.clone()); - clonedstMethodExecVertexCell.getGeometry().setX(dstMethodExecVertexCellAbsPt.getX()); - clonedstMethodExecVertexCell.getGeometry().setY(dstMethodExecVertexCellAbsPt.getY()); - clonedstMethodExecVertexCell.setStyle("fillColor=none;strokeColor=none;fontColor=#008000;"); - clonedstMethodExecVertexCell.setValue(null); - mxICell tmpEdge = (mxICell) mxgraph.insertEdge(mxDefaultParent, null, null, srcMethodExecVertexCell, clonedstMethodExecVertexCell); - tmpEdge.setStyle("dashed=1;strokeColor=#008000;exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;endArrow=none"); - + Point2D srcMethodExecVertexCellAbsPt = null; + Point2D dstMethodExecVertexCellAbsPt = null; + final mxICell[] clonedstMethodExecVertexCell = 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"); + } finally { + mxgraph.getModel().endUpdate(); + } + } // Animate an edge to shrink. - edgeAnimation.init(clonedstMethodExecVertexCell, new Point2D.Double(srcMethodExecVertexCellAbsPt.getX(), srcMethodExecVertexCellAbsPt.getY() + srcMethodExecVertexCell.getGeometry().getHeight()), threadPoolExecutor); + MagnetRONAnimation edgeAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + edgeAnim.setTotalCycleCount(10); + edgeAnim.setDelay(100); + edgeAnim.init(clonedstMethodExecVertexCell[0], srcMethodExecVertexCellAbsPt.getX(), srcMethodExecVertexCellAbsPt.getY() + srcMethodExecVertexCell.getGeometry().getHeight(), threadPoolExecutor); // Test code (will be deleted) System.out.println("absPointSourceVertexCell: " + srcMethodExecVertexCellAbsPt); - edgeAnimation.setOnFinished(new ActionListener() { + edgeAnim.setOnFinished(new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { - // Test code (will be deleted) - System.out.println("Shrink edge animation action performed. "); - mxgraph.removeCells(new Object[]{clonedstMethodExecVertexCell}); + // 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 { + // Test code (will be deleted) + System.out.println("Shrink edge animation action performed. "); + mxgraph.removeCells(new Object[]{clonedstMethodExecVertexCell[0]}); - // TODO: Confirm execution order. - dstMethodExecVertexCell.getParent().remove(dstMethodExecVertexCell); - dstMethodExecVertexCell.setParent(mxDefaultParent); - mxgraph.removeCells(new Object[] {dstMethodExecVertexCell}); + // TODO: Confirm execution order. +// dstMethodExecVertexCell.getParent().remove(dstMethodExecVertexCell); +// dstMethodExecVertexCell.setParent(mxDefaultParent); + if (!dstMethodExecVertexCell.getParent().equals(getMxDefaultParent())) { + // If parent of ObjectVertex cell isn't mxDefaltParent, reset parent. + dstMethodExecVertexCell.getParent().remove(dstMethodExecVertexCell); + dstMethodExecVertexCell.setParent(getMxDefaultParent()); + } + mxgraph.removeCells(new Object[] {dstMethodExecVertexCell}); + } finally { + mxgraph.getModel().endUpdate(); + } + } } }); - edgeAnimation.play(); + edgeAnim.play(); if (!calledMethodExecution.isStatic()) { objectToVertexMap.get(calledMethodExecution.getThisObjId()).getVertexMethodExecutions().remove(methodExecToVertexMap.get(calledMethodExecution)); @@ -1006,13 +1340,12 @@ methodExecToVertexMap.remove(calledMethodExecution); edgeMap.remove(methodExecution.getSignature()); - edgeAnimation.sleepThread(201); + sleepMainThread(400); } catch (CloneNotSupportedException e) { e.printStackTrace(); - } finally { - mxgraph.getModel().endUpdate(); - } + } } + // Test code (will be deleted) outputLog(); } @@ -1032,48 +1365,77 @@ // Draw an edge from sourceVertexCell to destinationVertexCell. mxICell srcMethodExecVertexCell = (mxICell)methodExecToVertexMap.get(srcMethodExec).getCell(); mxICell dstMethodExecVertexCell = (mxICell)methodExecToVertexMap.get(dstMethodExec).getCell(); - Point srcMethodExecVertexCellAbsPt = getAbsolutePointforCell(srcMethodExecVertexCell); - Point dstMethodExecVertexCellAbsPt = getAbsolutePointforCell(dstMethodExecVertexCell); + Point2D srcMethodExecVertexCellAbsPt = getAbsolutePointforCell(srcMethodExecVertexCell); + Point2D dstMethodExecVertexCellAbsPt = getAbsolutePointforCell(dstMethodExecVertexCell); - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - mxgraph.getModel().beginUpdate(); try { - mxICell clonedstMethodExecVertexCell = (mxICell) mxgraph.addCell(dstMethodExecVertexCell.clone()); - clonedstMethodExecVertexCell.getGeometry().setX(srcMethodExecVertexCellAbsPt.getX()); - clonedstMethodExecVertexCell.getGeometry().setY(srcMethodExecVertexCellAbsPt.getY() + dstMethodExecVertexCell.getGeometry().getHeight()); - clonedstMethodExecVertexCell.setStyle("fillColor=none;strokeColor=none;fontColor=#008000;"); - clonedstMethodExecVertexCell.setValue(null); - clonedstMethodExecVertexCell.setVisible(true); - mxICell tmpEdge = (mxICell) mxgraph.insertEdge(mxDefaultParent, null, null, srcMethodExecVertexCell, clonedstMethodExecVertexCell); - 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); + final mxICell[] clonedstMethodExecVertexCell = 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); + } finally { + mxgraph.getModel().endUpdate(); + } + } // Animate an edge to stretch. - edgeAnimation.init(clonedstMethodExecVertexCell, dstMethodExecVertexCellAbsPt, threadPoolExecutor); + MagnetRONAnimation edgeAnim = new TranslateAnimation(mxgraph, getGraphComponent()); + edgeAnim.setTotalCycleCount(10); + edgeAnim.setDelay(100); + edgeAnim.init(clonedstMethodExecVertexCell[0], dstMethodExecVertexCellAbsPt.getX(), dstMethodExecVertexCellAbsPt.getY(), threadPoolExecutor); // Test code (will be deleted) System.out.println("absPointSourceVertexCell: " + srcMethodExecVertexCellAbsPt); - edgeAnimation.setOnFinished(new ActionListener() { + edgeAnim.setOnFinished(new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { - // Test code (will be deleted) - System.out.println("Stretch edge animation action performed. "); - mxICell edge = (mxICell) mxgraph.insertDeltaEdge(mxDefaultParent, methodSig, null, srcMethodExecVertexCell, dstMethodExecVertexCell); - edge.getParent().remove(((mxCell)edge)); - edge.setParent(mxDefaultParent); - 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}); - update(); + // 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 { + // Test code (will be deleted) + System.out.println("Stretch edge animation action performed. "); + mxICell edge = (mxICell) mxgraph.insertDeltaEdge(getMxDefaultParent(), methodSig, null, srcMethodExecVertexCell, dstMethodExecVertexCell); + // edge.getParent().remove(edge); + // edge.setParent(mxDefaultParent); + if (!edge.getParent().equals(getMxDefaultParent())) { + // If parent of {@code Edge} cell isn't mxDefaltParent, reset parent. + edge.getParent().remove(edge); + edge.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]}); + update(); + } finally { + mxgraph.getModel().endUpdate(); + } + } } }); - edgeAnimation.play(); - update(); - edgeAnimation.sleepThread(201); + 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(); + } + } + sleepMainThread(400); } catch (CloneNotSupportedException e) { e.printStackTrace(); - } finally { - mxgraph.getModel().endUpdate(); } } } @@ -1085,7 +1447,7 @@ * @param srcCellAbsPt * @param dstCellAbsPt */ - protected void setEdgePoint(mxICell edge, Point srcCellAbsPt, Point 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������ @@ -1128,23 +1490,23 @@ 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; + 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; } } @@ -1187,15 +1549,16 @@ DEFAULT_WINDOW_SIZE.setSize(width, height); } - protected Point getAbsolutePointforCell(mxICell cell) { - Point p1 = cell.getGeometry().getPoint(); - if(cell.getParent().getValue() == null || cell == cell.getParent()) { + protected Point2D getAbsolutePointforCell(mxICell cell) { + Point2D p1 = new Point2D.Double(cell.getGeometry().getX(), cell.getGeometry().getY());; +// if(cell.getParent().getValue() == null || cell == cell.getParent()) { + if(cell.getParent().getValue() == null || cell.equals(cell.getParent())) { return p1; } // Test code (will be deleted) System.out.println(cell.getId() + ", " + cell.getParent().getId()); - Point p2 = getAbsolutePointforCell(cell.getParent()); - return new Point((int) (p1.getX() + p2.getX()), (int) (p1.getY() + p2.getY())); + Point2D p2 = getAbsolutePointforCell(cell.getParent()); + return new Point2D.Double(p1.getX() + p2.getX(), p1.getY() + p2.getY()); } /** @@ -1288,7 +1651,7 @@ * Test code (will be deleted) */ protected void outputLog() { - for (Object obj: mxgraph.getChildCells(mxDefaultParent)) { + for (Object obj: mxgraph.getChildCells(getMxDefaultParent())) { System.out.println(obj + " " + obj.hashCode()); for (int i = 0; i < ((mxICell)obj).getChildCount(); i++) { System.out.println(" " + ((mxICell)obj).getChildAt(i) + " " + obj.hashCode()); @@ -1321,7 +1684,7 @@ } } } - + /** * Whether sourceCell parents contain destinationCell. * @@ -1330,16 +1693,16 @@ * @return */ private boolean isParent(mxICell sourceCell, mxICell destinationCell) { - mxICell srcPtCell = sourceCell.getParent(); - if (srcPtCell == null || srcPtCell.getValue() == null) { + mxICell srcParentCell = sourceCell.getParent(); + if (srcParentCell == null || srcParentCell.getValue() == null || destinationCell == null) { return false; } - if (srcPtCell == destinationCell) { + if (srcParentCell.equals(destinationCell)) { return true; } // Test code (will be deleted) - System.out.println(sourceCell.getId() + ", " + srcPtCell.getId()); - return isParent(srcPtCell, destinationCell); + System.out.println(sourceCell.getId() + ", " + srcParentCell.getId()); + return isParent(srcParentCell, destinationCell); } protected void reflectCoordinates(DeltaGraphAdapter mxgraph) { @@ -1402,6 +1765,18 @@ return new AbstractMap.SimpleEntry<>(new Reference(rpSrcObjId, rpDstObjId, rpSrcClassName, rpDstClassName), rpFieldName); } + public void sleepMainThread(long millis) { + try { + // Test code (will be deleted) + System.out.println(TAG + ": Sleep Main thread " + millis + "millis."); + Thread.sleep(millis); + System.out.println(TAG + ": Resume Main thread."); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + protected class CurvedCanvas extends mxInteractiveCanvas { mxIShape shape = new CurvedConnector(); diff --git a/src/org/ntlab/deltaViewer/Vertex.java b/src/org/ntlab/deltaViewer/Vertex.java index a5ea317..d5952ff 100644 --- a/src/org/ntlab/deltaViewer/Vertex.java +++ b/src/org/ntlab/deltaViewer/Vertex.java @@ -1,6 +1,6 @@ package org.ntlab.deltaViewer; -import java.awt.Point; +import java.awt.geom.Point2D; import com.mxgraph.model.mxICell; @@ -97,8 +97,8 @@ } - public Point getInitialPoint() { - return new Point((int)initialX, (int)initialY); + public Point2D getInitialPoint() { + return new Point2D.Double(initialX, initialY); } public void setInitialPoint(double initX, double initY) {