
Signature
Knute Johnson
email s/nospam/knute/
>> In free time I'm slowly progressing with my applet displaying astronomical
>> images. Now I would like to implement scroll bars around an image.
>> Now I'd like to zoom the above thumbnail (which would require scroll bars)
>> as well as displaying larger images. I am currently testing with 1190x1190
>> images.
>> I wrapped the myDisplay in a scroll pane :
>> panel1 = new JScrollPane ( new myDisplay() ) ;
>> I declared that myDisplay extends JPanel implements Scrollable
>> In the myDisplay() constructor I added
>> setPreferredSize(new Dimension(256,256));
>> The paintComponent method of the myDisplay class does : [...]
>> - I then call (and this is new for this scrollabe version)
>> setPreferredSize(new Dimension(naxis1,naxis2));
>> Is there anything I should do about "viewports" in a custom scrollable
>> application like this ?
>
> I don't think so. In fact I'm not clear as to why your component needed to
> implement Scrollable.
Well, the vertical size of panel1 is limited. Say one third of the
screen (mine is 1280x1024, but others may have smaller ones) So it can
be higher then my image size, either because the actual image is bigger
(the 1190x1190) or the displayed image will be bigger (say a 197x197 at
zoom 2 with pixel replication will make a 394x394). So I should be able
to see only a part of it, but pan to the rest.
Having scroll bars seemed the way, and I thought that to have them one
had to implement Scrollable. Am I wrong ?
>> Is there anything I could do to make scroll faster ?
>
> Hard to tell without actual code but probably not. Get a faster computer,
> faster video card and run it on Windows, all those will improve performance.
Windows is out of question. We are a Linux factory. And zoom and pan
works fast enough in other applications, and also applets seen on the
web, so it must be some inefficiency in my code. I thought it could be
something in the very naive way I implemented Scrollable.
>> Does the setPreferredSize in paintComponent have counter-indications ?
>
> Yes.
OK. I'd try moving it elsewhere. As a candidate, the constructor for
myDisplay defines an anonymous KeyAdapter. Its keyTyped method deals
with a keyboard command which loads the image from the net via my custom
method fitsAndRegion() ; and then calls repaint() ; I could stick
setPreferredSize in between (the image size will be globally known after
the fitsAndRegion() call).
>> Any further suggestion for an efficient way of implementing zoom
> Well it depends on what you actually mean by zoom.
I mean that if my image is 200x200 I would like to display e.g. a
400x400 image where each 2x2 SCREEN pixels will contain the same value
as the original image pixels, etc. Does zoom mean anything else ?
> Probably the best thing you could do is to really tell us in detail
> what you want to end up with. That way we would have a better idea
> how to get there.
What I want to do is to emulate in an applet a subset of the behaviour
of the astronomical image display program "ds9". The purpose of this is
to validate the cross-identifications between several catalogues. To do
this I display "regions" (say a coloured circle whose radius is
proportional to source intensity, and whose colour depends on the
catalogue) over a sky image. In a JTable I have the list of regions with
other information, and with the mouse I can hilight a region and locate
it in the Jtable or viceversa. All this I have already. But the scale of
the image is such that at zoom 1 the regions will be too tiny and
packed.
The reason I want to emulate this in an applet is that I'd like to
interface it directly with our mysql database. So far I've done it using
our db query i/f and ds9 and XPA (a way of scripting ds9), but that
requires a lot of clicks. Also XPA is efficient for local use
(everything running on same machine or at least some network where the
data are), but I'd like to allow people elsewhere to participate to the
validation process.

Signature
----------------------------------------------------------------------
nospam@mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
LC's No-Spam Newsreading account - 14 Feb 2008 10:00 GMT
>> > Is there anything I could do to make scroll faster ?
> must be some inefficiency in my code.
>> > Does the setPreferredSize in paintComponent have counter-indications ?
>>
[quoted text clipped - 6 lines]
> stick setPreferredSize in between (the image size will be globally
> known after the fitsAndRegion() call).
I did this, and had at least the effect that scrolling is now reasonably
fast. I can click the arrows on the scrollbar and move by 1 pixel, I
can click in the scrollbar track and move by 100 pixel, I can even drag
the scrollbar knob, which before was virtually inactive.
I still observe a "funny" behaviour. Let's say that my top panel is a
rectangular area like this (height is LESS than 256)
.......................
.......................
.......................
.......................
.......................
When I initialize the applet the 256x256 ramp is loaded in the top left
corner (NOT in the centre as I'd like) with part off-screen and a
vertical scrollbar
xxxxxxx................ v
xxxxxxx................ v
xxxxxxx................ v
xxxxxxx................ v
xxxxxxx................ v
ooooooo
ooooooo
When I load a smaller image (197x197) it is initially loaded centered
in the former display area, with part off screen on the bottom, and the
scroll bar remains present
....................... v
.xxxxxx................ v
.xxxxxx................ v
.xxxxxx................ v
.xxxxxx................ v
oooooo
Then, in a non-reproducible way after a while when I move the cursor
around, the image relocates in the top left corner and the scrollbar
disappears (this is OK, why hasn'it been done at the beginning ?)
xxxxxx.................
xxxxxx.................
xxxxxx.................
xxxxxx.................
xxxxxx.................
when I load a larger image (actually larger than the panel in both
dimensions), a part of it appears in the same area covered by the
previous smaller image (i.e. as above). Only if I resize the
appletviewer slightly, the full part of the image is displayed with both
horizontal and vertical scrollbars.
There is another thing I do not fully understand about paintComponent.
Currently I do the scaling of my data array into the BufferedImage here.
For debug I print to stdout some message about the scaling (only when
histogram equalization is active). Now these messages appear more than
once (not only when the image is initially loaded), so it looks like the
method is called more often than I'd expect.
In the past I noted that calling some other methods from within
paintComponent generated infinite loops.
Possibly I should move all the image scaling to a separate method, and
leave in paintComponent only the image display
g2.drawImage(img,xoff,yoff,null) ;
and the region overlay ?

Signature
----------------------------------------------------------------------
nospam@mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
LC's No-Spam Newsreading account - 14 Feb 2008 10:55 GMT
>> > > Is there anything I could do to make scroll faster ?
>> > > Does the setPreferredSize in paintComponent have counter-indications
>> > Yes.
>> OK. I'd try moving it elsewhere.
> I did this, and had at least the effect that scrolling is now reasonably
> fast.
> There is another thing I do not fully understand about paintComponent.
> Currently I do the scaling of my data array into the BufferedImage
> here.
> Possibly I should move all the image scaling to a separate method, and
> leave in paintComponent only the image display
I did this too, and the scrolling speed had an ultimate improvement, now
scrolling is instantaneous !!
There are side effects, like the unability to display a message in a
component not yet realized, or the initialization to an unexpected LUT,
or the fact a LUT change from a tab in the tabbed pane no longer
repaints the panel automatically, but I guess now I could debug that
myself !

Signature
----------------------------------------------------------------------
nospam@mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.