JUNG:按顺序放置树节点 [英] JUNG: placing tree nodes in order

查看:103
本文介绍了JUNG:按顺序放置树节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 DelegateTree 中添加节点时,它们不会按我添加的顺序直观显示。
我一直在寻找解决方案,但还没有找到任何东西。
有没有人知道如何改变这个?

When adding nodes to my DelegateTree, they don't appear visually in the order I added them. I've been looking for a solution, but haven't found anything yet. Is there anyone who might know how to change this?

提前致谢!

编辑:我的代码

/**
 * Generate a visualization of the decision tree.
 * 
 * @param tree
 *            The decision tree
 * @return A component to be placed inside a JPanel
 */
public static GraphZoomScrollPane generateTree(Tree tree,
        GraphicalUserInterface gui) {

    /* Create a new tree */
    DelegateTree<Node, Edge> graphTree = new DelegateTree<Node, Edge>();

    /* Add all nodes and vertices to the tree */
    graphTree.addVertex(tree.getRoot());
    addChildren(tree.getRoot(), graphTree);

    /* Create the visualization */
    DynamicTreeLayout<Node, Edge> treeLayout = new DynamicTreeLayout<Node, Edge>(graphTree, 100, 100);
    VisualizationViewer<Node, Edge> vv = new VisualizationViewer<Node, Edge>(
            treeLayout);
    vv.setDoubleBuffered(true);
    vv.setBackground(Color.WHITE);
    vv.getRenderContext().setEdgeLabelTransformer(
            new ToStringLabeller<Edge>());
    vv.getRenderContext().setEdgeShapeTransformer(
            new EdgeShape.Line<Node, Edge>());
    vv.getRenderContext().setVertexLabelTransformer(
            new ToStringLabeller<Node>());
    vv.getRenderer().getVertexLabelRenderer()
            .setPosition(Renderer.VertexLabel.Position.S);

    vv.addGraphMouseListener(new ClickNode(gui, vv));

    final DefaultModalGraphMouse<Node, Edge> graphMouse = new DefaultModalGraphMouse<Node, Edge>();

    graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);

    vv.setGraphMouse(graphMouse);

    final GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);

    return gzsp;
}

/**
 * Recursively add all nodes and edges to the tree.
 * 
 * @param node
 *            The parent node
 * @param tree
 *            The tree visualization
 */
private static void addChildren(Node node, DelegateTree<Node, Edge> tree) {
    for (int i = 0; i < node.getChildren().size(); i++) {
        tree.addChild(new Edge(node.getChildren().get(i).getEdgeLabel()), node, node
        .getChildren().get(i));
        addChildren(node.getChildren().get(i), tree);
    }
}


推荐答案

使用DelegateTree的底层实现,它根据它们的自然排序(* Sorted * Graph)或使用插入排序(* Ordered * Graph)对顶点进行排序。

Use an underlying implementation for the DelegateTree that either sorts its vertices according to their natural ordering (*Sorted*Graph) or that uses insertion ordering (*Ordered*Graph).

这篇关于JUNG:按顺序放置树节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆