# HG changeset patch # User Frank Benoit # Date 1217717451 -7200 # Node ID 2ddf4a05e444d4fef991092596344f5c59d8be41 # Parent 6470136b55d9770c06fedbd4bdb1f457523a9a90 Added Draw2D example, UML Example diff -r 6470136b55d9 -r 2ddf4a05e444 draw2d/UmlExample.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/draw2d/UmlExample.d Sun Aug 03 00:50:51 2008 +0200 @@ -0,0 +1,192 @@ +module umlexample.UmlExample; + +import dwt.dwthelper.utils; +import dwt.dwthelper.ByteArrayInputStream; + +import dwtx.draw2d.Figure; +import dwtx.draw2d.IFigure; +import dwtx.draw2d.geometry.PointList; +import dwtx.draw2d.geometry.Rectangle; +import dwtx.draw2d.geometry.Insets; +import dwt.DWT; +import dwt.graphics.Font; +import dwt.graphics.Image; +import dwt.graphics.ImageData; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwtx.draw2d.AbstractBorder; +import dwtx.draw2d.Graphics; +import dwt.graphics.Color; +import dwtx.draw2d.Label; +import dwtx.draw2d.ToolbarLayout; +import dwtx.draw2d.LineBorder; +import dwtx.draw2d.ConnectionEndpointLocator; +import dwtx.draw2d.ChopboxAnchor; +import dwtx.draw2d.PolygonDecoration; +import dwtx.draw2d.PolylineConnection; +import dwtx.draw2d.ColorConstants; +import dwtx.draw2d.LightweightSystem; +import dwtx.draw2d.XYLayout; + +version(JIVE) import jive.stacktrace; + +public class CompartmentFigure : Figure { + + public this() { + ToolbarLayout layout = new ToolbarLayout(); + layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT); + layout.setStretchMinorAxis(false); + layout.setSpacing(2); + setLayoutManager(layout); + setBorder(new CompartmentFigureBorder()); + } + + public class CompartmentFigureBorder : 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()); + } + } +} + +public class UMLClassFigure : Figure { + public static Color classColor; + static this(){ + classColor = new Color(null,255,255,206); + } + + private CompartmentFigure attributeFigure; + private CompartmentFigure methodFigure; + + public this(Label name) { + + attributeFigure = new CompartmentFigure(); + methodFigure = new CompartmentFigure(); + + 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; + } +} + +static void[] imgDataClass = import("draw2d.umlexample.class.gif"); +static void[] imgDataMethod = import("draw2d.umlexample.method.gif"); +static void[] imgDataField = import("draw2d.umlexample.field.gif"); + +Image getImage( Display disp, void[] data ){ + ImageData imageData = new ImageData( new ByteArrayInputStream( cast(byte[]) data )); + return new Image( disp, imageData ); +} + +/** + * A test class to display a UMLFigure + */ +public static void main(){ + Display d = new Display(); + final Shell shell = new Shell(d); + shell.setSize(400, 400); + shell.setText("UMLClassFigure Test"); + LightweightSystem lws = new LightweightSystem(shell); + Figure contents = new Figure(); + XYLayout contentsLayout = new XYLayout(); + contents.setLayoutManager(contentsLayout); + + Font classFont = new Font(null, "Arial", 12, DWT.BOLD); + Label classLabel1 = new Label("Table", getImage(d, imgDataClass)); + classLabel1.setFont(classFont); + + Label classLabel2 = new Label("Column", getImage(d, imgDataClass)); + classLabel2.setFont(classFont); + + final UMLClassFigure classFigure = new UMLClassFigure(classLabel1); + final UMLClassFigure classFigure2 = new UMLClassFigure(classLabel2); + + Label attribute1 = new Label("columns: Column[]", getImage(d, imgDataField)); + Label attribute2 = new Label("rows: Row[]", getImage(d, imgDataField)); + Label attribute3 = new Label("columnID: int", getImage(d, imgDataField)); + Label attribute4 = new Label("items: List", getImage(d, imgDataField)); + + classFigure.getAttributesCompartment().add(attribute1); + classFigure.getAttributesCompartment().add(attribute2); + classFigure2.getAttributesCompartment().add(attribute3); + classFigure2.getAttributesCompartment().add(attribute4); + + Label method1 = new Label("getColumns(): Column[]", getImage(d, imgDataMethod)); + Label method2 = new Label("getRows(): Row[]", getImage(d, imgDataMethod)); + Label method3 = new Label("getColumnID(): int", getImage(d, imgDataMethod)); + Label method4 = new Label("getItems(): List", getImage(d, imgDataMethod)); + + classFigure.getMethodsCompartment().add(method1); + classFigure.getMethodsCompartment().add(method2); + classFigure2.getMethodsCompartment().add(method3); + classFigure2.getMethodsCompartment().add(method4); + + contentsLayout.setConstraint(classFigure, new Rectangle(10,10,-1,-1)); + contentsLayout.setConstraint(classFigure2, new Rectangle(200, 200, -1, -1)); + + /* Creating the connection */ + PolylineConnection c = new PolylineConnection(); + ChopboxAnchor sourceAnchor = new ChopboxAnchor(classFigure); + ChopboxAnchor targetAnchor = new ChopboxAnchor(classFigure2); + c.setSourceAnchor(sourceAnchor); + c.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); + c.setSourceDecoration(decoration); + + /* Adding labels to the connection */ + ConnectionEndpointLocator targetEndpointLocator = + new ConnectionEndpointLocator(c, true); + targetEndpointLocator.setVDistance(15); + Label targetMultiplicityLabel = new Label("1..*"); + c.add(targetMultiplicityLabel, targetEndpointLocator); + + ConnectionEndpointLocator sourceEndpointLocator = + new ConnectionEndpointLocator(c, false); + sourceEndpointLocator.setVDistance(15); + Label sourceMultiplicityLabel = new Label("1"); + c.add(sourceMultiplicityLabel, sourceEndpointLocator); + + ConnectionEndpointLocator relationshipLocator = + new ConnectionEndpointLocator(c,true); + relationshipLocator.setUDistance(10); + relationshipLocator.setVDistance(-20); + Label relationshipLabel = new Label("contains"); + c.add(relationshipLabel,relationshipLocator); + + contents.add(classFigure); + contents.add(classFigure2); + contents.add(c); + + lws.setContents(contents); + shell.open(); + while (!shell.isDisposed()) + while (!d.readAndDispatch()) + d.sleep(); +} + + + + diff -r 6470136b55d9 -r 2ddf4a05e444 draw2d/dsss.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/draw2d/dsss.conf Sun Aug 03 00:50:51 2008 +0200 @@ -0,0 +1,20 @@ +# DWT dwt-samples/jface directory + +[*] +buildflags+=-g -gc +buildflags+=-J$LIB_PREFIX/res -J../res -I.. + +version(Windows) { + # if no console window is wanted/needed use -version=gui + version(gui) { + buildflags+= -L/SUBSYSTEM:windows:5 + } else { + buildflags+= -L/SUBSYSTEM:console:5 + } + buildflags+= -L/rc:..\dwt +} + + + +[UmlExample.d] + diff -r 6470136b55d9 -r 2ddf4a05e444 res/draw2d.umlexample.class.gif Binary file res/draw2d.umlexample.class.gif has changed diff -r 6470136b55d9 -r 2ddf4a05e444 res/draw2d.umlexample.field.gif Binary file res/draw2d.umlexample.field.gif has changed diff -r 6470136b55d9 -r 2ddf4a05e444 res/draw2d.umlexample.method.gif Binary file res/draw2d.umlexample.method.gif has changed