The Node class has a lookup function which is used for finding a node in the scenegraph based on an id. Every node has a String id, similar to HTML. In theory it should be unique within the scenegraph though in practice this isn’t necessarily the case.
This lookup function currently only operates over the “public” or “logical” scenegraph, not the physical one. For example, a Button is a Control which delegates its visuals to its Skin. The Skin has a sub-scenegraph. But since we typically want to encapsulate all that, we hide it from the programmer such that most things don’t find this part of the scenegraph. Seems like a reasonable thing to do (Swing went the other way and all the gory details were public which led to issues sometimes where people would dig around and rely on internal details — the horror! — and this made it incredibly difficult to fix bugs later in Swing).
CustomNode was our level of encapsulation. Any CustomNode’s children was explicitly not part of the public API. However, a number of people have complained, likely because they aren’t using CustomNode for encapsulation but rather for modularization of their source code (ie: break a huge file into several files where each piece extended from CustomNode).
So it seems like this partitioning of “logical” and “physical” scenegraphs is quite confusing at times. So the question is, should the lookup function operate on the physical scenegraph? Vote!
[poll id=”2″]
I hate to say it, but I think we should just have an extra boolean indicating if you want to go inside custom nodes. Sort of like the booleans in other tree based apis for recursion, deep copy, etc. DOM does it. 🙂
Richard,
I agree with Joshua. Possibly the boolean would be set to ‘false’ (to not allow the user of the node to traverse tree) by default for be backwards compatible and speed. So, if the custom control or custom node implementer decides to expose the insides they can set it to ‘true’ allowing users to access ids (Except they better be unique and well documented). Unless you create a mixin class which the custom node would inherit called something like ‘AllowIdNodeTraversable’ (excuse my naming) containing the attribute to be set. I’m sure the Node has to be as small as possible and not to add extra attributes. Too bad JavaFX doesn’t have annotations (or is that a bad idea? just thinking out loud)
I also, think by solving this problem I believe GUI builders or JavaFX frameworks could benefit from this.
Thank you.
May you guys bless us with plenty of controls. 🙂