2

Can someone explain the difference/relationship between bounds and constraints in Draw2d?

I'm trying to set up a GEF editor where instances of the same EditPart class are nested inside each other (I can post a simplified version of the code if necessary, but my question is really just conceptual). Each figure has an XYLayout and I'm setting the bounds and constraints (Rectangles) of each figure in refreshVisuals.

Right now my bounds and constraints are the same for each figure. Is that correct? Since I'm using XYLayout, are the coordinates of the bounds relative to the parent Figure? How about for the constraints?

user1155252
  • 97
  • 1
  • 10

1 Answers1

1

The bounds of a child figure are only relative to the parent figure, if isCoordinateSystem() of the parent returns true - which is hardly ever the case. So in practice bounds are absolute coordinates.

The rectangles you provide as constraints in XYLayout are expected to contain coordinates relative to the parent and the layout then converts those relative coordinates in a way that is appropriate. If e.g. no figure in the parent chain has a local coordinate system, then the resulting bounds will be absolute coordinates.

Frettman
  • 2,251
  • 1
  • 13
  • 9
  • So in `refreshVisuals` should I only set the constraints and let `XYLayout` manage the bounds? In the few examples I've seen, the constraints are set but not the bounds. – user1155252 Mar 16 '12 at 13:38
  • 1
    The point of a layout manager is to let it manage the bounds of its children according to the settings and constraints you provide. So the answer to your question is: yes. – Frettman Mar 16 '12 at 15:08