Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Connections to a Polygon figure are not properly connected to its borders
Connections to a Polygon figure are not properly connected to its borders [message #897647] Tue, 24 July 2012 17:41 Go to previous message
Surya Kathayat is currently offline Surya Kathayat
Messages: 30
Registered: July 2012
Member
Hi,

As you can see in the figure, connections to a Polygon figure are not properly connected to the borders. I have (in the code below) an invisible rectangle that encloses a polygon and a text below it.

Can anyone give me some pointers?

Best Regards.
Surya


index.php/fa/10847/0/

public class ConditionTaskAddFeature extends AbstractAddShapeFeature implements IAddFeature {
	
	public static final int INVISIBLE_RECT_BUTTOM = 20;

	
	private static final IColorConstant CLASS_TEXT_FOREGROUND = new ColorConstant(51, 51, 153);
	private static final IColorConstant CLASS_FOREGROUND = new ColorConstant(255, 102, 0);
	private static final IColorConstant CLASS_BACKGROUND =  new ColorConstant(255, 204, 153);

	public ConditionTaskAddFeature(IFeatureProvider fp) {
		super(fp);
	}

	@Override
	public boolean canAdd(IAddContext context) {
		if (context.getNewObject() instanceof ConditionalTask) {
			if (context.getTargetContainer() instanceof Diagram) {
				return true;
			}
		}
		return false;	
	}

	@Override
	public PictogramElement add(IAddContext context) {

		ConditionalTask conditionTask = (ConditionalTask) context.getNewObject();
		Diagram targetDiagram = (Diagram) context.getTargetContainer();

		// CONTAINER SHAPE WITH ROUNDED RECTANGLE
		IPeCreateService peCreateService = Graphiti.getPeCreateService();
		ContainerShape containerShape = peCreateService.createContainerShape(targetDiagram, true);

		// define a default size for the shape
		int width = context.getWidth() <= 0 ? 80 : context.getWidth();
		int height = context.getHeight() <= 0 ? 80 : context.getHeight();

		Polygon diamond;
		IGaService gaService = Graphiti.getGaService();
		{
			// create invisible reactangle
			 Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
			 gaService.setLocationAndSize(invisibleRectangle, context.getX(), context.getY(), width, height + INVISIBLE_RECT_BUTTOM);

			// create polygon and set graphics algorithm
			int xy[] = new int[] {40,0,80,40,40,80,0,40};
			diamond = gaService.createPolygon(invisibleRectangle, xy);
			diamond.setParentGraphicsAlgorithm(invisibleRectangle);
			diamond.setForeground(manageColor(IColorConstant.LIGHT_BLUE));
			diamond.setBackground(manageColor(IColorConstant.LIGHT_BLUE));
			diamond.setLineWidth(2);
			gaService.setLocationAndSize(diamond, 0, 0, width, height);

			// if added Class has no resource we add it to the resource 
			// of the diagram
			// in a real scenario the business model would have its own resource
			if (conditionTask.eResource() == null) {
				getDiagram().eResource().getContents().add(conditionTask);
			}
			// create link and wire it
			link(containerShape, conditionTask);
		}
		
		// IMAGE
		{
			// create shape for Image
			Shape shape = peCreateService.createShape(containerShape, false);
			Image image = gaService.createImage(shape, ImageUtil.IMG_ORDEREDTASK);
			gaService.setLocationAndSize(image, 30, 30, 20, 20);
		}

		// SHAPE WITH TEXT
		{
			// create shape for text
			Shape shape = peCreateService.createShape(containerShape, false);

			// create and set text graphics algorithm
			Text text = gaService.createDefaultText(getDiagram(), shape, conditionTask.getName());
			text.setForeground(manageColor(CLASS_TEXT_FOREGROUND));
			text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
			text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
			gaService.setLocationAndSize(text, 10, height, width-20, 20);

			// create link and wire it
			link(shape, conditionTask);
			
		}
		
		// add a chopbox anchor to the shape 
		peCreateService.createChopboxAnchor(containerShape);
		
		// call the layout feature
                 layoutPictogramElement(containerShape);

		return containerShape;
	}	
  • Attachment: decision.gif
    (Size: 8.06KB, Downloaded 121 times)
 
Read Message
Read Message
Read Message
Previous Topic:Default Update Feature and Unresolvable Proxies
Next Topic:Resize without resizing subshapes
Goto Forum:
  


Current Time: Tue May 21 03:34:20 EDT 2013

Powered by FUDForum. Page generated in 0.01987 seconds