2

I am trying to allocate fixed coordinate positions for vertices using static layout. Normally we can get vertex coordinate as Point2D object using layout.transform(Vertex);

Now i wanted to initialize a layout and set the vertices at specified positions but somehow i am stuck. I read here on StackOverflow if i implement Transformer<Vertex, Point2D> interface:

Transformer<Vertex, Point2D> locationTransformer = 
                           new Transformer<Vertex, Point2D>() {
    @Override
    public Point2D transform(Vertex) {
        Point2D p2d = //here i calculate the position
        return p2D;
    }
};  

I have tried this. On fixed graph it works but i have an editable graph and on it nothing happens. I was expecting if i have fixed the position in above, then whichever node i add by mouse click, it should go to the fixed position irrespective where i put it?

can you please give me some idea what could be the reason? Or with editable graph, is it Overriding the position again somewhere?

UPDATE:
If i remove e.g these implementations from visualizaton viewer:

vv.getRenderContext().setVertexFontTransformer(fontTransfoer);
vv.getRenderContext().setVertexFillPaintTransformer(colorTransformer);
vv.getRenderContext().setVertexShapeTransformer(shapeTransformer);  

It starts working, but then the nodes have default shape circular red ones. I want to completely redraw the structure that i had drawn last time. So is there something that can be done with this problem?

Johnydep
  • 6,027
  • 20
  • 57
  • 74
  • I don't quite get what you want except that I believe you want to add vertices interactively. Check the simple tutorials here http://www.grotto-networking.com/JUNG/JUNG2-Tutorial.pdf – ecle Feb 17 '12 at 16:51
  • I recommend looking at the GraphEditorDemo for interactive vertex placement. Also, I recommend implementing Layout (optionally extending AbstractLayout); it's more than a vertex -> Point2D transformer. – Joshua O'Madadhain Feb 18 '12 at 05:30
  • @JoshuaO'Madadhain, what i want is an editable graph which user came make and then i want to store this graph in a file. Later i want to redraw the same graph with exact vertex position as was drawn by the user before. Now i can get the absolute points and when i have them again (say) reading from file, whenever i try to place them back to the static layout, it work but then all transformations fail like font, color etc. Im just wondering what is it that i am missing or i have to do, or is there any built in way of realizing this feature?? – Johnydep Feb 23 '12 at 13:52
  • @eee, i have already gone through that tutorial, i have my last comment makes sense what i want. – Johnydep Feb 23 '12 at 13:53
  • What you want is possible since I have done this before from learning the examples in `jung-samples-2.0.1.jar`. However, I suggest you to look into examples `PersistentLayoutDemo`, `WorldMapGraphDemo`, `GraphEditorDemo` from http://code.google.com/p/jung/source/checkout – ecle Feb 23 '12 at 15:02
  • In order for the transformers to work, the vertex/edge objects have to be the same (in terms of hashCode/equals). You can accomplish this either via suitable overriding of hashCode/equals--i.e., define them via properties that you write out along with the vertex positions--or by serializing the graph itself, as is demonstrated in PersistentLayoutDemo. – Joshua O'Madadhain Mar 05 '12 at 00:00
  • @JoshuaO'Madadhain, Ok i got it working perfectly by skipping the location transformer altogether. I simply set all node shape/color/size/position parameter in getter/setter while serializing and upon import when i create objects, i add them to the graph as vertex and edges, and before repainting the panel (visualizatoin viewer), i call: layout.transform(vertex).setLocation(x, y); and voila, it works perfectly. Same scenario is generated exactly as it was with same icon, chape, color, position, with all cosmetic effects. Thanks for the suggestion though :) – Johnydep May 03 '12 at 16:39

0 Answers0