`

Draw2D UML Diagram

阅读更多
/**
 * A test class to display a UMLFigure
 */
public class UMLClassFigureTest {
	private static Display display = Display.getDefault();
	
	public static void main(String args[]) {
		final Shell shell = new Shell(display);
		shell.setSize(400, 400);
		shell.setText("UMLClassFigure Test");
		LightweightSystem lws = new LightweightSystem(shell);
		
		Figure rootFigure = new Figure();
		XYLayout rootFigureLayout = new XYLayout();
		rootFigure.setLayoutManager(rootFigureLayout);

		UMLClassFigure classFigure1 = getClassFigure();
		UMLClassFigure classFigure2 = getClassFigure();
		UMLClassFigure classFigure3 = getClassFigure();
		
		rootFigureLayout.setConstraint(classFigure1, new Rectangle(10,10,-1,-1));
		rootFigureLayout.setConstraint(classFigure2, new Rectangle(200, 200, -1, -1));
		rootFigureLayout.setConstraint(classFigure3, new Rectangle(10, 200, -1, -1));

		rootFigure.add(classFigure1);
		rootFigure.add(classFigure2);
		rootFigure.add(classFigure3);
		rootFigure.add(createConnection(classFigure1,classFigure2));
		rootFigure.add(createConnection(classFigure1,classFigure3));

		lws.setContents(rootFigure);
		shell.open();
		while (!shell.isDisposed()) {
			while (!display.readAndDispatch())
				display.sleep();
		}
		
		if(!display.isDisposed()) {
			display.dispose();
		}
	}

	private static UMLClassFigure getClassFigure() {
		Label classLabel1 = new Label("Table", JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO));
		UMLClassFigure classFigure = new UMLClassFigure(classLabel1);
		
		Label attribute1 = new Label("columnID: int", JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
		Label attribute2 = new Label("items: List", JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));

		classFigure.getAttributesCompartment().add(attribute1);
		classFigure.getAttributesCompartment().add(attribute2);
		
		Label method1 = new Label("getColumns(): Column[]", JFaceResources.getImage(Dialog.DLG_IMG_HELP));
		Label method2 = new Label("getRows(): Row[]", JFaceResources.getImage(Dialog.DLG_IMG_HELP));

		classFigure.getMethodsCompartment().add(method1);
		classFigure.getMethodsCompartment().add(method2);
		
		return classFigure;
	}

	private static PolylineConnection createConnection(
			UMLClassFigure classFigure, UMLClassFigure classFigure2) {
		/* Creating the connection */
		PolylineConnection connection = new PolylineConnection();
		
		/* Creating the Anchor */
		ChopboxAnchor sourceAnchor = new ChopboxAnchor(classFigure);
		ChopboxAnchor targetAnchor = new ChopboxAnchor(classFigure2);
		connection.setSourceAnchor(sourceAnchor);
		connection.setTargetAnchor(targetAnchor);

		/* Creating the decoration */
		PolygonDecoration decoration = new PolygonDecoration();
		PointList decorationPointList = new PointList();
		decorationPointList.addPoint(0,0);
		decorationPointList.addPoint(-2,2);
		decorationPointList.addPoint(-4,0);
		decorationPointList.addPoint(-2,-2);
		decoration.setTemplate(decorationPointList);
		connection.setSourceDecoration(decoration);

		/* Adding labels to the connection */
		ConnectionEndpointLocator targetEndpointLocator = 
			new ConnectionEndpointLocator(connection, true);
		targetEndpointLocator.setVDistance(15);
		Label targetMultiplicityLabel = new Label("1..*");
		connection.add(targetMultiplicityLabel, targetEndpointLocator);

		ConnectionEndpointLocator sourceEndpointLocator = 
			new ConnectionEndpointLocator(connection, false);
		sourceEndpointLocator.setVDistance(15);
		Label sourceMultiplicityLabel = new Label("1");
		connection.add(sourceMultiplicityLabel, sourceEndpointLocator);

		ConnectionEndpointLocator relationshipLocator = 
			new ConnectionEndpointLocator(connection,true);
		relationshipLocator.setUDistance(50);
		relationshipLocator.setVDistance(-80);
		Label relationshipLabel = new Label("contains");
		connection.add(relationshipLabel,relationshipLocator);
		
		return connection;
	}
	
}

class UMLClassFigure extends Figure {
	public static Color classColor = new Color(null,255,255,206);
	private CompartmentFigure attributeFigure = new CompartmentFigure();
	private CompartmentFigure methodFigure = new CompartmentFigure();
	public UMLClassFigure(Label name) {
		ToolbarLayout layout = new ToolbarLayout();
		setLayoutManager(layout);	
		setBorder(new LineBorder(ColorConstants.black,1));
		setBackgroundColor(classColor);
		setOpaque(true);

		add(name);	
		add(attributeFigure);
		add(methodFigure);
	}
	public CompartmentFigure getAttributesCompartment() {
		return attributeFigure;
	}
	public CompartmentFigure getMethodsCompartment() {
		return methodFigure;
	}
}


class CompartmentFigure extends Figure {
	public CompartmentFigure() {
		ToolbarLayout layout = new ToolbarLayout();
		layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
		layout.setStretchMinorAxis(false);
		layout.setSpacing(2);
		setLayoutManager(layout);
		setBorder(new CompartmentFigureBorder());
	}

	public class CompartmentFigureBorder extends AbstractBorder {
		public Insets getInsets(IFigure figure) {
			return new Insets(1,0,0,0);
		}
		public void paint(IFigure figure, Graphics graphics, Insets insets) {
			graphics.drawLine(getPaintRectangle(figure, insets).getTopLeft(),
					tempRect.getTopRight());
		}
	}
}

 关键字:Draw2D UML

链接:http://www.eclipse.org/articles/Article-GEF-Draw2d/GEF-Draw2d.html

 

效果图:



 

 

源文件在附近。

 

更新源文件:

 

 

  • 大小: 11.4 KB
分享到:
评论

相关推荐

    Edraw UML Diagram 7.8.zip

    Edraw UML Diagram是软件工程师或软件设计师理想的UML建模工具。它在以下领域的UML建模:UML模型图,COM和OLE,数据流模型图,Jacobson应用案例,系统分析及设计方法,程序结构图,企业应用,Nassi-Shneiderman流程...

    ATM机系统UML图

    ATM机系统UML图是软件工程中用于设计和建模自动取款机(ATM)系统的工具集合,它利用统一建模语言(Unified Modeling Language)来清晰地描绘出系统的各个层面。UML是一种标准化的建模方法,可以帮助开发者、分析师...

    Edrawsoft.Edraw.UML.Diagram.v5.1.0.1214-Cracked-RedT

    UML Diagram is ideal for software engineers and software designers who need to draw detailed software design documentation. Edraw UML Diagram is a new software diagram design tool which works in the ...

    Edrawsoft.Edraw.UML.Diagram.v5.1.0.1214-Cracked-RedT2

    UML Diagram is ideal for software engineers and software designers who need to draw detailed software design documentation. Edraw UML Diagram is a new software diagram design tool which works in the ...

    UML class diagram

    UML class diagram

    Python库 | protobuf-uml-diagram-0.7.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:protobuf-uml-diagram-0.7.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    UML diagram

    ### UML图解析:建筑活动日常管理模型 #### 概述 本文将深入解析一个用于描述建筑行业日常活动的UML图模型。该模型通过一系列类及其相互关系,展现了建筑项目管理中的关键要素,包括活动(Activity)、日产量数据...

    Draw a phase diagram.rar

    能够根据自定义的matlab微分方程绘制二维相图,能够体现二阶系统的稳定点和该点的稳定特性。该文件包含了代码和说明文档。该资源本人同步上传到了百度云,可移步到本人博客...

    C# and UML class diagram

    在软件设计和开发中,C#和UML(统一建模语言)类图是两种重要的工具,用于描述和可视化代码结构。UML类图是一种图形表示法,它可以帮助开发者理解和设计复杂的系统,尤其是在大型项目中。C#是.NET框架中的主要编程...

    UML, Sequence Diagram

    在上一篇文章中,我们讨论了UML协作图(Collaboration Diagram),协作图着重展示了对象之间的关系,而较少关注消息传递的具体顺序。与此不同的是,**序列图强调的是消息传递的时间顺序**。尽管两者都包含了相同的...

    draw-io-note:用draw.io画的UML图等

    在draw.io中,使用“uml sequence diagram”模板,你可以轻松绘制对象和生命线,添加消息箭头来表示通信。 3. **用例图(Use Case Diagram)**:用例图描述了系统的主要参与者和他们与系统之间的交互。在draw.io中,...

    CorelDRAW Object Model Diagram 对象模型图解 思维导图

    适用于CorelDRAW插件扩展的开发,作为一个查找工具来使用。可以直观的查看各个对象自建的关系,可以用浏览器直接打开查看,支持关键字搜索,交互式操作。

    Angular-FabricJS-2d-Diagram:AngularJS,Fabric.js

    AngularJS&FabricJS-2D-图 关于 基于浏览器的2D图编辑器,使用AngularJS,AngularUI和Fabric.js构建。 该项目由[Big-Silver]构建。 预安装 如果未安装Bower和gulp,则要安装Bower,请访问 ;...$ cd 2d-diagram/cli

    UML建模之时序图(SequenceDiagram)

    时序图(SequenceDiagram)是显示对象之间交互的图,这些对象是按时间顺序排列的。顺序图中显示的是参与交互的对象及其对象之间消息交互的顺序。时序图中包括的建模元素主要有:对象(Actor)、生命线(Lifeline)、...

    eclipse中的uml类图插件jar包

    org.eclipse.uml2.uml.diagram:这个库包含了用于创建和编辑UML类图的类和接口。它提供了各种布局管理器,用于控制UML图中的元素的位置和大小。此外,它还包含了一些实用程序类,用于处理UML图中的属性和操作。 org...

    UML class diagram tutorial

    统一建模语言(UML)类图教程涵盖了如何使用UML来构建和可视化面向对象系统。UML类图是由一组类和类之间的关系集合构成的图形化表示方法。在面向对象系统中,一个类提供了一个明确定义责任集合的清晰抽象。类由三个...

    UML 2 Class Diagram Guidelines

    《UML 2 类图设计指南》 UML(统一建模语言)是软件工程领域中用于系统建模的一种标准语言,它通过图形化的方式帮助我们理解和表达软件系统的结构和行为。类图是UML中的一种核心图表,主要用于描绘系统的静态结构,...

    UML2.2-Visio2007.zip.

    UML use case diagram, class diagram, package diagram, object diagram, composite structure diagram, interaction diagram, sequence diagram, communication diagram, interaction overview diagram, activity...

    ObjectAid-1.1.5 最新版

    ObjectAid是一款强大的UML(统一建模语言)工具,专为Eclipse集成开发环境设计。它使得在IDE内部创建和编辑UML图变得轻松高效,对于理解和组织代码结构提供了极大的帮助。最新版本"ObjectAid-1.1.5"的发布,无疑为...

Global site tag (gtag.js) - Google Analytics