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

本文介绍了一个使用GEF Zest进行简单图形布局的示例,展示了其代码简洁、动态效果、交互性和布局算法应用。通过创建一个包含节点和连接的图形,演示了如何实现节点拖动、选中变化、弹出提示等功能,并利用Spring布局算法调整布局。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文的链接: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);
	}
}

 

 

效果图:



 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值