做了JUNG2的测试后,我发现所有的边缘线都是弯曲的,但不是直线line...How做的直线是由Jung2做的?
package pkg;
import javax.swing.JFrame;
import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseMultigraph;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
public class test {
public static void main(String[] args) {
// Graph<V, E> where V is the type of the vertices
// and E is the type of the edges
Graph<Integer, String> g = new SparseMultigraph<Integer, String>();
// Add some vertices. From above we defined these to be type Integer.
g.addVertex((Integer)1);
g.addVertex((Integer)2);
g.addVertex((Integer)3);
// Add some edges. From above we defined these to be of type String
// Note that the default is for undirected edges.
g.addEdge("Edge-A", 1, 2);
g.addEdge("Edge-B", 2, 3);
// Let's see what we have. Note the nice output from the
// SparseMultigraph<V,E> toString() method
// Note that we can use the same nodes and edges in two different graphs.
System.out.println("The graph g = " + g.toString());
Layout<Integer, String> layout = new CircleLayout(g);
VisualizationViewer<Integer,String> vv = new VisualizationViewer<Integer,String>(layout);
DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
gm.setMode(ModalGraphMouse.Mode.PICKING);
vv.setGraphMouse(gm);
JFrame frame = new JFrame("Simple Graph View");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
}
}跟着输出结果,黑线是默认的,我想得到的红线是:http://www.zhaocs.info/wp-content/uploads/2015/04/test.png
发布于 2015-04-12 08:44:00
tl;博士
打电话
vv.getRenderContext().setEdgeShapeTransformer(
new EdgeShape.Line<Integer,String>());在你的VisualizationViewer上
JUNG的边缘形状有多种选择。这些选项被实现为“边缘形状转换器”,这是edu.uci.ics.jung.visualization.decorators.EdgeShape类的嵌套类。默认情况下是EdgeShape.QuadCurve,这会导致弯曲的边。其他备选办法包括(摘自文件):
BentLine折线在顶点端点之间.Box循环,其最低点位于顶点的中心。CubicCurve CubicCurve在顶点端点之间。Line在顶点端点之间的直线。Loop循环,其最低点位于顶点的中心。Orthogonal折线在顶点端点之间.QuadCurve QuadCurve在顶点端点之间。SimpleLoop循环,其最低点位于顶点的中心。Wedge等腰三角形,其顶点位于有向边的目的顶点,而对于无向边则作为“蝴蝶结”形状。
https://stackoverflow.com/questions/29587011
复制相似问题