Skip to main content



      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 next message
Eclipse UserFriend
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 842 times)
Re: Connections to a Polygon figure are not properly connected to its borders [message #897964 is a reply to message #897647] Wed, 25 July 2012 10:10 Go to previous messageGo to next message
Eclipse UserFriend
If you use invisible rectangles it's a little bit tricky.

You toolbehaviour provider must override the method

public GraphicsAlgorithm getChopboxAnchorArea(PictogramElement pe)


If the pe is connected with the ConditionalTask simply return the first child of the invisible rectangle. In this case your diamand polygon.

BR,
Matthias
Re: Connections to a Polygon figure are not properly connected to its borders [message #897995 is a reply to message #897964] Wed, 25 July 2012 11:12 Go to previous message
Eclipse UserFriend
Thank you again.
Works great.

BR
Surya
Previous Topic:Default Update Feature and Unresolvable Proxies
Next Topic:Resize without resizing subshapes
Goto Forum:
  


Current Time: Thu Jul 10 06:03:25 EDT 2025

Powered by FUDForum. Page generated in 0.06259 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top