NanoGraphPanel p = null;
public void init() {
DefaultGraphModel g = new DefaultGraphModel();
p = new NanoGraphPanel();
p.setBorder(new LineBorder(Color.darkGray, 1, true));
p.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
p.getNanoGraph().setLayout(new ForceDirectedLayoutAlgorithm(p));
}
}
);
p.setModel(g);
if (getParameter("nodes") != null)
{
// parse graph from parameters
//
StringTokenizer st = new StringTokenizer(
this.getParameter("nodes"), ",");
while (st.hasMoreElements())
g.addNode(st.nextToken());
st = new StringTokenizer(this.getParameter("edges"), ",-");
while (st.hasMoreElements())
g.addEdge("edge", st.nextToken(), st.nextToken());
}
else
{
// default graph
g.addNode("Java");
g.addNode("Python");
g.addNode("C++");
g.addNode("Perl");
g.addNode("C#");
g.addNode("Programming Language");
g.addEdge("is a", "Java", "Programming Language");
g.addEdge("is a", "Java", "Python");
g.addEdge("is a", "C#", "Programming Language");
g.addEdge("is a", "C++", "Programming Language");
g.addEdge("is a", "Perl", "Programming Language");
g.addEdge("is a", "Python", "Programming Language");
}
p.getNanoGraph().setLayout(new CircularLayoutAlgorithm(200));
DefaultNodeRenderer r = new DefaultNodeRenderer();
r.setBodyColor(new GradientPaint(0,0,Color.YELLOW, 600, 600, Color.RED));