`

IMB的Zest文档学习 代码

 
阅读更多

第一个程序:

public class FirstZest { 

       public static void main(String[] args) { 
              // SWT 
              Display display = new Display(); 
              Shell shell = new Shell(display); 
              shell.setText("First Zest Program Demo"); 
              shell.setLayout(new FillLayout()); 
              shell.setSize(300, 300); 

              // 创建 Graph 
              Graph graph = new Graph(shell, SWT.NONE); 
              // 创建一个图形节点
              GraphNode startNode = new GraphNode(graph, SWT.NONE, "Start"); 
              // 创建另外一个图形节点
              GraphNode endNode = new GraphNode(graph, SWT.NONE, "End"); 
              // 创建节点关联
              new GraphConnection(graph, SWT.NONE, startNode, endNode); 
              // 设置布局管理器
              graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( 
                            LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 

              // 显示 SWT 
              shell.open(); 
              while (!shell.isDisposed()) { 
                     while (!display.readAndDispatch()) { 
                            display.sleep(); 
                     } 
              } 
       } 
 } 

 

第二个程序:设置图形的图像和连线箭头

public class FirstZest2 { 

	public static void main(String[] args) { 
		// SWT 
		Display display = new Display(); 
		Shell shell = new Shell(display); 
		shell.setText("First Zest Program Demo"); 
		shell.setLayout(new FillLayout()); 
		shell.setSize(300, 300); 

		Graph graph = new Graph(shell, SWT.NONE); 
		graph.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); 
		Image startIcon = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO);
		GraphNode startNode = new GraphNode(graph, SWT.NONE, "Start", startIcon);  
		GraphNode endNode = new GraphNode(graph, SWT.NONE, "End"); 
		new GraphConnection(graph, SWT.NONE, startNode, endNode); 
		graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( 
				LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 

		shell.open(); 
		while (!shell.isDisposed()) { 
			while (!display.readAndDispatch()) { 
				display.sleep(); 
			} 
		} 
	} 
} 

 

 

设置图形的事件,选中的加粗:

 public class FirstZest3 { 

       public static void main(String[] args) { 
              Display display = new Display(); 
              Shell shell = new Shell(display); 
              shell.setText("First Zest Program Demo"); 
              shell.setLayout(new FillLayout()); 
              shell.setSize(300, 300); 

              Graph graph = new Graph(shell, SWT.NONE); 
              GraphNode startNode = new GraphNode(graph, SWT.NONE, "Start"); 
              GraphNode endNode = new GraphNode(graph, SWT.NONE, "End"); 
              new GraphConnection(graph, SWT.NONE, startNode, endNode); 
              graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( 
                            LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
              
              // 注册对象选择侦听事件
              graph.addSelectionListener(new SelectionAdapter() { 
                    @Override 
                    public void widgetSelected(SelectionEvent e) { 
                           List selection = ((Graph) e.widget).getSelection(); 
                           // 确认只选择了一个对象
                           if (selection.size() == 1) { 
                                  Object o = selection.get(0); 
                                  // 图形节点对象
                                  if (o instanceof GraphNode) { 
                                         // 改变边线宽度
                                         ((GraphNode) o).setBorderWidth(3); 
                                  // 图形关联对象
                                  } else if (o instanceof GraphConnection) { 
                                         // 改变连线宽度
                                         ((GraphConnection) o).setLineWidth(3); 
                                  } 
                           } 
                    } 
              }); 

              shell.open(); 
              while (!shell.isDisposed()) { 
                     while (!display.readAndDispatch()) { 
                            display.sleep(); 
                     } 
              } 
       } 
 } 

 

 

测试不同的布局管理器算法:

 public class FirstZest4 { 

       public static void main(String[] args) { 
              // SWT 
              Display display = new Display(); 
              Shell shell = new Shell(display); 
              shell.setText("First Zest Program Demo"); 
              shell.setLayout(new FillLayout()); 
              shell.setSize(300, 300); 


              Graph graph = new Graph(shell, SWT.NONE); 
              graph.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); 
              for (int i = 0; i < 10; i++) { 
                 GraphNode node1 = new GraphNode(graph, ZestStyles.NODES_FISHEYE, 
                         "Begin"); 
                 GraphNode node2 = new GraphNode(graph, ZestStyles.NODES_FISHEYE, 
                         "Middle"); 
                 GraphNode node3 = new GraphNode(graph, ZestStyles.NODES_FISHEYE, 
                         "Finish"); 
                 new GraphConnection(graph, SWT.NONE, node1, node2); 
                 new GraphConnection(graph, SWT.NONE, node2, node3); 
              } 
              graph.setLayoutAlgorithm(new GridLayoutAlgorithm(
                     LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
              /* 
              graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( 
                     LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
              graph.setLayoutAlgorithm(new RadialLayoutAlgorithm( 
                     LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
              graph.setLayoutAlgorithm(new TreeLayoutAlgorithm(
                     LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
              graph.setLayoutAlgorithm(new DirectedGraphLayoutAlgorithm( 
                     LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
              */

              // 显示 SWT 
              shell.open(); 
              while (!shell.isDisposed()) { 
                     while (!display.readAndDispatch()) { 
                            display.sleep(); 
                     } 
              } 
       } 
 } 

 

 

定制布局管理器:

public class FirstZest5 { 

       public static void main(String[] args) { 
              // SWT 
              Display display = new Display(); 
              Shell shell = new Shell(display); 
              shell.setText("First Zest Program Demo"); 
              shell.setLayout(new FillLayout()); 
              shell.setSize(300, 300); 

              Graph graph = new Graph(shell, SWT.NONE); 
              graph.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); 
              GraphNode node1 = new GraphNode(graph, SWT.NONE, "Node 1"); 
              GraphNode node2 = new GraphNode(graph, SWT.NONE, "Node 2"); 
              GraphNode node3 = new GraphNode(graph, SWT.NONE, "Node 3"); 
              new GraphConnection(graph, SWT.NONE, node1, node2); 
              new GraphConnection(graph, SWT.NONE, node2, node3); 
              graph.setLayoutAlgorithm(new AbstractLayoutAlgorithm(SWT.NONE) { 
                 int totalNodes; 

                 protected int getCurrentLayoutStep() { 
                     return 0; 
                 } 

                 protected int getTotalNumberOfLayoutSteps() { 
                     return totalNodes; 
                 } 

                 protected boolean isValidConfiguration(boolean asynchronous, 
                         boolean continuous) { 
                     return true; 
              } 

                 protected void postLayoutAlgorithm(InternalNode[] entitiesToLayout, 
                         InternalRelationship[] relationshipsToConsider) { 
                 } 

                 protected void preLayoutAlgorithm(InternalNode[] entitiesToLayout, 
                         InternalRelationship[] relationshipsToConsider, double x, 
                         double y, double width, double height) { 
                 } 
                 public void setLayoutArea(double x, double y, double width, 
                         double height) { 
                 }

				@Override
				protected void applyLayoutInternal(
						InternalNode[] entitiesToLayout,
						InternalRelationship[] relationshipsToConsider,
						double boundsX, double boundsY, double boundsWidth,
						double boundsHeight) {
                    // 需要布局的对象数量
                    totalNodes = entitiesToLayout.length; 
                    // 设置固定间隔距离
                    double spcaing = 100; 
                    // 开始位置坐标
                    int startX = 10; 
                    // 触发布局进程
                    fireProgressStarted(totalNodes); 
                    // 循环所有对象,按照设定的布局算法来排列对象
                    for (int curNode = 0; curNode < entitiesToLayout.length; curNode++) { 
                        LayoutEntity layoutEntity = entitiesToLayout[curNode] 
                                .getLayoutEntity(); 
                        // 设置一个对象显示的位置
                        layoutEntity.setLocationInLayout(startX, layoutEntity 
                                .getYInLayout()+10); 
                        // 保持相同的间隔
                        startX += spcaing; 
                        // 让对象在新位置上显示
                        fireProgressEvent(curNode, totalNodes); 
                    } 
                    // 结束布局进程
                    fireProgressEnded(totalNodes); 
					// TODO Auto-generated method stub
				}
              }, true); 
              
              // 显示 SWT 
              shell.open(); 
              while (!shell.isDisposed()) { 
                     while (!display.readAndDispatch()) { 
                            display.sleep(); 
                     } 
              } 
       } 
 } 

 

 

定制图形:

public class FirstZest6 { 

	public static void main(String[] args) { 
		// SWT 
		Display display = new Display(); 
		Shell shell = new Shell(display); 
		shell.setText("First Zest Program Demo"); 
		shell.setLayout(new FillLayout()); 
		shell.setSize(300, 300); 

		Graph graph = new Graph(shell, SWT.NONE); 
		GraphNode startNode = new GraphNode(graph, SWT.NONE, "Start"); 
		EllipseGraphNode ellipseNode = new EllipseGraphNode(graph, SWT.NONE, "ellipse"); 
		GraphNode endNode = new GraphNode(graph, SWT.NONE, "End"); 

		// 创建节点关联
		new GraphConnection(graph, SWT.NONE, startNode, ellipseNode); 
		new GraphConnection(graph, SWT.NONE, ellipseNode, endNode); 
		// 设置布局管理器
		graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( 
				LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 

		// 显示 SWT 
		shell.open(); 
		while (!shell.isDisposed()) { 
			while (!display.readAndDispatch()) { 
				display.sleep(); 
			} 
		} 
	} 
} 

class EllipseGraphNode extends CGraphNode { 
	public EllipseGraphNode(IContainer graphModel, int style, IFigure figure) { 
		super(graphModel, style, figure); 
	}

	public EllipseGraphNode(IContainer graphModel, int style, String name) { 
		super(graphModel, style, createEllipseFigure(name)); 
	}

	private static IFigure createEllipseFigure(String name) { 
		EllipseFigure circleFigure = new EllipseFigure(name); 
		circleFigure.setSize(-1, -1); 
		return circleFigure; 
	}

} 

class EllipseFigure extends Figure { 


	public EllipseFigure(String name) { 
		// 定义显示名称
		Label label = new Label(name); 
		// 定义图形节点的显示布局
		ToolbarLayout layout = new ToolbarLayout(); 
		setLayoutManager(layout); 
		setBorder(new LineBorder(ColorConstants.white, 1)); 
		setOpaque(true); 

		add(label); 
	} 
	// 重写这个方法,实现自己需要显示的图形,更多的信息可以参考 Zest 的源代码
	@Override 
	public void paint(Graphics graphics) { 
		super.paint(graphics); 
		// 获取默认的矩形信息
		Rectangle rectangle = getBounds().getCopy(); 
		graphics.setLineWidth(2); 
		// 画椭圆
		graphics.drawOval(rectangle); 
	} 
} 

 

 

设置图形不让拖动:

package com.iteye.xmind.draw2d.zest2;

import java.util.Iterator;
import java.util.List;

import org.eclipse.draw2d.SWTEventDispatcher;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

public class FirstZest7 { 

       public static void main(String[] args) { 
              // SWT 
              Display display = new Display(); 
              Shell shell = new Shell(display); 
              shell.setText("First Zest Program Demo"); 
              shell.setLayout(new FillLayout()); 
              shell.setSize(300, 300); 

              // 创建 Graph 
              Graph graph = new Graph(shell, SWT.NONE); 
              // 创建一个图形节点
              GraphNode startNode = new GraphNode(graph, SWT.NONE, "Start"); 
              // 创建另外一个图形节点
              GraphNode endNode = new GraphNode(graph, SWT.NONE, "End"); 
              // 创建节点关联
              new GraphConnection(graph, SWT.NONE, startNode, endNode); 
              // 设置布局管理器
              graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( 
                            LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); 
      		graph.getLightweightSystem().setEventDispatcher( 
    				new SWTEventDispatcher() { 
    					public void dispatchMouseMoved(MouseEvent me) { 
    						List selection = ((Graph) me.widget).getSelection(); 
    						for (Iterator iterator = selection.iterator(); iterator.hasNext();) { 
    							Object object = (Object) iterator.next(); 
    							if (object instanceof GraphNode) { 
    								String nodeName = ((GraphNode) object).getText(); 
    								if ("Start".equalsIgnoreCase(nodeName)) { 
    									// 如果是 Start 图形节点,就无法被移动
    								} else { 
    									// 其他图形节点,不受影响
    									super.dispatchMouseMoved(me); 
    								} 
    							} 
    						} 
    					} 
    				}); 
              // 显示 SWT 
              shell.open(); 
              while (!shell.isDisposed()) { 
                     while (!display.readAndDispatch()) { 
                            display.sleep(); 
                     } 
              } 
       } 
 } 

 

分享到:
评论

相关推荐

    IMB LORA 源代码

    IMB LORA 源代码 IMB LORA 源代码 IMB LORA 源代码 IMB LORA 源代码

    [黑苹果EFI分享]联想天逸510s-07IMB 半完美

    在尝试这些解决方案时,用户应仔细研究各种论坛和资源,如MacRumors、tonymacx86和OpenCore官方文档,以获取最新信息和详细步骤。此外,创建备份和恢复策略也很重要,以防在调整过程中出现问题。通过耐心调试和不断...

    IMB-G41A_UMN_v1.01.doc

    【IMB-G41A_UMN_v1.01.doc】文档主要介绍了一款由IEI Technology Corp.生产的Micro-ATX主板——IEI-945。这款主板是专为Intel Core 2 Duo、Quad、Extreme系列CPU设计的,支持800/1066/1333MHz前端总线频率。以下是对...

    凌华IMB-M42H ATX工业母板选型样本.pdf

    凌华IMB-M42H ATX工业母板是一款专为工业应用设计的主板,具有高可靠性、丰富的I/O接口和强大的扩展能力。它支持Intel第四代Core™处理器和Celeron处理器,具备双通道DDR3内存插槽和丰富的扩展插槽,如PCI、PCI ...

    IMB-PC汇编语言程序设计第二版

    IMB-PC汇编语言程序设计第二版,是扫描版的,虽然效果不是很好,但还是比较清楚的。适合初学者,或一般考试用书。

    凌华IMB-M40H ATX工业主板选型样本.pdf

    凌华IMB-M40H ATX工业主板选型样本.pdf 凌华IMB-M40H ATX工业主板是一款支持第3代Intel Core处理器的高性能工业主板,采用Intel H61 Express芯片组,支持双通道DDR3内存,最大支持16GB内存容量。该主板具有丰富的I/...

    黑苹果EFI分享|联想天逸510S-07IMB,蓝牙+WIFI+GT730正常驱动

    这里提到的"联想天逸510S-07IMB"是联想的一款台式机型号,而"EFI"(Extensible Firmware Interface)则是电脑启动过程中使用的固件接口,对于黑苹果安装来说至关重要。 EFI是计算机启动时的第一个软件环境,它负责...

    imb-pc汇编程序设计答案

    6. **汇编与链接**:学习如何将汇编源代码转换成可执行文件,包括汇编过程(使用汇编器)和链接过程(使用链接器)。 7. **调试技巧**:学会使用调试工具(如DEBUG命令或现代的调试器)来分析和调试汇编程序。 ...

    IMB MQ 报错问题记录

    IMB MQ 报错问题记录

    中科曙光HPC培训教程汇总:D19-高性能集群性能评价—IMB.pptx

    中科曙光HPC培训教程汇总:D19-高性能集群性能评价—IMB.pptx

    Linpack 及IMB测试方法

    最后,下载并解压HPL源代码,根据系统的具体配置修改Makefile,然后编译生成可执行文件。 在运行Linpack测试之前,需要编辑HPL.dat配置文件,设定测试参数,如矩阵的大小、进程数等。运行时,使用`mpirun`命令启动...

    moeldv_FRGU9IMB

    标题“moeldv_FRGU9IMB”似乎代表了一个特定的项目或代码库的标识符,而“bot_dev01”可能是指这个项目的开发阶段或者是某种特定的机器人开发环境的名称。结合“Apex”标签,我们可以推断这可能与Apex编程语言或者...

    IMB的一款Java性能分析软件

    如果你的Java程序遇到性能问题,第一步,你可以使用JConsle进行查看,但是如果想了解性能被那部分代码损耗了,请不要犹豫的使用该工具进行查看,结合JConsle生成的日志文件,就能查找到程序的漏洞!

    imb-jca-线程堆栈.zip

    同时,它还能显示每个线程执行的Java方法调用链,这对于定位代码中的问题非常有帮助。 jca461则更进一步,它不仅具备jca436的功能,还可能包含额外的性能分析特性,比如CPU使用率分析、内存泄漏检测等。通过这些...

    信颐IMB多媒体会议室解决方案

    信颐IMB多媒体会议室解决方案涉及的IT知识点相当丰富,包括多媒体会议室的市场需求、现有技术的缺陷、信颐科技提供的产品特点、产品应用案例以及与竞品的对比等。下面是对这些内容的详细解读: 首先,多媒体会议室...

    imb-LAP3350点位图

    imb-LAP3350点位图

    imb-410M点位图

    imb-410M点位图

    imb-4100TN点位图

    imb-4100TN点位图

    imb-310TN点位图

    imb-310TN点位图

    imb-310N点位图

    imb-310N点位图

Global site tag (gtag.js) - Google Analytics