开发者

How to show rectangle shape for a node through PREFUSE visualization toolkit for JAVA?

开发者 https://www.devze.com 2022-12-20 04:42 出处:网络
I have coded the following code(some excerpts of the code) to display a node as rectangle but it is no working. It is just displaying a simple node.

I have coded the following code(some excerpts of the code) to display a node as rectangle but it is no working. It is just displaying a simple node.

Code excerpts:

...
ShapeAction nodeShape = new NodeShapeAction(treeNodes); // treeNodes is a datagroup representing the tree nodes
m_vis.putAction("nodeShape", nodeShape); // m_vis is referring the visualization object
m_vis.run(nodeShape);
....

/**
 * Se开发者_运维问答t node shapes
 */
public static class NodeShapeAction extends ShapeAction {
    public NodeShapeAction(String group) {
        super(group);
        add("type == 'APPLICATION'", Constants.SHAPE_RECTANGLE);
        add("type == 'DATABASE'", Constants.SHAPE_STAR);
        add("type == 'INTERFACE'", Constants.SHAPE_ELLIPSE);
    }

} // end of inner class NodeShapeAction


I got the answer so I am answering it here.

In prefuse, adding the Actions (in our case ShapeAction) to a visualization just sets the display properties of the VisualItems.

To display VisualItems that reflect those display properties, we need to set appropriate renderers to the Visualization.

ShapeRenderer m_nodeRenderer = new ShapeRenderer();
DefaultRendererFactory rf = new DefaultRendererFactory(m_nodeRenderer);
m_vis.setRendererFactory(rf);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号