protected static void createSPPFigure( SPPRef spp, boolean refspp, ContainerShape containerShape, GraphicsAlgorithm invisibleRectangle, Color darkColor, Color brightDolor) { boolean relay = ValidationUtil.isRelay(spp); int size = refspp ? ITEM_SIZE_SMALL : ITEM_SIZE; int line = refspp ? LINE_WIDTH / 2 : LINE_WIDTH; Color bg = brightDolor; if (refspp) { bg = darkColor; } else { if (relay) bg = brightDolor; else bg = darkColor; } IGaService gaService = Graphiti.getGaService(); // TODOHRR: depicting SPPs as diamond using polygon didn't work // int s2 = size/2; // int xy[] = new int[] { s2, 0, size, s2, s2, size, 0, s2}; // Polygon rect = gaService.createPolygon(invisibleRectangle, xy); // rect.setForeground(darkColor); // rect.setBackground(bg); // rect.setLineWidth(line); // gaService.setLocation(rect, s2, s2); // Rectangle rect = gaService.createRectangle(invisibleRectangle); Ellipse rect = gaService.createEllipse(invisibleRectangle); rect.setForeground(darkColor); rect.setBackground(bg); rect.setLineWidth(line); gaService.setLocationAndSize(rect, size / 2, size / 2, size, size); if (containerShape.getAnchors().isEmpty()) { // here we place our anchor IPeCreateService peCreateService = Graphiti.getPeCreateService(); // FixPointAnchor anchor = peCreateService.createFixPointAnchor(containerShape); // anchor.setLocation(gaService.createPoint(xy[0], xy[1])); // anchor = peCreateService.createFixPointAnchor(containerShape); // anchor.setLocation(gaService.createPoint(xy[2], xy[3])); // anchor = peCreateService.createFixPointAnchor(containerShape); // anchor.setLocation(gaService.createPoint(xy[4], xy[5])); // anchor = peCreateService.createFixPointAnchor(containerShape); // anchor.setLocation(gaService.createPoint(xy[6], xy[7])); // TODOHRR: EllipseAnchor would be nice ChopboxAnchor anchor = peCreateService.createChopboxAnchor(containerShape); anchor.setReferencedGraphicsAlgorithm(rect); } else { // we just set the referenced GA // containerShape.getAnchors().get(0).setReferencedGraphicsAlgorithm(rect); } }
Anchor execute(RelationConnection startConnection, EObject bo, ICustomContext context) { RelationShape relationShape = ActordiagramFactory.eINSTANCE.createRelationShape(); relationShape.setVisible(true); relationShape.setActive(true); int x = context.getX(); if (x < 0) x = 200; int y = context.getY(); if (y < 0) y = 200; GraphicsAlgorithm relationGa = Graphiti.getGaCreateService().createEllipse(relationShape); Graphiti.getGaService() .setLocationAndSize( relationGa, x - RELATION_SIZE / 2, y - RELATION_SIZE / 2, RELATION_SIZE, RELATION_SIZE); ChopboxAnchor anchor = Graphiti.getPeCreateService().createChopboxAnchor(relationShape); anchor.setReferencedGraphicsAlgorithm(relationGa); // Rectangle relationGa = // Graphiti.getGaCreateService().createInvisibleRectangle(relationShape); // int x = context.getX(); if (x < 0) x = 200; // int y = context.getY(); if (y < 0) y = 200; // Graphiti.getGaService().setLocationAndSize(relationGa, x, y, RELATION_SIZE, RELATION_SIZE); // GraphicsAlgorithm relationShapeGa = Graphiti.getGaCreateService().createEllipse(relationGa); // Graphiti.getGaService().setLocationAndSize(relationShapeGa, x, y, RELATION_SIZE, // RELATION_SIZE); // BoxRelativeAnchor anchor = // Graphiti.getPeCreateService().createBoxRelativeAnchor(relationShape); // anchor.setReferencedGraphicsAlgorithm(relationGa); // anchor.setRelativeHeight(0.5); // anchor.setRelativeWidth(0.5); // Rectangle anchorGa = Graphiti.getGaCreateService().createInvisibleRectangle(anchor); // Graphiti.getGaService().setLocationAndSize(anchorGa, -1, -1, 3, 3); relationShape.setContainer(startConnection.getParent()); RelationConnection endConnection = addRelationFeature.createRelationConnection(anchor, startConnection.getEnd()); startConnection.setEnd(anchor); // check class, in case RelationConnection does not subclass it if (startConnection instanceof FreeFormConnection) { splitBendPoints((FreeFormConnection) startConnection, endConnection, x, y); } link(relationShape, bo); link(endConnection, bo); return anchor; }