Extending Builders: Layout Builders

Tom Eugelink tbee at tbee.org
Thu Nov 29 10:42:23 PST 2012

On 2012-11-29 19:03, Tom Schindl wrote:
> Am 29.11.12 17:38, schrieb Richard Bair:
>> Actually, every node already has properties on it to support layout -- isResizable, layoutBounds, and so on. So having the constraints on the Node fits right in (and in fact is how we had done it previously). The bigger concern (if I remember correctly), is what is the *type* of this constraints object? Do all layout containers have to cast this and perform an instance of check? Having to do an instance of is distasteful, as is having a base class type that really isn't overly useful (you are likely to fail in finding a least-common-denominator for all constraints types).
>> Further, one advantage to having the layout constraints in the dynamic properties map is that you can have the constraints for two different layout managers at the same time. Niche, but the idea is that you could move a node from one layout container to another and it would just have the right settings. I don't think that is really all that important, but it is a use case.
> Correct and but what if they by chance use the same key for different
> values, then you hit an even worse problem today ;-)

Why would constraints need to have a common super class? Constraints can be so different that trying to force a general API IMHO always will be a bit of a kludge.

And I have a working proposal for the constraints-for-multiple-different-layout-managers in the JFXtras versions: each layout holds the contraints in a WeakHashmap<Node, Constaint>. As soon as a Node is no longer referenced, all its constraints are cleared. And this has another advantage: you can have different constaints; so a node can be left aligned in one layout and right aligned in the other.

>> It really is one of those situations where having a nice dynamic language would have been slick.
>> So the question I have here is, what is the type of the layoutConstraints (Object? LayoutConstraint?)? How does a layout container implement getting a constraint -- instance of and casting?

No instanceof, no casting, just a type safe constraint class, specific to this one layout.



More information about the openjfx-dev mailing list