K_U
K_U

Reputation: 17762

How to change the edge label of an edge in JUNG?

I'm using the JUNG API for graph visualization. I cannot figure out how to change the edge label of an edge in the graph.

The situation is that the graph has already been created in the program. I keep dropping edges and nodes and I've found a way to animate those things and update them in the graph. Some of the demos online are helpful. But is there no way to change an edge label of an edge in the graph later?

I understand that JUNG requires the edge labels to be unique.

Upvotes: 0

Views: 2626

Answers (1)

Emaad Ahmed Manzoor
Emaad Ahmed Manzoor

Reputation: 493

The basics of edge labelling in JUNG are demonstrated by this snippet of code:

            vv.getRenderContext().setEdgeLabelTransformer(new Transformer<MyEdge, String>() {
                public String transform(MyEdge e) {
                    return (e.toString() + " " + e.getWeight() + "/" + e.getCapacity());
                }
            });

Here, vv is your VisualizationViewer and MyEdge refers to your custom edge class. In my case, I've defined the functions getWeight() and getCapacity() to return the weight and capacity of my edge.

Then I created a popup menu for each edge that allows the user to enter the edge weight and capacity and then used the setWeight() and setCapacity() functions to update my edge. I picked up how exactly to create the edge popups from http://www.grotto-networking.com/JUNG/

You could borrow from this example to set your own edge labels.

Upvotes: 1

Related Questions