/*
* AnimatedGraphPanel.java
*
* Created on May 14, 2008, 1:32 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package medusa.example;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import medusa.display.EditableGraphPanel;
import medusa.display.PaintTools;
import medusa.graph.Node;
/**
*
* @author Sean
*/
public class AnimatedGraphPanel extends EditableGraphPanel{
private Animation animation;
/** Creates a new instance of AnimatedGraphPanel */
public AnimatedGraphPanel() {
super();
animation=new Animation();
animation.initDefault();
}
/**
* Paints out Node n
*
* @param g Graphics2D
* @param n Node n
*/
public void paintNode(Graphics2D g, Node n) {
g.setStroke(new BasicStroke(1));
g.setPaint(n.getColor());
int x = (int) n.getX()- correct;
int y = (int) n.getY() - correct;
Shape shape=animation.getShape();
if (shape==null){
shape = PaintTools.getShape(n.getShape(),x,y,nodeSize);
drawShape(shape, y, x, n, g);
}
else {
// translate this shape to the right place
AffineTransform at=new AffineTransform();
at.translate(x,y);
g.transform(at);
drawShape(shape, y, x, n, g);
at.setToIdentity();
g.transform(at);
}
}
private void drawShape(final Shape shape, final int y, final int x, final Node n, final Graphics2D g) {
g.fill(shape);
g.setPaint(Color.black);
if (n.isFixed())
g.setPaint(Color.yellow);
g.draw(shape);
g.setPaint(fontColor);
g.setFont(nodeFont);
if (label)
if (showAnnotation){
g.drawString(n.getAnnotation(),x-2,y-2);
} else
g.drawString(n.getLabel(),x-2,y-2);
}
private static final long DEMO_TIME=10000;
public void animationLoop(){
long startTime=System.currentTimeMillis();
long currentTime=startTime;
while (currentTime-startTime
Ads help maintain this website.