diff --git a/src/org/ntlab/deltaViewer/DeltaAnimation.java b/src/org/ntlab/deltaViewer/DeltaAnimation.java index c2494ce..b4c4fc9 100644 --- a/src/org/ntlab/deltaViewer/DeltaAnimation.java +++ b/src/org/ntlab/deltaViewer/DeltaAnimation.java @@ -29,13 +29,13 @@ private DeltaGraphAdapter mxgraph; private mxGraphComponent mxgraphComponent; - + private Graphics2D graphics2D; private Timer timer; private static int FINAL_STEP_COUNT = 10; private mxICell sourceCell; - + GeneralPath p = new GeneralPath(); // X, Y @@ -43,14 +43,14 @@ private mxPoint targetPoint; private mxPoint curPoint; private mxPoint updatePoint = new mxPoint(); - + // Width, Height private Dimension targetDimension; private Dimension curDimension = new Dimension(); private Dimension updateDimension = new Dimension(); private double scale = 1; - + /** * @param mxgraph * @param mxgraphComponent @@ -82,26 +82,19 @@ // System.out.println("targetPoint : " + targetPoint); calculateResizeLineModel(); } - + /** * Set stretch(expand) animation of edge from sourcePoint to targetPoint. * - * @param sourcePoint Edge sourcePoint. + * @param cloneTargetVertexCell Edge sourcePoint. * @param targetPoint Edge targetPoint. */ - public void setExpandEdgeAnimation(mxPoint sourcePoint, mxPoint targetPoint) { - this.sourcePoint = new mxPoint(sourcePoint.getX() * scale + 1, sourcePoint.getY() * scale + 1); - this.targetPoint = new mxPoint(targetPoint.getX() * scale, targetPoint.getY() * scale); - curPoint = this.sourcePoint; -// System.out.println("sourcePoint : " + sourcePoint); -// System.out.println("targetPoint : " + targetPoint); - - graphics2D = (Graphics2D)mxgraphComponent.getGraphics(); - graphics2D.setColor(Color.decode("#008000")); - - float width = (float) (1 * scale); - Stroke dashed = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[]{(float) (3.0f * scale * width), (float) (3.0f * scale * width)}, 0.0f); - graphics2D.setStroke(dashed); + public void setExpandEdgeAnimation(mxICell sourceCell, mxPoint targetPoint) { + this.sourceCell = sourceCell; + this.targetPoint = targetPoint; + curPoint = new mxPoint(sourceCell.getGeometry().getX(), sourceCell.getGeometry().getY()); + System.out.println("sourcePoint : " + sourceCell.getGeometry().getPoint()); + System.out.println("targetPoint : " + targetPoint); calculateResizeLineModel(); } @@ -139,11 +132,12 @@ public void calculateResizeLineModel() { mxPoint distancePoint = new mxPoint(); distancePoint.setX(targetPoint.getX() - curPoint.getX()); - distancePoint.setY(targetPoint.getY() - curPoint.getY()); + distancePoint.setY(targetPoint.getY() - curPoint.getY()); updatePoint.setX(distancePoint.getX() / FINAL_STEP_COUNT); updatePoint.setY(distancePoint.getY() / FINAL_STEP_COUNT); + System.out.println(updatePoint); } - + /** * Calculate updateDimension every second from curPoint and targetPoint. */ @@ -160,7 +154,7 @@ timer = new Timer(); timer.schedule(new TimerTask() { int stepCount = 0; - + @Override public void run() { if(stepCount < FINAL_STEP_COUNT) { @@ -178,20 +172,21 @@ e.printStackTrace(); } } - + /** * Start stretch(expand) animation of edge from sourcePoint to targetPoint for 10 sec. - */ + */ public void startExpandEdgeAnimation() { timer = new Timer(); timer.schedule(new TimerTask() { int stepCount = 0; - + @Override public void run() { if(stepCount < FINAL_STEP_COUNT) { updateExpandEdgeAnimation(); - stepCount++; + System.out.println(stepCount + ": " + curPoint.getX()); + stepCount++; if(stepCount >= FINAL_STEP_COUNT){ timer.cancel(); } @@ -229,22 +224,22 @@ // } catch (InterruptedException e) { // e.printStackTrace(); // } - ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); - scheduledThreadPoolExecutor.scheduleWithFixedDelay(new TimerTask() { - int stepCount = 0; - - @Override - public void run() { - if(stepCount < FINAL_STEP_COUNT) { + ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); + scheduledThreadPoolExecutor.scheduleWithFixedDelay(new TimerTask() { + int stepCount = 0; + + @Override + public void run() { + if(stepCount < FINAL_STEP_COUNT) { updateReductionEdgeAnimation(); - System.out.println(stepCount + ": " + curPoint.getX()); - stepCount++; - if(stepCount >= FINAL_STEP_COUNT){ - timer.cancel(); - } - } - } - }, 0, 100, TimeUnit.MILLISECONDS); + System.out.println(stepCount + ": " + curPoint.getX()); + stepCount++; + if(stepCount >= FINAL_STEP_COUNT){ + timer.cancel(); + } + } + } + }, 0, 100, TimeUnit.MILLISECONDS); try { System.out.println("Thread.sleep()"); Thread.sleep(1001); @@ -253,7 +248,7 @@ e.printStackTrace(); } } - + /** * Start animation resize vertex for 10 sec. */ @@ -278,23 +273,23 @@ // } catch (InterruptedException e) { // e.printStackTrace(); // } - - ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); - scheduledThreadPoolExecutor.scheduleWithFixedDelay(new TimerTask() { - int stepCount = 0; - - @Override - public void run() { - if(stepCount < FINAL_STEP_COUNT) { - updateResizeVertexAnimation(); - System.out.println(stepCount + ": " + curDimension.width); - stepCount++; - if(stepCount >= FINAL_STEP_COUNT){ - timer.cancel(); - } - } - } - }, 0, 100, TimeUnit.MILLISECONDS); + + ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); + scheduledThreadPoolExecutor.scheduleWithFixedDelay(new TimerTask() { + int stepCount = 0; + + @Override + public void run() { + if(stepCount < FINAL_STEP_COUNT) { + updateResizeVertexAnimation(); + System.out.println(stepCount + ": " + curDimension.width); + stepCount++; + if(stepCount >= FINAL_STEP_COUNT){ + timer.cancel(); + } + } + } + }, 0, 100, TimeUnit.MILLISECONDS); try { System.out.println("Thread.sleep()"); Thread.sleep(1001); @@ -317,52 +312,46 @@ sourceCell.getGeometry().setY(curPoint.getY() + updatePoint.getY()); // System.out.println(sourceCell.getGeometry().getPoint()); } finally { - mxgraph.getModel().endUpdate(); + mxgraph.getModel().endUpdate(); } - mxgraphComponent.refresh(); + mxgraphComponent.refresh(); } /** * Update stretch(expand) animation of edge length updatePoint every second. */ private void updateExpandEdgeAnimation() { - Runnable r = new Runnable() { - public void run() { - p.reset(); - p.moveTo((float)curPoint.getX(), (float)curPoint.getY()); - curPoint.setX(curPoint.getX() + updatePoint.getX()); - curPoint.setY(curPoint.getY() + updatePoint.getY()); -// System.out.println("curPoint : " + curPoint); - p.lineTo((float)curPoint.getX(), (float)curPoint.getY()); - graphics2D.draw(p); - } - }; - - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - if (!SwingUtilities.isEventDispatchThread()) { - SwingUtilities.invokeLater(r); - } else { - r.run(); - } + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. + mxgraph.getModel().beginUpdate(); + try { + curPoint.setX(sourceCell.getGeometry().getX()); + curPoint.setY(sourceCell.getGeometry().getY()); + sourceCell.getGeometry().setX(curPoint.getX() + updatePoint.getX()); + sourceCell.getGeometry().setY(curPoint.getY() + updatePoint.getY()); +// System.out.println(sourceCell.getGeometry().getPoint()); + } finally { + mxgraph.getModel().endUpdate(); + } + mxgraphComponent.refresh(); } - + /** * Update move animation sourcell vertex clone to targetPoint, reduce edge length updatePoint every second. */ private void updateReductionEdgeAnimation() { - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - mxgraph.getModel().beginUpdate(); - try { - curPoint.setX(sourceCell.getGeometry().getX()); - curPoint.setY(sourceCell.getGeometry().getY()); - sourceCell.getGeometry().setX(curPoint.getX() + updatePoint.getX()); - sourceCell.getGeometry().setY(curPoint.getY() + updatePoint.getY()); - // System.out.println(sourceCell.getGeometry().getPoint()); - } finally { - mxgraph.getModel().endUpdate(); - } - mxgraphComponent.refresh(); + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. + mxgraph.getModel().beginUpdate(); + try { + curPoint.setX(sourceCell.getGeometry().getX()); + curPoint.setY(sourceCell.getGeometry().getY()); + sourceCell.getGeometry().setX(curPoint.getX() + updatePoint.getX()); + sourceCell.getGeometry().setY(curPoint.getY() + updatePoint.getY()); +// System.out.println(sourceCell.getGeometry().getPoint()); + } finally { + mxgraph.getModel().endUpdate(); } + mxgraphComponent.refresh(); + } /** * Update animation resize vertex every second. @@ -372,33 +361,33 @@ mxgraph.getModel().beginUpdate(); try { double preCenterX = sourceCell.getGeometry().getCenterX(); - double preCenterY = sourceCell.getGeometry().getCenterY(); + double preCenterY = sourceCell.getGeometry().getCenterY(); curDimension.setSize(sourceCell.getGeometry().getWidth(), sourceCell.getGeometry().getHeight()); sourceCell.getGeometry().setWidth(curDimension.getWidth() + updateDimension.getWidth()); sourceCell.getGeometry().setHeight(curDimension.getHeight() + updateDimension.getHeight()); - double curCenterX = sourceCell.getGeometry().getCenterX(); - double curCenterY = sourceCell.getGeometry().getCenterY(); - double distanceX = (curCenterX - preCenterX); - double distanceY = (curCenterY - preCenterY); - double curX = sourceCell.getGeometry().getX(); - double curY = sourceCell.getGeometry().getY(); - - sourceCell.getGeometry().setX(curX - distanceX); - sourceCell.getGeometry().setY(curY - distanceY); + double curCenterX = sourceCell.getGeometry().getCenterX(); + double curCenterY = sourceCell.getGeometry().getCenterY(); + double distanceX = (curCenterX - preCenterX); + double distanceY = (curCenterY - preCenterY); + double curX = sourceCell.getGeometry().getX(); + double curY = sourceCell.getGeometry().getY(); - for (int i = 0; i < sourceCell.getChildCount(); i++) { - mxICell childCell = sourceCell.getChildAt(i); + sourceCell.getGeometry().setX(curX - distanceX); + sourceCell.getGeometry().setY(curY - distanceY); + + for (int i = 0; i < sourceCell.getChildCount(); i++) { + mxICell childCell = sourceCell.getChildAt(i); // System.out.println("child" + childCell); - curX = childCell.getGeometry().getX(); - curY = childCell.getGeometry().getY(); - childCell.getGeometry().setX(curX + distanceX); - childCell.getGeometry().setY(curY + distanceY); - } + curX = childCell.getGeometry().getX(); + curY = childCell.getGeometry().getY(); + childCell.getGeometry().setX(curX + distanceX); + childCell.getGeometry().setY(curY + distanceY); + } } finally { - mxgraph.getModel().endUpdate(); + mxgraph.getModel().endUpdate(); } - mxgraphComponent.refresh(); + mxgraphComponent.refresh(); } }