Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Resizing parent container does not properly resize its children
Resizing parent container does not properly resize its children [message #1840574] Mon, 19 April 2021 15:48 Go to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 561
Registered: November 2009
Senior Member
https://i.ibb.co/Q70Z3LJ/object.png

When I resize shape above I also want to resize its children - change position of the image and change width of horizontal line. Here is my resizeShape method

@Override
public void resizeShape(IResizeShapeContext context) {
               super.resizeShape(context);

               ContainerShape container = (ContainerShape) context.getPictogramElement();
               EList<Shape> children = container.getChildren();
			
               Shape image = children.get(0);
               Shape line = children.get(1);
               Shape text = children.get(2);
			
               GraphicsAlgorithm containerGA = container.getGraphicsAlgorithm();
               GraphicsAlgorithm lineGA = line.getGraphicsAlgorithm();
               GraphicsAlgorithm imageGA = image.getGraphicsAlgorithm();
			
               // reposition image
1.            int x = (container.getGraphicsAlgorithm().getWidth() - 30) / 2;
               Graphiti.getGaService().setLocation(imageGA, x, 5);
			
               // reposition line
2.           Graphiti.getGaService().setLocationAndSize(lineGA, lineGA.getX(), lineGA.getY(), containerGA.getWidth(), lineGA.getHeight());
}


The issues I am having with this code are:

In (1) I have to offset 'x' by 30 in order for the image be centered, it's centered initially, so why is offset needed? Without offset the image is positioned right of the center.
In (2) setting width to that of the container after it had been resized does noting to change the width of the line. Calling setLocationAndSize() works because if I change x and y of the lineGA to different values, I can see the line moving there after resize, so why does changing line width does not work?

[Updated on: Mon, 19 April 2021 15:51]

Report message to a moderator

Re: Resizing parent container does not properly resize its children [message #1840607 is a reply to message #1840574] Tue, 20 April 2021 15:21 Go to previous message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 561
Registered: November 2009
Senior Member
Found fixes for this

1. Reason for offset is because position is calculated at 0,0. I assumed that that it was at center.
2. I needed to explicitly modify points of the Polyline:
Polyline lineGA = (Polyline) line.getGraphicsAlgorithm();

EList<Point> points = lineGA.getPoints();
Point point = points.get(1);
point.setX(containerGA.getWidth());


I looked at tutorial example's resize feature https://github.com/eclipse/gmp.graphiti/blob/master/examples/org.eclipse.graphiti.examples.tutorial/src/org/eclipse/graphiti/examples/tutorial/features/TutorialResizeEClassFeature.java and I don't see explicit Polyline point manipulation there, yet line is being resized when container is resized.

This is how I define line
// create shape for line
final Shape shape = peCreateService.createShape(containerShape, false);

// create and set graphics algorithm
final Polyline polyline = gaService.createPlainPolyline(shape, new int[] { 0, 50, 100, 50 });
polyline.setStyle(StyleUtil.getStyleForEClass(getDiagram()));
Previous Topic:delete
Next Topic:Changing gradient background color during runtime
Goto Forum:
  


Current Time: Tue Nov 30 03:20:25 GMT 2021

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

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

Back to the top