Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » resizing elements nested in rectangle
resizing elements nested in rectangle [message #780941] Fri, 20 January 2012 04:38 Go to next message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Hi there, sorry to be an annoyance. I have really enjoyed this framework and think you have done a wonderful job here.

My current issue involves an invisible rectangle and some elements nested inside of it.
Inside of my invisible rectangle I have a standard rectangle stacked (horizontally) on a small polygon ( a diamond shape which only shows up under certain model conditions).

Here is my code for creating this:
          {
            	int offset = 0;
            	Rectangle invisible =   gaService.createInvisibleRectangle(containerShape);
            	if(addedClass.isToBeDeveloped()){
            		offset = 20;
            	}
            	gaService.setLocationAndSize(invisible,context.getX(), context.getY(), width, height+offset);
            	link(containerShape, addedClass);
            }
            {
            	Shape shape = peCreateService.createShape(containerShape, false);
                // create and set graphics algorithm
                Rectangle rectangle =
                    gaService.createRectangle(shape);
                rectangle.setForeground(manageColor(CLASS_FOREGROUND));
                rectangle.setBackground(manageColor(CLASS_BACKGROUND));
                rectangle.setLineWidth(2);
                gaService.setLocationAndSize(rectangle,
                		0,0,width,height);
                // create link and wire it
                link(shape, addedClass);
            }
            {
            	if(addedClass.isToBeDeveloped()){
            		Shape shape = peCreateService.createShape(containerShape, false);
            		int[] diamondXY = new int[] {10,0,20,10,10,20,0,10};
            		Polygon p = gaService.createPolygon(shape, diamondXY);
            		p.setBackground(manageColor(UNDEV_BACKGROUND));
            		p.setForeground(manageColor(UNDEV_FOREGROUND));
            		p.setLineWidth(2);
            		//gaService.setLocationAndSize(p, width/2, height, 10, 10);
            		gaService.setLocation(p,  (width/2-10), (height));
            		
            		link(shape, addedClass);
            	
            	}
            }


If I comment out the first "link" under the invisible rectangle I get the correct layout of my elements. A box on top of a small diamond.

If I leave it in, the box is fine, but the diamond is skewed. The right half of the diamond stretches out to the bounding invisible rectangle.

However, if I comment out the first link under the invisible rectangle the resize (implemented in Layout) does not work properly. The invisible rectangle is resized but the regular rectangle moves into the upper right hand corner.


If I leave it in the resize works for the regular rectangle as desired but the position of the diamond is static.


Here is the Layout code:

....
        for (Shape shape : containerShape.getChildren()){
            GraphicsAlgorithm graphicsAlgorithm = shape.getGraphicsAlgorithm();
            IGaService gaService = Graphiti.getGaService();
            IDimension size =
                 gaService.calculateSize(graphicsAlgorithm);
            if (containerWidth != size.getWidth()) {
                if (graphicsAlgorithm instanceof Polyline) {
                    Polyline polyline = (Polyline) graphicsAlgorithm;
                    Point secondPoint = polyline.getPoints().get(1);
                    Point newSecondPoint =
                        gaService.createPoint(containerWidth, secondPoint.getY());
                    polyline.getPoints().set(1, newSecondPoint);
                    anythingChanged = true;
                }else if (graphicsAlgorithm instanceof MultiText) {
                	MultiText mt = (MultiText) graphicsAlgorithm;
                	mt.setHeight(containerHeight - DESCRIPTION_OFFSET);
                	mt.setWidth(containerWidth);
                	anythingChanged = true;
                } else if (graphicsAlgorithm instanceof Rectangle){
                	Rectangle rt = (Rectangle) graphicsAlgorithm;
                	rt.setHeight(containerHeight - UNDEVELOPED_OFFSET );
                	rt.setWidth(containerWidth);
                } else if (graphicsAlgorithm instanceof Polygon){
                	Polygon pg = (Polygon) graphicsAlgorithm;
                	pg.setX(containerWidth/2);
                	pg.setY(containerHeight - UNDEVELOPED_OFFSET);
                }else {
                
                    gaService.setWidth(graphicsAlgorithm,
                        containerWidth);
                    anythingChanged = true;
                }
            }
        }
        return anythingChanged;



So here are my questions:
1. What would be causing the right hand side of my polygon to become skewed like that dependent on the link(containerShape,addedClass) addition?

2. What would keep my resize/layout adjustment from working properly?

I did notice that unless the link(containerShape, addedClass) line was in there the resize methods for this feature were not called, which I thought was a bit odd, but I could not come up with an answer on that one.

Thanks
Joe


Re: resizing elements nested in rectangle [message #781188 is a reply to message #780941] Fri, 20 January 2012 08:47 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Josef,

1) Probably the lines
Point newSecondPoint =
gaService.createPoint(containerWidth,
secondPoint.getY());
polyline.getPoints().set(1, newSecondPoint);

cause the diamond extension. I'm not sure why it is called, maybe your
update feature checks for the existance of the link?
2) Again I would check the update feature if it causes any unwanted
layouts...

Michael
Re: resizing elements nested in rectangle [message #781224 is a reply to message #781188] Fri, 20 January 2012 20:44 Go to previous messageGo to next message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Thank you very much Michael,

When I commented out, or moved the polyline code to the end of the if then else cascade the functionality was as desired.
It does seem odd that it would call the polyline layout feature update on a polygon. I am using the default update feature for this element but I will dig around further for other possibilities.

Is there a way to differentiate the behavior of the different polygons if I have multiple polygon GA's nested in the same way I have a rectangle and a polygon? In other words is there a way to tell the difference between one polygon and another, or to "name" them up front?

Thanks again for all your help!
Joe
Re: resizing elements nested in rectangle [message #782296 is a reply to message #781224] Mon, 23 January 2012 13:30 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
You can add properties to any GA (name value pairs) you could use for that.

Michael
Re: resizing elements nested in rectangle [message #782522 is a reply to message #782296] Mon, 23 January 2012 22:03 Go to previous message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Thanks again Michael. I did not realize I could use the properties for such a thing.
Thank you,
Joe
Previous Topic:Non-selectable connections?
Next Topic:Accessing eRessource or Diagram
Goto Forum:
  


Current Time: Thu Dec 18 16:25:28 GMT 2014

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

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