}});
this.g = og;
//create a graphdraw
layout = new FRLayout<Number,Number>(g);
layout.setSize(new Dimension(600,600));
Relaxer relaxer = new VisRunner((IterativeContext)layout);
relaxer.stop();
relaxer.prerelax();
Layout<Number,Number> staticLayout =
new StaticLayout<Number,Number>(g, layout);
vv = new VisualizationViewer<Number,Number>(staticLayout, new Dimension(600,600));
JRootPane rp = this.getRootPane();
rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
getContentPane().setLayout(new BorderLayout());
getContentPane().setBackground(java.awt.Color.lightGray);
getContentPane().setFont(new Font("Serif", Font.PLAIN, 12));
vv.setGraphMouse(new DefaultModalGraphMouse<Number,Number>());
vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Number>());
vv.setForeground(Color.white);
vv.addComponentListener(new ComponentAdapter() {
/**
* @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent)
*/
@Override
public void componentResized(ComponentEvent arg0) {
super.componentResized(arg0);
System.err.println("resized");
layout.setSize(arg0.getComponent().getSize());
}});
getContentPane().add(vv);
switchLayout = new JButton("Switch to SpringLayout");
switchLayout.addActionListener(new ActionListener() {
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent ae) {
Dimension d = vv.getSize();//new Dimension(600,600);
if (switchLayout.getText().indexOf("Spring") > 0) {
switchLayout.setText("Switch to FRLayout");
layout =
new SpringLayout<Number,Number>(g, new ConstantTransformer(EDGE_LENGTH));
layout.setSize(d);
Relaxer relaxer = new VisRunner((IterativeContext)layout);
relaxer.stop();
relaxer.prerelax();
StaticLayout<Number,Number> staticLayout =
new StaticLayout<Number,Number>(g, layout);
LayoutTransition<Number,Number> lt =
new LayoutTransition<Number,Number>(vv, vv.getGraphLayout(),
staticLayout);
Animator animator = new Animator(lt);
animator.start();
// vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
vv.repaint();
} else {
switchLayout.setText("Switch to SpringLayout");
layout = new FRLayout<Number,Number>(g, d);
layout.setSize(d);
Relaxer relaxer = new VisRunner((IterativeContext)layout);
relaxer.stop();
relaxer.prerelax();
StaticLayout<Number,Number> staticLayout =
new StaticLayout<Number,Number>(g, layout);
LayoutTransition<Number,Number> lt =
new LayoutTransition<Number,Number>(vv, vv.getGraphLayout(),
staticLayout);