vv = new VisualizationViewer<String,Number>(persistentLayout);
// add my listener for ToolTips
vv.setVertexToolTipTransformer(new ToStringLabeller());
DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
vv.setGraphMouse(gm);
// create a frome to hold the graph
final JFrame frame = new JFrame();
frame.getContentPane().add(new GraphZoomScrollPane(vv));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// create a control panel and buttons for demo
// functions
JPanel p = new JPanel();
JButton persist = new JButton("Save Layout");
// saves the graph vertex positions to a file
persist.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
persistentLayout.persist(fileName);
} catch (IOException e1) {
System.err.println("got "+e1);
}
}
});
p.add(persist);
JButton restore = new JButton("Restore Layout");
// restores the graph vertex positions from a file
// if new vertices were added since the last 'persist',
// they will be placed at random locations
restore.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// PersistentLayout<String,Number> pl = (PersistentLayout<String,Number>) vv.getGraphLayout();
try {
persistentLayout.restore(fileName);
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
p.add(restore);
p.add(gm.getModeComboBox());
frame.getContentPane().add(p, BorderLayout.SOUTH);
frame.pack();//setSize(600, 600);
frame.setVisible(true);
}