I think it would pay to take a step back and understand why you think a 'traditional' scenegraph-based (or retained mode) control is not sufficient for your needs? Unfortunately you've not detailed your use case, so it is hard to give any specific advice. Are you able to give any details about what it is you're trying to build and why you think the normal approach to building controls is not sufficient?

We've built some fairly complex controls using this approach, and if implemented wisely, there is very little that a scenegraph-based approach can't do. Specifically, do you think your control will render all of the 'thousands of nodes' at once, or will many of these nodes be off screen or otherwise not visible at any one time? For things like the TableView we only render the nodes that are visible. This means that regardless of whether there are 100 or 1,000,000 rows of data, we only have visual nodes for the 20 visible rows, for example. Keeping your scenegraph as minimal as possible is always a very wise idea, if performance is a concern.

As you note, the other problem is that you will run into issues if you want to mix canvas rendering with the scenegraph-based controls like Button. The best you're likely to achieve (having not tried it personally) is to position the control on top of the canvas, rather than attempting to render the control inside the canvas (and having to then deal with event handling, etc). This will likely prove to be finicky, and more cumbersome than simply using an entirely canvas-based or entirely scenegraph-based approach.

-- Jonathan

On 5/08/2013 10:11 p.m., Felix Bembrick wrote:
I am investigating the feasibility of developing a JavaFX 8 control based
on Canvas.  I have chosen Canvas as the base class as this control is of a
very dynamic nature and would not be easy to implement with a retained mode
style ancestor (at least as far as I can tell).

So is this feasible?  While I can readily see how to render the visual
aspects of the control, I am not sure how to best "embed" other controls
within it should that become necessary (and almost certainly will).

For example, how would I go about embedding a Button within my control?  It
looks to me like I would need to create an actual Button node somewhere
else in the scenegraph and then perhaps render it within my control using
gc.drawImage() passing in a snapshot of the Button node.  That's OK but
then I have to somehow handle events and I am not sure how best to do that.

Another issue I see is that there seems to be no way to apply effects to
individual graphic elements within the Canvas as the applyEffect() method
applies to the entire Canvas.

Finally, a significant obstacle is this issue:

https://javafx-jira.kenai.com/browse/RT-23822

This issue relates to the lack of support for LCD font smoothing within
Canvas.  This may not sound that serious but the difference between LCD
font-smoothed text in other controls and the grey-scale text in Canvas is
so distinct on my current machine that a control based on Canvas would
really stick out like a sore thumb and appear significantly less appealing
than a "standard" control.

So, am I wasting my time?
Are there any other issues I am likely to face?
Are there other ways to develop dynamic controls which may involve
thousands of nodes (such as lines, curves etc.)?

Thanks,

Felix

Reply via email to