首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

【学习】Eclipse官方Zest的两个例证(一)

2012-10-15 
【学习】Eclipse官方Zest的两个例子(一)原文的链接:http://wiki.eclipse.org/index.php/GEF_Zest_Visualizat

【学习】Eclipse官方Zest的两个例子(一)

原文的链接:http://wiki.eclipse.org/index.php/GEF_Zest_Visualization#Layout_Algorithms

?

感觉不错的有这么几点:

    代码很少;居然开始打开有动态效果;三个GraphNode点都是可以用鼠标动态调整位置的;三个GraphNode点和三个GraphConnection都可以选中,而且选中变色;三个GraphNode点都有Tooltip;三个GraphNode点拖动出窗口,自动有滚动条;

?

?

?

源代码:

/** * 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);}}

?

?

效果图:


【学习】Eclipse官方Zest的两个例证(一)
?

?

热点排行