Eclipse REST 庫使用

來源:互聯網
上載者:User

很高興今天成為了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使用起來更是方便.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.