Java 分层布局中的接收器布局
问题 JGraphX的早期版本(1.x)在MXHierarchyCallayout类中提供了属性layoutFromSinks。这是不可用的了,从我所看到的已经不是很长时间了 布局差异的问题最好用图片来解释: 旧JGraphX版本,启用从接收器布局,产生以下结果: 较新的JGraph版本(我尝试的最新版本是3.4.1.2)产生了以下结果: 如您所见,旧版本产生了更清晰的结果 问题 在最新版本的JGraphX中也可以使用这种分层布局吗?需要应用哪些设置才能实现相同的布局 代码 下面是生成上述布局的示例代码Java 分层布局中的接收器布局,java,jgraphx,Java,Jgraphx,问题 JGraphX的早期版本(1.x)在MXHierarchyCallayout类中提供了属性layoutFromSinks。这是不可用的了,从我所看到的已经不是很长时间了 布局差异的问题最好用图片来解释: 旧JGraphX版本,启用从接收器布局,产生以下结果: 较新的JGraph版本(我尝试的最新版本是3.4.1.2)产生了以下结果: 如您所见,旧版本产生了更清晰的结果 问题 在最新版本的JGraphX中也可以使用这种分层布局吗?需要应用哪些设置才能实现相同的布局 代码 下面是生成上述布
import java.awt.BorderLayout;
import javax.swing.JFrame;
import com.mxgraph.layout.mxIGraphLayout;
import com.mxgraph.layout.hierarchical.mxHierarchicalLayout;
import com.mxgraph.model.mxICell;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
public class HierarchyLayoutExample extends JFrame {
mxICell a,b,c,d,e,f,g,h;
public HierarchyLayoutExample() {
final mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try {
a = (mxICell) graph.insertVertex(parent, null, "a", 0, 0, 80, 30);
b = (mxICell) graph.insertVertex(parent, null, "b", 0, 0, 80, 30);
c = (mxICell) graph.insertVertex(parent, null, "c", 0, 0, 80, 30);
d = (mxICell) graph.insertVertex(parent, null, "d", 0, 0, 80, 30);
g = (mxICell) graph.insertVertex(parent, null, "g", 0, 0, 80, 30);
h = (mxICell) graph.insertVertex(parent, null, "h", 0, 0, 80, 30);
e = (mxICell) graph.insertVertex(parent, null, "e", 0, 0, 80, 30);
graph.insertEdge(parent, null, "", a, b);
graph.insertEdge(parent, null, "", a, c);
graph.insertEdge(parent, null, "", c, d);
graph.insertEdge(parent, null, "", e, d);
graph.insertEdge(parent, null, "", g, a);
graph.insertEdge(parent, null, "", b, d);
graph.insertEdge(parent, null, "", h, e);
} finally {
graph.getModel().endUpdate();
}
// define layout
mxHierarchicalLayout layout = new mxHierarchicalLayout(graph);
// layout.setLayoutFromSinks(true); // <== not available anymore
layout.execute(graph.getDefaultParent());
mxGraphComponent graphComponent = new mxGraphComponent(graph);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(graphComponent, BorderLayout.CENTER);
}
public static void main(String[] args) {
HierarchyLayoutExample frame = new HierarchyLayoutExample();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(460, 400);
frame.setVisible(true);
}
}
导入java.awt.BorderLayout;
导入javax.swing.JFrame;
导入com.mxgraph.layout.mxIGraphLayout;
导入com.mxgraph.layout.hierarchy.mxHierarchyCallayout;
导入com.mxgraph.model.mxICell;
导入com.mxgraph.swing.mxGraphComponent;
导入com.mxgraph.view.mxgraph;
公共类HierarchyLayoutExample扩展了JFrame{
mxICell a、b、c、d、e、f、g、h;
公共层次结构布局示例(){
最终mxGraph=新mxGraph();
对象父对象=graph.getDefaultParent();
graph.getModel().beginUpdate();
试一试{
a=(mxICell)graph.insertVertex(父对象,null,“a”,0,0,80,30);
b=(mxICell)graph.insertVertex(父对象,null,“b”,0,0,80,30);
c=(mxICell)graph.insertVertex(父对象,null,“c”,0,0,80,30);
d=(mxICell)graph.insertVertex(父对象,null,“d”,0,0,80,30);
g=(mxICell)graph.insertVertex(父对象,null,“g”,0,0,80,30);
h=(mxICell)graph.insertVertex(父对象,null,“h”,0,0,80,30);
e=(mxICell)graph.insertVertex(父对象,null,“e”,0,0,80,30);
图.insertEdge(父项,null,“,a,b);
插入图(父,空,“,a,c);
图.插入边缘(父,空,“,c,d);
图.插入边缘(父,空,“,e,d);
图.insertEdge(父项,null,“,g,a);
图.insertEdge(父项,null,“,b,d);
插入图(父,空,“,h,e);
}最后{
graph.getModel().endUpdate();
}
//定义布局
MXHierarchyCallayout布局=新MXHierarchyCallayout(图形);
//layout.setLayoutFromSinks(true);//据我所知,atm没有这样的选项。您可以查看MXHierarchyCallayout.SetFineTunning(false)
。如果这不符合您的需要,我认为您必须编写自己的mxEdgeStyleFunction
并将其设置为要使用的edgestyle,然后使用mxHierarchyCallayout.setDisableEdgeStyle(false)
谢谢,我已经试过了。没有给出预期的结果。目前我复制了最新版本的布局代码,并使用了该版本。