• Eclipse REST 库使用


    很高兴今天成为了CSDN的专家,所以再忙也要抽空写一篇博客。最近公司有个需求要在RCP应用中用树状结构显示层级关系。我找了半天的开源框架,最后发现Eclipse REST最符合现在的需求。REST是专门用来显示图状效果的,废话少说了上效果,上代码。


    public class DeviceTreeViewSWT {
    
        public static void main(String[] args) {
            Display d = new Display();
            Shell shell = new Shell(d);
            Image image1 = Display.getDefault().getSystemImage(SWT.ICON_INFORMATION);
            Image image2 = Display.getDefault().getSystemImage(SWT.ICON_WARNING);
            Image image3 = Display.getDefault().getSystemImage(SWT.ICON_ERROR);
            shell.setLayout(new FillLayout());
            shell.setSize(800, 800);
    
    
    
            Graph g = new Graph(shell, SWT.NONE);
            g.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    System.out.println(((Graph) e.widget).getSelection());
                }
            });
    
            g.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
            GraphNode n1 = new GraphNode(g, SWT.NONE, "Virtual");
            n1.setBackgroundColor(new Color(d,255,0,0));
            GraphNode n2 = new GraphNode(g, SWT.NONE, "Shanghai");
            GraphNode n3 = new GraphNode(g, SWT.NONE, "Beijing");
            GraphNode n4 = new GraphNode(g, SWT.NONE, "AGM001");
            GraphNode n5 = new GraphNode(g, SWT.NONE, "AGM002");
            GraphNode n6 = new GraphNode(g, SWT.NONE, "AGM003");
            GraphNode n7 = new GraphNode(g, SWT.NONE, "AGM004");
            GraphNode n8 = new GraphNode(g, SWT.NONE, "AGM005");
            GraphNode n9 = new GraphNode(g, SWT.NONE, "AGM006");
            GraphNode n10 = new GraphNode(g, SWT.NONE, "AGM007");
            GraphNode n11 = new GraphNode(g, SWT.NONE, "AGM008");
    //        class PathFigure extends PolylineConnection {
    //            public PathFigure() {
    //                setTargetDecoration(new PolylineDecoration());
    //                setConnectionRouter(new ManhattanConnectionRouter());
    //            }
    //        }
    
            new GraphConnection(g, SWT.NONE, n1, n2);
            new GraphConnection(g, SWT.NONE, n1, n3);
            new GraphConnection(g, SWT.NONE, n2, n4);
            new GraphConnection(g, SWT.NONE, n2, n5);
            new GraphConnection(g, SWT.NONE, n2, n6);
            new GraphConnection(g, SWT.NONE, n3, n7);
            new GraphConnection(g, SWT.NONE, n3, n8);
            new GraphConnection(g, SWT.NONE, n5, n9);
            new GraphConnection(g, SWT.NONE, n5, n10);
            new GraphConnection(g, SWT.NONE, n4, n11);
    
            //g.setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.ENFORCE_BOUNDS), true);
            //g.setLayoutAlgorithm(new HorizontalTreeLayoutAlgorithm(LayoutStyles.ENFORCE_BOUNDS),true);
            g.setLayoutAlgorithm(new RadialLayoutAlgorithm(LayoutStyles.ENFORCE_BOUNDS),true);
            //g.setLayoutAlgorithm(new GridLayoutAlgorithm(LayoutStyles.ENFORCE_BOUNDS), true);
    
            shell.open();
            while (!shell.isDisposed()) {
                while (!d.readAndDispatch()) {
                    d.sleep();
                }
            }
            image1.dispose();
            image2.dispose();
            image3.dispose();
    
        }
    }
    改下LayoutAlgorithm可以看到更炫的辐射状图

    效果不错吧,用来显示图,树等都非常的方便

    如果你用Jface封装的GraphViewer,那MVC使用起来更是方便.

  • 相关阅读:
    求求你规范下你的代码风格
    为啥用ip不可以访问知乎,而百度却可以?
    漫画:htts是如何保证一台主机把数据安全发给另一台主机
    如何从亿量级中判断一个数是否存在?
    广播路由算法 :我是如何优雅着把悄悄话带给其他人的
    什么?你不知道0.0.0.0和255.255.255.255这两个地址是干嘛的?
    一篇文章带你学会Linux三剑客之一:awk
    你真的了解 i++, ++i 和 i+++++i 以及 i+++i++ 吗?
    通俗易懂讲解TCP流量控制机制,了解一下
    一文读懂拥塞控制
  • 原文地址:https://www.cnblogs.com/muyuge/p/6152554.html
Copyright © 2020-2023  润新知