/** * 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
效果图:
源文件在附近。
更新源文件:
相关推荐
Edraw UML Diagram是软件工程师或软件设计师理想的UML建模工具。它在以下领域的UML建模:UML模型图,COM和OLE,数据流模型图,Jacobson应用案例,系统分析及设计方法,程序结构图,企业应用,Nassi-Shneiderman流程...
This is a UML diagram, describing an entire construction daily activity.
C# and UML class diagram,这是有关C#和UML class diagram的一个详细讲解和比较应用
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 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
资源分类:Python库 所属语言:Python 资源全名:protobuf-uml-diagram-0.7.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
能够根据自定义的matlab微分方程绘制二维相图,能够体现二阶系统的稳定点和该点的稳定特性。该文件包含了代码和说明文档。该资源本人同步上传到了百度云,可移步到本人博客...
UML Class Diagram Tutorial and tutorial for dia software
时序图(SequenceDiagram)是显示对象之间交互的图,这些对象是按时间顺序排列的。顺序图中显示的是参与交互的对象及其对象之间消息交互的顺序。时序图中包括的建模元素主要有:对象(Actor)、生命线(Lifeline)、...
适用于CorelDRAW插件扩展的开发,作为一个查找工具来使用。可以直观的查看各个对象自建的关系,可以用浏览器直接打开查看,支持关键字搜索,交互式操作。
AngularJS&FabricJS-2D-图 关于 基于浏览器的2D图编辑器,使用AngularJS,AngularUI和Fabric.js构建。 该项目由[Big-Silver]构建。 预安装 如果未安装Bower和gulp,则要安装Bower,请访问 ;...$ cd 2d-diagram/cli
event driving system draw the diagram
Sequence Diagrams of UML
UML建模之活动图介绍(Activity Diagram) 一、活动图的组成元素 Activity Diagram Element 1、活动状态图(Activity) 2、动作状态(Actions) 3、动作状态约束(Action Constraints) 4、动作流(Control Flow) ...
UML知识之二:类图的设计
UML use case diagram, class diagram, package diagram, object diagram, composite structure diagram, interaction diagram, sequence diagram, communication diagram, interaction overview diagram, activity...
UML簡介_Class Diagram 学习ERD的
图绘图diagram_drawio-源码