From: SourceForge.net <no...@so...> - 2006-07-31 17:44:27
|
Read and respond to this message at: https://sourceforge.net/forum/message.php?msg_id=3846443 By: matthewcornell Hi Folks, We're looking at animating a layout we created, and I'd very much appreciate your feedback on how best to do so within JUNG. I'm pasting two files to demonstrate my current thinking (DriverApp.java and AnimatingLayout.java) which I hope show our current issues. (I've not tried sharing code before here, so I apologize if the formatting is lost.) Here are the questions, repeated from the former file's comments: * 0. Is this the best approach to doing animation in JUNG? * 1. Delay before animation starts, though you see the incrementsAreDone() printouts before. (On my machine they reach about 20 before the animation is updated.) * 2. I'm not clear about the interactions between the Thread.sleep() call in AnimatingLayout.advancePositions() and the below setRelaxerThreadSleepTime() call (which I've commented out). Thanks in advance! matt ==== import edu.uci.ics.jung.graph.ArchetypeVertex; import edu.uci.ics.jung.graph.Graph; import edu.uci.ics.jung.graph.decorators.EdgeShape; import edu.uci.ics.jung.graph.decorators.VertexStringer; import edu.uci.ics.jung.graph.impl.DirectedSparseEdge; import edu.uci.ics.jung.graph.impl.SparseGraph; import edu.uci.ics.jung.graph.impl.SparseVertex; import edu.uci.ics.jung.visualization.AbstractLayout; import edu.uci.ics.jung.visualization.Coordinates; import edu.uci.ics.jung.visualization.DefaultSettableVertexLocationFunction; import edu.uci.ics.jung.visualization.GraphZoomScrollPane; import edu.uci.ics.jung.visualization.PluggableRenderer; import edu.uci.ics.jung.visualization.SettableVertexLocationFunction; import edu.uci.ics.jung.visualization.StaticLayout; import edu.uci.ics.jung.visualization.VisualizationViewer; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JFrame; /** * Usage: Run this application, click "Start" button. * * Questions/Issues: * 0. Is this the best approach to doing animation in JUNG? * 1. Delay before animation starts, though you see the incrementsAreDone() printouts * before. (On my machine they reach about 20 before the animation is updated.) * 2. I'm not clear about the interactions between the Thread.sleep() call in * AnimatingLayout.advancePositions() and the below setRelaxerThreadSleepTime() * call (which I've commented out). */ public class DriverApp { public DriverApp() { final SettableVertexLocationFunction vertexLocations = new DefaultSettableVertexLocationFunction(); final Graph graph = makeGraph(vertexLocations); final Dimension size = new Dimension(500, 500); AbstractLayout layout = new StaticLayout(graph); layout.initialize(size, vertexLocations); PluggableRenderer pr = new PluggableRenderer(); pr.setEdgeShapeFunction(new EdgeShape.QuadCurve()); pr.setVertexStringer(new VertexStringer() { public String getLabel(ArchetypeVertex v) { return v.toString(); } }); final VisualizationViewer vv = new VisualizationViewer(layout, pr); // vv.getModel().setRelaxerThreadSleepTime(500); JFrame jFrame = new JFrame(); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.getContentPane().add(new GraphZoomScrollPane(vv), BorderLayout.CENTER); JButton startJButton = new JButton(new AbstractAction("Start") { public void actionPerformed(ActionEvent e) { vv.stop(); AbstractLayout layout = new AnimatingLayout(graph); layout.initialize(size, vertexLocations); vv.setGraphLayout(layout); vv.restart(); } }); jFrame.getContentPane().add(startJButton, BorderLayout.SOUTH); jFrame.pack(); jFrame.setSize(size); jFrame.setVisible(true); } public static void main(String[] args) { new DriverApp(); } private Graph makeGraph(SettableVertexLocationFunction vertexLocations) { Graph graph = new SparseGraph(); SparseVertex v1 = new SparseVertex(); SparseVertex v2 = new SparseVertex(); graph.addVertex(v1); graph.addVertex(v2); graph.addEdge(new DirectedSparseEdge(v1, v2)); vertexLocations.setLocation(v1, new Coordinates(100, 100)); vertexLocations.setLocation(v2, new Coordinates(200, 200)); return graph; } } ==== import edu.uci.ics.jung.graph.Graph; import edu.uci.ics.jung.graph.Vertex; import edu.uci.ics.jung.visualization.AbstractLayout; import edu.uci.ics.jung.visualization.Coordinates; import java.util.Iterator; /** * A test layout to explore animation. Works thus: * <p/> * o make a new instance, passing it the Graph * o call initialize(), passing a VertexLocationFunction * o will run a fixed number of ticks, moving all vertices an arbitrary amount * o stops when done */ public class AnimatingLayout extends AbstractLayout { private static final int NUM_INCREMENTS = 50; // number of ticks private int incrementNum = 0; // current tick public AnimatingLayout(Graph g) { super(g); } protected void initialize_local_vertex(Vertex v) { // n/a. call initialize() - see docs above } public void advancePositions() { try { Thread.sleep(50); } catch (InterruptedException e) { } System.out.println("advancePositions()"); Graph graph = getGraph(); for (Iterator vertIter = graph.getVertices().iterator(); vertIter.hasNext();) { Vertex vertex = (Vertex) vertIter.next(); Coordinates coordinates = getCoordinates(vertex); coordinates.add(5, 5); } incrementNum++; } public boolean isIncremental() { return true; } public boolean incrementsAreDone() { System.out.println("incrementsAreDone(): " + incrementNum + ", " + NUM_INCREMENTS); return incrementNum >= NUM_INCREMENTS; } } ==== ______________________________________________________________________ You are receiving this email because you elected to monitor this forum. To stop monitoring this forum, login to SourceForge.net and visit: https://sourceforge.net/forum/unmonitor.php?forum_id=252062 |