避免JGraphX中不同末端单元的边重叠

时间:2020-06-17 07:25:41

标签: jgraphx

我想知道JGraphX中是否存在避免两个边缘重叠的布局,这两个边缘在同一顶点单元中开始但在不同单元中结束? 我找到了此帖子后的{Overlapping edges with JGraphx,建议使用mxParallelEdgeLayout,但是此布局仅适用于具有相同起点和终点顶点的边。我尝试了其他布局,例如mxOrthogonalLayout,但它也不起作用。 有谁知道路由不与其他顶点和边缘重叠的边缘的方法?另外,我需要在固定位置放置顶点单元,因此无法使用更改顶点位置的布局。 提前致谢。 这是一个示例代码,其中有重叠部分:


import com.mxgraph.layout.mxParallelEdgeLayout;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;

import javax.swing.*;

public class HelloWorld extends JFrame
{

    /**
     * 
     */
    private static final long serialVersionUID = -2707712944901661771L;

    public HelloWorld()
    {
        super("Hello Earth Planet!");

        mxGraph graph = new mxGraph();
        Object parent = graph.getDefaultParent();

        graph.getModel().beginUpdate();
        try
        {
            Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80,
                    30);
            Object v2 = graph.insertVertex(parent, null, "Earth", 240, 20,
                    80, 30);
            Object v3 = graph.insertVertex(parent, null, "Planet!", 480, 20,
                    80, 30);

            Object ed1 = graph.insertEdge(parent, "a", "Edge1", v1, v2);
            Object ed2 = graph.insertEdge(parent, "b", "Edge2", v1, v3);

            mxParallelEdgeLayout layout = new mxParallelEdgeLayout(graph, 30);
            layout.execute(parent);

        }
        finally
        {
            graph.setCellsMovable(false);
            graph.setCellsEditable(false);
            graph.setCellsResizable(false);
            graph.setVertexLabelsMovable(false);
            graph.setGridEnabled(false);
            graph.setCellsCloneable(false);
            graph.setCellsDeletable(false);
            graph.setCellsResizable(false);
            graph.setCellsBendable(false);

            graph.setConnectableEdges(false);
            graph.setEdgeLabelsMovable(false);
            graph.setAllowDanglingEdges(false);

            graph.setCellsSelectable(true);
            graph.setCellsLocked(true);

            graph.setCellsDisconnectable(true);

            graph.getModel().endUpdate();
        }

        mxGraphComponent graphComponent = new mxGraphComponent(graph);

        getContentPane().add(graphComponent);
    }

    public static void main(String[] args)
    {
        HelloWorld frame = new HelloWorld();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 320);
        frame.setVisible(true);
    }
}```

0 个答案:

没有答案