简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM