Show weights in JgraphT

I implemented this graph:

ListenableDirectedWeightedGraph<String, MyWeightedEdge> g = 
    new ListenableDirectedWeightedGraph<String, MyWeightedEdge>(MyWeightedEdge.class); 

To show what the class name says; A simple, listenable oriented weighted graph. I want to change the edge label and instead of format

return "(" + source + " : " + target + ")"; 

I want him to show the weight of the edge. I understand that all actions on nodes, for example. method getEdgesWeight(), delegated from the graph, not the edge. How can I show the weight of the edge? Should I ever pass on a chart?

Any help is appreciated.

+5
source share
1 answer

I assume that the MyWeightedEdge class already contains a method, for example

public void setWeight(double weight)

If this is true, then you need to do the following:

ListenableDirectedWeightedGraph (, ListenableDirectedWeightedGraph). , "super", .

,

ListenableDirectedWeightedGraph g = 
    new CustomListenableDirectedWeightedGraph(
        MyWeightedEdge.class);

setEdgeWeight :

public void setEdgeWeight(E e, double weight) {
    super.setEdgeWeight(e, weight);
    ((MyWeightedEdge)e).setWeight(weight);
}

, : toString MyWeightedEdge, , ( , ).

, .

+2

All Articles