Balaji - 2014-04-17

hi

My requirement is to get coordinates of the vertices. I dont have to visualize the graph.
Following code threw npe. What is the missing code that will give me the coordinates?
What I was expecting is, isomLayout.initialize() to set all the coordinates. Do I need to use a different layout?

            Graph<Integer, String> g = new DirectedSparseGraph<Integer, String>();
    g.addVertex((Integer)1);
    g.addVertex((Integer)2);
    g.addVertex((Integer)3);

    g.addEdge("Edge-A", 1, 2); 
    g.addEdge("Edge-B", 2, 3);

    System.out.println("The graph g = " + g.toString());

            ISOMLayout<Integer, String> isomLayout = new ISOMLayout<Integer, String>(g);

// isomLayout.setInitializer( new Transformer<Integer, Point2D="">() {
//
// @Override
// public Point2D transform(Integer arg0) {
// return new Point(10, 10);
// }
//
// });
isomLayout.initialize();

    System.out.println("p1 x=" + isomLayout.getX(1) + " y=" + isomLayout.getY(1));
    System.out.println("p2 x=" + isomLayout.getX(2) + " y=" + isomLayout.getY(2));
    System.out.println("p3 x=" + isomLayout.getX(3) + " y=" + isomLayout.getY(3));

Exception in thread "main" java.lang.NullPointerException
at edu.uci.ics.jung.algorithms.layout.util.RandomLocationTransformer.transform(RandomLocationTransformer.java:57)
at edu.uci.ics.jung.algorithms.layout.util.RandomLocationTransformer.transform(RandomLocationTransformer.java:33)
at org.apache.commons.collections15.functors.ChainedTransformer.transform(ChainedTransformer.java:127)
at org.apache.commons.collections15.map.LazyMap.get(LazyMap.java:158)
at edu.uci.ics.jung.algorithms.layout.AbstractLayout.getCoordinates(AbstractLayout.java:170)
at edu.uci.ics.jung.algorithms.layout.AbstractLayout.getX(AbstractLayout.java:183)
at hello.SampleJung.process(SampleJung.java:55)
at hello.SampleJung.main(SampleJung.java:72)