G
Guest
In free time I'm slowly progressing with my applet displaying
astronomical images. Now I would like to implement scroll bars around an
image.
The HTML defines so far <APPLET CODE=... WIDTH=512 HEIGHT=712>. Of
course if I run in the appletviewer I can freely resize it.
The applet itself is so far a JPanel divided horizontally in 3 equal
parts (a tabbed pane, a message text area, and a JTable). I plan to move
to a grid bag layout to make the tabbed pane somewhat taller.
One tab of the tabbed pane was a panel1 = new myDisplay();,
i.e. a custom JPanel where I display my images. Originally I displayed
there either a 256x256 ramp image, or a thumbnail image loaded from my
database (these are usually 197x197) which appeared centered.
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() ) ;
(so the tab added to the tab pane is still called panel1)
I declared that myDisplay extends JPanel implements Scrollable
In the myDisplay() constructor I added
setPreferredSize(new Dimension(256,256));
(if I did'nt do this no initial ramp image would be displayed, and no
focus for the keyboard commands I use to load further images would be
available)
To the myDisplay class I added the 5 methods for the Scrollable
interface. To stay simple,
- the getScrollableTracksViewportWidth() and
getScrollableTracksViewportHeight() return identically "false"
- the getScrollableUnitIncrement and getScrollableBlockIncrement
return respectively 1 and 50 (pixels ?) ... anyhow scrolling somehow
works, though slowly for larger images
- getPreferredScrollableViewportSize() simply returns
getPreferredSize();
The paintComponent method of the myDisplay class does :
- transfers into a global data array either the (FITS) image array
pre-loaded by a dedicated class, or build the ramp image
- I then call (and this is new for this scrollabe version)
setPreferredSize(new Dimension(naxis1,naxis2));
- then I scale the data array into a BufferedImage according to
a linear, log or histogram equalized ITT and using a proper LUT
and do a drawImage (plus appropriate overlays as instructed by
mouse and kbd commands, all this unchanged with respect to the
unscrolled version)
xoff=(size().width-naxis1)/2 ;
yoff=(size().height-naxis2)/2 ;
g2.drawImage(img,xoff,yoff,null) ;
Now in the non-scrolled version this was sufficient to center the
thumbnail image.
Now instead the ramp image appears in top left corner. Usually I have a
vertical scrollbar (scrolling reasonably fast).
If I load a thumbnail image from the db, it also goes in the top left
corner, and has no scrollbars. They appear if I resize the appletviewer
small enough.
If I load the larger (1190x1190) image, it originally appears in the
previous size, then, AS SOON AS I RESIZE THE WINDOW, it occupies the
full size, with scrollbars. Scrolling is however rather slow.
I have the impression there might be something odd with the coordinates.
Actually I'm reading coordinates via mouse, and the pixel and sky
coordinates appear converted correctly (by comparison with another image
display application). However commanded overlays do not appear.
Is there anything I should do about "viewports" in a custom scrollable
application like this ?
Is there anything I could do to make scroll faster ?
Does the setPreferredSize in paintComponent have counter-indications ?
Any further suggestion for an efficient way of implementing zoom
(otherwise I'd simply replicate the data array into a larger
BufferedImage with dimensions multiplied by the zoom factor) ?
astronomical images. Now I would like to implement scroll bars around an
image.
The HTML defines so far <APPLET CODE=... WIDTH=512 HEIGHT=712>. Of
course if I run in the appletviewer I can freely resize it.
The applet itself is so far a JPanel divided horizontally in 3 equal
parts (a tabbed pane, a message text area, and a JTable). I plan to move
to a grid bag layout to make the tabbed pane somewhat taller.
One tab of the tabbed pane was a panel1 = new myDisplay();,
i.e. a custom JPanel where I display my images. Originally I displayed
there either a 256x256 ramp image, or a thumbnail image loaded from my
database (these are usually 197x197) which appeared centered.
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() ) ;
(so the tab added to the tab pane is still called panel1)
I declared that myDisplay extends JPanel implements Scrollable
In the myDisplay() constructor I added
setPreferredSize(new Dimension(256,256));
(if I did'nt do this no initial ramp image would be displayed, and no
focus for the keyboard commands I use to load further images would be
available)
To the myDisplay class I added the 5 methods for the Scrollable
interface. To stay simple,
- the getScrollableTracksViewportWidth() and
getScrollableTracksViewportHeight() return identically "false"
- the getScrollableUnitIncrement and getScrollableBlockIncrement
return respectively 1 and 50 (pixels ?) ... anyhow scrolling somehow
works, though slowly for larger images
- getPreferredScrollableViewportSize() simply returns
getPreferredSize();
The paintComponent method of the myDisplay class does :
- transfers into a global data array either the (FITS) image array
pre-loaded by a dedicated class, or build the ramp image
- I then call (and this is new for this scrollabe version)
setPreferredSize(new Dimension(naxis1,naxis2));
- then I scale the data array into a BufferedImage according to
a linear, log or histogram equalized ITT and using a proper LUT
and do a drawImage (plus appropriate overlays as instructed by
mouse and kbd commands, all this unchanged with respect to the
unscrolled version)
xoff=(size().width-naxis1)/2 ;
yoff=(size().height-naxis2)/2 ;
g2.drawImage(img,xoff,yoff,null) ;
Now in the non-scrolled version this was sufficient to center the
thumbnail image.
Now instead the ramp image appears in top left corner. Usually I have a
vertical scrollbar (scrolling reasonably fast).
If I load a thumbnail image from the db, it also goes in the top left
corner, and has no scrollbars. They appear if I resize the appletviewer
small enough.
If I load the larger (1190x1190) image, it originally appears in the
previous size, then, AS SOON AS I RESIZE THE WINDOW, it occupies the
full size, with scrollbars. Scrolling is however rather slow.
I have the impression there might be something odd with the coordinates.
Actually I'm reading coordinates via mouse, and the pixel and sky
coordinates appear converted correctly (by comparison with another image
display application). However commanded overlays do not appear.
Is there anything I should do about "viewports" in a custom scrollable
application like this ?
Is there anything I could do to make scroll faster ?
Does the setPreferredSize in paintComponent have counter-indications ?
Any further suggestion for an efficient way of implementing zoom
(otherwise I'd simply replicate the data array into a larger
BufferedImage with dimensions multiplied by the zoom factor) ?