【学习】Eclipse官方Zest的两个例子(一)
原文的链接:http://wiki.eclipse.org/index.php/GEF_Zest_Visualization#Layout_Algorithms
?
感觉不错的有这么几点:
?
?
?
源代码:
/** * This snippet creates a very simple graph where Rock is connected to Paper * which is connected to scissors which is connected to rock. * * The nodes a layed out using a SpringLayout Algorithm, and they can be moved * around. * * @author Ian Bull * */public class GraphSnippet1 {private static Display display = Display.getDefault();private static Shell shell;private static void createShell() {shell = new Shell(display);shell.setText("GraphSnippet1");shell.setLayout(new FillLayout());shell.setSize(400, 400);}private static void openShell() {shell.open();while (!shell.isDisposed()) {while (!display.readAndDispatch()) {display.sleep();}}}public static void main(String[] args) {createShell();createZestExample();openShell();}private static void createZestExample() {Graph g = new Graph(shell, SWT.NONE);GraphNode n = new GraphNode(g, SWT.NONE, "Paper");GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock");GraphNode n3 = new GraphNode(g, SWT.NONE, "Scissors");new GraphConnection(g, SWT.NONE, n, n2);new GraphConnection(g, SWT.NONE, n2, n3);new GraphConnection(g, SWT.NONE, n3, n);g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);}}
?
?
效果图:
?
?