Scaling of Ruler (on JScrollPane) along with Image
Hi there,
I currently have an image in a JScrollPane with associated rulers.
http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html
I also implemented a mouselistener to it so that markers on those rulers move along with the mouse.
Now, the problem I have is with scaling of these rulers. These rulers associate themselves with the image in the JScrollPane. The idea is to scale the rulers accordingly when the image gets scaled. Image is getting scaled through JAI operators.
This is how am working out the logic for scaling rulers:
The DPI I have is 96 DPI. So, basically it means that 1 Inch = 96 Dots/Pixels on my screen.
When the image is scaled to 100%, the DPI remains same and everything is good. Now, lets take a scenario where the image is scaled to 33%. The scale factor according to which image is scaled is 0.33. For our ruler, it is 96 x 0.33 = 31.68 dots/pixels per inch. If I round it up, it is going to be 32 dots/pixel per inch, which sounds good. Now I repaint my ruler using 32 dpi, but the 0.32 dots/pixels which I omitted in rounding the original value is adding up to the end and is making a significant change in the overall dimensions (visual) of the image. That is, an image which is at 24.5 inches (visual) at 100% is only ~=24 inches (visual) when scaled down to 33%.
I was just wondering if I am thinking the right way or am I overlooking something. Any logical insight that would help is really appreciated.
Thanks!

