第一个程序:
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-PC汇编语言程序设计第二版,是扫描版的,虽然效果不是很好,但还是比较清楚的。适合初学者,或一般考试用书。
手把手教你如何配置IMB X系列的阵列卡RAID卡
中科曙光HPC培训教程汇总:D19-高性能集群性能评价—IMB.pptx
联想天逸510S-07IMB完美EFI,蓝牙+WIFI+GT730正常驱动,EFI OC7.6,支持MacOS 12
凌华IMB-M42H ATX工业母板选型样本pdf,凌华IMB-M42H ATX工业母板选型介绍
IMB-G41A_UMN_v1.01.doc
凌华IMB-M40H ATX工业主板选型样本pdf,凌华IMB-M40H ATX工业主板选型介绍
DB2数据库驱动程序
Linpack是国际上最流行的用于测试高性能计算机系统浮点性能的benchmark。通过对高性能计算机采用高斯消元法求解一元N次稠密线性代数方程组的测试,评价高性能计算机的浮点性能。 本文举例说明测试方法。
名人故事“计算机之父”IMB公司创始人托马斯.沃森个人发展过程.docx
如果你的Java程序遇到性能问题,第一步,你可以使用JConsle进行查看,但是如果想了解性能被那部分代码损耗了,请不要犹豫的使用该工具进行查看,结合JConsle生成的日志文件,就能查找到程序的漏洞!
IMB MQ 报错问题记录
IMB公司的面试文档
IBM-PC汇编语言程序设计(第二版)课后习题答案(清华大学出版社)(沈美明,温冬蝉著)
声音后插禁用,睡眠唤醒黑屏,wifi不正常,其余基本正常 oc0.7.6,可升级至12.0.1
installation_guide.rar
刃7000-28IMB刃7000K-28IMB蓝屏死机修复工具.exe
IMB软件学院的教程。里面包括教学课件、教学指导和上机作业
世界著名教材的汉化版,,内容精髓,,配合英文教材的好帮手!