Can JavaFX do CAD?
chris.gay5000 at gmail.com
Wed Jul 24 05:01:31 PDT 2013
I totally agree with your wishes, and even wonder if it is feasible in JavaFX.
With my Swing App, although I support mouse-over sensitivity on things like JButtons, I do not support it on graphical objects, simply because the effort would kill the system, given millions of objects. Only when the mouse is clicked, dragged, or active-up do I provide dynamic visual feedback. I have yet to find anything written about "Rubber-banding" using a XOR mode graphics context in JavaFX. The way 3D games work has tended to be significantly different to how 2D CAD has worked in the past.
I did not want limitations on how far I could zoom-in, so caching bitmaps to represent handles (XOR Mode) at a given scale was ruled-out, since they could be vast. Instead everything is done using Float data (mostly 64 bit Double Float in fact), with some key data, such as handle sizes having to dynamically scale for every new scale, so that they appear as a constant number of pixels. None of this data is parked in the graphical objects, but is held by the Viewport/Drawing Board, and supplied to the active Tool on request. Then everything is a vector draw using a Graphics2D context on the off-screen buffer, whether Bezier Curves, Fonts or whatever, and uses its own Drawing Thread. All the Event Thread does on paint, is a scaled bit-blt. With the concept of a Graphics Context being almost universal across systems, my hope was that it would get good hardware acceleration.
I just can't get my head around how I even go about this in JavaFX. A good demo application is badly needed. Surely someone within the JavaFX developers at Oracle has an idea, or maybe they never considered it?
I'm only considering JavaFX because Oracle seem to be deprecating Swing & AWT, and clearly have no intention of supporting touch interfaces & tablets in Swing.
On 24 Jul 2013, at 00:21, Daniel Zwolenski wrote:
> More specifically I would like to know the official recommended best practices for implementing a CAD style app in JFX.
> - How best to represent large numbers of complex shapes efficiently, and when to add shapes to the scene (add all and let jfx clip, or manually work out what should be showing, etc)
> - How best to handle font scaling and image scaling when rendered in a zoomed in/out viewport
> - How best to do panning and zooming with dynamic level of detail
> - How best to do the top level display in terms of panes vs regions vs canvas, vs whatever, how to manage overlays and layers (sharing same coordinate space, etc)
> - How best to do picking, mouse overs, dragging across the 'display'
> - How best to do infinite or dynamic bounds so you can add and move shapes and the scrolling adjusts accordingly.
> A JFX diagramming app would make a very powerful demo app in my mind.
> On 24/07/2013, at 1:47 AM, Chris Gay <chris.gay5000 at gmail.com> wrote:
>> Hello all.
>> Please could someone advise if it is even feasible for me to consider re-factoring the following Swing application, so that it becomes a JavaFX one. From trying to read about JavaFX, I get the feeling that Oracle never intended Java FX for the purpose I need.
>> I have a large Java Swing desktop CAD application which makes heavy use of the Java 2D API, and concurrency. It is a Menu Bar driven application, with a Toolbar for Tools, and a few buttons, but 99% of the user activity concerns selecting and manipulating vector graphical objects in a traditional manner using one Tool at a time (think Inkscape or LibreOffice Drawing apps). The application has multiple drawings open at the same time (but only one is visible), and each Drawing contains it's own Drawing and Processing threads (in addition to sharing the Main and Event Threads), which keeps the Event Thread lively. Each Drawing contains an ArrayList, acting as a Display List of all graphical objects, and each graphical object can be a tree structure. In many cases I use simple iteration instead of Iterators, simply for speed, and to avoid garbage. The graphical objects are lightweight, in that they do not carry references to events and handlers. All they carry is their basic geometric data and properties, a bounding box which they can lend as Read Only, and a boolean flag to indicate selection, which means there can be millions of the objects, with a minimum memory footprint. To support them, there are many hundreds of methods, which the tools interact with. There can be multiple Drawing Windows active on a single drawing, where each Window is backed up by an offscreen image, which handles the zoom and sliding buffer behaviour for fast scrolling, to allow rapid bit-blt's to the actual window. Lastly, the user manipulates the Drawing (Display List), using one of many Tools, where the active Tool receives events from the event queue, and then manipulates selected and/or unselected graphical objects, by using XOR Mode graphics onto the offscreen buffer, generally using callbacks.
>> The system is fast and very responsive on large data sets, but what I do not know is whether JavaFX will help me make a better implementation, or whether it will fight me all the way. With JavaFX claiming hardware acceleration, I do not understand whether it depends on transferring the very large data sets into graphics hardware to render, and what happens if the hardware cannot cope. So far, I have found little in the way of discussions that help me get a mental picture of how JavaFX is intended to work. Should I stick with Swing?
More information about the openjfx-dev