简体   繁体   English

jgraphx更改顶点大小

[英]jgraphx change vertex size

I draw a simple graph (using Java swing interface). 我绘制了一个简单的图形(使用Java swing接口)。

The graph is OK, but the default / automatic vertices size is small for my purpose. 该图还可以,但是默认/自动顶点的尺寸很小。 How to set the vertex size (rectangle or ellipse)? 如何设置顶点大小(矩形或椭圆形)?

I can change some graph behavior using put() ( like put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE)) but not the size of vertices. 我可以使用put()更改某些图形行为(例如put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE))但不能put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE))顶点的大小。

The graph is OK, but the default / automatic vertices size is small for my purpose. 该图还可以,但是默认/自动顶点的尺寸很小。 How to set the vertex size (rectangle or ellipse)? 如何设置顶点大小(矩形或椭圆形)?

May I have misunderstood many about jgraphx? 我可能对jgraphx有误解吗?

The documentation is very difficult to understand, very cryptic (at least for me), can I have suggestions for books or links for better understand jgraphx for Java. 该文档非常难以理解,非常晦涩(至少对我来说是这样),我是否可以提出一些书籍或链接的建议以更好地理解Java jgraphx。

One more detail: the graph isn't built element by element, but it come from a graph built with jgraphT using jGraphXAdapter 更详细一点:该图不是逐个元素构建的,而是来自使用jGraphXAdapter使用jgraphT构建的图

JGraphXAdapter<Incrocio, Strada> graphAdapter = new JGraphXAdapter<Incrocio, Strada>(listenableGraph);

Thank to Andrew for her patience. 感谢安德鲁的耐心配合。 English is not my language, and sometime I make a mistakes even in italian (my native language). 英语不是我的语言,有时候我甚至会以意大利语(我的母语)犯错。 Add that I'm new in Java. 补充一点,我是Java新手。 New even in this forum (an related rules, and this may not be the right place for my replay). 即使在该论坛中也是新手(相关规则,这可能不是我重放的合适位置)。 I've not read your message previous with the due attention. 之前,我没有仔细阅读您的留言。

I put the code, whith a partial solution, I hope it's more clear. 我把代码,部分解决方案,我希望它更清楚。

package it.rex.view;

public class StradarioViewBis2 extends JFrame {

    private JPanel contentPane;

    // listenableGraph is a complete graph done with JgraphT
    public StradarioViewBis2(ListenableGraph<Incrocio, Strada> listenableGraph) {

        JGraphXAdapter<Incrocio, Strada> graphAdapter = 
                new JGraphXAdapter<Incrocio, Strada>(listenableGraph);

        //graphAdapter.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1");  //remove label from edge

        graphAdapter.getModel().beginUpdate();
        try {
            graphAdapter.clearSelection(); 
            graphAdapter.selectAll();
            Object[] cells = graphAdapter.getSelectionCells(); //here you have all cells

            // Iterate into graph to change cells
            for (Object c : cells) {
                mxCell cell = (mxCell) c; //cast
                mxGeometry geometry = cell.getGeometry();

                if (cell.isVertex()) { //isVertex
                    // Here I can change vertex dimensions 
                    geometry.setWidth(40);
                    geometry.setHeight(40);
                }else{ //is not a vertex, so u can get source and target 
                    //  cell.setStyle("orthogonalEdgeStyle"); 
                    //  cell.getChildAt(x); //Returns the child at the specified index. (target)
                }
            }
        }
        finally
        {
            graphAdapter.getModel().endUpdate();
        }

        mxIGraphLayout layout = new mxCircleLayout(graphAdapter);  // questo sistema le posizione degli elementi

        layout.execute(graphAdapter.getDefaultParent());

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 550, 450);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        mxGraphComponent graphComponent = new mxGraphComponent(graphAdapter);  // is JScrollPane extension 

        graphComponent.setPageVisible(true);
        graphComponent.setBounds(30, 30, 300, 300);
        contentPane.add(graphComponent);

        //graphComponent.setEnabled(false);
        graphComponent.getViewport().setBackground(Color.white);
        ;

    }

}

After some tries, I've found that the vertex's size is back to initial dimension when I change the cell's label, not when I move the focus away from cell. 经过一些尝试,我发现,当我更改单元格的标签时,而不是将焦点从单元格移开时,顶点的大小恢复到初始尺寸。

I think I need to change the default behavior of the graph, but i'm not yet discovered how. 我想我需要更改图形的默认行为,但是我还没有发现如何做。

This is the result, after editing label on top vetex: enter image description here 这是在顶部顶点上编辑标签后的结果: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM