首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用JUNG2绘制直线?

如何用JUNG2绘制直线?
EN

Stack Overflow用户
提问于 2015-04-12 07:17:04
回答 1查看 679关注 0票数 2

做了JUNG2的测试后,我发现所有的边缘线都是弯曲的,但不是直线line...How做的直线是由Jung2做的?

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-12 08:44:00

tl;博士

打电话

代码语言:javascript
复制
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等腰三角形,其顶点位于有向边的目的顶点,而对于无向边则作为“蝴蝶结”形状。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29587011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档