diff --git a/src/org/ntlab/animations/EdgeAnimation.java b/src/org/ntlab/animations/EdgeAnimation.java new file mode 100644 index 0000000..cdd0a87 --- /dev/null +++ b/src/org/ntlab/animations/EdgeAnimation.java @@ -0,0 +1,66 @@ +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(); + } + +}