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!

[1541 byte] By [Bristle-a-jinksa] at [2007-11-27 4:20:01]
# 1
any one that could help me?
Bristle-a-jinksa at 2007-7-12 9:26:59 > top of Java-index,Desktop,Core GUI APIs...
# 2

Are you not able to calculate the actual pixel height, post scaling, and then set the scrollbars to have that height after the fact? You can use the scrollbar's setMaximum property to adjust these values.

A better option would be to carry a BoundedRangeModel alongside your image, and set the model on the scrollpane to this BRM during initialization. That way, you can set a callback on the BRM that returns values related to the image's pixel dimensions:

http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/BoundedRangeModel.html

Good luck.

Alex

Saevena at 2007-7-12 9:26:59 > top of Java-index,Desktop,Core GUI APIs...