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

 

感觉不错的有这么几点:

  1. 代码很少;
  2. 居然开始打开有动态效果;
  3. 三个GraphNode点都是可以用鼠标动态调整位置的;
  4. 三个GraphNode点和三个GraphConnection都可以选中,而且选中变色;
  5. 三个GraphNode点都有Tooltip;
  6. 三个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);
	}
}