Canvas carving in Java SWT
I have already worked a lot on what I can only describe as "carving cloth" for some time now. At some point I will describe what I have, but since I am really open to new ideas, existing solutions, or a completely new beginning, I will pose the problem.
The canvas is for displaying genetic information (although the specific purpose is somewhat irrelevant). As a normal text editor, this genetic code accesses a canvas on which the user can interact with it by typing, selecting, etc. The code is then further decorated with various non-textual features such as shapes, lines, and colors.
The main problem here is that significant calculations must be done before displaying certain information.
Consider the following layout:
Sample Canvas http://img23.imageshack.us/img23/9931/canvasgv.png
As you can see, the genetic code is monospaced, but the enzyme contractions (shown above the genetic code) are not. Calculating where the enzymes are cut is tedious as the function (above, blue arrow) can be displayed as there can be so many on the screen. Three-letter codes mean translations of three blocks of the genetic code; although this is fast, putting one letter in the sequence makes them all shifted by one — requiring recalculation.
Preferably, to speed up the process, each of these parts can occur in a separate stream, converging at the end to compose the final image.
To summarize: the individual parts of the display are computationally complex, although, of course, it is desirable that the editor is as responsive as possible.
My current implementation involves executing all draw events on separate threads. Typing, resizing, or making a selection can create a large number of threads, but only the update gets updated. This ensures that the display update takes no more than one iteration, but does not provide instant feedback to the user interface.
I've looked for modifications to existing editors such as StyledText , but anything more than some bold fonts and colors makes it significantly slower.
Any suggestions?
source to share
Instead, I chose a solution using multiple buffers where each buffer is drawn on a separate thread. The performance is much better than StyledText and I have complete flexibility in drawing things wherever I like.
The only drawback is that I have to override the basics of text editing: text selection, navigation - even the basics of typing. I am still happy with the result.
I'm afraid I can't provide the source code as it is part of a copyrighted project.
source to share
It is probably best to embed other SWT widgets in StyledText. Each widget will perform a specific calculation in a background thread and update its visual representation as results come in. Note that you can perform calculations in the background, but rendering must happen on the SWT thread. Therefore, you cannot do a lot of complicated things while rendering. If things get too slow, use cache images (create a couple of off-screen images where you can display the results and then just draw those images).
Extend these widgets from Canvas
as this is a widget designed for personalized rendering. It will also allow you to react to various events (for example, display additional information when the user hovers over the enzyme slice).
Be careful with the enzyme cuts: they vary in height. I suggest giving this widget a bit more default space (even if not in use) so the text doesn't jump much while the widget calculates and adds abbreviations.
source to share