I am working through the design of a disp[lay for a CAD/GIS program written in Java. (I haven't decided firmly if I will use SWT or Swing.)
This program will have to display a large number of Java 2D Shapes. I'm want to make the rendering process as quick and efficient as possible. I had a couple of questions about how I can do this. I will ask the first in this thread:
Let's say for the sake of this discussion that the area I will use to display my map, or the canvas, will be 600 by 300 pixels. Would it be possible to render the shapes that would fall within an area 20% larger than this to allow for quicker panning and zooming?
I'm trying to avoid a situation where everytime the user pans the display a minor amount that the whole screen needs to be rendered. In the above situation I would have that 20% buffer to allow some limited space for panning.
Is this method possible? Any ideas or suggestions on how I can learn the techniques I need to implement it?
(P.S. - I already have the O'Reilly book on Java 2D Graphics...)
Well, you could render into a BufferedImage instead of directly on the screen, and then render the visible part of the Image on the screen.
Another option is to reuse the previously rendered image by just panning it by the necessary amount and then only redraw those areas that weren't visible beforehand.
But you should probably get your basic rendering working before you worry about these things - those optimizations shouldn't be too hard to introduce later, and you might learn that there are other things that are more important to optimize. "Premature optimization is the root of all evil."
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus