I have problem with JUNG and edge (vertex) labels.
My application is based on JUNG. It needs to calculate some values from given graph. Graph needs to be drown "by hand", and on that graph I need to set "starting values". I was thinking to use labels for that values (names for vertex, length for edges).
Now, I can draw a graph; I can get the number of vertexes and edges, but I don't know how to get the labels and values.
I tried using custom classes for edges and vertexes, but than I don't know how to set labels at all.
This is part of my code. It is taken from documentation. Can somebody tell me what to change so I can set labels while drawing graph and after that retrieve values?
graph = new SparseMultigraph<Number, Number>();
this.layout = new StaticLayout<Number, Number>(graph,
new Dimension(600, 600));
vv = new VisualizationViewer<Number, Number>(layout);
vv.setBackground(Color.white);
vv.getRenderContext().setVertexLabelTransformer(
MapTransformer.<Number, String>getInstance(LazyMap.<Number, String>decorate(
new HashMap<Number, String>(),
new ToStringLabeller<Number>())));
vv.getRenderContext().setEdgeLabelTransformer(
MapTransformer.<Number, String>getInstance(LazyMap.<Number, String>decorate(
new HashMap<Number, String>(),
new ToStringLabeller<Number>())));
vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer());
Container content = getContentPane();
final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
content.add(panel);
Factory<Number> vertexFactory = new VertexFactory();
Factory<Number> edgeFactory = new EdgeFactory();
final EditingModalGraphMouse<Number, Number> graphMouse = new EditingModalGraphMouse<Number, Number>(
vv.getRenderContext(), vertexFactory, edgeFactory);
vv.setGraphMouse(graphMouse);
vv.addKeyListener(graphMouse.getModeKeyListener());
you can use this method to set labels in jung for edges.
edgeName : your edge name
vv.getRenderContext().setEdgeLabelRenderer(new Transformer<String, String>() {
@Override
public String transform(String edgeName) {
String label;
//map your label to your edgeName
return label;
}
});
and so on for vertex