package draw2d;
import org.eclipse.draw2d.ChopboxAnchor;
import org.eclipse.draw2d.ConnectionEndpointLocator;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* A test class to display a UMLFigure
*/
public class Draw2DTest {
private static XYLayout contentsLayout;
public static void main(String args[]) {
Display d = new Display();
final Shell shell = new Shell(d, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
shell.setSize(400, 400);
shell.setText("UMLClassFigure Test");
LightweightSystem lws = new LightweightSystem(shell);
Image i = new Image(Display.getDefault(), "deine bilder/Wasserlilien.jpg");
final Figure contents = new Label(i);
contentsLayout = new XYLayout();
contents.setLayoutManager(contentsLayout);
Font classFont = new Font(null, "Arial", 12, SWT.BOLD);
Label classLabel1 = new Label("Table", null);
classLabel1.setFont(classFont);
classLabel1.setOpaque(true);
Label classLabel2 = new Label("Column", null);
classLabel2.setFont(classFont);
classLabel2.setOpaque(true);
final UMLClassFigure classFigure = new UMLClassFigure(classLabel1);
classFigure.setOpaque(true);
final UMLClassFigure classFigure2 = new UMLClassFigure(classLabel2);
classFigure2.setOpaque(true);
Label attribute1 = new Label("columns: Column[]", null);
Label attribute2 = new Label("rows: Row[]", null);
Label attribute3 = new Label("columnID: int", null);
Label attribute4 = new Label("items: List", null);
attribute1.setOpaque(true);
attribute2.setOpaque(true);
attribute3.setOpaque(true);
attribute4.setOpaque(true);
classFigure.getAttributesCompartment().add(attribute1);
classFigure.getAttributesCompartment().add(attribute2);
classFigure2.getAttributesCompartment().add(attribute3);
classFigure2.getAttributesCompartment().add(attribute4);
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();
}
}